fix size of CVTLEN to support fcvtmod.w.d; add max macro to config-shared.vh

This commit is contained in:
Jordan Carlin 2024-03-14 14:07:15 -07:00
parent efc1d66e1c
commit cbd61d008f
No known key found for this signature in database
2 changed files with 10 additions and 6 deletions

View file

@ -1,3 +1,6 @@
//max function
`define max(a,b) (((a) > (b)) ? (a) : (b))
// constants defining different privilege modes // constants defining different privilege modes
// defined in Table 1.1 of the privileged spec // defined in Table 1.1 of the privileged spec
localparam M_MODE = (2'b11); localparam M_MODE = (2'b11);
@ -107,12 +110,13 @@ localparam DURLEN = $clog2(FPDUR); // enough bi
localparam DIVBLEN = $clog2(DIVb+1); // enough bits to count number of fractional bits + 1 integer bit localparam DIVBLEN = $clog2(DIVb+1); // enough bits to count number of fractional bits + 1 integer bit
// largest length in IEU/FPU // largest length in IEU/FPU
localparam CVTLEN = ((NF<XLEN) ? (XLEN) : (NF)); // max(XLEN, NF) localparam BASECVTLEN = `max(XLEN, NF); // convert length excluding Zfa fcvtmod.w.d
localparam LLEN = (($unsigned(FLEN)<$unsigned(XLEN)) ? ($unsigned(XLEN)) : ($unsigned(FLEN))); localparam CVTLEN = ZFA_SUPPORTED ? `max(BASECVTLEN, 32'd84) : BASECVTLEN; // fcvtmod.w.d needs at least 32+52 because a double with 52 fractional bits might be into upper bits of 32 bit word
localparam LLEN = `max($unsigned(FLEN), $unsigned(XLEN));
localparam LOGCVTLEN = $unsigned($clog2(CVTLEN+1)); localparam LOGCVTLEN = $unsigned($clog2(CVTLEN+1));
localparam NORMSHIFTSZ = (((CVTLEN+NF+1)>(DIVb + 1 +NF+1) & (CVTLEN+NF+1)>(3*NF+6)) ? (CVTLEN+NF+1) : ((DIVb + 1 +NF+1) > (3*NF+6) ? (DIVb + 1 +NF+1) : (3*NF+6))); // max(CVTLEN+NF+1, DIVb + 1 + NF + 1, 3*NF+6) localparam NORMSHIFTSZ = `max(`max((CVTLEN+NF+1), (DIVb + 1 + NF + 1)), (3*NF+6));
localparam LOGNORMSHIFTSZ = ($clog2(NORMSHIFTSZ)); localparam LOGNORMSHIFTSZ = ($clog2(NORMSHIFTSZ));
localparam CORRSHIFTSZ = (NORMSHIFTSZ-2 > (DIVMINb + 1 + NF)) ? NORMSHIFTSZ-2 : (DIVMINb+1+NF); // max(NORMSHIFTSZ-2, DIVMINb + 1 + NF) localparam CORRSHIFTSZ = `max((NORMSHIFTSZ-2), (DIVMINb + 1 + NF));
// Disable spurious Verilator warnings // Disable spurious Verilator warnings

View file

@ -305,7 +305,7 @@ module specialcase import cvw::*; #(parameter cvw_t P) (
// signed | 2^31-1 | 2^63-1 | // signed | 2^31-1 | 2^63-1 |
// unsigned | 2^32-1 | 2^64-1 | // unsigned | 2^32-1 | 2^64-1 |
// //
// other: 32 bit unsinged res should be sign extended as if it were a signed number // other: 32 bit unsigned res should be sign extended as if it were a signed number
if(P.IEEE754) begin if(P.IEEE754) begin
always_comb always_comb
@ -343,7 +343,7 @@ module specialcase import cvw::*; #(parameter cvw_t P) (
else OfIntRes2 = OfIntRes; else OfIntRes2 = OfIntRes;
if (Zfa) Int64Res = {{(P.XLEN-32){CvtNegRes[P.XLEN-1]}}, CvtNegRes[31:0]}; if (Zfa) Int64Res = {{(P.XLEN-32){CvtNegRes[P.XLEN-1]}}, CvtNegRes[31:0]};
else Int64Res = CvtNegRes[P.XLEN-1:0]; else Int64Res = CvtNegRes[P.XLEN-1:0];
if (Zfa) SelCvtOfRes = InfIn | NaNIn | (CvtCe > 32 + 52); // fcvtmod.w.d only overflows to 0 on NaN or Infinity, or if the shift is so large that only zeros are left if (Zfa) SelCvtOfRes = InfIn | NaNIn | (CvtCe > 32 + 52); // fcvtmod.w.d only overflows to 0 on NaN or Infinity, or if the shift is so large that only zeros are left
else SelCvtOfRes = IntInvalid; // regular fcvt gives an overflow if out of range else SelCvtOfRes = IntInvalid; // regular fcvt gives an overflow if out of range
end end
else else