B
Bil Bob
Guest
Hi all,
I'm trying to find the better way to describe a simple mux in Verilog.
for now let's consider 4-1 mux (with 16b, meaning 16 muxes), so we
have (as I see it) 2 options:
1.
wire [15:0] out_bus;
wire [1:0] ctrl;
wire [15:0] bus0;
wire [15:0] bus1;
wire [15:0] bus2;
wire [15:0] bus3;
assign out_bus = ctrl == 2'd0 ? bus0 :
ctrl == 2'd1 ? bus1 :
ctrl == 2'd2 ? bus2 : bus3;
2.
reg [15:0] out_bus;
wire [1:0] ctrl;
wire [15:0] bus0;
wire [15:0] bus1;
wire [15:0] bus2;
wire [15:0] bus3;
always @*
begin
case (ctrl)
2'd0 : out_bus = bus0 ;
2'd1 : out_bus = bus1 ;
2'd2 : out_bus = bus2 ;
2'd3 : out_bus = bus3 ;
endcase
both seem to in order, but... option 1 is simulator friendly, but
some synthesis tools might generate priority encoder (I know the
synopsys tools our backend guys are using did), even if one is not
needed. option 2 is sysnthesis friendly, but simulation, when ctrl
changes to 'X', out_bus preserves it's value.
I'm trying to understand how this 'simple' design should be written in
order for simulation and synthesis tools to understand the same
thanks in advance
I'm trying to find the better way to describe a simple mux in Verilog.
for now let's consider 4-1 mux (with 16b, meaning 16 muxes), so we
have (as I see it) 2 options:
1.
wire [15:0] out_bus;
wire [1:0] ctrl;
wire [15:0] bus0;
wire [15:0] bus1;
wire [15:0] bus2;
wire [15:0] bus3;
assign out_bus = ctrl == 2'd0 ? bus0 :
ctrl == 2'd1 ? bus1 :
ctrl == 2'd2 ? bus2 : bus3;
2.
reg [15:0] out_bus;
wire [1:0] ctrl;
wire [15:0] bus0;
wire [15:0] bus1;
wire [15:0] bus2;
wire [15:0] bus3;
always @*
begin
case (ctrl)
2'd0 : out_bus = bus0 ;
2'd1 : out_bus = bus1 ;
2'd2 : out_bus = bus2 ;
2'd3 : out_bus = bus3 ;
endcase
both seem to in order, but... option 1 is simulator friendly, but
some synthesis tools might generate priority encoder (I know the
synopsys tools our backend guys are using did), even if one is not
needed. option 2 is sysnthesis friendly, but simulation, when ctrl
changes to 'X', out_bus preserves it's value.
I'm trying to understand how this 'simple' design should be written in
order for simulation and synthesis tools to understand the same
thanks in advance