lza cleanup

This commit is contained in:
David Harris 2022-08-01 15:47:03 -07:00
parent f56b26ec40
commit 91597bba87

View File

@ -37,28 +37,28 @@ module fmalza( // [Schmookler & Nowka, Leading zero anticipation and detection,
output logic [$clog2(3*`NF+7)-1:0] SCnt // normalization shift count for the positive result
);
localparam WIDTH = 3*`NF+7;
localparam WIDTH = 3*`NF+6;
logic [WIDTH-1:0] F;
logic [WIDTH-2:0] B, P, G, K;
logic [WIDTH-2:0] Pp1, Gm1, Km1;
logic [WIDTH:0] F;
logic [WIDTH-1:0] B, P, G, K;
logic [WIDTH-1:0] Pp1, Gm1, Km1;
assign B = {{(`NF+2){1'b0}}, Pm}; // Zero extend product
assign P = A[WIDTH-2:0]^B;
assign G = A[WIDTH-2:0]&B;
assign K= ~A[WIDTH-2:0]&~B;
assign P = A^B;
assign G = A&B;
assign K= ~A&~B;
assign Pp1 = {sub, P[WIDTH-2:1]};
assign Gm1 = {G[WIDTH-3:0], Cin};
assign Km1 = {K[WIDTH-3:0], ~Cin};
assign Pp1 = {sub, P[WIDTH-1:1]};
assign Gm1 = {G[WIDTH-2:0], Cin};
assign Km1 = {K[WIDTH-2: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] = ~sub&P[WIDTH-2];
assign F[WIDTH-2:0] = (Pp1&(G&~Km1 | K&~Gm1)) | (~Pp1&(K&~Km1 | G&~Gm1));
assign F[WIDTH] = ~sub&P[WIDTH-1];
assign F[WIDTH-1:0] = (Pp1&(G&~Km1 | K&~Gm1)) | (~Pp1&(K&~Km1 | G&~Gm1));
lzc #(WIDTH) lzc (.num(F), .ZeroCnt(SCnt));
lzc #(WIDTH+1) lzc (.num(F), .ZeroCnt(SCnt));
endmodule