From afa8c62071b33d31a441dccabd5d0a0bb96014c0 Mon Sep 17 00:00:00 2001 From: zhushengle Date: Fri, 17 Sep 2021 17:55:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20vfprintf=E4=BE=9D=E8=B5=96=E7=9A=84=5F?= =?UTF-8?q?=5Fsignbitl=E5=92=8C=5F=5Ffpclassifyl=E6=9C=AA=E5=8F=82?= =?UTF-8?q?=E4=B8=8E=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close #I4BPHX Change-Id: I0b40d4fea658aaac46a00f78193c7407f8188864 Signed-off-by: zhushengle --- porting/liteos_m/kernel/BUILD.gn | 4 ++ .../liteos_m/kernel/src/math/__fpclassify.c | 11 +++++ .../liteos_m/kernel/src/math/__fpclassifyl.c | 42 +++++++++++++++++++ porting/liteos_m/kernel/src/math/__signbit.c | 13 ++++++ porting/liteos_m/kernel/src/math/__signbitl.c | 14 +++++++ 5 files changed, 84 insertions(+) create mode 100644 porting/liteos_m/kernel/src/math/__fpclassify.c create mode 100644 porting/liteos_m/kernel/src/math/__fpclassifyl.c create mode 100644 porting/liteos_m/kernel/src/math/__signbit.c create mode 100644 porting/liteos_m/kernel/src/math/__signbitl.c diff --git a/porting/liteos_m/kernel/BUILD.gn b/porting/liteos_m/kernel/BUILD.gn index b0cead99..664f9493 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 00000000..f7c0e2df --- /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 00000000..e41781b6 --- /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 00000000..e700b6b7 --- /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 00000000..63b3dc5a --- /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 -- GitLab