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;
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.
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.