aboutsummaryrefslogtreecommitdiff
path: root/source/RISCV/specialize.h
diff options
context:
space:
mode:
authorJerry Zhao <jerryz123@berkeley.edu>2023-10-13 15:23:50 -0700
committerGitHub <noreply@github.com>2023-10-13 15:23:50 -0700
commiteb498c55bab0f49c3903f69524e2674abe71c26b (patch)
treebe448123945308a8bc01e831adb0c83b640aa979 /source/RISCV/specialize.h
parent5c06db33fc1e2130f67c045327b0ec949032df1d (diff)
parentbef5a34e1b2ef862e2c5cc0ed4f1ab6e92d01af1 (diff)
downloadberkeley-softfloat-3-eb498c55bab0f49c3903f69524e2674abe71c26b.zip
berkeley-softfloat-3-eb498c55bab0f49c3903f69524e2674abe71c26b.tar.gz
berkeley-softfloat-3-eb498c55bab0f49c3903f69524e2674abe71c26b.tar.bz2
Merge pull request #21 from nibrunieAtSi5/bf16-support
[#18] Adding minimal BFloat16 support
Diffstat (limited to 'source/RISCV/specialize.h')
-rw-r--r--source/RISCV/specialize.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/source/RISCV/specialize.h b/source/RISCV/specialize.h
index c638264..cb95900 100644
--- a/source/RISCV/specialize.h
+++ b/source/RISCV/specialize.h
@@ -88,6 +88,13 @@ struct commonNaN { char _unused; };
#define softfloat_isSigNaNF16UI( uiA ) ((((uiA) & 0x7E00) == 0x7C00) && ((uiA) & 0x01FF))
/*----------------------------------------------------------------------------
+| Returns true when 16-bit unsigned integer 'uiA' has the bit pattern of a
+| 16-bit brain floating-point (BF16) signaling NaN.
+| Note: This macro evaluates its argument more than once.
+*----------------------------------------------------------------------------*/
+#define softfloat_isSigNaNBF16UI( uiA ) ((((uiA) & 0x7FC0) == 0x7F80) && ((uiA) & 0x003F))
+
+/*----------------------------------------------------------------------------
| Assuming 'uiA' has the bit pattern of a 16-bit floating-point NaN, converts
| this NaN to the common NaN form, and stores the resulting common NaN at the
| location pointed to by 'zPtr'. If the NaN is a signaling NaN, the invalid
@@ -96,6 +103,14 @@ struct commonNaN { char _unused; };
#define softfloat_f16UIToCommonNaN( uiA, zPtr ) if ( ! ((uiA) & 0x0200) ) softfloat_raiseFlags( softfloat_flag_invalid )
/*----------------------------------------------------------------------------
+| Assuming 'uiA' has the bit pattern of a 16-bit BF16 floating-point NaN, converts
+| this NaN to the common NaN form, and stores the resulting common NaN at the
+| location pointed to by 'zPtr'. If the NaN is a signaling NaN, the invalid
+| exception is raised.
+*----------------------------------------------------------------------------*/
+#define softfloat_bf16UIToCommonNaN( uiA, zPtr ) if ( ! ((uiA) & 0x0040) ) softfloat_raiseFlags( softfloat_flag_invalid )
+
+/*----------------------------------------------------------------------------
| Converts the common NaN pointed to by 'aPtr' into a 16-bit floating-point
| NaN, and returns the bit pattern of this value as an unsigned integer.
*----------------------------------------------------------------------------*/
@@ -111,6 +126,17 @@ uint_fast16_t
softfloat_propagateNaNF16UI( uint_fast16_t uiA, uint_fast16_t uiB );
/*----------------------------------------------------------------------------
+| The bit pattern for a default generated 16-bit BF16 floating-point NaN.
+*----------------------------------------------------------------------------*/
+#define defaultNaNBF16UI 0x7FC0
+
+/*----------------------------------------------------------------------------
+| Converts the common NaN pointed to by 'aPtr' into a 16-bit floating-point
+| NaN, and returns the bit pattern of this value as an unsigned integer.
+*----------------------------------------------------------------------------*/
+#define softfloat_commonNaNToBF16UI( aPtr ) ((uint_fast16_t) defaultNaNBF16UI)
+
+/*----------------------------------------------------------------------------
| The bit pattern for a default generated 32-bit floating-point NaN.
*----------------------------------------------------------------------------*/
#define defaultNaNF32UI 0x7FC00000