如何在 Verilog 中合成 While 循环? [英] How to Synthesize While Loop in Verilog?
问题描述
我曾尝试设计一个 Booth 乘法器,它在所有编译器中运行良好,包括:
Modelsim、Verilogger Extreame、Aldec Active Hdl &Xilinx 的 Isim......
我知道模拟和综合是两个不同的过程,只有少数具有各种限制的 Verilog 结构用于综合.但我不知道发生了什么While loop
在我的程序中无法在 Synopsys Synplify 9.6 和 Xilinx ise 14.2 中工作.>
当我尝试综合时 Synopsys 说 超过循环迭代限制 2000"
而 Xilinx' XST 说"This Xilinx application内存不足或遇到内存冲突"
我在下面附上了我的代码.我还写了这个 <-------"Error Generated Here due to this while loop" 其中合成器由于 while 循环而产生错误......
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////作者/Coder-Shrikant Vaishnav//////////////////////////////////////////////////////////////////////////////////////设计展位算法演示///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////模块booth_synt(输入线[4:0]a,输入线[4:0]b,输出regsigned[9:0]g);reg signed[10:0]c;//符号位多出一位......我的意思是第 11 位.//我们使用Signed Reg bcoz ASR用MSB填充空位,然后将其他用于无符号reg的它们用零填充然后移位..reg[4:0]d;reg [4:0]e;reg [2:0]count1;reg [2:0]count2;reg [2:0]count3;reg [2:0]count4;//每当发生任何变化时总是开始总是@(a,b)开始:关闭//如果用于符号位检查...//然后2的补...count1=3'b000;//初始化计数器count2=3'b000;count3=3'b000;count4=3'b000;//对于负数if(a[4]==1'b1)//内部检查开始如果(a==5'b10000)开始g[9:0]=10'b0000000000;结尾别的开始d=~{1'b0,a[3],a[2],a[1],a[0]};//我们放置 1'b0 因为它的倒数是 1d=d+5'b00001;//2 的补码我们使用额外的寄存器 d 来保存数据.....bcoz 线不保存数据if(d[4]==1'b0)//这个if"被使用bcoz if由于计算如果不小心d[5]==1'b0那么这个改变符号位,从而ans开始d[4]=1'b1;结尾c[5:1]=d;结尾结尾如果(b[4]==1'b1)开始如果(b==5'b10000)开始g[9:0]=10'b0000000000;禁用关闭;结尾别的开始e=~{1'b0,b[3],b[2],b[1],b[0]};//我们放置 1'b0 因为它的倒数是 1e=e+5'b00001;if(e[4]==1'b0)//这个if"用bcoz if由于计算如果不小心e[4]==1'b0那么这个改变符号位,从而ans开始e[4]=1'b1;结尾结尾结尾//为正如果(b[4]==1'b0)开始e[4:0]=b[4:0];结尾如果(a[4]==1'b0)开始c[1]=a[0];c[2]=a[1];//a"是乘数,而b"是被乘数...c[3]=a[2];c[4]=a[3];c[5]=a[4];结尾//初始化输出........c[0]=1'b0;//所有MSB的初始设置为零c[6]=1'b0;c[7]=1'b0;c[8]=1'b0;c[9]=1'b0;c[10]=1'b0;//四种不同的条件检查......案例({c[1],c[0]})2'b00:begin//案例1while(count1<3'b101) **<-------由于此 while 循环,此处生成错误"**开始if({c[1],c[0]}==2'b10)//cond1 为 10开始c[10:6]=(c[10:6]-e[4:0]);c=c>>>1;count1=count1+1'b1;if(count1==3'b101)//计数器值检查开始如果(c[10]==1)开始c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//我们放置1'b0,因为它的倒数是1c=c+10'b0000000010;c[10]=1'b1;//再次给1以保证g[9:0]=c[10:1];结尾如果(c[10]==0)开始c[10]=1'b0;g[9:0]=c[10:1];结尾end//结束 if==4结尾if(({c[1],c[0]}==2'b00) || ({c[1],c[0]}==2'b11))//在其中的条件 2 我们描述了两者00和11.........算术右移操作开始c=c>>>1;count1=count1+1'b1;if(count1==3'b101)//计数器值检查开始如果(c[10]==1)开始c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//我们放置1'b0,因为它的倒数是1c=c+10'b0000000010;c[10]=1'b1;//再次给1以确保g[9:0]=c[10:1];结尾如果(c[10]==0)开始c[10]=1'b0;g[9:0]=c[10:1];结尾结尾结尾if({c[1],c[0]}==2'b01)//cond3 为 01开始c[10:6]=(c[10:6]+e[4:0]);c=c>>>1;count1=count1+1'b1;if(count1==3'b101)//计数器值检查开始如果(c[10]==1)开始c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//我们放置1'b0,因为它的倒数是1c=c+10'b0000000010;c[10]=1'b1;//再次给1以保证g[9:0]=c[10:1];结尾如果(c[10]==0)开始c[10]=1'b0;g[9:0]=c[10:1];结尾结尾结尾结尾结束//结束//案例22'b11:开始while(count2<3'b101) **<-------由于这个while循环,这里产生错误"**开始if({c[1],c[0]}==2'b10)//cond1 为 10开始c[10:6]=(c[10:6]-e[4:0]);c=c>>>1;count2=count2+1'b1;if(count2==3'b101)//计数器值检查开始如果(c[10]==1)开始c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//我们放置1'b0,因为它的倒数是1c=c+10'b0000000010;c[10]=1'b1;//再次给1以保证g[9:0]=c[10:1];结尾如果(c[10]==0)开始c[10]=1'b0;g[9:0]=c[10:1];结尾结尾结尾if(({c[1],c[0]}==2'b00)||({c[1],c[0]}==2'b11))//其中的条件 2 我们描述了两者00和11.........算术右移操作开始c=c>>>1;count2=count2+1'b1;if(count2==3'b101)//计数器值检查开始如果(c[10]==1)开始c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//我们放置1'b0,因为它的倒数是1c=c+10'b0000000010;c[10]=1'b1;//再次给1以保证g[9:0]=c[10:1];结尾如果(c[10]==0)开始c[10]=1'b0;g[9:0]=c[10:1];结尾结尾结尾if({c[1],c[0]}==2'b01)//cond3 为 01开始c[10:6]=(c[10:6]+e[4:0]);c=c>>>1;count2=count2+1'b1;if(count2==3'b101)//计数器值检查开始如果(c[10]==1)开始c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//我们放置1'b0,因为它的倒数是1c=c+10'b0000000010;c[10]=1'b1;//再次给1以保证g[9:0]=c[10:1];结尾如果(c[10]==0)开始c[10]=1'b0;g[9:0]=c[10:1];结尾结尾结尾结尾end//while 结束//案例32'b10:开始while(count3<3'b101) **<-------由于此 while 循环,此处生成错误"**开始if({c[1],c[0]}==2'b10)//Cond1 for 10开始c[10:6]=(c[10:6]-e[4:0]);c=c>>>1;count3=count3+1'b1;if(count3==3'b101)//计数器值检查开始如果(c[10]==1)开始c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//我们放置1'b0,因为它的倒数是1c=c+10'b0000000010;c[10]=1'b1;//再次给1以保证g[9:0]=c[10:1];结尾如果(c[10]==0)开始c[10]=1'b0;g[9:0]=c[10:1];结尾结尾结尾if(({c[1],c[0]}==2'b00)||({c[1],c[0]}==2'b11))//其中的条件 2 我们描述了两者00和11.........算术右移操作开始c=c>>>1;count3=count3+1'b1;if(count3==3'b101)//计数器值检查开始如果(c[10]==1)开始c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//我们放置1'b0,因为它的倒数是1c=c+10'b0000000010;c[10]=1'b1;//再次给1以保证g[9:0]=c[10:1];结尾如果(c[10]==0)开始c[10]=1'b0;g[9:0]=c[10:1];结尾结尾结尾if({c[1],c[0]}==2'b01)//cond3 为 01开始c[10:6]=(c[10:6]+e[4:0]);c=c>>>1;count3=count3+1'd1;if(count3==3'b101)//计数器值检查开始如果(c[10]==1)开始c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//我们放置1'b0,因为它的倒数是1c=c+10'b0000000010;c[10]=1'b1;//再次给1以保证g[9:0]=c[10:1];结尾如果(c[10]==0)开始c[10]=1'b0;g[9:0]=c[10:1];结尾结尾结尾结尾end//while 结束//案例42'b01:开始while(count4<3'b101) **<-------由于此 while 循环,此处生成错误"**开始if({c[1],c[0]}==2'b10)//cond1 为 10开始c[10:6]=(c[10:6]-e[4:0]);c=c>>>1;count4=count4+1'b1;if(count4==3'b101)//计数器值检查开始如果(c[10]==1)开始c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//我们放置1'b0,因为它的倒数是1c=c+10'b0000000010;c[10]=1'b1;//再次给1以确保g[9:0]=c[10:1];结尾如果(c[10]==0)开始c[10]=1'b0;g[9:0]=c[10:1];结尾结尾结尾if(({c[1],c[0]}==2'b00)||({c[1],c[0]}==2'b11))//其中的条件 2 我们描述了两者00和11.........算术右移操作开始c=c>>>1;count4=count4+1'b1;if(count4==3'b101)//计数器值检查开始如果(c[10]==1)开始c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//我们放置1'b0,因为它的倒数是1c=c+10'b0000000010;c[10]=1'b1;//再次给1以确保g[9:0]=c[10:1];结尾如果(c[10]==0)开始c[10]=1'b0;g[9:0]=c[10:1];结尾结尾结尾if({c[1],c[0]}==2'b01)//cond3 为 01开始c[10:6]=(c[10:6]+e[4:0]);c=c>>>1;count4<=count4+1'b1;if(count4==3'b101)开始如果(c[10]==1)开始c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//我们放置1'b0,因为它的倒数是1c=c+10'b0000000010;c[10]=1'b1;//再次给1以保证g[9:0]=c[10:1];结尾如果(c[10]==0)开始c[10]=1'b0;g[9:0]=c[10:1];结尾结尾结尾end//while 结束结束//01的结束endcase//案例结束end//总是结束结束模块
这是写得不好的代码.你把它写得像一个计算机程序.Verilog 是一种硬件描述语言,而不是一种编程语言.在您的情况下,合成器正在尝试在 case 语句中复制 while 循环内的逻辑.
- 在将硬件转换为 HDL 之前在纸上设计硬件
- 在编码之前确定设计中的组合逻辑和顺序逻辑.
- 想想合成器将使用什么逻辑来实现您编写的逻辑.
I have tried to design a Booth multiplier and it runs well in all compilers including:
Modelsim,Verilogger Extreame,Aldec Active Hdl & Xilinx's Isim......
I know Simulation and Synthesis are two Different Process and only few Verilog constructs with various restrictions are there for synthesis. But I don't know what happen While loop
in my program not work in Synopsys Synplify 9.6 as well as in Xilinx ise 14.2.
When I try to synthesize Synopsys says "loop iteration limit 2000 exceeded"
while Xilinx' XST says " This Xilinx application has run out of memory or has encountered a memory conflict"
I have attached my code below. I Also write this <-------"Error Generated Here due to this while loop" where Synthesizer generates error due to while loop......
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////Author/Coder-Shrikant Vaishnav///////////////////////////////////////////////
/////////////////////////////////////////Design-Booth Algorithm Demonstration////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
module booth_synt(input wire [4:0]a,input wire [4:0]b,output reg signed[9:0] g);
reg signed[10:0]c;// One extra bit for sign bit.....I mean 11th bit.
//We used Signed Reg bcoz ASR fill vacant bit with MSB and then shift other for unsigned reg they fill it with zeros and then shift..
reg[4:0]d;
reg [4:0]e;
reg [2:0]count1;
reg [2:0]count2;
reg [2:0]count3;
reg [2:0]count4;
//Always start whenever any changes happens
always@(a,b)
begin :close
//If's for sign bit check...
//Then 2's Complement...
count1=3'b000; //Initialize Counter
count2=3'b000;
count3=3'b000;
count4=3'b000;
//For negative
if(a[4]==1'b1) //Internal checking
begin
if(a==5'b10000)
begin
g[9:0]=10'b0000000000;
end
else
begin
d=~{1'b0,a[3],a[2],a[1],a[0]}; //we place 1'b0 because its inversion is 1
d=d+5'b00001; //2's Complement we use additional register d for data holding.....bcoz wire not hold data
if(d[4]==1'b0)//This "if" is used bcoz if due to calculation if accidently d[5]==1'b0 then this changs sign bit and thus ans
begin
d[4]=1'b1;
end
c[5:1]=d;
end
end
if(b[4]==1'b1)
begin
if(b==5'b10000)
begin
g[9:0]=10'b0000000000;
disable close;
end
else
begin
e=~{1'b0,b[3],b[2],b[1],b[0]}; //we place 1'b0 because its inversion is 1
e=e+5'b00001;
if(e[4]==1'b0)//This "if" is used bcoz if due to calculation if accidently e[4]==1'b0 then this changs sign bit and thus ans
begin
e[4]=1'b1;
end
end
end
//For positive
if(b[4]==1'b0)
begin
e[4:0]=b[4:0];
end
if(a[4]==1'b0)
begin
c[1]=a[0];
c[2]=a[1]; //"a" is multiplier while "b" is multiplicand...
c[3]=a[2];
c[4]=a[3];
c[5]=a[4];
end
//Initialization of Output ........
c[0]=1'b0;
//All MSB's are Initially set to Zeros
c[6]=1'b0;
c[7]=1'b0;
c[8]=1'b0;
c[9]=1'b0;
c[10]=1'b0;
//Four Different Conditions Checking......
case({c[1],c[0]})
2'b00:begin //Case 1
while(count1<3'b101) **<-------"Error Generated Here due to this while loop"**
begin
if({c[1],c[0]}==2'b10) //cond1 for 10
begin
c[10:6]=(c[10:6]-e[4:0]);
c=c>>>1;
count1=count1+1'b1;
if(count1==3'b101)// Counter value check
begin
if(c[10]==1)
begin
c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//we place 1'b0 because its inversion is 1
c=c+10'b0000000010;
c[10]=1'b1; //Again giving 1 for surity
g[9:0]=c[10:1];
end
if(c[10]==0)
begin
c[10]=1'b0;
g[9:0]=c[10:1];
end
end //end if==4
end
if(({c[1],c[0]}==2'b00) || ({c[1],c[0]}==2'b11)) //cond 2 in it we describe both 00 and11.........Arithemetic Right Shift operation
begin
c=c>>>1;
count1=count1+1'b1;
if(count1==3'b101) // Counter value check
begin
if(c[10]==1)
begin
c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//we place 1'b0 because its inversion is 1
c=c+10'b0000000010;
c[10]=1'b1; //Again giving 1 for surity
g[9:0]=c[10:1];
end
if(c[10]==0)
begin
c[10]=1'b0;
g[9:0]=c[10:1];
end
end
end
if({c[1],c[0]}==2'b01) //cond3 for 01
begin
c[10:6]=(c[10:6]+e[4:0]);
c=c>>>1;
count1=count1+1'b1;
if(count1==3'b101) // Counter value check
begin
if(c[10]==1)
begin
c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//we place 1'b0 because its inversion is 1
c=c+10'b0000000010;
c[10]=1'b1; //Again giving 1 for surity
g[9:0]=c[10:1];
end
if(c[10]==0)
begin
c[10]=1'b0;
g[9:0]=c[10:1];
end
end
end
end
end//while's end
//Case2
2'b11:begin
while(count2<3'b101) **<-------"Error Generated Here due to this while loop"**
begin
if({c[1],c[0]}==2'b10) //cond1 for 10
begin
c[10:6]=(c[10:6]-e[4:0]);
c=c>>>1;
count2=count2+1'b1;
if(count2==3'b101) // Counter value check
begin
if(c[10]==1)
begin
c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//we place 1'b0 because its inversion is 1
c=c+10'b0000000010;
c[10]=1'b1; //Again giving 1 for surity
g[9:0]=c[10:1];
end
if(c[10]==0)
begin
c[10]=1'b0;
g[9:0]=c[10:1];
end
end
end
if(({c[1],c[0]}==2'b00)||({c[1],c[0]}==2'b11))//cond 2 in it we describe both 00 and11.........Arithemetic Right Shift operation
begin
c=c>>>1;
count2=count2+1'b1;
if(count2==3'b101)// Counter value check
begin
if(c[10]==1)
begin
c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//we place 1'b0 because its inversion is 1
c=c+10'b0000000010;
c[10]=1'b1; //Again giving 1 for surity
g[9:0]=c[10:1];
end
if(c[10]==0)
begin
c[10]=1'b0;
g[9:0]=c[10:1];
end
end
end
if({c[1],c[0]}==2'b01) //cond3 for 01
begin
c[10:6]=(c[10:6]+e[4:0]);
c=c>>>1;
count2=count2+1'b1;
if(count2==3'b101)// Counter value check
begin
if(c[10]==1)
begin
c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//we place 1'b0 because its inversion is 1
c=c+10'b0000000010;
c[10]=1'b1; //Again giving 1 for surity
g[9:0]=c[10:1];
end
if(c[10]==0)
begin
c[10]=1'b0;
g[9:0]=c[10:1];
end
end
end
end
end //while's end
//Case 3
2'b10:begin
while(count3<3'b101) **<-------"Error Generated Here due to this while loop"**
begin
if({c[1],c[0]}==2'b10) //Cond1 for 10
begin
c[10:6]=(c[10:6]-e[4:0]);
c=c>>>1;
count3=count3+1'b1;
if(count3==3'b101)// Counter value check
begin
if(c[10]==1)
begin
c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//we place 1'b0 because its inversion is 1
c=c+10'b0000000010;
c[10]=1'b1; //Again giving 1 for surity
g[9:0]=c[10:1];
end
if(c[10]==0)
begin
c[10]=1'b0;
g[9:0]=c[10:1];
end
end
end
if(({c[1],c[0]}==2'b00)||({c[1],c[0]}==2'b11))//cond 2 in it we describe both 00 and11.........Arithemetic Right Shift operation
begin
c=c>>>1;
count3=count3+1'b1;
if(count3==3'b101)// Counter value check
begin
if(c[10]==1)
begin
c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//we place 1'b0 because its inversion is 1
c=c+10'b0000000010;
c[10]=1'b1; //Again giving 1 for surity
g[9:0]=c[10:1];
end
if(c[10]==0)
begin
c[10]=1'b0;
g[9:0]=c[10:1];
end
end
end
if({c[1],c[0]}==2'b01) //cond3 for 01
begin
c[10:6]=(c[10:6]+e[4:0]);
c=c>>>1;
count3=count3+1'd1;
if(count3==3'b101)// Counter value check
begin
if(c[10]==1)
begin
c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//we place 1'b0 because its inversion is 1
c=c+10'b0000000010;
c[10]=1'b1; //Again giving 1 for surity
g[9:0]=c[10:1];
end
if(c[10]==0)
begin
c[10]=1'b0;
g[9:0]=c[10:1];
end
end
end
end
end //while's end
//Case 4
2'b01:begin
while(count4<3'b101) **<-------"Error Generated Here due to this while loop"**
begin
if({c[1],c[0]}==2'b10) //cond1 for 10
begin
c[10:6]=(c[10:6]-e[4:0]);
c=c>>>1;
count4=count4+1'b1;
if(count4==3'b101)// Counter value check
begin
if(c[10]==1)
begin
c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//we place 1'b0 because its inversion is 1
c=c+10'b0000000010;
c[10]=1'b1; //Again giving 1 for surity
g[9:0]=c[10:1];
end
if(c[10]==0)
begin
c[10]=1'b0;
g[9:0]=c[10:1];
end
end
end
if(({c[1],c[0]}==2'b00)||({c[1],c[0]}==2'b11))//cond 2 in it we describe both 00 and11.........Arithemetic Right Shift operation
begin
c=c>>>1;
count4=count4+1'b1;
if(count4==3'b101)// Counter value check
begin
if(c[10]==1)
begin
c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//we place 1'b0 because its inversion is 1
c=c+10'b0000000010;
c[10]=1'b1; //Again giving 1 for surity
g[9:0]=c[10:1];
end
if(c[10]==0)
begin
c[10]=1'b0;
g[9:0]=c[10:1];
end
end
end
if({c[1],c[0]}==2'b01) //cond3 for 01
begin
c[10:6]=(c[10:6]+e[4:0]);
c=c>>>1;
count4<=count4+1'b1;
if(count4==3'b101)
begin
if(c[10]==1)
begin
c=~{1'b0,c[9],c[8],c[7],c[6],c[5],c[4],c[3],c[2],c[1],c[0]};//we place 1'b0 because its inversion is 1
c=c+10'b0000000010;
c[10]=1'b1; //Again giving 1 for surity
g[9:0]=c[10:1];
end
if(c[10]==0)
begin
c[10]=1'b0;
g[9:0]=c[10:1];
end
end
end
end //while's end
end//01's end
endcase //case end
end //always end
endmodule
This is poorly written code.You have written it like a computer program. Verilog is a Hardware Description Language - not a programming language. In your case, synthesizer is trying to replicate logic inside the while loop in the case statement.
- Design the hardware on a piece of paper before translating it to HDL
- Identify the combinational and sequential logic in the design before coding.
- Think what logic will synthesizer use to realize the logic you have written.
这篇关于如何在 Verilog 中合成 While 循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!