2023-04-12 03:16:20 +00:00
|
|
|
///////////////////////////////////////////
|
2022-07-07 23:01:33 +00:00
|
|
|
//
|
|
|
|
// Written: me@KatherineParry.com
|
|
|
|
// Modified: 7/5/2022
|
2023-04-02 23:16:23 +00:00
|
|
|
// Modified: 4/2/2023
|
2022-07-07 23:01:33 +00:00
|
|
|
//
|
|
|
|
// Purpose: Testbench for Testfloat
|
|
|
|
//
|
|
|
|
// A component of the Wally configurable RISC-V project.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2021 Harvey Mudd College & Oklahoma State University
|
|
|
|
//
|
2023-02-04 16:19:20 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
|
2022-07-07 23:01:33 +00:00
|
|
|
//
|
2023-02-04 16:19:20 +00:00
|
|
|
// Licensed under the Solderpad Hardware License v 2.1 (the “License”); you may not use this file
|
|
|
|
// except in compliance with the License, or, at your option, the Apache License version 2.0. You
|
|
|
|
// may obtain a copy of the License at
|
2022-07-07 23:01:33 +00:00
|
|
|
//
|
2023-02-04 16:19:20 +00:00
|
|
|
// https://solderpad.org/licenses/SHL-2.1/
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, any work distributed under the
|
|
|
|
// License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
|
|
// either express or implied. See the License for the specific language governing permissions
|
|
|
|
// and limitations under the License.
|
2022-07-07 23:01:33 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2022-05-19 16:32:30 +00:00
|
|
|
`include "wally-config.vh"
|
|
|
|
`include "tests-fp.vh"
|
|
|
|
|
|
|
|
module testbenchfp;
|
|
|
|
parameter TEST="none";
|
|
|
|
|
2023-04-12 03:16:20 +00:00
|
|
|
string Tests[]; // list of tests to be run
|
|
|
|
logic [2:0] OpCtrl[]; // list of op controls
|
|
|
|
logic [2:0] Unit[]; // list of units being tested
|
|
|
|
logic WriteInt[]; // Is being written to integer resgiter
|
2023-04-02 23:16:23 +00:00
|
|
|
logic [2:0] Frm[4:0] = {3'b100, 3'b010, 3'b011, 3'b001, 3'b000}; // rounding modes: rne-000, rz-001, ru-011, rd-010, rnm-100
|
2023-04-12 03:16:20 +00:00
|
|
|
logic [1:0] Fmt[]; // list of formats for the other units
|
2022-05-19 16:32:30 +00:00
|
|
|
|
2023-04-02 23:16:23 +00:00
|
|
|
logic clk=0;
|
2023-04-12 03:16:20 +00:00
|
|
|
logic [31:0] TestNum=0; // index for the test
|
|
|
|
logic [31:0] OpCtrlNum=0; // index for OpCtrl
|
|
|
|
logic [31:0] errors=0; // how many errors
|
|
|
|
logic [31:0] VectorNum=0; // index for test vector
|
|
|
|
logic [31:0] FrmNum=0; // index for rounding mode
|
2023-04-02 23:16:23 +00:00
|
|
|
logic [`FLEN*4+7:0] TestVectors[8388609:0]; // list of test vectors
|
2022-05-20 17:19:50 +00:00
|
|
|
|
2023-04-12 03:16:20 +00:00
|
|
|
logic [1:0] FmtVal; // value of the current Fmt
|
2023-04-02 23:16:23 +00:00
|
|
|
logic [2:0] UnitVal, OpCtrlVal, FrmVal; // value of the currnet Unit/OpCtrl/FrmVal
|
|
|
|
logic WriteIntVal; // value of the current WriteInt
|
|
|
|
logic [`FLEN-1:0] X, Y, Z; // inputs read from TestFloat
|
2023-04-12 03:16:20 +00:00
|
|
|
logic [`FLEN-1:0] XPostBox; // inputs read from TestFloat
|
2023-04-02 23:16:23 +00:00
|
|
|
logic [`XLEN-1:0] SrcA; // integer input
|
|
|
|
logic [`FLEN-1:0] Ans; // correct answer from TestFloat
|
|
|
|
logic [`FLEN-1:0] Res; // result from other units
|
|
|
|
logic [4:0] AnsFlg; // correct flags read from testfloat
|
|
|
|
logic [4:0] ResFlg, Flg; // Result flags
|
|
|
|
logic [`FMTBITS-1:0] ModFmt; // format - 10 = half, 00 = single, 01 = double, 11 = quad
|
|
|
|
logic [`FLEN-1:0] FpRes, FpCmpRes; // Results from each unit
|
|
|
|
logic [`XLEN-1:0] IntRes, CmpRes; // Results from each unit
|
|
|
|
logic [4:0] FmaFlg, CvtFlg, DivFlg, CmpFlg; // Outputed flags
|
|
|
|
logic AnsNaN, ResNaN, NaNGood;
|
|
|
|
logic Xs, Ys, Zs; // sign of the inputs
|
|
|
|
logic [`NE-1:0] Xe, Ye, Ze; // exponent of the inputs
|
|
|
|
logic [`NF:0] Xm, Ym, Zm; // mantissas of the inputs
|
|
|
|
logic XNaN, YNaN, ZNaN; // is the input NaN
|
|
|
|
logic XSNaN, YSNaN, ZSNaN; // is the input a signaling NaN
|
2023-04-12 03:16:20 +00:00
|
|
|
logic XSubnorm, ZSubnorm; // is the input denormalized
|
2023-04-02 23:16:23 +00:00
|
|
|
logic XInf, YInf, ZInf; // is the input infinity
|
|
|
|
logic XZero, YZero, ZZero; // is the input zero
|
|
|
|
logic XExpMax, YExpMax, ZExpMax; // is the input's exponent all ones
|
|
|
|
logic [`CVTLEN-1:0] CvtLzcInE; // input to the Leading Zero Counter (priority encoder)
|
|
|
|
logic IntZero;
|
|
|
|
logic CvtResSgnE;
|
2023-04-12 03:16:20 +00:00
|
|
|
logic [`NE:0] CvtCalcExpE; // the calculated expoent
|
|
|
|
logic [`LOGCVTLEN-1:0] CvtShiftAmtE; // how much to shift by
|
2023-04-02 23:16:23 +00:00
|
|
|
logic [`DIVb:0] Quot;
|
|
|
|
logic CvtResSubnormUfE;
|
|
|
|
logic DivStart, FDivBusyE, OldFDivBusyE;
|
|
|
|
logic reset = 1'b0;
|
|
|
|
logic [$clog2(`NF+2)-1:0] XZeroCnt, YZeroCnt;
|
|
|
|
logic [`DURLEN-1:0] Dur;
|
2022-05-20 17:19:50 +00:00
|
|
|
|
|
|
|
// in-between FMA signals
|
2023-04-02 23:16:23 +00:00
|
|
|
logic Mult;
|
|
|
|
logic Ss;
|
|
|
|
logic [`NE+1:0] Pe;
|
|
|
|
logic [`NE+1:0] Se;
|
|
|
|
logic ASticky;
|
|
|
|
logic KillProd;
|
|
|
|
logic [$clog2(3*`NF+5)-1:0] SCnt;
|
|
|
|
logic [3*`NF+3:0] Sm;
|
|
|
|
logic InvA;
|
|
|
|
logic NegSum;
|
|
|
|
logic As;
|
|
|
|
logic Ps;
|
|
|
|
logic DivSticky;
|
|
|
|
logic DivDone;
|
|
|
|
logic DivNegSticky;
|
|
|
|
logic [`NE+1:0] DivCalcExp;
|
|
|
|
logic divsqrtop;
|
2022-05-19 16:32:30 +00:00
|
|
|
|
2023-04-12 03:16:20 +00:00
|
|
|
// Missing logic vectors fdivsqrt
|
|
|
|
logic [2:0] Funct3E;
|
|
|
|
logic [2:0] Funct3M;
|
|
|
|
logic FlushE;
|
|
|
|
logic IFDivStartE, FDivDoneE;
|
|
|
|
logic [`NE+1:0] QeM;
|
|
|
|
logic [`DIVb:0] QmM;
|
|
|
|
logic [`XLEN-1:0] FIntDivResultM;
|
|
|
|
|
2022-05-19 16:32:30 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ||||||||| |||||||| ||||||| ||||||||| ||||||| |||||||| |||
|
|
|
|
// ||| ||| ||| ||| ||| ||| |||
|
|
|
|
// ||| |||||||| ||||||| ||| ||||||| |||||||| |||
|
|
|
|
// ||| ||| ||| ||| ||| ||| |||
|
|
|
|
// ||| |||||||| ||||||| ||| ||||||| |||||||| |||||||||
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// select tests relevent to the specified configuration
|
|
|
|
// cvtint - test integer conversion unit (fcvtint)
|
|
|
|
// cvtfp - test floating-point conversion unit (fcvtfp)
|
|
|
|
// cmp - test comparison unit's LT, LE, EQ opperations (fcmp)
|
|
|
|
// add - test addition
|
|
|
|
// sub - test subtraction
|
|
|
|
// div - test division
|
|
|
|
// sqrt - test square root
|
|
|
|
// all - test all of the above
|
|
|
|
initial begin
|
|
|
|
$display("TEST is %s", TEST);
|
|
|
|
if (`Q_SUPPORTED) begin // if Quad percision is supported
|
|
|
|
if (TEST === "cvtint"| TEST === "all") begin // if testing integer conversion
|
2023-04-02 23:16:23 +00:00
|
|
|
// add the 128-bit cvtint tests to the to-be-tested list
|
|
|
|
Tests = {Tests, f128rv32cvtint};
|
|
|
|
// add the op-codes for these tests to the op-code list
|
|
|
|
OpCtrl = {OpCtrl, `FROM_UI_OPCTRL, `FROM_I_OPCTRL, `TO_UI_OPCTRL, `TO_I_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0, 1'b1, 1'b1};
|
|
|
|
// add what unit is used and the fmt to their lists (one for each test)
|
|
|
|
for(int i = 0; i<20; i++) begin
|
|
|
|
Unit = {Unit, `CVTINTUNIT};
|
|
|
|
Fmt = {Fmt, 2'b11};
|
|
|
|
end
|
|
|
|
if (`XLEN == 64) begin // if 64-bit integers are supported add their conversions
|
|
|
|
Tests = {Tests, f128rv64cvtint};
|
|
|
|
// add the op-codes for these tests to the op-code list
|
|
|
|
OpCtrl = {OpCtrl, `FROM_UL_OPCTRL, `FROM_L_OPCTRL, `TO_UL_OPCTRL, `TO_L_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0, 1'b1, 1'b1};
|
|
|
|
// add what unit is used and the fmt to their lists (one for each test)
|
|
|
|
for(int i = 0; i<20; i++) begin
|
|
|
|
Unit = {Unit, `CVTINTUNIT};
|
|
|
|
Fmt = {Fmt, 2'b11};
|
|
|
|
end
|
|
|
|
end
|
2023-04-12 03:16:20 +00:00
|
|
|
end
|
|
|
|
// if the floating-point conversions are being tested
|
|
|
|
if (TEST === "cvtfp" | TEST === "all") begin
|
2022-05-19 16:32:30 +00:00
|
|
|
if(`D_SUPPORTED) begin // if double precision is supported
|
|
|
|
// add the 128 <-> 64 bit conversions to the to-be-tested list
|
|
|
|
Tests = {Tests, f128f64cvt};
|
|
|
|
// add the op-ctrls (i.e. the format of the result)
|
|
|
|
OpCtrl = {OpCtrl, 3'b01, 3'b11};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
// add the unit being tested and fmt (input format)
|
2022-05-25 23:02:02 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
2022-05-19 16:32:30 +00:00
|
|
|
Unit = {Unit, `CVTFPUNIT};
|
|
|
|
Fmt = {Fmt, 2'b11};
|
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `CVTFPUNIT};
|
|
|
|
Fmt = {Fmt, 2'b01};
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
if(`F_SUPPORTED) begin // if single precision is supported
|
|
|
|
// add the 128 <-> 32 bit conversions to the to-be-tested list
|
|
|
|
Tests = {Tests, f128f32cvt};
|
|
|
|
// add the op-ctrls (i.e. the format of the result)
|
|
|
|
OpCtrl = {OpCtrl, 3'b00, 3'b11};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
// add the unit being tested and fmt (input format)
|
2022-05-25 23:02:02 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
2022-05-19 16:32:30 +00:00
|
|
|
Unit = {Unit, `CVTFPUNIT};
|
|
|
|
Fmt = {Fmt, 2'b11};
|
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `CVTFPUNIT};
|
|
|
|
Fmt = {Fmt, 2'b00};
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
if(`ZFH_SUPPORTED) begin // if half precision is supported
|
|
|
|
// add the 128 <-> 16 bit conversions to the to-be-tested list
|
|
|
|
Tests = {Tests, f128f16cvt};
|
|
|
|
// add the op-ctrls (i.e. the format of the result)
|
|
|
|
OpCtrl = {OpCtrl, 3'b10, 3'b11};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
// add the unit being tested and fmt (input format)
|
2022-05-25 23:02:02 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
2022-05-19 16:32:30 +00:00
|
|
|
Unit = {Unit, `CVTFPUNIT};
|
|
|
|
Fmt = {Fmt, 2'b11};
|
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `CVTFPUNIT};
|
|
|
|
Fmt = {Fmt, 2'b10};
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if (TEST === "cmp" | TEST === "all") begin// if comparisons are being tested
|
|
|
|
// add the compare tests/op-ctrls/unit/fmt
|
|
|
|
Tests = {Tests, f128cmp};
|
|
|
|
OpCtrl = {OpCtrl, `EQ_OPCTRL, `LE_OPCTRL, `LT_OPCTRL};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
for(int i = 0; i<15; i++) begin
|
|
|
|
Unit = {Unit, `CMPUNIT};
|
|
|
|
Fmt = {Fmt, 2'b11};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (TEST === "add" | TEST === "all") begin // if addition is being tested
|
|
|
|
// add the addition tests/op-ctrls/unit/fmt
|
|
|
|
Tests = {Tests, f128add};
|
|
|
|
OpCtrl = {OpCtrl, `ADD_OPCTRL};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `FMAUNIT};
|
|
|
|
Fmt = {Fmt, 2'b11};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (TEST === "sub" | TEST === "all") begin // if subtraction is being tested
|
|
|
|
// add the subtraction tests/op-ctrls/unit/fmt
|
|
|
|
Tests = {Tests, f128sub};
|
|
|
|
OpCtrl = {OpCtrl, `SUB_OPCTRL};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `FMAUNIT};
|
|
|
|
Fmt = {Fmt, 2'b11};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (TEST === "mul" | TEST === "all") begin // if multiplication is being tested
|
|
|
|
// add the multiply tests/op-ctrls/unit/fmt
|
|
|
|
Tests = {Tests, f128mul};
|
|
|
|
OpCtrl = {OpCtrl, `MUL_OPCTRL};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `FMAUNIT};
|
|
|
|
Fmt = {Fmt, 2'b11};
|
|
|
|
end
|
|
|
|
end
|
2022-06-23 00:07:34 +00:00
|
|
|
if (TEST === "div" | TEST === "all") begin // if division is being tested
|
|
|
|
// add the divide tests/op-ctrls/unit/fmt
|
|
|
|
Tests = {Tests, f128div};
|
|
|
|
OpCtrl = {OpCtrl, `DIV_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0};
|
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `DIVUNIT};
|
|
|
|
Fmt = {Fmt, 2'b11};
|
|
|
|
end
|
|
|
|
end
|
2022-07-22 22:02:04 +00:00
|
|
|
if (TEST === "sqrt" | TEST === "all") begin // if square-root is being tested
|
|
|
|
// add the square-root tests/op-ctrls/unit/fmt
|
|
|
|
Tests = {Tests, f128sqrt};
|
|
|
|
OpCtrl = {OpCtrl, `SQRT_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0};
|
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `DIVUNIT};
|
|
|
|
Fmt = {Fmt, 2'b11};
|
|
|
|
end
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
if (TEST === "fma" | TEST === "all") begin // if fused-mutliply-add is being tested
|
2022-06-13 22:47:51 +00:00
|
|
|
Tests = {Tests, f128fma};
|
|
|
|
OpCtrl = {OpCtrl, `FMA_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0};
|
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `FMAUNIT};
|
|
|
|
Fmt = {Fmt, 2'b11};
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if (`D_SUPPORTED) begin // if double precision is supported
|
|
|
|
if (TEST === "cvtint"| TEST === "all") begin // if integer conversion is being tested
|
2023-04-02 23:16:23 +00:00
|
|
|
Tests = {Tests, f64rv32cvtint};
|
|
|
|
// add the op-codes for these tests to the op-code list
|
|
|
|
OpCtrl = {OpCtrl, `FROM_UI_OPCTRL, `FROM_I_OPCTRL, `TO_UI_OPCTRL, `TO_I_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0, 1'b1, 1'b1};
|
|
|
|
// add what unit is used and the fmt to their lists (one for each test)
|
|
|
|
for(int i = 0; i<20; i++) begin
|
|
|
|
Unit = {Unit, `CVTINTUNIT};
|
|
|
|
Fmt = {Fmt, 2'b01};
|
|
|
|
end
|
|
|
|
if (`XLEN == 64) begin // if 64-bit integers are being supported
|
|
|
|
Tests = {Tests, f64rv64cvtint};
|
|
|
|
// add the op-codes for these tests to the op-code list
|
|
|
|
OpCtrl = {OpCtrl, `FROM_UL_OPCTRL, `FROM_L_OPCTRL, `TO_UL_OPCTRL, `TO_L_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0, 1'b1, 1'b1};
|
|
|
|
// add what unit is used and the fmt to their lists (one for each test)
|
|
|
|
for(int i = 0; i<20; i++) begin
|
|
|
|
Unit = {Unit, `CVTINTUNIT};
|
|
|
|
Fmt = {Fmt, 2'b01};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
if (TEST === "cvtfp" | TEST === "all") begin // if floating point conversions are being tested
|
|
|
|
if(`F_SUPPORTED) begin // if single precision is supported
|
|
|
|
// add the 64 <-> 32 bit conversions to the to-be-tested list
|
|
|
|
Tests = {Tests, f64f32cvt};
|
|
|
|
// add the op-ctrls (i.e. the format of the result)
|
|
|
|
OpCtrl = {OpCtrl, 3'b00, 3'b01};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
// add the unit being tested and fmt (input format)
|
2022-05-25 23:02:02 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
2022-05-19 16:32:30 +00:00
|
|
|
Unit = {Unit, `CVTFPUNIT};
|
|
|
|
Fmt = {Fmt, 2'b01};
|
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `CVTFPUNIT};
|
|
|
|
Fmt = {Fmt, 2'b00};
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
if(`ZFH_SUPPORTED) begin // if half precision is supported
|
|
|
|
// add the 64 <-> 16 bit conversions to the to-be-tested list
|
|
|
|
Tests = {Tests, f64f16cvt};
|
|
|
|
// add the op-ctrls (i.e. the format of the result)
|
|
|
|
OpCtrl = {OpCtrl, 3'b10, 3'b01};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
// add the unit being tested and fmt (input format)
|
2022-05-25 23:02:02 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
2022-05-19 16:32:30 +00:00
|
|
|
Unit = {Unit, `CVTFPUNIT};
|
|
|
|
Fmt = {Fmt, 2'b01};
|
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `CVTFPUNIT};
|
|
|
|
Fmt = {Fmt, 2'b10};
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if (TEST === "cmp" | TEST === "all") begin // if comparisions are being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
|
|
|
Tests = {Tests, f64cmp};
|
|
|
|
OpCtrl = {OpCtrl, `EQ_OPCTRL, `LE_OPCTRL, `LT_OPCTRL};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
for(int i = 0; i<15; i++) begin
|
|
|
|
Unit = {Unit, `CMPUNIT};
|
|
|
|
Fmt = {Fmt, 2'b01};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (TEST === "add" | TEST === "all") begin // if addition is being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
|
|
|
Tests = {Tests, f64add};
|
|
|
|
OpCtrl = {OpCtrl, `ADD_OPCTRL};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `FMAUNIT};
|
|
|
|
Fmt = {Fmt, 2'b01};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (TEST === "sub" | TEST === "all") begin // if subtration is being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
|
|
|
Tests = {Tests, f64sub};
|
|
|
|
OpCtrl = {OpCtrl, `SUB_OPCTRL};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `FMAUNIT};
|
|
|
|
Fmt = {Fmt, 2'b01};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (TEST === "mul" | TEST === "all") begin // if multiplication is being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
|
|
|
Tests = {Tests, f64mul};
|
|
|
|
OpCtrl = {OpCtrl, `MUL_OPCTRL};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `FMAUNIT};
|
|
|
|
Fmt = {Fmt, 2'b01};
|
|
|
|
end
|
|
|
|
end
|
2022-06-23 00:07:34 +00:00
|
|
|
if (TEST === "div" | TEST === "all") begin // if division is being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
|
|
|
Tests = {Tests, f64div};
|
|
|
|
OpCtrl = {OpCtrl, `DIV_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0};
|
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `DIVUNIT};
|
|
|
|
Fmt = {Fmt, 2'b01};
|
|
|
|
end
|
|
|
|
end
|
2022-07-22 22:02:04 +00:00
|
|
|
if (TEST === "sqrt" | TEST === "all") begin // if square-root is being tessted
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
|
|
|
Tests = {Tests, f64sqrt};
|
|
|
|
OpCtrl = {OpCtrl, `SQRT_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0};
|
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `DIVUNIT};
|
|
|
|
Fmt = {Fmt, 2'b01};
|
|
|
|
end
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
if (TEST === "fma" | TEST === "all") begin // if the fused multiply add is being tested
|
2022-06-13 22:47:51 +00:00
|
|
|
Tests = {Tests, f64fma};
|
|
|
|
OpCtrl = {OpCtrl, `FMA_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0};
|
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `FMAUNIT};
|
|
|
|
Fmt = {Fmt, 2'b01};
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if (`F_SUPPORTED) begin // if single precision being supported
|
|
|
|
if (TEST === "cvtint"| TEST === "all") begin // if integer conversion is being tested
|
2023-04-02 23:16:23 +00:00
|
|
|
Tests = {Tests, f32rv32cvtint};
|
|
|
|
// add the op-codes for these tests to the op-code list
|
|
|
|
OpCtrl = {OpCtrl, `FROM_UI_OPCTRL, `FROM_I_OPCTRL, `TO_UI_OPCTRL, `TO_I_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0, 1'b1, 1'b1};
|
|
|
|
// add what unit is used and the fmt to their lists (one for each test)
|
|
|
|
for(int i = 0; i<20; i++) begin
|
|
|
|
Unit = {Unit, `CVTINTUNIT};
|
|
|
|
Fmt = {Fmt, 2'b00};
|
|
|
|
end
|
|
|
|
if (`XLEN == 64) begin // if 64-bit integers are supported
|
|
|
|
Tests = {Tests, f32rv64cvtint};
|
|
|
|
// add the op-codes for these tests to the op-code list
|
|
|
|
OpCtrl = {OpCtrl, `FROM_UL_OPCTRL, `FROM_L_OPCTRL, `TO_UL_OPCTRL, `TO_L_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0, 1'b1, 1'b1};
|
|
|
|
// add what unit is used and the fmt to their lists (one for each test)
|
|
|
|
for(int i = 0; i<20; i++) begin
|
|
|
|
Unit = {Unit, `CVTINTUNIT};
|
|
|
|
Fmt = {Fmt, 2'b00};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
if (TEST === "cvtfp" | TEST === "all") begin // if floating point conversion is being tested
|
|
|
|
if(`ZFH_SUPPORTED) begin
|
|
|
|
// add the 32 <-> 16 bit conversions to the to-be-tested list
|
|
|
|
Tests = {Tests, f32f16cvt};
|
|
|
|
// add the op-ctrls (i.e. the format of the result)
|
|
|
|
OpCtrl = {OpCtrl, 3'b10, 3'b00};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
// add the unit being tested and fmt (input format)
|
2022-05-25 23:02:02 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
2022-05-19 16:32:30 +00:00
|
|
|
Unit = {Unit, `CVTFPUNIT};
|
|
|
|
Fmt = {Fmt, 2'b00};
|
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `CVTFPUNIT};
|
|
|
|
Fmt = {Fmt, 2'b10};
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if (TEST === "cmp" | TEST === "all") begin // if comparision is being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
|
|
|
Tests = {Tests, f32cmp};
|
|
|
|
OpCtrl = {OpCtrl, `EQ_OPCTRL, `LE_OPCTRL, `LT_OPCTRL};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
for(int i = 0; i<15; i++) begin
|
|
|
|
Unit = {Unit, `CMPUNIT};
|
|
|
|
Fmt = {Fmt, 2'b00};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (TEST === "add" | TEST === "all") begin // if addition is being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
|
|
|
Tests = {Tests, f32add};
|
|
|
|
OpCtrl = {OpCtrl, `ADD_OPCTRL};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `FMAUNIT};
|
|
|
|
Fmt = {Fmt, 2'b00};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (TEST === "sub" | TEST === "all") begin // if subtration is being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
|
|
|
Tests = {Tests, f32sub};
|
|
|
|
OpCtrl = {OpCtrl, `SUB_OPCTRL};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `FMAUNIT};
|
|
|
|
Fmt = {Fmt, 2'b00};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (TEST === "mul" | TEST === "all") begin // if multiply is being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
|
|
|
Tests = {Tests, f32mul};
|
|
|
|
OpCtrl = {OpCtrl, `MUL_OPCTRL};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `FMAUNIT};
|
|
|
|
Fmt = {Fmt, 2'b00};
|
|
|
|
end
|
|
|
|
end
|
2022-06-23 00:07:34 +00:00
|
|
|
if (TEST === "div" | TEST === "all") begin // if division is being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
|
|
|
Tests = {Tests, f32div};
|
|
|
|
OpCtrl = {OpCtrl, `DIV_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0};
|
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `DIVUNIT};
|
|
|
|
Fmt = {Fmt, 2'b00};
|
|
|
|
end
|
|
|
|
end
|
2022-07-22 22:02:04 +00:00
|
|
|
if (TEST === "sqrt" | TEST === "all") begin // if sqrt is being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
|
|
|
Tests = {Tests, f32sqrt};
|
|
|
|
OpCtrl = {OpCtrl, `SQRT_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0};
|
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `DIVUNIT};
|
|
|
|
Fmt = {Fmt, 2'b00};
|
|
|
|
end
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
if (TEST === "fma" | TEST === "all") begin // if fma is being tested
|
2022-06-13 22:47:51 +00:00
|
|
|
Tests = {Tests, f32fma};
|
|
|
|
OpCtrl = {OpCtrl, `FMA_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0};
|
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `FMAUNIT};
|
|
|
|
Fmt = {Fmt, 2'b00};
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if (`ZFH_SUPPORTED) begin // if half precision supported
|
|
|
|
if (TEST === "cvtint"| TEST === "all") begin // if in conversions are being tested
|
2023-04-02 23:16:23 +00:00
|
|
|
Tests = {Tests, f16rv32cvtint};
|
|
|
|
// add the op-codes for these tests to the op-code list
|
|
|
|
OpCtrl = {OpCtrl, `FROM_UI_OPCTRL, `FROM_I_OPCTRL, `TO_UI_OPCTRL, `TO_I_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0, 1'b1, 1'b1};
|
|
|
|
// add what unit is used and the fmt to their lists (one for each test)
|
|
|
|
for(int i = 0; i<20; i++) begin
|
|
|
|
Unit = {Unit, `CVTINTUNIT};
|
|
|
|
Fmt = {Fmt, 2'b10};
|
|
|
|
end
|
|
|
|
if (`XLEN == 64) begin // if 64-bit integers are supported
|
|
|
|
Tests = {Tests, f16rv64cvtint};
|
|
|
|
// add the op-codes for these tests to the op-code list
|
|
|
|
OpCtrl = {OpCtrl, `FROM_UL_OPCTRL, `FROM_L_OPCTRL, `TO_UL_OPCTRL, `TO_L_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0, 1'b1, 1'b1};
|
|
|
|
// add what unit is used and the fmt to their lists (one for each test)
|
|
|
|
for(int i = 0; i<20; i++) begin
|
|
|
|
Unit = {Unit, `CVTINTUNIT};
|
|
|
|
Fmt = {Fmt, 2'b10};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
if (TEST === "cmp" | TEST === "all") begin // if comparisions are being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
|
|
|
Tests = {Tests, f16cmp};
|
|
|
|
OpCtrl = {OpCtrl, `EQ_OPCTRL, `LE_OPCTRL, `LT_OPCTRL};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0, 1'b0, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
for(int i = 0; i<15; i++) begin
|
|
|
|
Unit = {Unit, `CMPUNIT};
|
|
|
|
Fmt = {Fmt, 2'b10};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (TEST === "add" | TEST === "all") begin // if addition is being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
|
|
|
Tests = {Tests, f16add};
|
|
|
|
OpCtrl = {OpCtrl, `ADD_OPCTRL};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `FMAUNIT};
|
|
|
|
Fmt = {Fmt, 2'b10};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (TEST === "sub" | TEST === "all") begin // if subtraction is being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
|
|
|
Tests = {Tests, f16sub};
|
|
|
|
OpCtrl = {OpCtrl, `SUB_OPCTRL};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `FMAUNIT};
|
|
|
|
Fmt = {Fmt, 2'b10};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (TEST === "mul" | TEST === "all") begin // if multiplication is being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
|
|
|
Tests = {Tests, f16mul};
|
|
|
|
OpCtrl = {OpCtrl, `MUL_OPCTRL};
|
2022-05-25 23:02:02 +00:00
|
|
|
WriteInt = {WriteInt, 1'b0};
|
2022-05-19 16:32:30 +00:00
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `FMAUNIT};
|
|
|
|
Fmt = {Fmt, 2'b10};
|
|
|
|
end
|
|
|
|
end
|
2022-06-23 00:07:34 +00:00
|
|
|
if (TEST === "div" | TEST === "all") begin // if division is being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
2023-04-12 03:16:20 +00:00
|
|
|
Tests = {Tests, f16div};
|
2022-06-23 00:07:34 +00:00
|
|
|
OpCtrl = {OpCtrl, `DIV_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0};
|
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `DIVUNIT};
|
|
|
|
Fmt = {Fmt, 2'b10};
|
2023-04-12 03:16:20 +00:00
|
|
|
end
|
2022-06-23 00:07:34 +00:00
|
|
|
end
|
2022-07-22 22:02:04 +00:00
|
|
|
if (TEST === "sqrt" | TEST === "all") begin // if sqrt is being tested
|
|
|
|
// add the correct tests/op-ctrls/unit/fmt to their lists
|
2023-04-12 03:16:20 +00:00
|
|
|
Tests = {Tests, f16sqrt};
|
2022-07-22 22:02:04 +00:00
|
|
|
OpCtrl = {OpCtrl, `SQRT_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0};
|
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `DIVUNIT};
|
|
|
|
Fmt = {Fmt, 2'b10};
|
2023-04-12 03:16:20 +00:00
|
|
|
end
|
2022-07-22 22:02:04 +00:00
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
if (TEST === "fma" | TEST === "all") begin // if fma is being tested
|
2022-06-13 22:47:51 +00:00
|
|
|
Tests = {Tests, f16fma};
|
|
|
|
OpCtrl = {OpCtrl, `FMA_OPCTRL};
|
|
|
|
WriteInt = {WriteInt, 1'b0};
|
|
|
|
for(int i = 0; i<5; i++) begin
|
|
|
|
Unit = {Unit, `FMAUNIT};
|
|
|
|
Fmt = {Fmt, 2'b10};
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
// check if nothing is being tested
|
2022-06-13 22:47:51 +00:00
|
|
|
if (Tests.size() == 0) begin
|
2022-05-19 16:32:30 +00:00
|
|
|
$display("TEST %s not supported in this configuration", TEST);
|
|
|
|
$stop;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ||||||||| |||||||| ||||||||| ||||||| ||||||||| |||||||| ||||||| |||||||||
|
|
|
|
// ||| ||| ||| ||| ||| || || ||| ||| ||| |||
|
|
|
|
// |||||||| |||||||| ||||||||| || || ||| |||||||| ||||||| |||
|
|
|
|
// ||| || ||| ||| ||| || || ||| ||| ||| |||
|
|
|
|
// ||| ||| |||||||| ||| ||| ||||||| ||| |||||||| ||||||| |||
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Read the first test
|
|
|
|
initial begin
|
|
|
|
$display("\n\nRunning %s vectors", Tests[TestNum]);
|
|
|
|
$readmemh({`PATH, Tests[TestNum]}, TestVectors);
|
|
|
|
// set the test index to 0
|
|
|
|
TestNum = 0;
|
|
|
|
end
|
|
|
|
|
|
|
|
// set a the signals for all tests
|
|
|
|
always_comb UnitVal = Unit[TestNum];
|
|
|
|
always_comb FmtVal = Fmt[TestNum];
|
|
|
|
always_comb OpCtrlVal = OpCtrl[OpCtrlNum];
|
2022-05-25 23:02:02 +00:00
|
|
|
always_comb WriteIntVal = WriteInt[OpCtrlNum];
|
2022-05-19 16:32:30 +00:00
|
|
|
always_comb FrmVal = Frm[FrmNum];
|
|
|
|
|
|
|
|
// modify the format signal if only 2 percisions supported
|
|
|
|
// - 1 for the larger precision
|
|
|
|
// - 0 for the smaller precision
|
|
|
|
always_comb begin
|
2022-06-06 16:06:04 +00:00
|
|
|
if(`FMTBITS == 1) ModFmt = FmtVal == `FMT;
|
|
|
|
else ModFmt = FmtVal;
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
|
2022-05-20 17:19:50 +00:00
|
|
|
// extract the inputs (X, Y, Z, SrcA) and the output (Ans, AnsFlg) from the current test vector
|
2023-04-12 03:16:20 +00:00
|
|
|
readvectors readvectors (.clk, .Fmt(FmtVal), .ModFmt, .TestVector(TestVectors[VectorNum]),
|
|
|
|
.VectorNum, .Ans(Ans), .AnsFlg(AnsFlg), .SrcA,
|
|
|
|
.Xs, .Ys, .Zs, .Unit(UnitVal),
|
|
|
|
.Xe, .Ye, .Ze, .TestNum, .OpCtrl(OpCtrlVal),
|
|
|
|
.Xm, .Ym, .Zm, .DivStart,
|
|
|
|
.XNaN, .YNaN, .ZNaN,
|
|
|
|
.XSNaN, .YSNaN, .ZSNaN,
|
|
|
|
.XSubnorm, .ZSubnorm,
|
|
|
|
.XZero, .YZero, .ZZero,
|
|
|
|
.XInf, .YInf, .ZInf, .XExpMax,
|
|
|
|
.X, .Y, .Z, .XPostBox);
|
2022-05-19 16:32:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ||||||| ||| ||| |||||||||
|
|
|
|
// ||| ||| ||| ||| |||
|
|
|
|
// ||| ||| ||| ||| |||
|
|
|
|
// ||| ||| ||| ||| |||
|
|
|
|
// ||||||| ||||||||| |||
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// instantiate devices under test
|
2023-04-02 23:16:23 +00:00
|
|
|
if (TEST === "fma"| TEST === "mul" | TEST === "add" | TEST === "sub" | TEST === "all") begin : fma
|
2022-08-29 11:04:05 +00:00
|
|
|
fma fma(.Xs(Xs), .Ys(Ys), .Zs(Zs),
|
|
|
|
.Xe(Xe), .Ye(Ye), .Ze(Ze),
|
|
|
|
.Xm(Xm), .Ym(Ym), .Zm(Zm),
|
|
|
|
.XZero, .YZero, .ZZero, .Ss, .Se,
|
2022-12-28 05:24:38 +00:00
|
|
|
.OpCtrl(OpCtrlVal), .Sm, .InvA, .SCnt, .As, .Ps,
|
2022-12-29 21:54:17 +00:00
|
|
|
.ASticky);
|
2022-08-29 11:04:05 +00:00
|
|
|
end
|
2022-06-13 22:47:51 +00:00
|
|
|
|
2022-07-21 01:20:06 +00:00
|
|
|
postprocess postprocess(.Xs(Xs), .Ys(Ys), .PostProcSel(UnitVal[1:0]),
|
2023-01-12 04:02:30 +00:00
|
|
|
.OpCtrl(OpCtrlVal), .DivQm(Quot), .DivQe(DivCalcExp),
|
|
|
|
.Xm(Xm), .Ym(Ym), .Zm(Zm), .CvtCe(CvtCalcExpE), .DivSticky(DivSticky), .FmaSs(Ss),
|
|
|
|
.XNaN(XNaN), .YNaN(YNaN), .ZNaN(ZNaN), .CvtResSubnormUf(CvtResSubnormUfE),
|
|
|
|
.XZero(XZero), .YZero(YZero), .CvtShiftAmt(CvtShiftAmtE),
|
2022-07-08 19:30:43 +00:00
|
|
|
.XInf(XInf), .YInf(YInf), .ZInf(ZInf), .CvtCs(CvtResSgnE), .ToInt(WriteIntVal),
|
|
|
|
.XSNaN(XSNaN), .YSNaN(YSNaN), .ZSNaN(ZSNaN), .CvtLzcIn(CvtLzcInE), .IntZero,
|
2023-01-03 21:55:30 +00:00
|
|
|
.FmaASticky(ASticky), .FmaSe(Se),
|
2022-12-23 23:01:34 +00:00
|
|
|
.FmaSm(Sm), .FmaSCnt(SCnt), .FmaAs(As), .FmaPs(Ps), .Fmt(ModFmt), .Frm(FrmVal),
|
2022-07-12 01:30:21 +00:00
|
|
|
.PostProcFlg(Flg), .PostProcRes(FpRes), .FCvtIntRes(IntRes));
|
2022-05-25 23:02:02 +00:00
|
|
|
|
2022-08-29 11:04:05 +00:00
|
|
|
if (TEST === "cvtfp" | TEST === "cvtint" | TEST === "all") begin : fcvt
|
|
|
|
fcvt fcvt (.Xs(Xs), .Xe(Xe), .Xm(Xm), .Int(SrcA), .ToInt(WriteIntVal),
|
2023-03-28 16:35:19 +00:00
|
|
|
.XZero(XZero), .OpCtrl(OpCtrlVal), .IntZero,
|
2023-01-12 04:02:30 +00:00
|
|
|
.Fmt(ModFmt), .Ce(CvtCalcExpE), .ShiftAmt(CvtShiftAmtE), .ResSubnormUf(CvtResSubnormUfE), .Cs(CvtResSgnE), .LzcIn(CvtLzcInE));
|
2022-08-29 11:04:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if (TEST === "cmp" | TEST === "all") begin: fcmp
|
|
|
|
fcmp fcmp (.Fmt(ModFmt), .OpCtrl(OpCtrlVal), .Xs, .Ys, .Xe, .Ye,
|
|
|
|
.Xm, .Ym, .XZero, .YZero, .CmpIntRes(CmpRes),
|
|
|
|
.XNaN, .YNaN, .XSNaN, .YSNaN, .X, .Y, .CmpNV(CmpFlg[4]), .CmpFpRes(FpCmpRes));
|
|
|
|
end
|
|
|
|
if (TEST === "div" | TEST === "sqrt" | TEST === "all") begin: fdivsqrt
|
2023-04-12 03:16:20 +00:00
|
|
|
fdivsqrt fdivsqrt(.clk, .reset, .XsE(Xs), .FmtE(ModFmt), .XmE(Xm), .YmE(Ym),
|
|
|
|
.XeE(Xe), .YeE(Ye), .SqrtE(OpCtrlVal[0]), .SqrtM(OpCtrlVal[0]),
|
|
|
|
.XInfE(XInf), .YInfE(YInf), .XZeroE(XZero), .YZeroE(YZero),
|
|
|
|
.XNaNE(XNaN), .YNaNE(YNaN),
|
|
|
|
.FDivStartE(DivStart), .IDivStartE(1'b0), .W64E(1'b0),
|
|
|
|
.StallM(1'b0), .DivStickyM(DivSticky), .FDivBusyE, .QeM(DivCalcExp),
|
|
|
|
.QmM(Quot),
|
|
|
|
.FlushE(1'b0), .ForwardedSrcAE('0), .ForwardedSrcBE('0), .Funct3M(Funct3M),
|
|
|
|
.Funct3E(Funct3E), .IntDivE(1'b0), .FIntDivResultM(FIntDivResultM),
|
|
|
|
.FDivDoneE(FDivDoneE), .IFDivStartE(IFDivStartE));
|
2022-08-29 11:04:05 +00:00
|
|
|
end
|
2022-07-07 23:01:33 +00:00
|
|
|
|
2022-05-20 17:19:50 +00:00
|
|
|
assign CmpFlg[3:0] = 0;
|
2022-05-19 16:32:30 +00:00
|
|
|
|
|
|
|
// produce clock
|
|
|
|
always begin
|
|
|
|
clk = 1; #5; clk = 0; #5;
|
|
|
|
end
|
2023-04-12 03:16:20 +00:00
|
|
|
|
|
|
|
// Provide reset for divsqrt to reset state to IDLE
|
|
|
|
// Previous version did not initiate a divide due to missing state
|
|
|
|
// information. This starts the FSM by putting the fdivsqrt into
|
|
|
|
// the IDLE state.
|
|
|
|
initial
|
|
|
|
begin
|
|
|
|
#0 reset = 1'b1;
|
|
|
|
#25 reset = 1'b0;
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ||||| ||| |||||||||| ||||| |||
|
|
|
|
// ||||||| ||| ||| ||| ||||||| |||
|
|
|
|
// |||| ||| ||| |||||||||| |||| ||| |||
|
|
|
|
// |||| ||| ||| ||| ||| |||| ||| |||
|
|
|
|
// |||| ||| ||| ||| ||| |||| ||| |||
|
|
|
|
// |||| |||||| ||| ||| |||| ||||||
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-04-12 03:16:20 +00:00
|
|
|
// Check if the correct answer and result is a NaN
|
2022-05-20 17:19:50 +00:00
|
|
|
always_comb begin
|
2022-05-19 16:32:30 +00:00
|
|
|
if(UnitVal === `CVTINTUNIT | UnitVal === `CMPUNIT) begin
|
2022-05-20 17:19:50 +00:00
|
|
|
// an integer output can't be a NaN
|
2022-05-19 16:32:30 +00:00
|
|
|
AnsNaN = 1'b0;
|
|
|
|
ResNaN = 1'b0;
|
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
else if (UnitVal === `CVTFPUNIT) begin
|
|
|
|
case (OpCtrlVal[1:0])
|
|
|
|
4'b11: begin // quad
|
|
|
|
AnsNaN = &Ans[`Q_LEN-2:`NF]&(|Ans[`Q_NF-1:0]);
|
|
|
|
ResNaN = &Res[`Q_LEN-2:`NF]&(|Res[`Q_NF-1:0]);
|
|
|
|
end
|
|
|
|
4'b01: begin // double
|
|
|
|
AnsNaN = &Ans[`D_LEN-2:`D_NF]&(|Ans[`D_NF-1:0]);
|
|
|
|
ResNaN = &Res[`D_LEN-2:`D_NF]&(|Res[`D_NF-1:0]);
|
|
|
|
end
|
|
|
|
4'b00: begin // single
|
|
|
|
AnsNaN = &Ans[`S_LEN-2:`S_NF]&(|Ans[`S_NF-1:0]);
|
|
|
|
ResNaN = &Res[`S_LEN-2:`S_NF]&(|Res[`S_NF-1:0]);
|
|
|
|
end
|
|
|
|
4'b10: begin // half
|
|
|
|
AnsNaN = &Ans[`H_LEN-2:`H_NF]&(|Ans[`H_NF-1:0]);
|
|
|
|
ResNaN = &Res[`H_LEN-2:`H_NF]&(|Res[`H_NF-1:0]);
|
|
|
|
end
|
|
|
|
endcase
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
else begin
|
|
|
|
case (FmtVal)
|
|
|
|
4'b11: begin // quad
|
2022-05-25 23:02:02 +00:00
|
|
|
AnsNaN = &Ans[`Q_LEN-2:`Q_NF]&(|Ans[`Q_NF-1:0]);
|
|
|
|
ResNaN = &Res[`Q_LEN-2:`Q_NF]&(|Res[`Q_NF-1:0]);
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
4'b01: begin // double
|
2022-05-25 23:02:02 +00:00
|
|
|
AnsNaN = &Ans[`D_LEN-2:`D_NF]&(|Ans[`D_NF-1:0]);
|
|
|
|
ResNaN = &Res[`D_LEN-2:`D_NF]&(|Res[`D_NF-1:0]);
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
4'b00: begin // single
|
2022-05-25 23:02:02 +00:00
|
|
|
AnsNaN = &Ans[`S_LEN-2:`S_NF]&(|Ans[`S_NF-1:0]);
|
|
|
|
ResNaN = &Res[`S_LEN-2:`S_NF]&(|Res[`S_NF-1:0]);
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
4'b10: begin // half
|
|
|
|
AnsNaN = &Ans[`H_LEN-2:`H_NF]&(|Ans[`H_NF-1:0]);
|
2022-05-25 23:02:02 +00:00
|
|
|
ResNaN = &Res[`H_LEN-2:`H_NF]&(|Res[`H_NF-1:0]);
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
endcase
|
|
|
|
end
|
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
always_comb begin
|
2022-05-20 17:19:50 +00:00
|
|
|
// select the result to check
|
2022-05-19 16:32:30 +00:00
|
|
|
case (UnitVal)
|
2022-06-13 22:47:51 +00:00
|
|
|
`FMAUNIT: Res = FpRes;
|
|
|
|
`DIVUNIT: Res = FpRes;
|
2022-05-20 17:19:50 +00:00
|
|
|
`CMPUNIT: Res = CmpRes;
|
2022-06-13 22:47:51 +00:00
|
|
|
`CVTINTUNIT: if(WriteIntVal) Res = IntRes; else Res = FpRes;
|
|
|
|
`CVTFPUNIT: Res = FpRes;
|
2022-05-19 16:32:30 +00:00
|
|
|
endcase
|
2022-05-20 17:19:50 +00:00
|
|
|
|
|
|
|
// select the flag to check
|
2022-05-19 16:32:30 +00:00
|
|
|
case (UnitVal)
|
2022-06-13 22:47:51 +00:00
|
|
|
`FMAUNIT: ResFlg = Flg;
|
|
|
|
`DIVUNIT: ResFlg = Flg;
|
2022-05-20 17:19:50 +00:00
|
|
|
`CMPUNIT: ResFlg = CmpFlg;
|
2022-06-13 22:47:51 +00:00
|
|
|
`CVTINTUNIT: ResFlg = Flg;
|
|
|
|
`CVTFPUNIT: ResFlg = Flg;
|
2022-05-19 16:32:30 +00:00
|
|
|
endcase
|
2022-05-25 23:02:02 +00:00
|
|
|
end
|
2022-08-30 17:55:21 +00:00
|
|
|
|
2022-09-19 04:27:21 +00:00
|
|
|
logic ResMatch, FlagMatch, CheckNow;
|
|
|
|
|
2022-12-28 05:24:38 +00:00
|
|
|
always @(posedge clk)
|
2023-04-12 03:16:20 +00:00
|
|
|
OldFDivBusyE = FDivDoneE;
|
2022-12-28 05:24:38 +00:00
|
|
|
|
2022-08-30 17:55:21 +00:00
|
|
|
// check results on falling edge of clk
|
|
|
|
always @(negedge clk) begin
|
2022-05-25 23:02:02 +00:00
|
|
|
|
2022-05-19 16:32:30 +00:00
|
|
|
|
2022-05-19 20:31:23 +00:00
|
|
|
// check if the NaN value is good. IEEE754-2019 sections 6.3 and 6.2.3 specify:
|
|
|
|
// - the sign of the NaN does not matter for the opperations being tested
|
|
|
|
// - when 2 or more NaNs are inputed the NaN that is propigated doesn't matter
|
2022-05-19 16:32:30 +00:00
|
|
|
if (UnitVal !== `CVTFPUNIT & UnitVal !== `CVTINTUNIT)
|
|
|
|
case (FmtVal)
|
2022-06-06 16:06:04 +00:00
|
|
|
4'b11: NaNGood = (((`IEEE754==0)&AnsNaN&(Res === {1'b0, {`Q_NE+1{1'b1}}, {`Q_NF-1{1'b0}}})) |
|
2022-06-03 15:34:17 +00:00
|
|
|
(AnsFlg[4]&(Res[`Q_LEN-2:0] === {{`Q_NE+1{1'b1}}, {`Q_NF-1{1'b0}}})) |
|
2022-05-19 16:32:30 +00:00
|
|
|
(XNaN&(Res[`Q_LEN-2:0] === {X[`Q_LEN-2:`Q_NF],1'b1,X[`Q_NF-2:0]})) |
|
2022-05-19 20:31:23 +00:00
|
|
|
(YNaN&(Res[`Q_LEN-2:0] === {Y[`Q_LEN-2:`Q_NF],1'b1,Y[`Q_NF-2:0]})) |
|
|
|
|
(ZNaN&(Res[`Q_LEN-2:0] === {Z[`Q_LEN-2:`Q_NF],1'b1,Z[`Q_NF-2:0]})));
|
2022-06-06 16:06:04 +00:00
|
|
|
4'b01: NaNGood = (((`IEEE754==0)&AnsNaN&(Res[`D_LEN-1:0] === {1'b0, {`D_NE+1{1'b1}}, {`D_NF-1{1'b0}}})) |
|
2022-06-03 15:34:17 +00:00
|
|
|
(AnsFlg[4]&(Res[`D_LEN-2:0] === {{`D_NE+1{1'b1}}, {`D_NF-1{1'b0}}})) |
|
2022-05-19 16:32:30 +00:00
|
|
|
(XNaN&(Res[`D_LEN-2:0] === {X[`D_LEN-2:`D_NF],1'b1,X[`D_NF-2:0]})) |
|
2022-05-19 20:31:23 +00:00
|
|
|
(YNaN&(Res[`D_LEN-2:0] === {Y[`D_LEN-2:`D_NF],1'b1,Y[`D_NF-2:0]})) |
|
|
|
|
(ZNaN&(Res[`D_LEN-2:0] === {Z[`D_LEN-2:`D_NF],1'b1,Z[`D_NF-2:0]})));
|
2022-06-06 16:06:04 +00:00
|
|
|
4'b00: NaNGood = (((`IEEE754==0)&AnsNaN&(Res[`S_LEN-1:0] === {1'b0, {`S_NE+1{1'b1}}, {`S_NF-1{1'b0}}})) |
|
2022-06-03 15:34:17 +00:00
|
|
|
(AnsFlg[4]&(Res[`S_LEN-2:0] === {{`S_NE+1{1'b1}}, {`S_NF-1{1'b0}}})) |
|
2022-05-19 16:32:30 +00:00
|
|
|
(XNaN&(Res[`S_LEN-2:0] === {X[`S_LEN-2:`S_NF],1'b1,X[`S_NF-2:0]})) |
|
2022-05-19 20:31:23 +00:00
|
|
|
(YNaN&(Res[`S_LEN-2:0] === {Y[`S_LEN-2:`S_NF],1'b1,Y[`S_NF-2:0]})) |
|
|
|
|
(ZNaN&(Res[`S_LEN-2:0] === {Z[`S_LEN-2:`S_NF],1'b1,Z[`S_NF-2:0]})));
|
2022-06-06 16:06:04 +00:00
|
|
|
4'b10: NaNGood = (((`IEEE754==0)&AnsNaN&(Res[`H_LEN-1:0] === {1'b0, {`H_NE+1{1'b1}}, {`H_NF-1{1'b0}}})) |
|
2022-06-03 15:34:17 +00:00
|
|
|
(AnsFlg[4]&(Res[`H_LEN-2:0] === {{`H_NE+1{1'b1}}, {`H_NF-1{1'b0}}})) |
|
2022-05-19 16:32:30 +00:00
|
|
|
(XNaN&(Res[`H_LEN-2:0] === {X[`H_LEN-2:`H_NF],1'b1,X[`H_NF-2:0]})) |
|
2022-05-19 20:31:23 +00:00
|
|
|
(YNaN&(Res[`H_LEN-2:0] === {Y[`H_LEN-2:`H_NF],1'b1,Y[`H_NF-2:0]})) |
|
|
|
|
(ZNaN&(Res[`H_LEN-2:0] === {Z[`H_LEN-2:`H_NF],1'b1,Z[`H_NF-2:0]})));
|
2022-05-19 16:32:30 +00:00
|
|
|
endcase
|
|
|
|
else if (UnitVal === `CVTFPUNIT) // if converting from floating point to floating point OpCtrl contains the final FP format
|
|
|
|
case (OpCtrlVal[1:0])
|
2022-06-06 16:06:04 +00:00
|
|
|
2'b11: NaNGood = (((`IEEE754==0)&AnsNaN&(Res === {1'b0, {`Q_NE+1{1'b1}}, {`Q_NF-1{1'b0}}})) |
|
2022-06-03 15:34:17 +00:00
|
|
|
(AnsFlg[4]&(Res[`Q_LEN-2:0] === {{`Q_NE+1{1'b1}}, {`Q_NF-1{1'b0}}})) |
|
2022-05-25 23:02:02 +00:00
|
|
|
(AnsNaN&(Res[`Q_LEN-2:0] === Ans[`Q_LEN-2:0])) |
|
2022-05-19 16:32:30 +00:00
|
|
|
(XNaN&(Res[`Q_LEN-2:0] === {X[`Q_LEN-2:`Q_NF],1'b1,X[`Q_NF-2:0]})) |
|
|
|
|
(YNaN&(Res[`Q_LEN-2:0] === {Y[`Q_LEN-2:`Q_NF],1'b1,Y[`Q_NF-2:0]})));
|
2022-06-06 16:06:04 +00:00
|
|
|
2'b01: NaNGood = (((`IEEE754==0)&AnsNaN&(Res[`D_LEN-1:0] === {1'b0, {`D_NE+1{1'b1}}, {`D_NF-1{1'b0}}})) |
|
2022-06-03 15:34:17 +00:00
|
|
|
(AnsFlg[4]&(Res[`D_LEN-2:0] === {{`D_NE+1{1'b1}}, {`D_NF-1{1'b0}}})) |
|
2022-05-25 23:02:02 +00:00
|
|
|
(AnsNaN&(Res[`D_LEN-2:0] === Ans[`D_LEN-2:0])) |
|
2022-05-19 16:32:30 +00:00
|
|
|
(XNaN&(Res[`D_LEN-2:0] === {X[`D_LEN-2:`D_NF],1'b1,X[`D_NF-2:0]})) |
|
|
|
|
(YNaN&(Res[`D_LEN-2:0] === {Y[`D_LEN-2:`D_NF],1'b1,Y[`D_NF-2:0]})));
|
2022-06-06 16:06:04 +00:00
|
|
|
2'b00: NaNGood = (((`IEEE754==0)&AnsNaN&(Res[`S_LEN-1:0] === {1'b0, {`S_NE+1{1'b1}}, {`S_NF-1{1'b0}}})) |
|
2022-06-03 15:34:17 +00:00
|
|
|
(AnsFlg[4]&(Res[`S_LEN-2:0] === {{`S_NE+1{1'b1}}, {`S_NF-1{1'b0}}})) |
|
2022-05-25 23:02:02 +00:00
|
|
|
(AnsNaN&(Res[`S_LEN-2:0] === Ans[`S_LEN-2:0])) |
|
2022-05-19 16:32:30 +00:00
|
|
|
(XNaN&(Res[`S_LEN-2:0] === {X[`S_LEN-2:`S_NF],1'b1,X[`S_NF-2:0]})) |
|
|
|
|
(YNaN&(Res[`S_LEN-2:0] === {Y[`S_LEN-2:`S_NF],1'b1,Y[`S_NF-2:0]})));
|
2022-06-06 16:06:04 +00:00
|
|
|
2'b10: NaNGood = (((`IEEE754==0)&AnsNaN&(Res[`H_LEN-1:0] === {1'b0, {`H_NE+1{1'b1}}, {`H_NF-1{1'b0}}})) |
|
2022-06-03 15:34:17 +00:00
|
|
|
(AnsFlg[4]&(Res[`H_LEN-2:0] === {{`H_NE+1{1'b1}}, {`H_NF-1{1'b0}}})) |
|
2022-05-25 23:02:02 +00:00
|
|
|
(AnsNaN&(Res[`H_LEN-2:0] === Ans[`H_LEN-2:0])) |
|
2022-05-19 16:32:30 +00:00
|
|
|
(XNaN&(Res[`H_LEN-2:0] === {X[`H_LEN-2:`H_NF],1'b1,X[`H_NF-2:0]})) |
|
|
|
|
(YNaN&(Res[`H_LEN-2:0] === {Y[`H_LEN-2:`H_NF],1'b1,Y[`H_NF-2:0]})));
|
|
|
|
endcase
|
2022-05-20 17:19:50 +00:00
|
|
|
else NaNGood = 1'b0; // integers can't be NaNs
|
2022-05-19 16:32:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ||||||| ||| ||| ||||||| ||||||| ||| |||
|
|
|
|
// ||| ||| ||| ||| ||| ||| |||
|
|
|
|
// ||| |||||||||| ||||||| ||| ||||||
|
|
|
|
// ||| ||| ||| ||| ||| ||| |||
|
|
|
|
// ||||||| ||| ||| ||||||| ||||||| ||| |||
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2022-06-27 20:43:55 +00:00
|
|
|
// check if result is correct
|
|
|
|
// - wait till the division result is done or one extra cylcle for early termination (to simulate the EM pipline stage)
|
2022-11-22 22:22:26 +00:00
|
|
|
// if(~((Res === Ans | NaNGood | NaNGood === 1'bx) & (ResFlg === AnsFlg | AnsFlg === 5'bx))&~((FDivBusyE===1'b1)|DivStart)&(UnitVal !== `CVTINTUNIT)&(UnitVal !== `CMPUNIT)) begin
|
2022-09-21 20:19:48 +00:00
|
|
|
ResMatch = (Res === Ans | NaNGood | NaNGood === 1'bx);
|
|
|
|
FlagMatch = (ResFlg === AnsFlg | AnsFlg === 5'bx);
|
|
|
|
divsqrtop = OpCtrlVal == `SQRT_OPCTRL | OpCtrlVal == `DIV_OPCTRL;
|
2022-12-28 05:24:38 +00:00
|
|
|
assign DivDone = OldFDivBusyE & ~FDivBusyE;
|
2022-09-21 20:19:48 +00:00
|
|
|
|
|
|
|
//assign divsqrtop = OpCtrl[TestNum] == `SQRT_OPCTRL | OpCtrl[TestNum] == `DIV_OPCTRL;
|
|
|
|
CheckNow = (DivDone | ~divsqrtop) & (UnitVal !== `CVTINTUNIT)&(UnitVal !== `CMPUNIT);
|
2022-09-19 04:27:21 +00:00
|
|
|
if(~(ResMatch & FlagMatch) & CheckNow) begin
|
|
|
|
// if(~((Res === Ans | NaNGood | NaNGood === 1'bx) & (ResFlg === AnsFlg | AnsFlg === 5'bx))&(DivDone | (TEST != "sqrt" & TEST != "div"))&(UnitVal !== `CVTINTUNIT)&(UnitVal !== `CMPUNIT)) begin
|
2022-05-20 17:19:50 +00:00
|
|
|
errors += 1;
|
2022-09-21 20:19:48 +00:00
|
|
|
$display("TestNum %d OpCtrl %d", TestNum, OpCtrl[TestNum]);
|
2022-08-30 17:55:21 +00:00
|
|
|
$display("Error in %s", Tests[TestNum]);
|
|
|
|
$display("inputs: %h %h %h\nSrcA: %h\n Res: %h %h\n Expected: %h %h", X, Y, Z, SrcA, Res, ResFlg, Ans, AnsFlg);
|
2022-05-20 17:19:50 +00:00
|
|
|
$stop;
|
|
|
|
end
|
2022-05-27 18:36:04 +00:00
|
|
|
|
2022-05-25 23:02:02 +00:00
|
|
|
// TestFloat sets the result to all 1's when there is an invalid result, however in
|
|
|
|
// http://www.jhauser.us/arithmetic/TestFloat-3/doc/TestFloat-general.html it says
|
|
|
|
// for an unsigned integer result 0 is also okay
|
|
|
|
|
|
|
|
// Testfloat outputs 800... for both the largest integer values for both positive and negitive numbers but
|
|
|
|
// the riscv spec specifies 2^31-1 for positive values out of range and NaNs ie 7fff...
|
2022-07-21 01:20:06 +00:00
|
|
|
else if ((UnitVal === `CVTINTUNIT) & ~(((WriteIntVal&~OpCtrlVal[0]&AnsFlg[4]&Xs&(Res[`XLEN-1:0] === (`XLEN)'(0))) |
|
|
|
|
(WriteIntVal&OpCtrlVal[0]&AnsFlg[4]&(~Xs|XNaN)&OpCtrlVal[1]&(Res[`XLEN-1:0] === {1'b0, {`XLEN-1{1'b1}}})) |
|
|
|
|
(WriteIntVal&OpCtrlVal[0]&AnsFlg[4]&(~Xs|XNaN)&~OpCtrlVal[1]&(Res[`XLEN-1:0] === {{`XLEN-32{1'b0}}, 1'b0, {31{1'b1}}})) |
|
|
|
|
(~(WriteIntVal&~OpCtrlVal[0]&AnsFlg[4]&Xs&~XNaN)&(Res === Ans | NaNGood | NaNGood === 1'bx))) & (ResFlg === AnsFlg | AnsFlg === 5'bx))) begin
|
2022-05-19 16:32:30 +00:00
|
|
|
errors += 1;
|
|
|
|
$display("There is an error in %s", Tests[TestNum]);
|
2022-05-20 17:19:50 +00:00
|
|
|
$display("inputs: %h %h %h\nSrcA: %h\n Res: %h %h\n Ans: %h %h", X, Y, Z, SrcA, Res, ResFlg, Ans, AnsFlg);
|
2022-05-19 16:32:30 +00:00
|
|
|
$stop;
|
|
|
|
end
|
2022-05-20 17:19:50 +00:00
|
|
|
|
2023-04-12 03:16:20 +00:00
|
|
|
// Add extra clock cycles in beginning for fdivsqrt to adequate reset state
|
|
|
|
if(~(FDivBusyE|DivStart)|(UnitVal != `DIVUNIT)) begin
|
|
|
|
repeat (12)
|
|
|
|
@(posedge clk);
|
|
|
|
if (reset != 1'b1)
|
|
|
|
VectorNum += 1; // increment the vector
|
|
|
|
end
|
|
|
|
|
|
|
|
if (TestVectors[VectorNum][0] === 1'bx & Tests[TestNum] !== "") begin // if reached the eof
|
2022-05-19 16:32:30 +00:00
|
|
|
|
2022-05-20 17:19:50 +00:00
|
|
|
// increment the test
|
2022-05-19 16:32:30 +00:00
|
|
|
TestNum += 1;
|
2022-05-20 17:19:50 +00:00
|
|
|
|
2022-05-25 23:02:02 +00:00
|
|
|
// clear the vectors
|
2022-06-13 22:47:51 +00:00
|
|
|
for(int i=0; i<6133248; i++) TestVectors[i] = {`FLEN*4+8{1'bx}};
|
2022-05-19 16:32:30 +00:00
|
|
|
// read next files
|
|
|
|
$readmemh({`PATH, Tests[TestNum]}, TestVectors);
|
2022-05-20 17:19:50 +00:00
|
|
|
|
|
|
|
// set the vector index back to 0
|
2022-05-19 16:32:30 +00:00
|
|
|
VectorNum = 0;
|
2022-05-20 17:19:50 +00:00
|
|
|
// incemet the operation if all the rounding modes have been tested
|
2022-05-19 16:32:30 +00:00
|
|
|
if(FrmNum === 4) OpCtrlNum += 1;
|
2022-05-20 17:19:50 +00:00
|
|
|
// increment the rounding mode or loop back to rne
|
2022-05-19 16:32:30 +00:00
|
|
|
if(FrmNum < 4) FrmNum += 1;
|
|
|
|
else FrmNum = 0;
|
2022-05-20 17:19:50 +00:00
|
|
|
|
2022-05-19 16:32:30 +00:00
|
|
|
// if no more Tests - finish
|
2022-06-13 22:47:51 +00:00
|
|
|
if(Tests[TestNum] === "") begin
|
2022-05-19 16:32:30 +00:00
|
|
|
$display("\nAll Tests completed with %d errors\n", errors);
|
|
|
|
$stop;
|
|
|
|
end
|
|
|
|
|
|
|
|
$display("Running %s vectors", Tests[TestNum]);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
endmodule
|
|
|
|
|
|
|
|
|
|
|
|
module readvectors (
|
2023-04-12 03:16:20 +00:00
|
|
|
input logic clk,
|
|
|
|
input logic [`FLEN*4+7:0] TestVector,
|
2022-06-02 19:50:28 +00:00
|
|
|
input logic [`FMTBITS-1:0] ModFmt,
|
2023-04-12 03:16:20 +00:00
|
|
|
input logic [1:0] Fmt,
|
|
|
|
input logic [2:0] Unit,
|
|
|
|
input logic [31:0] VectorNum,
|
|
|
|
input logic [31:0] TestNum,
|
|
|
|
input logic [2:0] OpCtrl,
|
|
|
|
output logic [`FLEN-1:0] Ans,
|
|
|
|
output logic [`XLEN-1:0] SrcA,
|
|
|
|
output logic [4:0] AnsFlg,
|
|
|
|
output logic Xs, Ys, Zs, // sign bits of XYZ
|
|
|
|
output logic [`NE-1:0] Xe, Ye, Ze, // exponents of XYZ (converted to largest supported precision)
|
|
|
|
output logic [`NF:0] Xm, Ym, Zm, // mantissas of XYZ (converted to largest supported precision)
|
|
|
|
output logic XNaN, YNaN, ZNaN, // is XYZ a NaN
|
|
|
|
output logic XSNaN, YSNaN, ZSNaN, // is XYZ a signaling NaN
|
|
|
|
output logic XSubnorm, ZSubnorm, // is XYZ denormalized
|
|
|
|
output logic XZero, YZero, ZZero, // is XYZ zero
|
|
|
|
output logic XInf, YInf, ZInf, // is XYZ infinity
|
|
|
|
output logic XExpMax,
|
|
|
|
output logic DivStart,
|
|
|
|
output logic [`FLEN-1:0] X, Y, Z, XPostBox
|
2022-05-19 16:32:30 +00:00
|
|
|
);
|
2022-07-21 01:20:06 +00:00
|
|
|
logic XEn, YEn, ZEn;
|
2022-05-19 16:32:30 +00:00
|
|
|
|
|
|
|
// apply test vectors on rising edge of clk
|
2022-05-20 17:19:50 +00:00
|
|
|
// Format of vectors Inputs(1/2/3)_AnsFlg
|
2022-06-23 21:38:04 +00:00
|
|
|
always @(VectorNum) begin
|
2022-05-19 16:32:30 +00:00
|
|
|
#1;
|
2022-05-20 17:19:50 +00:00
|
|
|
AnsFlg = TestVector[4:0];
|
2022-06-23 00:07:34 +00:00
|
|
|
DivStart = 1'b0;
|
2022-05-19 16:32:30 +00:00
|
|
|
case (Unit)
|
|
|
|
`FMAUNIT:
|
|
|
|
case (Fmt)
|
|
|
|
2'b11: begin // quad
|
2022-06-13 22:47:51 +00:00
|
|
|
if(OpCtrl === `FMA_OPCTRL) begin
|
|
|
|
X = TestVector[8+4*(`Q_LEN)-1:8+3*(`Q_LEN)];
|
|
|
|
Y = TestVector[8+3*(`Q_LEN)-1:8+2*(`Q_LEN)];
|
|
|
|
Z = TestVector[8+2*(`Q_LEN)-1:8+`Q_LEN];
|
|
|
|
end
|
|
|
|
else begin
|
|
|
|
X = TestVector[8+3*(`Q_LEN)-1:8+2*(`Q_LEN)];
|
|
|
|
if(OpCtrl === `MUL_OPCTRL) Y = TestVector[8+2*(`Q_LEN)-1:8+(`Q_LEN)]; else Y = {2'b0, {`Q_NE-1{1'b1}}, (`Q_NF)'(0)};
|
|
|
|
if(OpCtrl === `MUL_OPCTRL) Z = 0; else Z = TestVector[8+2*(`Q_LEN)-1:8+(`Q_LEN)];
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
Ans = TestVector[8+(`Q_LEN-1):8];
|
|
|
|
end
|
2022-07-07 23:01:33 +00:00
|
|
|
2'b01: if (`D_SUPPORTED)begin // double
|
2022-06-13 22:47:51 +00:00
|
|
|
if(OpCtrl === `FMA_OPCTRL) begin
|
|
|
|
X = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+4*(`D_LEN)-1:8+3*(`D_LEN)]};
|
|
|
|
Y = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+3*(`D_LEN)-1:8+2*(`D_LEN)]};
|
|
|
|
Z = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+2*(`D_LEN)-1:8+`D_LEN]};
|
|
|
|
end
|
|
|
|
else begin
|
|
|
|
X = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+3*(`D_LEN)-1:8+2*(`D_LEN)]};
|
|
|
|
if(OpCtrl === `MUL_OPCTRL) Y = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+2*(`D_LEN)-1:8+(`D_LEN)]};
|
|
|
|
else Y = {{`FLEN-`D_LEN{1'b1}}, 2'b0, {`D_NE-1{1'b1}}, (`D_NF)'(0)};
|
|
|
|
if(OpCtrl === `MUL_OPCTRL) Z = {{`FLEN-`D_LEN{1'b1}}, {`D_LEN{1'b0}}};
|
|
|
|
else Z = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+2*(`D_LEN)-1:8+(`D_LEN)]};
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
Ans = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+(`D_LEN-1):8]};
|
|
|
|
end
|
2022-07-07 23:01:33 +00:00
|
|
|
2'b00: if (`S_SUPPORTED)begin // single
|
2022-06-13 22:47:51 +00:00
|
|
|
if(OpCtrl === `FMA_OPCTRL) begin
|
|
|
|
X = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+4*(`S_LEN)-1:8+3*(`S_LEN)]};
|
|
|
|
Y = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+3*(`S_LEN)-1:8+2*(`S_LEN)]};
|
|
|
|
Z = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+2*(`S_LEN)-1:8+`S_LEN]};
|
|
|
|
end
|
|
|
|
else begin
|
|
|
|
X = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+3*(`S_LEN)-1:8+2*(`S_LEN)]};
|
|
|
|
if(OpCtrl === `MUL_OPCTRL) Y = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+2*(`S_LEN)-1:8+(`S_LEN)]};
|
|
|
|
else Y = {{`FLEN-`S_LEN{1'b1}}, 2'b0, {`S_NE-1{1'b1}}, (`S_NF)'(0)};
|
|
|
|
if(OpCtrl === `MUL_OPCTRL) Z = {{`FLEN-`S_LEN{1'b1}}, {`S_LEN{1'b0}}};
|
|
|
|
else Z = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+2*(`S_LEN)-1:8+(`S_LEN)]};
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
Ans = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+(`S_LEN-1):8]};
|
|
|
|
end
|
|
|
|
2'b10: begin // half
|
2022-06-13 22:47:51 +00:00
|
|
|
if(OpCtrl === `FMA_OPCTRL) begin
|
|
|
|
X = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+4*(`H_LEN)-1:8+3*(`H_LEN)]};
|
|
|
|
Y = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+3*(`H_LEN)-1:8+2*(`H_LEN)]};
|
|
|
|
Z = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+2*(`H_LEN)-1:8+`H_LEN]};
|
|
|
|
end
|
|
|
|
else begin
|
|
|
|
X = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+3*(`H_LEN)-1:8+2*(`H_LEN)]};
|
|
|
|
if(OpCtrl === `MUL_OPCTRL) Y = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+2*(`H_LEN)-1:8+(`H_LEN)]};
|
|
|
|
else Y = {{`FLEN-`H_LEN{1'b1}}, 2'b0, {`H_NE-1{1'b1}}, (`H_NF)'(0)};
|
|
|
|
if(OpCtrl === `MUL_OPCTRL) Z = {{`FLEN-`H_LEN{1'b1}}, {`H_LEN{1'b0}}};
|
|
|
|
else Z = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+2*(`H_LEN)-1:8+(`H_LEN)]};
|
|
|
|
end
|
2022-05-19 16:32:30 +00:00
|
|
|
Ans = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+(`H_LEN-1):8]};
|
|
|
|
end
|
|
|
|
endcase
|
|
|
|
`DIVUNIT:
|
2022-07-22 22:02:04 +00:00
|
|
|
if(OpCtrl[0])
|
|
|
|
case (Fmt)
|
|
|
|
2'b11: begin // quad
|
|
|
|
X = TestVector[8+2*(`Q_LEN)-1:8+(`Q_LEN)];
|
|
|
|
Ans = TestVector[8+(`Q_LEN-1):8];
|
|
|
|
if (~clk) #5;
|
|
|
|
DivStart = 1'b1; #10 // one clk cycle
|
|
|
|
DivStart = 1'b0;
|
|
|
|
end
|
|
|
|
2'b01: if (`D_SUPPORTED)begin // double
|
|
|
|
X = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+2*(`D_LEN)-1:8+(`D_LEN)]};
|
|
|
|
Ans = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+(`D_LEN-1):8]};
|
|
|
|
if (~clk) #5;
|
|
|
|
DivStart = 1'b1; #10
|
|
|
|
DivStart = 1'b0;
|
|
|
|
end
|
|
|
|
2'b00: if (`S_SUPPORTED)begin // single
|
|
|
|
X = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+2*(`S_LEN)-1:8+1*(`S_LEN)]};
|
|
|
|
Ans = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+(`S_LEN-1):8]};
|
|
|
|
if (~clk) #5;
|
|
|
|
DivStart = 1'b1; #10
|
|
|
|
DivStart = 1'b0;
|
|
|
|
end
|
|
|
|
2'b10: begin // half
|
|
|
|
X = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+2*(`H_LEN)-1:8+(`H_LEN)]};
|
|
|
|
Ans = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+(`H_LEN-1):8]};
|
|
|
|
if (~clk) #5;
|
|
|
|
DivStart = 1'b1; #10
|
|
|
|
DivStart = 1'b0;
|
|
|
|
end
|
|
|
|
endcase
|
|
|
|
else
|
|
|
|
case (Fmt)
|
|
|
|
2'b11: begin // quad
|
|
|
|
X = TestVector[8+3*(`Q_LEN)-1:8+2*(`Q_LEN)];
|
|
|
|
Y = TestVector[8+2*(`Q_LEN)-1:8+(`Q_LEN)];
|
|
|
|
Ans = TestVector[8+(`Q_LEN-1):8];
|
|
|
|
if (~clk) #5;
|
|
|
|
DivStart = 1'b1; #10 // one clk cycle
|
|
|
|
DivStart = 1'b0;
|
|
|
|
end
|
|
|
|
2'b01: if (`D_SUPPORTED)begin // double
|
|
|
|
X = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+3*(`D_LEN)-1:8+2*(`D_LEN)]};
|
|
|
|
Y = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+2*(`D_LEN)-1:8+(`D_LEN)]};
|
|
|
|
Ans = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+(`D_LEN-1):8]};
|
|
|
|
if (~clk) #5;
|
|
|
|
DivStart = 1'b1; #10
|
|
|
|
DivStart = 1'b0;
|
|
|
|
end
|
|
|
|
2'b00: if (`S_SUPPORTED)begin // single
|
|
|
|
X = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+3*(`S_LEN)-1:8+2*(`S_LEN)]};
|
|
|
|
Y = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+2*(`S_LEN)-1:8+1*(`S_LEN)]};
|
|
|
|
Ans = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+(`S_LEN-1):8]};
|
|
|
|
if (~clk) #5;
|
|
|
|
DivStart = 1'b1; #10
|
|
|
|
DivStart = 1'b0;
|
|
|
|
end
|
|
|
|
2'b10: begin // half
|
|
|
|
X = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+3*(`H_LEN)-1:8+2*(`H_LEN)]};
|
|
|
|
Y = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+2*(`H_LEN)-1:8+(`H_LEN)]};
|
|
|
|
Ans = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+(`H_LEN-1):8]};
|
|
|
|
if (~clk) #5;
|
|
|
|
DivStart = 1'b1; #10
|
|
|
|
DivStart = 1'b0;
|
|
|
|
end
|
|
|
|
endcase
|
2022-05-19 16:32:30 +00:00
|
|
|
`CMPUNIT:
|
2022-05-20 17:19:50 +00:00
|
|
|
case (Fmt)
|
2022-05-19 16:32:30 +00:00
|
|
|
2'b11: begin // quad
|
2022-05-20 17:19:50 +00:00
|
|
|
X = TestVector[12+2*(`Q_LEN)-1:12+(`Q_LEN)];
|
|
|
|
Y = TestVector[12+(`Q_LEN)-1:12];
|
2022-05-19 16:32:30 +00:00
|
|
|
Ans = TestVector[8];
|
|
|
|
end
|
2022-07-07 23:01:33 +00:00
|
|
|
2'b01: if (`D_SUPPORTED)begin // double
|
2022-05-20 17:19:50 +00:00
|
|
|
X = {{`FLEN-`D_LEN{1'b1}}, TestVector[12+2*(`D_LEN)-1:12+(`D_LEN)]};
|
|
|
|
Y = {{`FLEN-`D_LEN{1'b1}}, TestVector[12+(`D_LEN)-1:12]};
|
|
|
|
Ans = TestVector[8];
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
2022-07-07 23:01:33 +00:00
|
|
|
2'b00: if (`S_SUPPORTED)begin // single
|
2022-05-20 17:19:50 +00:00
|
|
|
X = {{`FLEN-`S_LEN{1'b1}}, TestVector[12+2*(`S_LEN)-1:12+(`S_LEN)]};
|
|
|
|
Y = {{`FLEN-`S_LEN{1'b1}}, TestVector[12+(`S_LEN)-1:12]};
|
|
|
|
Ans = TestVector[8];
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
2'b10: begin // half
|
2022-05-27 18:36:04 +00:00
|
|
|
X = {{`FLEN-`H_LEN{1'b1}}, TestVector[12+2*(`H_LEN)-1:12+(`H_LEN)]};
|
2022-05-20 17:19:50 +00:00
|
|
|
Y = {{`FLEN-`H_LEN{1'b1}}, TestVector[12+(`H_LEN)-1:12]};
|
|
|
|
Ans = TestVector[8];
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
endcase
|
|
|
|
`CVTFPUNIT:
|
|
|
|
case (Fmt)
|
|
|
|
2'b11: begin // quad
|
|
|
|
case (OpCtrl[1:0])
|
|
|
|
2'b11: begin // quad
|
2022-06-13 22:47:51 +00:00
|
|
|
X = {TestVector[8+`Q_LEN+`Q_LEN-1:8+(`Q_LEN)]};
|
2022-05-19 16:32:30 +00:00
|
|
|
Ans = TestVector[8+(`Q_LEN-1):8];
|
|
|
|
end
|
2022-07-07 23:01:33 +00:00
|
|
|
2'b01: if (`D_SUPPORTED)begin // double
|
2022-06-13 22:47:51 +00:00
|
|
|
X = {TestVector[8+`Q_LEN+`D_LEN-1:8+(`D_LEN)]};
|
2022-05-19 16:32:30 +00:00
|
|
|
Ans = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+(`D_LEN-1):8]};
|
|
|
|
end
|
|
|
|
2'b00: begin // single
|
2022-06-13 22:47:51 +00:00
|
|
|
X = {TestVector[8+`Q_LEN+`S_LEN-1:8+(`S_LEN)]};
|
2022-05-19 16:32:30 +00:00
|
|
|
Ans = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+(`S_LEN-1):8]};
|
|
|
|
end
|
|
|
|
2'b10: begin // half
|
2022-06-13 22:47:51 +00:00
|
|
|
X = {TestVector[8+`Q_LEN+`H_LEN-1:8+(`H_LEN)]};
|
2022-05-19 16:32:30 +00:00
|
|
|
Ans = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+(`H_LEN-1):8]};
|
|
|
|
end
|
|
|
|
endcase
|
|
|
|
end
|
2022-07-07 23:01:33 +00:00
|
|
|
2'b01: if (`D_SUPPORTED)begin // double
|
2022-05-19 16:32:30 +00:00
|
|
|
case (OpCtrl[1:0])
|
|
|
|
2'b11: begin // quad
|
|
|
|
X = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+`D_LEN+`Q_LEN-1:8+(`Q_LEN)]};
|
|
|
|
Ans = TestVector[8+(`Q_LEN-1):8];
|
|
|
|
end
|
|
|
|
2'b01: begin // double
|
|
|
|
X = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+`D_LEN+`D_LEN-1:8+(`D_LEN)]};
|
|
|
|
Ans = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+(`D_LEN-1):8]};
|
|
|
|
end
|
|
|
|
2'b00: begin // single
|
|
|
|
X = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+`D_LEN+`S_LEN-1:8+(`S_LEN)]};
|
|
|
|
Ans = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+(`S_LEN-1):8]};
|
|
|
|
end
|
|
|
|
2'b10: begin // half
|
|
|
|
X = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+`D_LEN+`H_LEN-1:8+(`H_LEN)]};
|
|
|
|
Ans = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+(`H_LEN-1):8]};
|
|
|
|
end
|
|
|
|
endcase
|
|
|
|
end
|
2022-07-07 23:01:33 +00:00
|
|
|
2'b00: if (`S_SUPPORTED)begin // single
|
2022-05-19 16:32:30 +00:00
|
|
|
case (OpCtrl[1:0])
|
|
|
|
2'b11: begin // quad
|
|
|
|
X = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+`S_LEN+`Q_LEN-1:8+(`Q_LEN)]};
|
|
|
|
Ans = TestVector[8+(`Q_LEN-1):8];
|
|
|
|
end
|
2022-07-07 23:01:33 +00:00
|
|
|
2'b01: if (`D_SUPPORTED)begin // double
|
2022-05-19 16:32:30 +00:00
|
|
|
X = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+`S_LEN+`D_LEN-1:8+(`D_LEN)]};
|
|
|
|
Ans = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+(`D_LEN-1):8]};
|
|
|
|
end
|
|
|
|
2'b00: begin // single
|
|
|
|
X = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+`S_LEN+`S_LEN-1:8+(`S_LEN)]};
|
|
|
|
Ans = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+(`S_LEN-1):8]};
|
|
|
|
end
|
|
|
|
2'b10: begin // half
|
|
|
|
X = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+`S_LEN+`H_LEN-1:8+(`H_LEN)]};
|
|
|
|
Ans = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+(`H_LEN-1):8]};
|
|
|
|
end
|
|
|
|
endcase
|
|
|
|
end
|
|
|
|
2'b10: begin // half
|
|
|
|
case (OpCtrl[1:0])
|
|
|
|
2'b11: begin // quad
|
|
|
|
X = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+`H_LEN+`Q_LEN-1:8+(`Q_LEN)]};
|
|
|
|
Ans = TestVector[8+(`Q_LEN-1):8];
|
|
|
|
end
|
2022-07-07 23:01:33 +00:00
|
|
|
2'b01: if (`D_SUPPORTED)begin // double
|
2022-05-19 16:32:30 +00:00
|
|
|
X = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+`H_LEN+`D_LEN-1:8+(`D_LEN)]};
|
|
|
|
Ans = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+(`D_LEN-1):8]};
|
|
|
|
end
|
2022-07-07 23:01:33 +00:00
|
|
|
2'b00: if (`S_SUPPORTED)begin // single
|
2022-05-19 16:32:30 +00:00
|
|
|
X = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+`H_LEN+`S_LEN-1:8+(`S_LEN)]};
|
|
|
|
Ans = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+(`S_LEN-1):8]};
|
|
|
|
end
|
|
|
|
2'b10: begin // half
|
|
|
|
X = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+`H_LEN+`H_LEN-1:8+(`H_LEN)]};
|
|
|
|
Ans = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+(`H_LEN-1):8]};
|
|
|
|
end
|
|
|
|
endcase
|
|
|
|
end
|
|
|
|
endcase
|
|
|
|
|
|
|
|
`CVTINTUNIT:
|
|
|
|
case (Fmt)
|
|
|
|
2'b11: begin // quad
|
|
|
|
// {is the integer a long, is the opperation to an integer}
|
2022-05-25 23:02:02 +00:00
|
|
|
casex ({OpCtrl[2:1]})
|
2022-05-19 16:32:30 +00:00
|
|
|
2'b11: begin // long -> quad
|
2022-05-25 23:02:02 +00:00
|
|
|
X = {`FLEN{1'bx}};
|
2022-05-19 16:32:30 +00:00
|
|
|
SrcA = TestVector[8+`Q_LEN+`XLEN-1:8+(`Q_LEN)];
|
|
|
|
Ans = TestVector[8+(`Q_LEN-1):8];
|
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
2'b10: begin // int -> quad
|
2022-05-19 16:32:30 +00:00
|
|
|
// correctly sign extend the integer depending on if it's a signed/unsigned test
|
2022-05-25 23:02:02 +00:00
|
|
|
X = {`FLEN{1'bx}};
|
|
|
|
SrcA = {{`XLEN-32{TestVector[8+`Q_LEN+32-1]}}, TestVector[8+`Q_LEN+32-1:8+(`Q_LEN)]};
|
2022-05-19 16:32:30 +00:00
|
|
|
Ans = TestVector[8+(`Q_LEN-1):8];
|
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
2'b01: begin // quad -> long
|
2022-06-13 22:47:51 +00:00
|
|
|
X = {TestVector[8+`XLEN+`Q_LEN-1:8+(`XLEN)]};
|
2022-05-25 23:02:02 +00:00
|
|
|
SrcA = {`XLEN{1'bx}};
|
2022-05-19 16:32:30 +00:00
|
|
|
Ans = {TestVector[8+(`XLEN-1):8]};
|
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
2'b00: begin // quad -> int
|
2022-06-13 22:47:51 +00:00
|
|
|
X = {TestVector[8+32+`Q_LEN-1:8+(32)]};
|
2022-05-25 23:02:02 +00:00
|
|
|
SrcA = {`XLEN{1'bx}};
|
|
|
|
Ans = {{`XLEN-32{TestVector[8+32-1]}},TestVector[8+(32-1):8]};
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
endcase
|
|
|
|
end
|
2022-07-07 23:01:33 +00:00
|
|
|
2'b01: if (`D_SUPPORTED)begin // double
|
2022-05-25 23:02:02 +00:00
|
|
|
// {Int->Fp?, is the integer a long}
|
|
|
|
casex ({OpCtrl[2:1]})
|
2022-05-19 16:32:30 +00:00
|
|
|
2'b11: begin // long -> double
|
2022-05-25 23:02:02 +00:00
|
|
|
X = {`FLEN{1'bx}};
|
2022-05-19 16:32:30 +00:00
|
|
|
SrcA = TestVector[8+`D_LEN+`XLEN-1:8+(`D_LEN)];
|
2022-05-25 23:02:02 +00:00
|
|
|
Ans = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+(`D_LEN-1):8]};
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
2'b10: begin // int -> double
|
2022-05-19 16:32:30 +00:00
|
|
|
// correctly sign extend the integer depending on if it's a signed/unsigned test
|
2022-05-25 23:02:02 +00:00
|
|
|
X = {`FLEN{1'bx}};
|
|
|
|
SrcA = {{`XLEN-32{TestVector[8+`D_LEN+32-1]}}, TestVector[8+`D_LEN+32-1:8+(`D_LEN)]};
|
|
|
|
Ans = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+(`D_LEN-1):8]};
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
2'b01: begin // double -> long
|
2022-05-19 16:32:30 +00:00
|
|
|
X = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+`XLEN+`D_LEN-1:8+(`XLEN)]};
|
2022-05-25 23:02:02 +00:00
|
|
|
SrcA = {`XLEN{1'bx}};
|
2022-05-19 16:32:30 +00:00
|
|
|
Ans = {TestVector[8+(`XLEN-1):8]};
|
|
|
|
end
|
|
|
|
2'b00: begin // double -> int
|
2022-05-25 23:02:02 +00:00
|
|
|
X = {{`FLEN-`D_LEN{1'b1}}, TestVector[8+32+`D_LEN-1:8+(32)]};
|
|
|
|
SrcA = {`XLEN{1'bx}};
|
|
|
|
Ans = {{`XLEN-32{TestVector[8+32-1]}},TestVector[8+(32-1):8]};
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
endcase
|
|
|
|
end
|
2022-07-07 23:01:33 +00:00
|
|
|
2'b00: if (`S_SUPPORTED)begin // single
|
2022-05-19 16:32:30 +00:00
|
|
|
// {is the integer a long, is the opperation to an integer}
|
2022-05-25 23:02:02 +00:00
|
|
|
casex ({OpCtrl[2:1]})
|
2022-05-19 16:32:30 +00:00
|
|
|
2'b11: begin // long -> single
|
2022-05-25 23:02:02 +00:00
|
|
|
X = {`FLEN{1'bx}};
|
2022-05-19 16:32:30 +00:00
|
|
|
SrcA = TestVector[8+`S_LEN+`XLEN-1:8+(`S_LEN)];
|
2022-05-25 23:02:02 +00:00
|
|
|
Ans = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+(`S_LEN-1):8]};
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
2'b10: begin // int -> single
|
2022-05-19 16:32:30 +00:00
|
|
|
// correctly sign extend the integer depending on if it's a signed/unsigned test
|
2022-05-25 23:02:02 +00:00
|
|
|
X = {`FLEN{1'bx}};
|
|
|
|
SrcA = {{`XLEN-32{TestVector[8+`S_LEN+32-1]}}, TestVector[8+`S_LEN+32-1:8+(`S_LEN)]};
|
|
|
|
Ans = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+(`S_LEN-1):8]};
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
2'b01: begin // single -> long
|
2022-05-19 16:32:30 +00:00
|
|
|
X = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+`XLEN+`S_LEN-1:8+(`XLEN)]};
|
2022-05-25 23:02:02 +00:00
|
|
|
SrcA = {`XLEN{1'bx}};
|
2022-05-19 16:32:30 +00:00
|
|
|
Ans = {TestVector[8+(`XLEN-1):8]};
|
|
|
|
end
|
|
|
|
2'b00: begin // single -> int
|
2022-05-25 23:02:02 +00:00
|
|
|
X = {{`FLEN-`S_LEN{1'b1}}, TestVector[8+32+`S_LEN-1:8+(32)]};
|
|
|
|
SrcA = {`XLEN{1'bx}};
|
|
|
|
Ans = {{`XLEN-32{TestVector[8+32-1]}},TestVector[8+(32-1):8]};
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
endcase
|
|
|
|
end
|
|
|
|
2'b10: begin // half
|
|
|
|
// {is the integer a long, is the opperation to an integer}
|
2022-05-25 23:02:02 +00:00
|
|
|
casex ({OpCtrl[2:1]})
|
2022-05-19 16:32:30 +00:00
|
|
|
2'b11: begin // long -> half
|
2022-05-25 23:02:02 +00:00
|
|
|
X = {`FLEN{1'bx}};
|
2022-05-19 16:32:30 +00:00
|
|
|
SrcA = TestVector[8+`H_LEN+`XLEN-1:8+(`H_LEN)];
|
2022-05-25 23:02:02 +00:00
|
|
|
Ans = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+(`H_LEN-1):8]};
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
2'b10: begin // int -> half
|
2022-05-19 16:32:30 +00:00
|
|
|
// correctly sign extend the integer depending on if it's a signed/unsigned test
|
2022-05-25 23:02:02 +00:00
|
|
|
X = {`FLEN{1'bx}};
|
|
|
|
SrcA = {{`XLEN-32{TestVector[8+`H_LEN+32-1]}}, TestVector[8+`H_LEN+32-1:8+(`H_LEN)]};
|
|
|
|
Ans = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+(`H_LEN-1):8]};
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
2022-05-25 23:02:02 +00:00
|
|
|
2'b01: begin // half -> long
|
2022-05-19 16:32:30 +00:00
|
|
|
X = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+`XLEN+`H_LEN-1:8+(`XLEN)]};
|
2022-05-25 23:02:02 +00:00
|
|
|
SrcA = {`XLEN{1'bx}};
|
2022-05-19 16:32:30 +00:00
|
|
|
Ans = {TestVector[8+(`XLEN-1):8]};
|
|
|
|
end
|
|
|
|
2'b00: begin // half -> int
|
2022-05-25 23:02:02 +00:00
|
|
|
X = {{`FLEN-`H_LEN{1'b1}}, TestVector[8+32+`H_LEN-1:8+(32)]};
|
|
|
|
SrcA = {`XLEN{1'bx}};
|
|
|
|
Ans = {{`XLEN-32{TestVector[8+32-1]}}, TestVector[8+(32-1):8]};
|
2022-05-19 16:32:30 +00:00
|
|
|
end
|
|
|
|
endcase
|
|
|
|
end
|
|
|
|
endcase
|
|
|
|
endcase
|
|
|
|
end
|
|
|
|
|
2022-07-21 01:20:06 +00:00
|
|
|
assign XEn = ~((Unit == `CVTINTUNIT)&OpCtrl[2]);
|
2022-07-22 22:02:04 +00:00
|
|
|
assign YEn = ~((Unit == `CVTINTUNIT)|(Unit == `CVTFPUNIT)|((Unit == `DIVUNIT)&OpCtrl[0]));
|
2022-07-21 01:20:06 +00:00
|
|
|
assign ZEn = (Unit == `FMAUNIT);
|
|
|
|
|
|
|
|
unpack unpack(.X, .Y, .Z, .Fmt(ModFmt), .Xs, .Ys, .Zs, .Xe, .Ye, .Ze,
|
|
|
|
.Xm, .Ym, .Zm, .XNaN, .YNaN, .ZNaN, .XSNaN, .YSNaN, .ZSNaN,
|
2023-01-12 04:02:30 +00:00
|
|
|
.XSubnorm, .XZero, .YZero, .ZZero, .XInf, .YInf, .ZInf,
|
2023-04-12 03:16:20 +00:00
|
|
|
.XEn, .YEn, .ZEn, .XExpMax, .XPostBox);
|
2023-04-02 23:16:23 +00:00
|
|
|
endmodule
|