EmbDev.net

Forum: FPGA, VHDL & Verilog If or else if? Which is faster?


Author: techno-rogue (Guest)
Posted on:

Rate this post
0 useful
not useful
In a Verilog/VHDL design, Say that you have n (any number) completely 
mutually exclusive events i.e. the events never occur simultaneously and 
there is hence no priority associated with any event.In such a scenario, 
what would be faster?


if (condition 1)
if (condition 2)
if (condition 3)
.
.
.
.
.
--------   OR  ----------
if (condition 1)
else if (condition 2)
else if (condition 3)
.
.
.
.
.

In my opinion, I think the simple ifs would work out better since the 
priority doesn't have to be checked and would infer less hardware.In C 
or MATLAB, the opposite may be true because if condition 1 turns out to 
be true then all remaining conditions can be skipped by using else if. 
My question is specific to VERILOG/VHDL.

Author: -gb- (Guest)
Posted on:

Rate this post
0 useful
not useful
Look at the generated Hardware! I guess it is identical.

Author: c.m. (Guest)
Posted on:

Rate this post
0 useful
not useful
its not so much a question of speed, but the fact that multiple 
consecutive if-statements are another contruct than an "if .. else if" 
block.

consecutive if's are executed each one by one, while an "if .. else if" 
block is finished if one condition is met.

Author: -gb- (Guest)
Posted on:

Rate this post
0 useful
not useful
In Hardware, really? VHDL is no programming Language.

Author: techno-rogue (Guest)
Posted on:

Rate this post
0 useful
not useful
I get that.It is not a matter of speed, but what would infer simpler 
hardware? I guess by speed I meant fewer gates and less 
hardware/combinational logic.

Author: -gb- (Guest)
Posted on:

Rate this post
0 useful
not useful
Test it! Write two simple Designs which are nearly identical and look at 
the Hardware.

Author: -gb- (Guest)
Posted on:
Attached files:

Rate this post
0 useful
not useful
Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity test is Port(
  in_a: in std_logic_vector(3 downto 0);
  select_a: in std_logic_vector(1 downto 0);
  out_a: out std_logic;
  in_b: in std_logic_vector(3 downto 0);
  select_b: in std_logic_vector(1 downto 0);
  out_b: out std_logic);
end test;

architecture Behavioral of test is

begin

process (select_a, select_b) begin
  if select_a = "00" then out_a <= in_a(0); end if;
  if select_a = "01" then out_a <= in_a(1); end if;
  if select_a = "10" then out_a <= in_a(2); end if;
  if select_a = "11" then out_a <= in_a(3); end if;

  if    select_b = "00" then
    out_b <= in_b(0);
  elsif select_b = "01" then
    out_b <= in_b(1);
  elsif select_b = "10" then
    out_b <= in_b(2);
  elsif select_b = "11" then
    out_b <= in_b(3);
  end if;
end process;

end Behavioral;

Author: techno-rogue (Guest)
Posted on:

Rate this post
0 useful
not useful
Thank you for your input! I plan on doing something similar in Quartus 
Prime and Xilinx ISE.
Thank you!

Author: Matthias (Guest)
Posted on:

Rate this post
0 useful
not useful
Yes, iff the condition is mutually exclusive.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.