Peruzzi
|
For behavioral modeling as opposed to RTL code for synthesis, I wonder if there's a simulation execution speed advantage to using the ternary operator rather than the more readable if/else construct.
Here's an example of a digital mux, but my question applies to both digital and analog behavioral models:
// If/Else approach
reg t;
always @ (a or b or select) if (select) t = a; else t = b;
// Ternary approach: wire t = (select ? a : b);
If the goal were digital synthesis, there's a difference: if/else results in a register with multiplexed input. Ternary results in just the mux, but that's not the point.
The two approaches give identical behavioral results.
My instinct tells me the ternary approach takes the same number of cycles to execute as the if/else code, even though it looks more compact and clever, but does anybody know if this is in fact true?
I tend to use the if/else approach to make the code more readable to others (as well as to myself months later). But I would change to the ternary approach if it offered even a small speed advantage.
Thanks,
Bob P.
|