0

以下のコードを書きました。

私の問題:

インデックス 1 で

いくつかの値を使用して for ループに入ります。これは 'if' ステートメントに入ります。ご覧のとおり、すべての 'if' からの最後の命令は 'P=....' のようなものです。

インデックス 2 で(次のステップ)

「if」ステートメントに入りますが、P の値はステップ 1 からのものではなく、初期値です。

次のステップで「P」の最後の値を使用するにはどうすればよいですか? (指数+1)

module multiplier(prod, a, b, wireP, wireA, wireS);
  output [15:0] prod;
  output [16:0] wireA;
  output [16:0] wireS;
  output [16:0] wireP;
  reg    [15:0] prod;

  input  [7:0] a;
  input  [7:0] b;
  reg   [16:0] P;
  reg   [16:0] S;
  reg   [16:0] A;

  wire [16:0] tempshift;
  reg  [16:0] tempoutshift;

  arithmeticShift shiftP(tempshift,P);

  wire [16:0] tempPS;
  reg  [16:0] tempoutPS;

  carryForPbooth  sumPS(coutPS,tempPS,P,S,0);


  wire [16:0]tempPA;
  reg [16:0]tempoutPA;
  carryForPbooth  sumPA(coutPA,tempPA,P,A,0);

  reg [16:0] regP;
  reg [16:0] regA;
  reg [16:0] regS;
  integer    index;

  always @(*) begin

    A[16:9] = a[7:0];
    A[8:0]  = 9'b000000000;
    S[16:9] = ~a[7:0]+1'b1;
    S[8:0]  = 9'b000000000;
    P[16:9] = 8'b00000000;
    P[8:1]  = b[7:0];
    P[0]    = 1'b0;

    #1 tempoutPS    = tempPS;
    #1 tempoutPA    = tempPA;
    #1 tempoutshift = tempshift;

    for(index = 1; index < 9; index = index + 1) begin
      if((P[1:0] == 2'b00) | (P[1:0] == 2'b11)) begin
        #1 tempoutshift = tempshift;
        #1 P            = tempoutshift;
      end
      if(P[1:0] == 2'b01) begin
        #1 tempoutPA    = tempPA;
        #1 P            = tempoutPA;
        #1 tempoutshift = tempshift;
        #1 P            = tempoutshift;
      end
      if(P[1:0] == 2'b10) begin
        #1 tempoutPS    = tempPS;
        #1 P            = tempoutPS;
        #1 tempoutshift = tempshift;
        #1 P            = tempoutshift;
      end
    end

    #1 prod=P[16:1];
  end

  assign wireP = P;
  assign wireS = S;
  assign wireA = A;
endmodule
4

1 に答える 1

0

乗算値が 9 クロック サイクルで計算される、合成可能な Shift and Add 乗算器アーキテクチャを作成しようとしているようです。

コードに目を通し、いくつかの一時変数を削除して、次のように減らしました。

module multiplier(
  input      [7:0]  a,
  input      [7:0]  b,

  output     [15:0] prod,
  output reg [16:0] A,
  output reg [16:0] S,
  output reg [16:0] P
);

  wire [16:0] tempshift;
  arithmeticShift shiftP(tempshift,P);

  wire [16:0] tempPS;
  carryForPbooth  sumPS(coutPS,tempPS,P,S,0);


  wire [16:0] tempPA;
  carryForPbooth sumPA(coutPA,tempPA,P,A,0);

  reg [3:0] index;

  always @(*) begin
    A = {  a, 9'b000000000};
    S = { -a, 9'b000000000} ;// -x => ~x+1
    P = {8'b00000000, b, 1'b0}; 

    for(index = 1; index < 9; index = index + 1) begin
      if((P[1:0] == 2'b00) | (P[1:0] == 2'b11)) begin
        #1 P            = tempshift;
      end
      if(P[1:0] == 2'b01) begin
        #1 P            = tempPA;
        #1 P            = tempshift;
      end
      if(P[1:0] == 2'b10) begin
        #1 P            = tempPS;
        #1 P            = tempshift;
      end
    end
  end

  assign prod = P[16:1];
endmodule

を使用してクロックサイクルを偽造していると思います#1。これはシミュレータでのみ機能し、合成されないか、最後の割り当てのみが有効になります。

これを 9 クロック サイクルに分割する場合は、for ループではなく、シフト値に関連付けられたカウンターが必要です。Verilog では、for ループはコンパイル時に展開され、テストベンチの一部として使用されない限り、ゼロ タイムで実行可能になります。

次のようなコードのセクションが数回表示されます。

#1 P            = tempPA;
#1 P            = tempshift;

モジュールに値を適用し、同じ変数を使用してその出力をキャプチャしようとしていると思いますが、インスタンス化したブロックのインターフェイスがないため、これを知るのは困難です。コードを合成したい場合、Verilog でこれを行うことはできません。別の中間変数を使用して接続する必要があります。

always @* begin ... endこれは組み合わせ論理であり、答えの計算に関係するリップル以外にタイミングがないことを思い出してください。D-Type フリップフロップを暗示するために、以下を使用します。

always @(posedge clk or negedge rst_n) begin
  if (~rst_n) begin
    // Reset conditions
  end
  else begin
    // Next clock conditions
  end
end
于 2012-11-12T13:17:34.950 に答える