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] Which is more efficient way to write HDL code?

Status
Not open for further replies.

amitjagtap

Full Member level 5
Joined
Jan 10, 2007
Messages
304
Helped
42
Reputation
84
Reaction score
36
Trophy points
1,308
Activity points
3,273
hi all,
Which is more efficient way to write HDL code.
Bellow...which one is good...and why?
1st way----------
If Din=0 then ab<="00" else
If Din=1 then ab<="01" else
If Din=2 then ab<="10" else
If Din=3 then ab<="11" end if;

2nd Way------------
If Din=0 or Din=1 then a<=0 else
If Din=2 or Din=3 then a<=1 end if;
If Din=0 or Din=2 then b<=0 else
If Din=1 or Din=3 then b<=1 end if;

:lol:
 

Because both are equivalent, they will result in the same gate level logic. Readability would be my primary criterion, I guess the first is better in this regard. I would however use a case construct as third variant.
 

Yes you are right....
Can you tell me the difference at synthesis level if i used 'if else' and 'Case' statement for the same logic.
 

it is going to depend on the code. They can produce the same logic, but if implies a preference where case does not.
 

You can check that in the RTL schematic. The one with fewer number of gates is a better way.
 

Assuming that by
Code:
If Din=0 or Din=1 then a<=0 else
If Din=2 or Din=3 then a<=1 end if;
If Din=0 or Din=2 then b<=0 else
If Din=1 or Din=3 then b<=1 end if;
you mean
Code:
If Din=0 or Din=1 then ab(1)<='0'; else
If Din=2 or Din=3 then ab(1)<='1'; end if;
If Din=0 or Din=2 then ab(0)<='0'; else
If Din=1 or Din=3 then ab(0)<='1'; end if;
then these two should be the same but i would prefer the first way from your post.

Alex
 

Ha.....
I haven't written the code for checking my syntax ....its for logic that i m asking..........
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top