我使用以下逻辑在Verilog中的双峰预测器中实现了2位饱和计数器,并且我还使用了以下verilator:
• For each branch, maintain a 2-bit saturating counter:
-if the branch is taken: counter = min(3,counter+1)
-if the branch is not taken: counter = max(0,counter-1)
• If (counter >= 2), predict taken, else predict not taken
module Bimodal(
input clk,
input reset,
input taken, //from ALU unit in execute stage
input branch, //from control unit in decode stage
input [31:0] instrAddr, // current address taken from fetch/decode stage
output reg predicted_taken_or_not);
reg [1:0] saturating_counter [0:1023];
integer i;
parameter max_val = 3 ;
parameter min_val = 0 ;
assign predicted_taken_or_not = saturating_counter[instrAddr[11:2]]>= 2'd2 && branch? 1'd1 : 1'd0;
// write ports to update the 2-bit saturating counter
always @(posedge clk) begin
if(reset) begin
for(int i=0; i<1024; i++) begin
saturating_counter[i] = 2'd1;
end
end
else if (taken) begin
if(max_val>saturating_counter[instrAddr[11:2]]+1)
saturating_counter[instrAddr[11:2]]<=saturating_counter[instrAddr[11:2]]+1;
else
saturating_counter[instrAddr[11:2]]<=max_val;
end
else if (~taken) begin
if(min_val>saturating_counter[instrAddr[11:2]]-1)
saturating_counter[instrAddr[11:2]]<=min_val;
else
saturating_counter[instrAddr[11:2]]<=saturating_counter[instrAddr[11:2]]-1;
end
end
endmodule但我还是会犯错误
%Warning-UNSIGNED: Bimodal.v:36: Comparison is constant due to unsigned arithmetic
%Warning-UNSIGNED: Use "/* verilator lint_off UNSIGNED */" and lint_on around source to disable this message.
%Error: Exiting due to 1 warning(s)
%Error: Command Failed /home/verilator-3.884/verilator_bin -O4 --cc MIPS.v --exe sim_main.cpp我做错什么了吗?
发布于 2017-03-20 06:37:43
请记住,verilog中的regs是无符号值,您分配给reg的任何内容都是一个正的无符号值。与零比较的所有未确定值都将大于或等于零。如果要进行签名比较,可以使用$signed()指令。
if(min_val>$signed(saturating_counter[instrAddr[11:2]]-1))发布于 2017-03-17 21:57:21
您的编译器当前设置为在某些警告上失败。问题的根源可能是您的min_val参数当前为0。同时,您只检查min_val (除非在某个地方覆盖参数,它总是为0)是否大于没有符号的RHS (右侧)上的2位值。这意味着它永远不会是负面的。
Is 0 > 0 ? No
Is 0 > 1 ? No
is 0 > 2 ? No
Is 0 > 3 ? No答案总是“否”,所以结果是恒定的。
你是想测试一下
Is 0 > 0 ? No
Is 0 > 1 ? No
Is 0 > -2 ? Yes
Is 0 > -1 ? Yes如果需要这样做,则需要更改逻辑类型,或更改比较。
https://stackoverflow.com/questions/42867392
复制相似问题