I currently have the following verilog expression...
wire [15:0] address_delta = (rx_address_in * 8 + (rx_eof_in ? rx_len_in : 8)) - (seek_address + OUT_BYTES);
rx_address_in is 13 bits and OUT_BYTES is a parameter which is an integer constant (so I guess 32 bits). I am assuming the 8x multiplication will get optimized into a left shift of 3. If this is a bad assumption to make please let me know. I am using the latest Vivado.
Right now my design is having trouble meeting timing. Although my address_delta is only 16 bits, since I am using 32 bit constants inside the expression which I think might cause the operations to be carried out at a higher precision than necessary. How would you rewrite this expression for efficiency or is it fine the way it is?
I am thinking I could do something like this...
wire [15:0] seek_end = (seek_address + OUT_BYTES);
wire [15:0] address_delta = ((rx_address_in << 2'd3) + (rx_eof_in ? rx_len_in : 4'd8)) - seek_end;
-
1\$\begingroup\$ Have you looked in the timing report to identify the critical path? Synthesis tools are pretty good at discarding logic that isn't needed, so I doubt that you really have identified the problem. \$\endgroup\$Elliot Alderson– Elliot Alderson2018年07月11日 19:09:44 +00:00Commented Jul 11, 2018 at 19:09
1 Answer 1
No, using an intermediate assignment does not solve your problem.
HDL languages do not work like C. There still is a continuous timing path from seek_address
to address_delta
.
To break the path you must e.g. insert a register. But that may stop your design from working as seek_end
will arrive one clock cycle later.
Your calculation will not be done in 32 bits. Maybe in a simulator but the synthesis tool will remove all superfluous bits.
You do not tell us how fast your design must be, but as Elliot Alderson already suggest in the comment: three 16 bit adders are rarely critical. (The rx_address_in << 2'd3
does not cause any delay.) Unless this expression is part of a logic cone.
-
\$\begingroup\$ I think the OP is saying that using
wire[15:0]
will force the intermediate result to be truncated to 16 bits, which might help meet timing since less stuff is computed. \$\endgroup\$Stack Exchange Broke The Law– Stack Exchange Broke The Law2018年07月12日 02:06:32 +00:00Commented Jul 12, 2018 at 2:06 -
\$\begingroup\$ @immibis As I said: the synthesis tool will remove all superfluous bits. \$\endgroup\$Oldfart– Oldfart2018年07月12日 02:09:04 +00:00Commented Jul 12, 2018 at 2:09