On Thu,  5 Nov 2026 03:41:16 +0800 Max Chou <[email protected]> wrote:

> Include following checking functions liked other fp types:
> - *_nan_is_snan
> - *_is_quiet_nan
> - *_is_signaling_nan
> - *_is_any_nan
> - *_is_neg
> - *_is_infinity
> - *_is_zero
> - *_is_zero_or_denormal
> - *_is_normal
> 
> Signed-off-by: Max Chou <[email protected]>
Reviewed-by: Chao Liu <[email protected]>

Thanks,
Chao

> ---
>  fpu/softfloat-specialize.c.inc | 55 ++++++++++++++++++++++++++
>  include/fpu/softfloat.h        | 70 ++++++++++++++++++++++++++++++++++
>  2 files changed, 125 insertions(+)
> 
> diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
> index 8b765ef623f..22a3188f99b 100644
> --- a/fpu/softfloat-specialize.c.inc
> +++ b/fpu/softfloat-specialize.c.inc
> @@ -255,6 +255,61 @@ floatx80 floatx80_default_inf(bool zSign, float_status 
> *status)
>      return packFloatx80(zSign, 0x7fff, z ? 0 : (1ULL << 63));
>  }
>  
> +/*----------------------------------------------------------------------------
> +| Determine if a OCP FP8 E4M3 NaN is signaling NaN.
> +| E4M3 has only one NaN encoding, so classification is policy-based.
> +*----------------------------------------------------------------------------*/
> +
> +static bool float8_e4m3_nan_is_snan(float8_e4m3 a, float_status *status)
> +{
> +    return get_float_e4m3_nan_is_snan(status);
> +}
> +
> +/*----------------------------------------------------------------------------
> +| Returns 1 if the OCP FP8 E4M3 value `a' is a quiet NaN; otherwise returns 
> 0.
> +*----------------------------------------------------------------------------*/
> +
> +bool float8_e4m3_is_quiet_nan(float8_e4m3 a_, float_status *status)
> +{
> +    return float8_e4m3_is_any_nan(a_) && !float8_e4m3_nan_is_snan(a_, 
> status);
> +}
> +
> +/*----------------------------------------------------------------------------
> +| Returns 1 if the OCP FP8 E4M3 value `a' is a signaling NaN; otherwise 0.
> +*----------------------------------------------------------------------------*/
> +
> +bool float8_e4m3_is_signaling_nan(float8_e4m3 a_, float_status *status)
> +{
> +    return float8_e4m3_is_any_nan(a_) && float8_e4m3_nan_is_snan(a_, status);
> +}
> +
> +/*----------------------------------------------------------------------------
> +| Determine if a OCP FP8 E5M2 NaN is signaling NaN.
> +*----------------------------------------------------------------------------*/
> +
> +static bool float8_e5m2_nan_is_snan(float8_e5m2 a, float_status *status)
> +{
> +    return frac_msb_is_snan((a >> 1) & 1, status);
> +}
> +
> +/*----------------------------------------------------------------------------
> +| Returns 1 if the OCP FP8 E5M2 value `a' is a quiet NaN; otherwise returns 
> 0.
> +*----------------------------------------------------------------------------*/
> +
> +bool float8_e5m2_is_quiet_nan(float8_e5m2 a_, float_status *status)
> +{
> +    return float8_e5m2_is_any_nan(a_) && !float8_e5m2_nan_is_snan(a_, 
> status);
> +}
> +
> +/*----------------------------------------------------------------------------
> +| Returns 1 if the OCP FP8 E5M2 value `a' is a signaling NaN; otherwise 0.
> +*----------------------------------------------------------------------------*/
> +
> +bool float8_e5m2_is_signaling_nan(float8_e5m2 a_, float_status *status)
> +{
> +    return float8_e5m2_is_any_nan(a_) && float8_e5m2_nan_is_snan(a_, status);
> +}
> +
>  
> /*----------------------------------------------------------------------------
>  | Determine if a float16 NaN is signaling NaN.
>  
> *----------------------------------------------------------------------------*/
> diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h
> index d48fc6b0437..4d91599e25d 100644
> --- a/include/fpu/softfloat.h
> +++ b/include/fpu/softfloat.h
> @@ -222,6 +222,76 @@ bfloat16 float8_e5m2_to_bfloat16(float8_e5m2, 
> float_status *status);
>  float8_e5m2 bfloat16_to_float8_e5m2(bfloat16, bool sat, float_status 
> *status);
>  float8_e5m2 float32_to_float8_e5m2(float32, bool sat, float_status *status);
>  
> +/*----------------------------------------------------------------------------
> +| OCP FP{4,8} classify operations.
> +*----------------------------------------------------------------------------*/
> +
> +bool float8_e4m3_is_quiet_nan(float8_e4m3, float_status *status);
> +bool float8_e4m3_is_signaling_nan(float8_e4m3, float_status *status);
> +bool float8_e5m2_is_quiet_nan(float8_e5m2, float_status *status);
> +bool float8_e5m2_is_signaling_nan(float8_e5m2, float_status *status);
> +
> +static inline bool float8_e4m3_is_any_nan(float8_e4m3 a)
> +{
> +    return ((a & ~0x80) == 0x7f);
> +}
> +
> +static inline bool float8_e5m2_is_any_nan(float8_e5m2 a)
> +{
> +    return ((a & ~0x80) > 0x7c);
> +}
> +
> +static inline bool float8_e4m3_is_neg(float8_e4m3 a)
> +{
> +    return a >> 7;
> +}
> +
> +static inline bool float8_e5m2_is_neg(float8_e5m2 a)
> +{
> +    return a >> 7;
> +}
> +
> +static inline bool float8_e4m3_is_infinity(float8_e4m3 a)
> +{
> +    return false;
> +}
> +
> +static inline bool float8_e5m2_is_infinity(float8_e5m2 a)
> +{
> +    return (a & 0x7f) == 0x7c;
> +}
> +
> +static inline bool float8_e4m3_is_zero(float8_e4m3 a)
> +{
> +    return (a & 0x7f) == 0;
> +}
> +
> +static inline bool float8_e5m2_is_zero(float8_e5m2 a)
> +{
> +    return (a & 0x7f) == 0;
> +}
> +
> +static inline bool float8_e4m3_is_zero_or_denormal(float8_e4m3 a)
> +{
> +    return (a & 0x78) == 0;
> +}
> +
> +static inline bool float8_e5m2_is_zero_or_denormal(float8_e5m2 a)
> +{
> +    return (a & 0x7c) == 0;
> +}
> +
> +static inline bool float8_e4m3_is_normal(float8_e4m3 a)
> +{
> +    uint8_t em = a & 0x7f;
> +    return em >= 0x8 && em <= 0x7e;
> +}
> +
> +static inline bool float8_e5m2_is_normal(float8_e5m2 a)
> +{
> +    return (((a >> 2) + 1) & 0x1f) >= 2;
> +}
> +
>  
> /*----------------------------------------------------------------------------
>  | Software half-precision conversion routines.
>  
> *----------------------------------------------------------------------------*/
> -- 
> 2.56.0
> 
> 
> 

Sent using hkml (https://github.com/sjp38/hackermail)

Reply via email to