/* ISO C Runtime Library Copyright (c) 1983-2020 Green Hills Software, Inc. This program is the property of Green Hills Software, Inc, its contents are proprietary information and no part of it is to be disclosed to anyone except employees of Green Hills Software, Inc., or as agreed in writing signed by the President of Green Hills Software, Inc. */ /* This header provides the underlying functions __fpclassify*, __isnan*, etc. used by the standard macros fpclassify, isnan, etc. This file should only be included from other Green Hills headers. */ #ifndef _GHS_FPCLASSIFY_H #ifdef __ghs__ #pragma ghs startnomisra #endif #define _GHS_FPCLASSIFY_H #if !defined(__NoFloat) #ifdef __cplusplus extern "C" { #endif #if !defined(__ATTRIBUTES) && !defined(__attribute__) #define __attribute__(x) #define __undefine_attribute_at_end__ #endif #if defined(__GHS_GENERATE_FEE) && defined(__ghs__) #pragma ghs entry_exit_history push on #endif #if !defined(_WIN32) #if !defined(__NoDouble) int __fpclassifyd (double) __attribute__((__const__)); int __fpclassifyl (long double) __attribute__((__const__)); #endif /* __NoDouble */ int __fpclassifyf (float) __attribute__((__const__)); #if defined(__FP16_BIT) int __fpclassifyh (__fp16) __attribute__((__const__)); #endif # undef __32type # if (__SHRT_BIT == 32) # define __32type short # elif (__INT_BIT == 32) # define __32type int # elif (__LONG_BIT == 32) # define __32type long # endif # undef __16type # if (__SHRT_BIT == 16) # define __16type short # elif (__INT_BIT == 16) # define __16type int # elif (__CHAR_BIT == 16) # define __16type char # endif #define __u16type unsigned __16type #if !defined(__32type) || defined(__ONLY_STANDARD_KEYWORDS_IN_C) int __isnanf (float); int __isinff (float); #if !defined(__NoDouble) int __isnand (double); int __isinfd (double); int __isnanl (long double); int __isinfl (long double); int __signbitl (long double); int __signbitd (double); int __isnormall (long double); int __isnormald (double); int __isfinitel (long double); int __isfinited (double); #endif /* __NoDouble */ int __signbitf (float); int __isnormalf (float); int __isfinitef (float); #else #define __u32type unsigned __32type #if defined(__GNUC__) && !defined(__GNUC_STDC_INLINE__) #define __Inline_keyword_ static inline #elif defined(__cplusplus) || defined(__SC3__) || \ (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) #define __Inline_keyword_ inline #else #define __Inline_keyword_ __inline #endif /* note, the first test will fail if float.h is not #include'd first */ #if (defined(DBL_MANT_DIG) && (LDBL_MANT_DIG > DBL_MANT_DIG)) || (__LDBL_SIZE>=12) # define _M_ _MM_, # if defined(__LittleEndian) # define __GeT_ExP(_H_) (_H_ << 17) # define _Shift 17 # else # define __GeT_ExP(_H_) (_H_ << 1) # define _Shift 1 # endif # define __LDbl_Max_Exp 0xfffe0000u /* ignore integer bit when checking mantissa */ # define __LDbl_Mant_Zero ((_V_._I_._L_ ==0) && ((_V_._I_._MM_<<1)==0)) #else # define _M_ # define __GeT_ExP(_H_) ((_H_ << 1) >> 21) # define _Shift 1 # define __LDbl_Max_Exp 0x7ffu # define __LDbl_Mant_Zero ((_V_._I_._L_==0) && ((_V_._I_._H_ << 12)==0)) #endif #if defined(__ghs_max_pack_value) #pragma ghs nowarning 1959,1968 #pragma pack (push, __ghs_max_pack_value) #endif #if defined(__NoDouble) #elif defined(__DOUBLE_HL) typedef union { struct { __32type _H_, _M_ _L_; } _I_; long double _X_; } __Ldouble_int_u; typedef union { struct { __u32type _H_, _M_ _L_; } _I_; long double _X_; } __Ldouble_uns_u; typedef union { struct { __32type _H_, _L_; } _I_; double _X_; } __Double_int_u; typedef union { struct { __u32type _H_, _L_; } _I_; double _X_; } __Double_uns_u; #else typedef union { struct { __32type _L_, _M_ _H_; } _I_; long double _X_; } __Ldouble_int_u; typedef union { struct { __u32type _L_, _M_ _H_; } _I_; long double _X_; } __Ldouble_uns_u; typedef union { struct { __32type _L_, _H_; } _I_; double _X_; } __Double_int_u; typedef union { struct { __u32type _L_, _H_; } _I_; double _X_; } __Double_uns_u; #endif # undef __64type # if (__INT_BIT == 64) # define __64type int # elif (__LONG_BIT == 64) # define __64type long # elif defined(__LLONG_BIT) && (__LLONG_BIT == 64) # define __64type long long # endif # ifdef __64type # define __u64type unsigned __64type # endif #if !defined(__NO_GHS_GETDBITS) && defined(__64type) && !defined(__FloatSingle__) && !defined(__NoDouble) __u64type __ghs_getdbits(double) __attribute__((__const__)); double __ghs_setdbits(__u64type) __attribute__((__const__)); #endif #if !defined(__NO_GHS_GETFBITS) && defined(__32type) __u32type __ghs_getfbits(float) __attribute__((__const__)); float __ghs_setfbits(__u32type) __attribute__((__const__)); #endif #if defined(__16type) && defined(__FP16_BIT) __u16type __ghs_gethbits(__fp16) __attribute__((__const__)); __fp16 __ghs_sethbits(__u16type) __attribute__((__const__)); #endif /* signbit */ __Inline_keyword_ int __signbitf(float __x) { #if defined(__BigEndian__) && defined(__FR__) return (*(const unsigned char*)&__x) >> 7; #elif defined(__mc68000) && !defined(__SoftwareFloat) return (*(const unsigned char*)&__x) >> 7; #elif defined(__NO_GHS_GETFBITS) || (defined(__mc68000)) union { __32type _I_; float _X_; } _V_; _V_._X_ = __x; return _V_._I_ < 0; #else return 0 > (__32type)__ghs_getfbits((float)__x); #endif } #if !defined(__NoDouble) __Inline_keyword_ int __signbitd(double __x) { #if defined(__FloatSingle) return __signbitf(__x); #elif defined(__BigEndian__) && (defined(__mc68000) || defined(__ColdFire__)) return (*(const unsigned char*)&__x) >> 7; #elif defined(__i386) return ((const unsigned char*)&__x)[7] >> 7; #elif defined(__BigEndian__) && (defined(__SH7000) && defined(__SoftwareDouble)) return (*(const signed char*)&__x) < 0; #elif defined(__LittleEndian__) && (defined(__SH7000) && defined(__SoftwareDouble)) return ((const signed char*)&__x)[7] < 0; #elif !defined(__NO_GHS_GETFBITS) && defined(__FloatSingle__) return 0 > (__32type)__ghs_getfbits((float)__x); #elif defined(__NO_GHS_GETDBITS) || !defined(__64type) __Double_int_u _V_; _V_._X_ = __x; return _V_._I_._H_ < 0; #else return (__u64type)__ghs_getdbits((double)__x) >> 63; #endif } __Inline_keyword_ int __signbitl(long double __x) { #if defined(__BigEndian__) && (defined(__mc68000) || defined(__ColdFire__)) return (*(const unsigned char*)&__x) >> 7; #elif (__LDBL_SIZE <= 8) return __signbitd(__x); #else # if defined(__BigEndian__) return (*(const unsigned char*)&__x) >> 7; # else return ((const unsigned char*)&__x)[9] >> 7; # endif #endif } #endif /* __NoDouble */ #if defined(__FP16_BIT) __Inline_keyword_ int __signbith(__fp16 __x) { return 0 > (__16type)__ghs_gethbits((__fp16)__x); } #endif /* isnormal */ __Inline_keyword_ int __isnormalf(float __x) { #if defined(__NO_GHS_GETFBITS) union { __u32type _I_; float _X_; } _V_; __u32type __ExP__; _V_._X_ = __x; __ExP__ = ((_V_._I_ << 1) >> 24); return (0 < __ExP__) && (__ExP__ < 255); #else /* increment exponent field so 0 becomes 1, and all 1's becomes 0 */ const __u32type __ExP__ = __ghs_getfbits(__x) + (1 << 23); /* extract the exponent field, shifting out the low bit */ return (__ExP__ << 1) >> 25; /* return 0 if the original exponent was all 0's or all 1's. non-zero otherwise. */ #endif } #if !defined(__NoDouble) __Inline_keyword_ int __isnormald(double __x) { #if defined(__FloatSingle) return __isnormalf(__x); #elif defined(__NO_GHS_GETDBITS) || !defined(__64type) __Double_uns_u _V_; __u32type __ExP__; _V_._X_ = __x; __ExP__ = ((_V_._I_._H_ << 1) >> 21); return (0 < __ExP__) && (__ExP__ < 2047); #elif defined(__REG_BIT) && (__REG_BIT == 64) /* increment exponent field so 0 becomes 1, and all 1's becomes 0 */ const __u64type __ExP__ = __ghs_getdbits(__x) + (1LL << 52); /* extract the exponent field, shifting out the low bit */ return (__ExP__ << 1) >> 54; /* return 0 if the original exponent was all 0's or all 1's. non-zero otherwise. */ #else /* increment exponent field so 0 becomes 1, and all 1's becomes 0 */ const __u32type __ExP__ = (__u32type)(__ghs_getdbits(__x) >> 32) + (1 << 20); /* extract the exponent field, shifting out the low bit */ return (__ExP__ << 1) >> 22; /* return 0 if the original exponent was all 0's or all 1's. non-zero otherwise. */ #endif } __Inline_keyword_ int __isnormall(long double __x) { #if (__LDBL_SIZE <= 8) return __isnormald(__x); #else __Ldouble_uns_u _V_; __u32type __ExP__; _V_._X_ = __x; __ExP__ = __GeT_ExP(_V_._I_._H_); return (0 < __ExP__) && (__ExP__ < __LDbl_Max_Exp); #endif } #endif /* __NoDouble */ #if defined(__FP16_BIT) __Inline_keyword_ int __isnormalh(__fp16 __x) { /* increment exponent field so 0 becomes 1, and all 1's becomes 0 */ const __u32type __ExP__ = __ghs_gethbits(__x) + (1 << 10); /* extract the exponent field, shifting out the low bit */ return (__ExP__ << 17) >> 28; /* return 0 if the original exponent was all 0's or all 1's. non-zero otherwise. */ } #endif /* isfinite */ __Inline_keyword_ int __isfinitef(float __x) { #if defined(__NO_GHS_GETFBITS) union { __u32type _I_; float _X_; } _V_; _V_._X_ = __x; return ((_V_._I_ << 1) >> 24) < 255; #else const __32type __ExP__ = (__32type)(__ghs_getfbits(__x) << 1) >> 24; return (__ExP__ + 1); /* non-zero unless exponent is all 1's */ #endif } #if !defined(__NoDouble) __Inline_keyword_ int __isfinited(double __x) { #if defined(__FloatSingle) return __isfinitef(__x); #elif defined(__NO_GHS_GETDBITS) || !defined(__64type) || defined(__FloatSingle__) __Double_uns_u _V_; _V_._X_ = __x; return ((_V_._I_._H_ << 1) >> 21) < 2047; #elif defined(__REG_BIT) && (__REG_BIT == 64) const int __ExP__ = (int)((__64type)(__ghs_getdbits(__x) << 1) >> 53); return (__ExP__ + 1); /* non-zero unless exponent is all 1's */ #else __32type __ExP__ = (__32type)(__ghs_getdbits(__x) >> 32); __ExP__ <<= 1; __ExP__ >>= 21; return (__ExP__ + 1); /* non-zero unless exponent is all 1's */ #endif } __Inline_keyword_ int __isfinitel(long double __x) { #if (__LDBL_SIZE <= 8) return __isfinited(__x); #else __Ldouble_uns_u _V_; _V_._X_ = __x; return __GeT_ExP(_V_._I_._H_) < __LDbl_Max_Exp; #endif } #endif /* __NoDouble */ #if defined(__FP16_BIT) __Inline_keyword_ int __isfiniteh(__fp16 __x) { const __16type __ExP__ = (__16type)(__ghs_gethbits(__x) << 1) >> 11; return (__ExP__ + 1); /* non-zero unless exponent is all 1's */ } #endif /* isnan */ __Inline_keyword_ int __isnanf(float __x) { #if defined(__NO_GHS_GETFBITS) union { __u32type _I_; float _X_; } _V_; _V_._X_ = __x; return (_V_._I_ << 1) > 0xff000000u; #else const __u32type _I_ = (__ghs_getfbits(__x) << 1); return (_I_ > 0xff000000u); #endif } #if !defined(__NoDouble) __Inline_keyword_ int __isnand(double __x) { #if defined(__FloatSingle) return __isnanf(__x); #elif defined(__NO_GHS_GETDBITS) || !defined(__64type) || defined(__FloatSingle__) __Double_uns_u _V_; __u32type __t__; _V_._X_ = __x; __t__ = (_V_._I_._H_ << 1) >> 21; return (__t__==2047) && ((_V_._I_._L_!=0) || ((_V_._I_._H_ << 12)!=0)); #elif defined(__REG_BIT) && (__REG_BIT == 64) const __u64type __X__ = (__ghs_getdbits(__x) << 1); return (__X__ > 0xffe0000000000000ULL); #else const __u64type __X__ = __ghs_getdbits(__x); __u32type __H__ = (__u32type)(__X__ >> 32) << 1; if ((__u32type)__X__ != 0) __H__++; return (__H__ > 0xffe00000u); #endif } __Inline_keyword_ int __isnanl(long double __x) { #if (__LDBL_SIZE <= 8) return __isnand(__x); #else __Ldouble_uns_u _V_; _V_._X_ = __x; return (__GeT_ExP(_V_._I_._H_) == __LDbl_Max_Exp) && !__LDbl_Mant_Zero; #endif } #endif /* __NoDouble */ #if defined(__FP16_BIT) __Inline_keyword_ int __isnanh(__fp16 __x) { const __u16type _I_ = (__u16type)(__ghs_gethbits(__x) << 1); return (_I_ > 0xf800u); } #endif /* isinf */ __Inline_keyword_ int __isinff(float __x) { #if defined(__NO_GHS_GETFBITS) union { __u32type _I_; float _X_; } _V_; _V_._X_ = __x; return ((_V_._I_ << 1) == 0xff000000u); #else const __u32type _I_ = (__ghs_getfbits(__x) << 1); return (_I_ == 0xff000000u); #endif } #if !defined(__NoDouble) __Inline_keyword_ int __isinfd(double __x) { #if defined(__FloatSingle) return __isinff(__x); #elif defined(__NO_GHS_GETDBITS) || !defined(__64type) || defined(__FloatSingle__) || defined(__mc68000) __Double_uns_u _V_; _V_._X_ = __x; return (((_V_._I_._H_ << 1) == 0xffe00000u) && (_V_._I_._L_==0)); #elif defined(__REG_BIT) && (__REG_BIT == 64) const __u64type __X__ = (__ghs_getdbits(__x) << 1); return (__X__ == 0xffe0000000000000ULL); #else const __u64type __X__ = __ghs_getdbits(__x); const __u32type __H__ = (__u32type)(__X__ >> 32) << 1; return (__H__ == 0xffe00000u) && ((__u32type)__X__ == 0); /* if ((__u32type)__X__ != 0) __H__++; return (__H__ == 0xffe00000u); */ #endif } __Inline_keyword_ int __isinfl(long double __x) { #if (__LDBL_SIZE <= 8) return __isinfd(__x); #else __Ldouble_uns_u _V_; _V_._X_ = __x; return (__GeT_ExP(_V_._I_._H_) == __LDbl_Max_Exp) && __LDbl_Mant_Zero; #endif } #endif /* __NoDouble */ #if defined(__FP16_BIT) __Inline_keyword_ int __isinfh(__fp16 __x) { const __u16type _I_ = (__u16type)(__ghs_gethbits(__x) << 1); return (_I_ == 0xf800u); } #endif #if defined(__ghs_max_pack_value) #pragma ghs endnowarning 1959,1968 #pragma pack(pop) #endif #undef __Inline_keyword_ #undef __32type #undef __u32type #undef _M_ #undef _Shift #undef __LDbl_Max_Exp #undef __LDbl_Mant_Zero #endif /* __32type */ #endif /* !defined(_WIN32) */ #if defined(__undefine_attribute_at_end__) #undef __attribute__ #endif #if defined(__GHS_GENERATE_FEE) && defined(__ghs__) #pragma ghs entry_exit_history pop #endif #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* !defined(__NoFloat) */ #ifdef __ghs__ #pragma ghs endnomisra #endif #endif /* !defined(_GHS_FPCLASSIFY_H) */