/////////////////////////////////////////// // // Written: me@KatherineParry.com // Modified: 7/5/2022 // // Purpose: Comparison 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" // FOpCtrlE values // 110 min // 101 max // 010 equal // 001 less than // 011 less than or equal module fcmp ( input logic [`FMTBITS-1:0] FmtE, // precision 1 = double 0 = single input logic [2:0] FOpCtrlE, // see above table input logic XSgnE, YSgnE, // input signs input logic [`NE-1:0] XExpE, YExpE, // input exponents input logic [`NF:0] XManE, YManE, // input mantissa input logic XZeroE, YZeroE, // is zero input logic XNaNE, YNaNE, // is NaN input logic XSNaNE, YSNaNE, // is signaling NaN input logic [`FLEN-1:0] FSrcXE, FSrcYE, // original, non-converted to double, inputs output logic CmpNVE, // invalid flag output logic [`FLEN-1:0] CmpFpResE, // compare resilt output logic [`XLEN-1:0] CmpIntResE // compare resilt ); logic LTabs, LT, EQ; // is X < or > or = Y logic [`FLEN-1:0] NaNRes; logic BothZero, EitherNaN, EitherSNaN; assign LTabs= {1'b0, XExpE, XManE} < {1'b0, YExpE, YManE}; // unsigned comparison, treating FP as integers assign LT = (XSgnE & ~YSgnE) | (XSgnE & YSgnE & ~LTabs & ~EQ) | (~XSgnE & ~YSgnE & LTabs); // assign LT = {~XSgnE, XExpE, XManE[`NF-1:0]} < {~YSgnE, YExpE, YManE[`NF-1:0]}; // *** James look at whether we can simplify to this, but it fails regression //assign LT = $signed({XSgnE, XExpE, XManE[`NF-1:0]}) < $signed({YSgnE, YExpE, YManE[`NF-1:0]}); //assign LT = XInt < YInt; // assign LT = XSgnE^YSgnE ? XSgnE : XExpE==YExpE ? ((XManE