Both of the following 2 always blocks should synthesize to a decoder.
always @(address) case (address) 2'b00 : row = 4'b0001; 2'b01 : row = 4'b0010; 2'b10 : row = 4'b0100; 2'b11 : row = 4'b1000; endcase
always @(address) row = 2**address;
- The first always block has 4 lines, and it will take much more lines for wider address, but anybody who reads it notices immediately that the code synthesizes to a decoder. The second always block only takes one line, irrespective of the address' width. But it's harder to find out what that line synthesize to. How do I know when to write my code in "brute force" way (the first always code), or the "high level" way (the second always block), which takes full advantage of HDLs with a lot less lines? From all my previous projects, I always do the brute force way. But sometimes I am wondering whether I am taking the right approach. The brute force way seems like schematic, which can be done as well by pulling components from the schematic library, which kind of defeating the purpose of HDLs. On the other hand, if I use the high level way, my code will take full advantage of HDLs, much shorter but more difficult to debug. How do I know which one to choose?
- When I do my projects, I always like to be able to see what my code synthesize to (the schematic equivalent of the HDLs). That gives me confident on the realibility of my projects. But should I forget about the schematic equivalent and treat it just like C and as long as it works then who cares about the schematic equivalent?
I need advise from professional engineers who have been in this field for several years. I appreciate if you can help me making the decision. Thank You!
Hendra