2022-07-07 23:01:33 +00:00
|
|
|
///////////////////////////////////////////
|
2022-08-29 11:04:05 +00:00
|
|
|
// fdivsqrtpreproc.sv
|
2022-07-07 23:01:33 +00:00
|
|
|
//
|
2022-09-19 21:26:32 +00:00
|
|
|
// Written: David_Harris@hmc.edu, me@KatherineParry.com, cturek@hmc.edu
|
2022-07-07 23:01:33 +00:00
|
|
|
// Modified:13 January 2022
|
|
|
|
//
|
|
|
|
// Purpose: Combined Divide and Square Root Floating Point and Integer Unit
|
|
|
|
//
|
|
|
|
// A component of the Wally configurable RISC-V project.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2021 Harvey Mudd College & Oklahoma State University
|
|
|
|
//
|
|
|
|
// MIT LICENSE
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
|
|
// software and associated documentation files (the "Software"), to deal in the Software
|
|
|
|
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
|
|
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
|
|
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in all copies or
|
|
|
|
// substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
|
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
|
|
|
// OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
`include "wally-config.vh"
|
|
|
|
|
2022-08-29 11:04:05 +00:00
|
|
|
module fdivsqrtpreproc (
|
2022-07-21 19:38:06 +00:00
|
|
|
input logic clk,
|
2022-09-29 23:30:25 +00:00
|
|
|
input logic DivStartE,
|
2022-07-15 20:16:59 +00:00
|
|
|
input logic [`NF:0] Xm, Ym,
|
2022-07-21 19:38:06 +00:00
|
|
|
input logic [`NE-1:0] Xe, Ye,
|
|
|
|
input logic [`FMTBITS-1:0] Fmt,
|
|
|
|
input logic Sqrt,
|
2022-10-25 17:48:43 +00:00
|
|
|
input logic XZero,
|
2022-09-29 23:30:25 +00:00
|
|
|
input logic [`XLEN-1:0] ForwardedSrcAE, ForwardedSrcBE, // *** these are the src outputs before the mux choosing between them and PCE to put in srcA/B
|
|
|
|
input logic [2:0] Funct3E, Funct3M,
|
|
|
|
input logic MDUE, W64E,
|
2022-11-06 22:08:18 +00:00
|
|
|
output logic [`DIVBLEN:0] n, p, m,
|
2022-11-06 21:53:48 +00:00
|
|
|
output logic [`NE+1:0] QeM,
|
2022-09-14 17:26:56 +00:00
|
|
|
output logic [`DIVb+3:0] X,
|
2022-09-07 17:21:27 +00:00
|
|
|
output logic [`DIVN-2:0] Dpreproc
|
2022-07-07 23:01:33 +00:00
|
|
|
);
|
|
|
|
// logic [`DIVLEN-1:0] ExtraA, ExtraB, PreprocA, PreprocB, PreprocX, PreprocY;
|
2022-07-21 19:38:06 +00:00
|
|
|
logic [`NF-1:0] PreprocA, PreprocX;
|
|
|
|
logic [`NF-1:0] PreprocB, PreprocY;
|
2022-07-22 22:02:04 +00:00
|
|
|
logic [`NF+1:0] SqrtX;
|
2022-10-26 16:18:05 +00:00
|
|
|
logic [`DIVb+3:0] DivX;
|
2022-11-06 22:21:35 +00:00
|
|
|
logic [`DIVBLEN:0] L;
|
2022-10-26 16:18:05 +00:00
|
|
|
logic [`NE+1:0] Qe;
|
|
|
|
// Intdiv signals
|
2022-11-06 21:53:48 +00:00
|
|
|
logic [`DIVb-1:0] ZeroBufX, ZeroBufY;
|
2022-10-26 16:18:05 +00:00
|
|
|
logic [`XLEN-1:0] PosA, PosB;
|
2022-11-06 21:53:48 +00:00
|
|
|
logic As, Bs;
|
|
|
|
logic [`XLEN-1:0] A64, B64;
|
2022-11-06 22:08:18 +00:00
|
|
|
logic [`DIVBLEN:0] ZeroDiff, IntBits, RightShiftX;
|
2022-11-06 22:31:48 +00:00
|
|
|
logic [`DIVBLEN:0] pPlusr, pPrCeil;
|
|
|
|
logic [`LOGRK-1:0] pPrTrunc;
|
2022-11-06 21:53:48 +00:00
|
|
|
logic [`DIVb+3:0] PreShiftX;
|
2022-07-07 23:01:33 +00:00
|
|
|
|
|
|
|
// ***can probably merge X LZC with conversion
|
|
|
|
// cout the number of leading zeros
|
2022-11-06 21:53:48 +00:00
|
|
|
|
|
|
|
assign As = ForwardedSrcAE[`XLEN-1] & Funct3E[0];
|
|
|
|
assign Bs = ForwardedSrcBE[`XLEN-1] & Funct3E[0];
|
|
|
|
assign A64 = W64E ? {{(`XLEN-32){As}}, ForwardedSrcAE[31:0]} : ForwardedSrcAE;
|
|
|
|
assign B64 = W64E ? {{(`XLEN-32){Bs}}, ForwardedSrcBE[31:0]} : ForwardedSrcBE;
|
|
|
|
|
|
|
|
assign PosA = As ? -A64 : A64;
|
|
|
|
assign PosB = Bs ? -B64 : B64;
|
|
|
|
|
|
|
|
assign ZeroBufX = MDUE ? {PosA, {`DIVb-`XLEN{1'b0}}} : {Xm, {`DIVb-`NF-1{1'b0}}};
|
|
|
|
assign ZeroBufY = MDUE ? {PosB, {`DIVb-`XLEN{1'b0}}} : {Ym, {`DIVb-`NF-1{1'b0}}};
|
2022-11-06 22:21:35 +00:00
|
|
|
lzc #(`DIVb) lzcX (ZeroBufX, L);
|
|
|
|
lzc #(`DIVb) lzcY (ZeroBufY, m);
|
2022-07-07 23:01:33 +00:00
|
|
|
|
2022-11-06 22:21:35 +00:00
|
|
|
assign PreprocX = Xm[`NF-1:0]<<L;
|
|
|
|
assign PreprocY = Ym[`NF-1:0]<<m;
|
2022-07-07 23:01:33 +00:00
|
|
|
|
2022-11-06 22:24:21 +00:00
|
|
|
assign ZeroDiff = m - L;
|
|
|
|
assign p = ZeroDiff[`DIVBLEN] ? '0 : ZeroDiff;
|
2022-11-06 21:53:48 +00:00
|
|
|
|
2022-11-06 22:31:48 +00:00
|
|
|
assign pPlusr = (`DIVBLEN)'(`LOGR) + p;
|
|
|
|
assign pPrTrunc = pPlusr[`LOGRK-1:0];
|
|
|
|
assign pPrCeil = (pPlusr >> `LOGRK) + {{`DIVBLEN-1{1'b0}}, |(pPrTrunc)};
|
|
|
|
assign n = (pPrCeil << `LOGK) - 1;
|
|
|
|
assign IntBits = (`DIVBLEN)'(`RK) + p;
|
|
|
|
assign RightShiftX = (`DIVBLEN)'(`RK) - {{(`DIVBLEN-`RK){1'b0}}, IntBits[`RK-1:0]};
|
2022-11-06 21:53:48 +00:00
|
|
|
|
2022-11-06 22:21:35 +00:00
|
|
|
assign SqrtX = Xe[0]^L[0] ? {1'b0, ~XZero, PreprocX} : {~XZero, PreprocX, 1'b0};
|
2022-09-15 16:10:57 +00:00
|
|
|
assign DivX = {3'b000, ~XZero, PreprocX, {`DIVb-`NF{1'b0}}};
|
2022-09-21 11:55:43 +00:00
|
|
|
|
2022-10-25 17:48:43 +00:00
|
|
|
// *** explain why X is shifted between radices (initial assignment of WS=RX)
|
2022-09-15 16:10:57 +00:00
|
|
|
if (`RADIX == 2) assign X = Sqrt ? {3'b111, SqrtX, {`DIVb-1-`NF{1'b0}}} : DivX;
|
|
|
|
else assign X = Sqrt ? {2'b11, SqrtX, {`DIVb-1-`NF{1'b0}}, 1'b0} : DivX;
|
2022-11-06 21:53:48 +00:00
|
|
|
// assign X = MDUE ? PreShiftX >> RightShiftX : PreShiftX;
|
2022-07-22 22:02:04 +00:00
|
|
|
assign Dpreproc = {PreprocY, {`DIVN-1-`NF{1'b0}}};
|
2022-07-07 23:01:33 +00:00
|
|
|
|
2022-07-12 01:30:21 +00:00
|
|
|
// radix 2 radix 4
|
|
|
|
// 1 copies DIVLEN+2 DIVLEN+2/2
|
|
|
|
// 2 copies DIVLEN+2/2 DIVLEN+2/2*2
|
|
|
|
// 4 copies DIVLEN+2/4 DIVLEN+2/2*4
|
|
|
|
// 8 copies DIVLEN+2/8 DIVLEN+2/2*8
|
|
|
|
|
|
|
|
// DIVRESLEN = DIVLEN or DIVLEN+2
|
|
|
|
// r = 1 or 2
|
|
|
|
// DIVRESLEN/(r*`DIVCOPIES)
|
2022-09-29 23:30:25 +00:00
|
|
|
flopen #(`NE+2) expflop(clk, DivStartE, Qe, QeM);
|
2022-11-06 22:21:35 +00:00
|
|
|
expcalc expcalc(.Fmt, .Xe, .Ye, .Sqrt, .XZero, .L, .m, .Qe);
|
2022-07-12 01:30:21 +00:00
|
|
|
|
2022-07-21 19:38:06 +00:00
|
|
|
endmodule
|
|
|
|
|
|
|
|
module expcalc(
|
2022-11-06 22:21:35 +00:00
|
|
|
input logic [`FMTBITS-1:0] Fmt,
|
2022-07-21 19:38:06 +00:00
|
|
|
input logic [`NE-1:0] Xe, Ye,
|
2022-11-06 22:21:35 +00:00
|
|
|
input logic Sqrt,
|
|
|
|
input logic XZero,
|
|
|
|
input logic [`DIVBLEN:0] L, m,
|
|
|
|
output logic [`NE+1:0] Qe
|
2022-07-21 19:38:06 +00:00
|
|
|
);
|
|
|
|
logic [`NE-2:0] Bias;
|
2022-07-22 22:02:04 +00:00
|
|
|
logic [`NE+1:0] SXExp;
|
|
|
|
logic [`NE+1:0] SExp;
|
2022-07-21 19:38:06 +00:00
|
|
|
logic [`NE+1:0] DExp;
|
|
|
|
|
|
|
|
if (`FPSIZES == 1) begin
|
|
|
|
assign Bias = (`NE-1)'(`BIAS);
|
|
|
|
|
|
|
|
end else if (`FPSIZES == 2) begin
|
|
|
|
assign Bias = Fmt ? (`NE-1)'(`BIAS) : (`NE-1)'(`BIAS1);
|
|
|
|
|
|
|
|
end else if (`FPSIZES == 3) begin
|
|
|
|
always_comb
|
|
|
|
case (Fmt)
|
|
|
|
`FMT: Bias = (`NE-1)'(`BIAS);
|
|
|
|
`FMT1: Bias = (`NE-1)'(`BIAS1);
|
|
|
|
`FMT2: Bias = (`NE-1)'(`BIAS2);
|
|
|
|
default: Bias = 'x;
|
|
|
|
endcase
|
|
|
|
|
|
|
|
end else if (`FPSIZES == 4) begin
|
|
|
|
always_comb
|
|
|
|
case (Fmt)
|
|
|
|
2'h3: Bias = (`NE-1)'(`Q_BIAS);
|
|
|
|
2'h1: Bias = (`NE-1)'(`D_BIAS);
|
|
|
|
2'h0: Bias = (`NE-1)'(`S_BIAS);
|
|
|
|
2'h2: Bias = (`NE-1)'(`H_BIAS);
|
|
|
|
endcase
|
|
|
|
end
|
2022-11-06 22:21:35 +00:00
|
|
|
assign SXExp = {2'b0, Xe} - {{(`NE+1-`DIVBLEN){1'b0}}, L} - (`NE+2)'(`BIAS);
|
2022-07-22 22:02:04 +00:00
|
|
|
assign SExp = {SXExp[`NE+1], SXExp[`NE+1:1]} + {2'b0, Bias};
|
2022-07-21 19:38:06 +00:00
|
|
|
// correct exponent for denormalized input's normalization shifts
|
2022-11-06 22:21:35 +00:00
|
|
|
assign DExp = ({2'b0, Xe} - {{(`NE+1-`DIVBLEN){1'b0}}, L} - {2'b0, Ye} + {{(`NE+1-`DIVBLEN){1'b0}}, m} + {3'b0, Bias}) & {`NE+2{~XZero}};
|
2022-07-21 19:38:06 +00:00
|
|
|
|
2022-07-22 22:02:04 +00:00
|
|
|
assign Qe = Sqrt ? SExp : DExp;
|
2022-07-07 23:01:33 +00:00
|
|
|
endmodule
|