Finding the next in round-robin scheduling by bit twiddling

前端 未结 9 1718
日久生厌
日久生厌 2021-02-02 02:46

Consider the following problem. You have a bit-string that represents the current scheduled slave in one-hot encoding. For example, \"00000100\" (with the leftmost bit being #7

9条回答
  •  悲哀的现实
    2021-02-02 03:14

    I've found the following Verilog code for implementing the task in the Altera advanced synthesis cookbook.

    // 'base' is a one hot signal indicating the first request
    // that should be considered for a grant.  Followed by higher
    // indexed requests, then wrapping around.
    //
    
    module arbiter (
        req, grant, base
    );
    
    parameter WIDTH = 16;
    
    input [WIDTH-1:0] req;
    output [WIDTH-1:0] grant;
    input [WIDTH-1:0] base;
    
    wire [2*WIDTH-1:0] double_req = {req,req};
    wire [2*WIDTH-1:0] double_grant = double_req & ~(double_req-base);
    assign grant = double_grant[WIDTH-1:0] | double_grant[2*WIDTH-1:WIDTH];
    
    endmodule
    

    It uses subtraction (only once, though), so conceptually it's quite similar to Doug's solution.

提交回复
热议问题