promach
Advanced Member level 4
I am trying to understand how using 'or' avoids synthesizing priority encoder with the following circuit diagrams generated by yosys, Why would we have 31:2 bits of $10_Y mapped back to itself ? The verilog source code could be found below or https://www.edaplayground.com/x/4H6a
With OR
Without OR
- - - Updated - - -
What are actual purposes of the $or labelled $10 and $12 ?
With OR
Without OR
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 // // Convert a one-hot signal to a binary index corresponding to the active bit. // (Binary encoder) // If DIRECTION is "LSB0", index 0 corresponds to the least significant bit // If "MSB0", index 0 corresponds to the most significant bit // `timescale 1ns/100ps module oh_to_idx #(parameter NUM_SIGNALS = 4, parameter DIRECTION = "LSB0", parameter INDEX_WIDTH = $clog2(NUM_SIGNALS)) (input[NUM_SIGNALS - 1:0] one_hot, output reg [INDEX_WIDTH - 1:0] index); integer oh_index; always @(*) begin : convert index = 0; for (oh_index = 0; oh_index < NUM_SIGNALS; oh_index=oh_index+1) begin if (one_hot[oh_index]) begin if (DIRECTION == "LSB0") index = index | oh_index[INDEX_WIDTH - 1:0]; // Use 'or' to avoid synthesizing priority encoder else index = index | ~oh_index[INDEX_WIDTH - 1:0]; end end end endmodule
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 `timescale 1ns/100ps module oh_to_idx_tb; reg[3:0] one_hot; wire[1:0] index; oh_to_idx A1 ( .one_hot(one_hot), .index(index) ); initial begin $dumpfile("oh_to_idx.vcd"); $dumpvars(0, oh_to_idx_tb); one_hot = 4'b1000; #5 one_hot = 4'b0100; #5 one_hot = 4'b0010; #5 one_hot = 4'b0001; #20 $finish; end endmodule
- - - Updated - - -
What are actual purposes of the $or labelled $10 and $12 ?