Verilog代码优化技巧

Verilog代码优化技巧:


1. 条件b为TRUE时,将c赋值给a;

always@(posedge fclk or negedge frstn)
	if(!frstn)
		a <= 0;
	else if(b)
		a <= c;
	else
  		a <= a;

时序逻辑里,后面的else如果不写的话,综合时会自动插入门控时钟。也就是说,只有满足if和else if里的条件,时钟fclk才有效,否则fclk无效,寄存器不翻转,从而达到节省功耗的目的;

always@(posedge fclk or negedge frstn)
	if(!frstn)
		a <= 0;
	else if(b)
		a <= c;

2. 条件b为TRUE时, 若c为TURE将d赋值给a,否则将a赋值给a。

always@(posedge fclk or negedge frstn)
	if(!frstn)
		a <= 0;
	else if(b)
		a <= c ? d : a;

其实b, c均为TRUE时,a才翻转,因此完全可以写成

always@(posedge fclk or negedge frstn)
	if(!frstn)
		a <= 0;
	else if

你可能感兴趣的:(数字IC设计,fpga开发,数字电路设计)