- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello people,
I was recently reading the ALTERA synthesis manual and I saw that the IF statement is more resource demanding than the CASE statement. In cases where we use a lone IF as in the following: (reseting a counter)
...........
SIGNAL DATAREF : SIGNED(15 DOWNTO 0);
.........
IF(DATAREF >= TO_SIGNED(1000,16)) THEN
DATAREF<= TO_SIGNED(0,16);
END IF;
Then, does it matter if we use an IF or a CASE statement? Thanks in advance
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would challenge you to use a case statement in that code.
It really referes to muxes. an if/elsif/else tree builds a priority encoder, whereas a similar casestatement will build a simple mux. But synthesisors are getting better now, so they can work out when a load of if/elseifs are mutually exclusive and therefore build a mux instead of a priority encoder. But unless you really care about logic usage (you probably dont with modern devices - ram and DSP usages are usually the problem areas) you should write readible code, rather than code that is really bady written but saves you a couple of LUTs.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey! Thanks for the answer!
The thing is that this block of code is not the only one. For example I have a protection block that takes some 32 bit values from an ADC and checks each one individually for values over a limit. So I use maybe 10 or 12 IF statements with comparison for 32 bit values. How do I optimize that? IF(VOLTAGE >= TO_SIGNED(2400,32)) THEN ERROR<= ERROR OR X"0A" END IF; IF(CURRENT >= TO_SIGNED(1400,32)) THEN ERROR<= ERROR OR X"10" END IF; and so on.. Thanks- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have seen somewhere that I should save the result of the comparison to a signal and then make the IF or CASE check. So as pipeling the comparison with the decision. Is it the way to go?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thess are parallel statements, no priority involved if the results are ORed. A case construct won't represent the function.
If pipelining is necessary depends on the timing constraints, you should try.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page