LZA refactoring

This commit is contained in:
David Harris 2022-08-01 11:36:21 -07:00
parent 7f9b601467
commit 3c08aabcd3
2 changed files with 17 additions and 11 deletions

View File

@ -85,6 +85,6 @@ module fma(
fmaadd add(.Am, .Pm, .Ze, .Pe, .Ps, .As, .KillProd, .ZmSticky, .AmInv, .PmKilled, .NegSum, .InvA, .Sm, .Se, .Ss);
fmalza lza(.A(AmInv+{(3*`NF+6)'(0),InvA&~((ZmSticky&~KillProd))}), .Pm({PmKilled, 1'b0, InvA&Ps&ZmSticky&KillProd}), .SCnt);
fmalza lza(.A(AmInv), .Pm({PmKilled, 1'b0, InvA&Ps&ZmSticky&KillProd}), .Cin(InvA & ~(ZmSticky & ~KillProd)), .SCnt);
endmodule

View File

@ -30,28 +30,34 @@
`include "wally-config.vh"
module fmalza( // [Schmookler & Nowka, Leading zero anticipation and detection, IEEE Sym. Computer Arithmetic, 2001]
input logic [3*`NF+6:0] A, // addend
input logic [2*`NF+3:0] Pm, // product
output logic [$clog2(3*`NF+7)-1:0] SCnt // normalization shift count for the positive result
input logic [3*`NF+6:0] A, // addend
input logic [2*`NF+3:0] Pm, // product
input logic Cin, // carry in
output logic [$clog2(3*`NF+7)-1:0] SCnt // normalization shift count for the positive result
);
localparam WIDTH = 3*`NF+7;
logic [WIDTH-1:0] B, P, G, K, F;
logic [WIDTH-1:0] Pp1, Gm1, Km1;
logic [WIDTH-1:0] AA, B, P, G, K, F;
logic [WIDTH-2:0] Pp1, Gm1, Km1;
assign B = {{(`NF+3){1'b0}}, Pm}; // Zero extend product
assign AA = A + Cin;
assign P = A^B;
assign G = A&B;
assign K= ~A&~B;
assign P = AA^B;
assign G = AA&B;
assign K= ~AA&~B;
assign Pp1 = P[WIDTH-1:1];
assign Gm1 = {G[WIDTH-3:0], Cin};
assign Km1 = {K[WIDTH-3:0], ~Cin};
// Apply function to determine Leading pattern
// - note: the paper linked above uses the numbering system where 0 is the most significant bit
//f[n] = ~P[n]&P[n-1] note: n is the MSB
//f[i] = (P[i+1]&(G[i]&~K[i-1] | K[i]&~G[i-1])) | (~P[i+1]&(K[i]&~K[i-1] | G[i]&~G[i-1]))
assign F[WIDTH-1] = ~P[WIDTH-1]&P[WIDTH-2];
assign F[WIDTH-2:0] = (P[3*`NF+6:1]&(G[3*`NF+5:0]&{~K[3*`NF+4:0], 1'b0} | K[3*`NF+5:0]&{~G[3*`NF+4:0], 1'b1})) | (~P[3*`NF+6:1]&(K[3*`NF+5:0]&{~K[3*`NF+4:0], 1'b0} | G[3*`NF+5:0]&{~G[3*`NF+4:0], 1'b1}));
assign F[WIDTH-2:0] = (Pp1&(G[3*`NF+5:0]&{~K[3*`NF+4:0], 1'b0} | K[3*`NF+5:0]&{~G[3*`NF+4:0], 1'b1})) | (~P[3*`NF+6:1]&(K[3*`NF+5:0]&{~K[3*`NF+4:0], 1'b0} | G[3*`NF+5:0]&{~G[3*`NF+4:0], 1'b1}));
lzc #(3*`NF+7) lzc (.num(F), .ZeroCnt(SCnt));
lzc #(WIDTH) lzc (.num(F), .ZeroCnt(SCnt));
endmodule