mirror of
https://github.com/aolofsson/oh.git
synced 2025-01-17 20:02:53 +08:00
Adding generic N:1 mux
This commit is contained in:
parent
1e35436b10
commit
b3c0cdc082
38
common/hdl/oh_mux.v
Normal file
38
common/hdl/oh_mux.v
Normal file
@ -0,0 +1,38 @@
|
||||
//#########################################################################
|
||||
//# GENERIC "ONE HOT" N:1 MUX
|
||||
//# See also oh_mux2.v, oh_mux3.v, etc
|
||||
//#########################################################################
|
||||
module oh_mux (/*AUTOARG*/
|
||||
// Outputs
|
||||
out,
|
||||
// Inputs
|
||||
sel, in
|
||||
);
|
||||
|
||||
//#####################################################################
|
||||
//# INTERFACE
|
||||
//#####################################################################
|
||||
parameter DW = 32; // width of data inputs
|
||||
parameter N = 99;
|
||||
|
||||
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
|
||||
|
||||
//#####################################################################
|
||||
//# BODY
|
||||
//#####################################################################
|
||||
reg [DW-1:0] out;
|
||||
|
||||
//parametrized mux
|
||||
integer i;
|
||||
always @*
|
||||
begin
|
||||
out[DW-1:0] = 'b0;
|
||||
for(i=0;i<N;i=i+1)
|
||||
out[DW-1:0] |= {(DW){sel[i]}} & in[((i+1)*DW-1)-:DW];
|
||||
end
|
||||
|
||||
endmodule // oh_mux
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user