One-hot Mux
A parameterized implementation of a one-hot mux. Takes PORTS input ports each of width
DATA_WIDTH as a concatenated input vector, i_data, and using the one-hot select input,
i_select, muxes the selected input port to the output, o_data.
Parameters
PORTSnumber of input ports of eachDATA_WIDTHbitsDATA_WIDTHdata width in bits per input port
Ports
i_dataconcatenated input vector (PORTS*DATA_WIDTHbits)i_selectselect (PORTSbits)o_dataoutput vector (DATA_WIDTHbits)
Source Code
onehot_mux.sv
1`ifndef LIBSV_MUXES_ONEHOT_MUX
2`define LIBSV_MUXES_ONEHOT_MUX
3
4module onehot_mux #(
5 parameter int PORTS /* verilator public_flat_rd */ = 4,
6 parameter int DATA_WIDTH /* verilator public_flat_rd */ = 8
7) (
8 input logic [PORTS*DATA_WIDTH-1:0] i_data,
9 input logic [ PORTS-1:0] i_select,
10 output logic [ DATA_WIDTH-1:0] o_data
11);
12
13 always_comb begin
14 o_data = '0;
15 for (int i = 0; i < PORTS; ++i) begin
16 o_data |= {(DATA_WIDTH) {i_select[i]}} & i_data[((i+1)*DATA_WIDTH-1)-:DATA_WIDTH];
17 end
18 end
19
20endmodule : onehot_mux
21
22`endif /* LIBSV_MUXES_ONEHOT_MUX */