I am learning SystemVerilog. While coding, the synthesis schematic for the following if
statements don't make sense to me.
module ifelseDUT(
input logic sela, selb, selc, da,db,dc,
output logic dout
);
always @*
begin
dout = 0;
priority if(sela)
dout = da;
if(selb)
dout = db;
if(selc)
dout = dc;
end
endmodule
Here is the synthesized schematic:
How to understand the schematic when sela
is not used? I am also not able to make sense of S=default
value on the muxes.
Here is the message generated by Vivado. There are no errors or warnings during the synthesis.
[Synth 8-293] found qualifier priority on case statement: implementing as full_case ["C:/Users/homealien/Xilinx/ifelse-test/ifelse-test.srcs/sources_1/new/ifelseDUT.sv":32]
Because your priority if
statement does not contain an else clause, synthesis is treating it as:
if(sela)
dout = da;
else
dout = 'x; // don't care
and that is being optimized as just
dout = da;
This is because the priority
is an assumption/assertion that a conditional branch will always be taken. Without an else
clause, synthesis is generating logic assuming the condition is always true. This should have been caught as a synthesis error, but it is a legal description.
What you probably intended is:
always_comb
priority if(sela)
dout = da;
else if(selb)
dout = db;
else if(selc)
dout = dc;
else
dout = 0;
Now you have written the code is such a way that a conditional branch statement will always be taken under all possible conditions.