Altera Coding Style 之 计数器

For the best area utilization, ensure that the up/down control or controls are expressed in terms of one addition instead of two separate addition operators.

当然,构造计数器的时候都会希望这样,但是不好的编码风格可能导致不一样的结果。

1、不好的风格

out <= count_up ? out + 1 : out –1;

这会综合出2个独立的进位链

2、推荐的风格

out <=  out + ( out_up ? 1 : -1 );

这只需要1个进位链。

-1通过LUT实现,在LAB中LUT是在加法器之前的,所以也不会增加额外的面积。

… because there is only one carry chain adder, and the –1 constant logic is implemented in the LUT in front of the adder without adding extra area utilization.

原文地址:https://www.cnblogs.com/freshair_cnblog/p/2642161.html