Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] If or else if? Which is better?

Status
Not open for further replies.

FecP

Newbie level 6
Joined
Oct 17, 2016
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
160
In a Verilog 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/simpler/less inferred hardware?


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 an else if.
My question ,however, is specific to VERILOG/VHDL.
 

Modern synthesis tools will synthesize mutually exclusive if statements (assuming the exclusivity is visible in compile time) into MUXs - and not priority encoders).

But I suggest you stick to a case statement...
Which is explicit and more readable.
 

In the case of synthesis, it should produce the same hardware
For simulation, you probably give yourself a performance penalty with just ifs because it has to check them all. But with today's processors, it's unlikely to be noticable.
 

Vhdl case statements do this. Verilog has pragmas for full case and parallel case, but this can lead to a simulation mismatch if your code doesn't match your assumptions.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top