data/full_repos/permissive/524949268/round_robin_arbiter.v
data/verilator_xmls/29110479-33e3-4be7-a34f-44faa6eb4ee7.xml
module round_robin_arbiter_4(
    clk,
    reset_n,
    req,
    grant
);

input clk;
input reset_n;
input [3:0] req;

output [3:0] grant;

wire [3:0] req_r0;
wire [3:0] req_r1;
wire [3:0] gnt;
wire at_least_one_req;

reg [3:0] grant;
reg [1:0] select_update;


barrel_shifter_right_4 bs4_0 (.in(req), .yout(req_r0), .select(select_update));
fixed_priority_arbiter #(.WIDTH(4)) fpa0 (.req(req_r0), .grant(req_r1));
barrel_shifter_left_4 bs4_1 (.in(req_r1), .yout(gnt), .select(select_update));




always @ (posedge clk or negedge reset_n) begin
    
    if (!reset_n) begin
        select_update <= 2'b00;
        grant <= 4'b0000;
    end
    else begin
        grant <= gnt;
        case (1'b1)
            gnt[3]: select_update <= 2'b00;
            gnt[2]: select_update <= 2'b11;
            gnt[1]: select_update <= 2'b10;
            gnt[0]: select_update <= 2'b01;
            default: select_update <= 2'b00;
        endcase
    end 
end

endmodule
module round_robin_arbiter_4(
    clk,
    reset_n,
    req,
    grant
);


input clk;
input reset_n;
input [3:0] req;

output [3:0] grant;

wire [3:0] req_r0;
wire [3:0] req_r1;
wire [3:0] gnt;
wire at_least_one_req;

reg [3:0] grant;
reg [1:0] select_update;


barrel_shifter_right_4 bs4_0 (.in(req), .yout(req_r0), .select(select_update));
fixed_priority_arbiter #(.WIDTH(4)) fpa0 (.req(req_r0), .grant(req_r1));
barrel_shifter_left_4 bs4_1 (.in(req_r1), .yout(gnt), .select(select_update));




always @ (posedge clk or negedge reset_n) begin
    
    if (!reset_n) begin
        select_update <= 2'b00;
        grant <= 4'b0000;
    end
    else begin
        grant <= gnt;
        case (1'b1)
            gnt[3]: select_update <= 2'b00;
            gnt[2]: select_update <= 2'b11;
            gnt[1]: select_update <= 2'b10;
            gnt[0]: select_update <= 2'b01;
            default: select_update <= 2'b00;
        endcase
    end 
end

endmodule