From 3d0376df7b25ea90ac62b2f89374e7d98ff84f5f Mon Sep 17 00:00:00 2001 From: Nicolas Brunie Date: Sat, 12 Aug 2023 04:13:37 +0200 Subject: adding initial bf16 support --- source/RISCV/specialize.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source/RISCV/specialize.h') diff --git a/source/RISCV/specialize.h b/source/RISCV/specialize.h index c638264..70fb808 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 -- cgit v1.1 From ac8688db85f554b7e165e0ee25a45bb50a2c50c7 Mon Sep 17 00:00:00 2001 From: Nicolas Brunie Date: Sat, 12 Aug 2023 06:52:03 +0200 Subject: Adding more bf16 support function + skeleton for f32_to_bf16 --- source/RISCV/specialize.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source/RISCV/specialize.h') diff --git a/source/RISCV/specialize.h b/source/RISCV/specialize.h index 70fb808..4137bd7 100644 --- a/source/RISCV/specialize.h +++ b/source/RISCV/specialize.h @@ -118,6 +118,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 defaultNaNF16UI 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 -- cgit v1.1 From fab20258f0ba207b30753031a33d84f6c2e7d724 Mon Sep 17 00:00:00 2001 From: Nicolas Brunie Date: Sat, 12 Aug 2023 08:00:12 +0200 Subject: Continuing f32_to_bf16 development --- source/RISCV/specialize.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/RISCV/specialize.h') diff --git a/source/RISCV/specialize.h b/source/RISCV/specialize.h index 4137bd7..ec9eda2 100644 --- a/source/RISCV/specialize.h +++ b/source/RISCV/specialize.h @@ -120,7 +120,7 @@ uint_fast16_t /*---------------------------------------------------------------------------- | The bit pattern for a default generated 16-bit BF16 floating-point NaN. *----------------------------------------------------------------------------*/ -#define defaultNaNF16UI 0x7FC0 +#define defaultNaNBF16UI 0x7FC0 /*---------------------------------------------------------------------------- | Converts the common NaN pointed to by 'aPtr' into a 16-bit floating-point -- cgit v1.1 From 54da0e1be7a9c90b4225ac29cf5b5c8b4ec8304c Mon Sep 17 00:00:00 2001 From: Nicolas Brunie Date: Sat, 12 Aug 2023 10:34:58 +0200 Subject: Fixing dummy bf16_to_f32 conversion --- source/RISCV/specialize.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source/RISCV/specialize.h') diff --git a/source/RISCV/specialize.h b/source/RISCV/specialize.h index ec9eda2..cb95900 100644 --- a/source/RISCV/specialize.h +++ b/source/RISCV/specialize.h @@ -103,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. *----------------------------------------------------------------------------*/ -- cgit v1.1