Read in KR

Combinational Switch

Standard conditional statements often imply a priority. The following statement implements a multiplexer where the output is determined by the value of sel. During synthesis, this structure will check if sel is 0, then 1, then 2, establishing a priority order.

o <= (in0, sel == 0, in1, sel == 1, in2, sel == 2, in3)

Such priority structures can generate additional logic and impact system performance. To create non-prioritized conditional logic, use the switch statement instead.

with switch(sel):
    with case(0) : o <= in0
    with case(1) : o <= in1
    with case(2) : o <= in2
    with others() : o <= in3

The statement above is converted into a process as shown below:

process(sel, in0, in1, in2, in3)
begin
    case sel is
        when "00" => o <= in0;
        when "01" => o <= in1;
        when "10" => o <= in2;
        when others => o <= in3;
    end case;
end process;
← All posts