|
| 1 | +//------------------------------------------------------------------------------ |
| 2 | +// round_robin_performance_enc.sv |
| 3 | +// Konstantin Pavlov, [email protected] |
| 4 | +//------------------------------------------------------------------------------ |
| 5 | + |
| 6 | +// INFO ------------------------------------------------------------------------- |
| 7 | +// VErsion of round robin combinational encoder to select only one bit from |
| 8 | +// the input bus. Feature of this particular version is a performance boost |
| 9 | +// motivated by skipping inactive inputs while performing round_robin. |
| 10 | +// |
| 11 | +// In contrast to priority encoder, every input bit (on average) has equal |
| 12 | +// chance to get to the output when all inputs are equally probable |
| 13 | +// |
| 14 | +// See also round_robin_enc.sv |
| 15 | +// See also priority_enc.sv |
| 16 | +// |
| 17 | + |
| 18 | + |
| 19 | +/* --- INSTANTIATION TEMPLATE BEGIN --- |
| 20 | +
|
| 21 | +round_robin_performance_enc #( |
| 22 | + .WIDTH( 32 ) |
| 23 | +) RE1 ( |
| 24 | + .clk( clk ), |
| 25 | + .nrst( nrst ), |
| 26 | + .id( ), |
| 27 | + .od_valid( ), |
| 28 | + .od_filt( ), |
| 29 | + .od_bin( ) |
| 30 | +); |
| 31 | +
|
| 32 | +--- INSTANTIATION TEMPLATE END ---*/ |
| 33 | + |
| 34 | + |
| 35 | +module round_robin_performance_enc #( parameter |
| 36 | + WIDTH = 32, |
| 37 | + WIDTH_W = $clog2(WIDTH) |
| 38 | +)( |
| 39 | + input clk, // clock |
| 40 | + input nrst, // inversed reset, synchronous |
| 41 | + |
| 42 | + input [WIDTH-1:0] id, // input data bus |
| 43 | + output od_valid, // output valid (some bits are active) |
| 44 | + output logic [WIDTH-1:0] od_filt, // filtered data (only one priority bit active) |
| 45 | + output logic [WIDTH_W-1:0] od_bin // priority bit binary index |
| 46 | +); |
| 47 | + |
| 48 | + |
| 49 | +// current bit selector |
| 50 | +logic [WIDTH_W-1:0] priority_bit = '0; |
| 51 | + |
| 52 | +// prepare double width buffer with LSB bits masked out |
| 53 | +logic [2*WIDTH-1:0] mask; |
| 54 | +logic [2*WIDTH-1:0] id_buf; |
| 55 | +always_comb begin |
| 56 | + integer i; |
| 57 | + for ( i=0; i<2*WIDTH; i++ ) begin |
| 58 | + if( i>priority_bit[WIDTH_W-1:0] ) begin |
| 59 | + mask[i] = 1'b1; |
| 60 | + end else begin |
| 61 | + mask[i] = 1'b0; |
| 62 | + end |
| 63 | + end |
| 64 | + id_buf[2*WIDTH-1:0] = {2{id[WIDTH-1:0]}} & mask[2*WIDTH-1:0]; |
| 65 | +end |
| 66 | + |
| 67 | +logic [2*WIDTH-1:0] id_buf_filt; |
| 68 | +leave_one_hot #( |
| 69 | + .WIDTH( 2*WIDTH ) |
| 70 | +) one_hot_b ( |
| 71 | + .in( id_buf[2*WIDTH-1:0] ), |
| 72 | + .out( id_buf_filt[2*WIDTH-1:0] ) |
| 73 | +); |
| 74 | + |
| 75 | +logic [(WIDTH_W+1)-1:0] id_buf_bin; // one more bit to decode double width input |
| 76 | + |
| 77 | +logic err_no_hot; |
| 78 | +assign od_valid = ~err_no_hot; |
| 79 | + |
| 80 | +pos2bin #( |
| 81 | + .BIN_WIDTH( (WIDTH_W+1) ) |
| 82 | +) pos2bin_b ( |
| 83 | + .pos( id_buf_filt[2*WIDTH-1:0] ), |
| 84 | + .bin( id_buf_bin[(WIDTH_W+1)-1:0] ), |
| 85 | + |
| 86 | + .err_no_hot( err_no_hot ), |
| 87 | + .err_multi_hot( ) |
| 88 | +); |
| 89 | + |
| 90 | +always_comb begin |
| 91 | + if( od_valid ) begin |
| 92 | + od_bin[WIDTH_W-1:0] = id_buf_bin[(WIDTH_W+1)-1:0] % WIDTH; |
| 93 | + od_filt[WIDTH-1:0] = 1'b1 << od_bin[WIDTH_W-1:0]; |
| 94 | + end else begin |
| 95 | + od_bin[WIDTH_W-1:0] = '0; |
| 96 | + od_filt[WIDTH-1:0] = '0; |
| 97 | + end |
| 98 | +end |
| 99 | + |
| 100 | +// latching current |
| 101 | +always_ff @(posedge clk) begin |
| 102 | + if( ~nrst ) begin |
| 103 | + priority_bit[WIDTH_W-1:0] <= '0; |
| 104 | + end else begin |
| 105 | + if( od_valid ) begin |
| 106 | + priority_bit[WIDTH_W-1:0] <= od_bin[WIDTH_W-1:0]; |
| 107 | + end else begin |
| 108 | + // nop, |
| 109 | + end // if |
| 110 | + end // if nrst |
| 111 | +end |
| 112 | + |
| 113 | +endmodule |
0 commit comments