From 4953ccf273bf874e23d898a35f508dc2cfaf7d5c Mon Sep 17 00:00:00 2001 From: David Harris Date: Mon, 1 Aug 2022 15:37:09 -0700 Subject: [PATCH] lza cleanup --- pipelined/src/fpu/fma.sv | 3 ++- pipelined/src/fpu/fmalza.sv | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pipelined/src/fpu/fma.sv b/pipelined/src/fpu/fma.sv index e698cdaf..68a50967 100644 --- a/pipelined/src/fpu/fma.sv +++ b/pipelined/src/fpu/fma.sv @@ -85,6 +85,7 @@ module fma( fmaadd add(.Am, .Pm, .Ze, .Pe, .Ps, .As, .KillProd, .ZmSticky, .AmInv, .PmKilled, .NegSum, .InvA, .Sm, .Se, .Ss); - fmalza lza(.A(AmInv), .Pm({PmKilled, 1'b0, InvA&Ps&ZmSticky&KillProd}), .Cin(InvA & ~(ZmSticky & ~KillProd)), .SCnt); + fmalza lza(.A(AmInv), .Pm({PmKilled, 1'b0, InvA&Ps&ZmSticky&KillProd}), .Cin(InvA & ~(ZmSticky & ~KillProd)), .sub(InvA), .SCnt); endmodule + diff --git a/pipelined/src/fpu/fmalza.sv b/pipelined/src/fpu/fmalza.sv index f70b1bc9..9de1d745 100644 --- a/pipelined/src/fpu/fmalza.sv +++ b/pipelined/src/fpu/fmalza.sv @@ -32,26 +32,27 @@ 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 - input logic Cin, // carry in + input logic Cin, // carry in + input logic sub, 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,F; - logic [WIDTH-1:0] P, G; - logic [WIDTH-2:0] K; + logic [WIDTH-2:0] P, G, K; logic [WIDTH-2:0] Pp1, Gm1, Km1; assign B = {{(`NF+3){1'b0}}, Pm}; // Zero extend product // next steps***replace P[WIDTH-1] with sub, then remove one bit from A - assign P = A^B; + assign P = A[WIDTH-2:0]^B[WIDTH-2:0]; assign G = A[WIDTH-2:0]&B[WIDTH-2:0]; assign K= ~A[WIDTH-2:0]&~B[WIDTH-2:0]; - assign Pp1 = {A[WIDTH-1], P[WIDTH-2:1]}; + assign Pp1 = {sub, P[WIDTH-2:1]}; +// assign Pp1 = {A[WIDTH-1], P[WIDTH-2:1]}; assign Gm1 = {G[WIDTH-3:0], Cin}; assign Km1 = {K[WIDTH-3:0], ~Cin}; @@ -59,7 +60,7 @@ module fmalza( // [Schmookler & Nowka, Leading zero anticipation and detection, // - 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-1] = ~sub&P[WIDTH-2]; assign F[WIDTH-2:0] = (Pp1&(G&~Km1 | K&~Gm1)) | (~Pp1&(K&~Km1 | G&~Gm1)); lzc #(WIDTH) lzc (.num(F), .ZeroCnt(SCnt));