You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SystemVerilog超前进位加法器仿真出现X传播问题求助

问题原因

    1. 最低位全加器缺失:全加器生成循环起始索引为i=1,仅生成了第1到WIDTH-1位的全加器,w_SUM[0]没有任何驱动源,初始状态为X且始终无法被刷新,直接导致输出结果的最低位恒为X。
    1. 超前进位传播项逻辑错误:超前进位的传播位w_P的定义应为输入两位的异或(i_add1[jj] ^ i_add2[jj]),原代码写为了或运算,直接导致所有进位计算结果错误。
    1. 初始进位赋值时序错误:原代码把初始进位w_C[0] = 1'b0的赋值语句放在了进位链生成循环之后,仿真初始阶段计算w_C[1]到w_C[WIDTH]时w_C[0]还未完成赋值,会触发X的连锁传播。

修复后的核心代码片段

// 超前进位加法器修改部分
module carry_lookahead_adder
  #(parameter WIDTH)
  (input logic [WIDTH-1:0] i_add1,
   input logic [WIDTH-1:0] i_add2,
   output logic [WIDTH:0] o_result
  );
  logic [WIDTH:0]  w_C;
  logic [WIDTH-1:0] w_G, w_P, w_SUM;
  
  // 初始进位赋值移到最前面,优先完成初始值定义
  assign w_C[0] = 1'b0; 
  
  //Generate full adders,循环起始索引改为0,补全最低位全加器
  genvar i;
  generate for (i= 0; i<WIDTH; i++)
    begin : f_loop   
      fulladder fi ( 
              .i_bit1(i_add1[i]),
              .i_bit2(i_add2[i]),
              .i_carry(w_C[i]),
              .o_sum(w_SUM[i]),
              .o_carry()
              );
    end 
  endgenerate
  
  genvar jj;
  generate 
    for (jj=0; jj<WIDTH; jj++)
      begin 
        assign w_G[jj]  = i_add1[jj] & i_add2[jj];
        assign w_P[jj]  = i_add1[jj] ^ i_add2[jj]; // 传播项改为异或运算
        assign w_C[jj+1] = w_G[jj] | (w_P[jj] & w_C[jj]);
      end
  endgenerate     
     
  assign o_result = {w_C[WIDTH], w_SUM};
                                          
endmodule

内容的提问来源于stack exchange,提问作者Braeden Hamson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 12:45:03