1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-02-07 06:44:09 +08:00
oh/common/hdl/oh_mux.v

34 lines
1.0 KiB
Coq
Raw Normal View History

//#############################################################################
//# Function: "ONE HOT" N:1 MUX #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
2016-01-20 17:22:05 -05:00
module oh_mux #( parameter DW = 1, // width of data inputs
parameter N = 1 // number of inputs
)
(
input [N-1:0] sel, // select vector
input [N*DW-1:0] in, // concatenated input {..,in1[DW-1:0],in0[DW-1:0]
output [DW-1:0] out // output
);
2016-01-20 17:22:05 -05:00
//local variable
reg [DW-1:0] mux;
2016-01-20 17:22:05 -05:00
integer i;
always @*
begin
mux[DW-1:0] = 'b0;
2016-01-20 17:22:05 -05:00
for(i=0;i<N;i=i+1)
mux[DW-1:0] = mux[DW-1:0] | {(DW){sel[i]}} & in[((i+1)*DW-1)-:DW];
2016-01-20 17:22:05 -05:00
end
assign out[DW-1:0] = mux;
2016-01-20 17:22:05 -05:00
endmodule // oh_mux