赞
踩
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 logic[INDEX_WIDTH - 1:0] index); always_comb begin : convert index = 0; for (int oh_index = 0; oh_index < NUM_SIGNALS; oh_index++) begin if (one_hot[oh_index]) begin if (DIRECTION == "LSB0") index |= oh_index[INDEX_WIDTH - 1:0]; // Use 'or' to avoid synthesizing priority encoder else index |= INDEX_WIDTH'(NUM_SIGNALS - oh_index - 1); end end end endmodule
似乎是上面这种写法好点
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。