diff --git a/porting/liteos_m/kernel/BUILD.gn b/porting/liteos_m/kernel/BUILD.gn index b0cead99a766a15403b49ff0520c1c81382dc8dd..664f9493766dfd946f73d9e9d96bb8b1890e23b0 100644 --- a/porting/liteos_m/kernel/BUILD.gn +++ b/porting/liteos_m/kernel/BUILD.gn @@ -174,6 +174,10 @@ static_library(libc) { static_library(libm) { sources = [ + "src/math/__fpclassify.c", + "src/math/__fpclassifyl.c", + "src/math/__signbit.c", + "src/math/__signbitl.c", "src/math/exp_data.c", "src/math/frexp.c", "src/math/frexpl.c", diff --git a/porting/liteos_m/kernel/src/math/__fpclassify.c b/porting/liteos_m/kernel/src/math/__fpclassify.c new file mode 100644 index 0000000000000000000000000000000000000000..f7c0e2dfac828616b43f76664c6821de1b348f8d --- /dev/null +++ b/porting/liteos_m/kernel/src/math/__fpclassify.c @@ -0,0 +1,11 @@ +#include +#include + +int __fpclassify(double x) +{ + union {double f; uint64_t i;} u = {x}; + int e = u.i>>52 & 0x7ff; + if (!e) return u.i<<1 ? FP_SUBNORMAL : FP_ZERO; + if (e==0x7ff) return u.i<<12 ? FP_NAN : FP_INFINITE; + return FP_NORMAL; +} diff --git a/porting/liteos_m/kernel/src/math/__fpclassifyl.c b/porting/liteos_m/kernel/src/math/__fpclassifyl.c new file mode 100644 index 0000000000000000000000000000000000000000..e41781b689af7f7db420fc437cc4a72e4dd00c33 --- /dev/null +++ b/porting/liteos_m/kernel/src/math/__fpclassifyl.c @@ -0,0 +1,42 @@ +#include "libm.h" + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +int __fpclassifyl(long double x) +{ + return __fpclassify(x); +} +#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 +int __fpclassifyl(long double x) +{ + union ldshape u = {x}; + int e = u.i.se & 0x7fff; + int msb = u.i.m>>63; + if (!e && !msb) + return u.i.m ? FP_SUBNORMAL : FP_ZERO; + if (e == 0x7fff) { + /* The x86 variant of 80-bit extended precision only admits + * one representation of each infinity, with the mantissa msb + * necessarily set. The version with it clear is invalid/nan. + * The m68k variant, however, allows either, and tooling uses + * the version with it clear. */ + if (__BYTE_ORDER == __LITTLE_ENDIAN && !msb) + return FP_NAN; + return u.i.m << 1 ? FP_NAN : FP_INFINITE; + } + if (!msb) + return FP_NAN; + return FP_NORMAL; +} +#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 +int __fpclassifyl(long double x) +{ + union ldshape u = {x}; + int e = u.i.se & 0x7fff; + u.i.se = 0; + if (!e) + return u.i2.lo | u.i2.hi ? FP_SUBNORMAL : FP_ZERO; + if (e == 0x7fff) + return u.i2.lo | u.i2.hi ? FP_NAN : FP_INFINITE; + return FP_NORMAL; +} +#endif diff --git a/porting/liteos_m/kernel/src/math/__signbit.c b/porting/liteos_m/kernel/src/math/__signbit.c new file mode 100644 index 0000000000000000000000000000000000000000..e700b6b75fcb91e1919ad64b7da4e8c6a16f6065 --- /dev/null +++ b/porting/liteos_m/kernel/src/math/__signbit.c @@ -0,0 +1,13 @@ +#include "libm.h" + +// FIXME: macro in math.h +int __signbit(double x) +{ + union { + double d; + uint64_t i; + } y = { x }; + return y.i>>63; +} + + diff --git a/porting/liteos_m/kernel/src/math/__signbitl.c b/porting/liteos_m/kernel/src/math/__signbitl.c new file mode 100644 index 0000000000000000000000000000000000000000..63b3dc5a08f3d89a3dd39a3ce74d7974317a0aa9 --- /dev/null +++ b/porting/liteos_m/kernel/src/math/__signbitl.c @@ -0,0 +1,14 @@ +#include "libm.h" + +#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 +int __signbitl(long double x) +{ + union ldshape u = {x}; + return u.i.se >> 15; +} +#elif LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +int __signbitl(long double x) +{ + return __signbit(x); +} +#endif