From b3d3a3057af06dce9bab156860292c4d1e570685 Mon Sep 17 00:00:00 2001 From: arvinzzz Date: Tue, 14 Dec 2021 19:51:29 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E8=A1=A5=E5=85=85M=E6=A0=B8C?= =?UTF-8?q?=E5=BA=93=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close: #I4MGIJ Signed-off-by: arvinzzz Change-Id: Ifb5e691b1ca939ae4806316908d6044b2f98d591 --- porting/liteos_m/kernel/BUILD.gn | 19 +++++++++--- .../liteos_m/kernel/src/math/__math_divzero.c | 6 ++++ .../kernel/src/math/__math_divzerof.c | 6 ++++ .../liteos_m/kernel/src/math/__math_invalid.c | 6 ++++ .../kernel/src/math/__math_invalidf.c | 6 ++++ .../liteos_m/kernel/src/math/__math_oflow.c | 6 ++++ .../liteos_m/kernel/src/math/__math_oflowf.c | 6 ++++ .../liteos_m/kernel/src/math/__math_uflow.c | 6 ++++ .../liteos_m/kernel/src/math/__math_uflowf.c | 6 ++++ .../liteos_m/kernel/src/math/__math_xflow.c | 6 ++++ .../liteos_m/kernel/src/math/__math_xflowf.c | 6 ++++ porting/liteos_m/kernel/src/math/arm/fabs.c | 15 +++++++++ porting/liteos_m/kernel/src/math/fabs.c | 9 ++++++ porting/liteos_m/kernel/src/math/floor.c | 31 +++++++++++++++++++ 14 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 porting/liteos_m/kernel/src/math/__math_divzero.c create mode 100644 porting/liteos_m/kernel/src/math/__math_divzerof.c create mode 100644 porting/liteos_m/kernel/src/math/__math_invalid.c create mode 100644 porting/liteos_m/kernel/src/math/__math_invalidf.c create mode 100644 porting/liteos_m/kernel/src/math/__math_oflow.c create mode 100644 porting/liteos_m/kernel/src/math/__math_oflowf.c create mode 100644 porting/liteos_m/kernel/src/math/__math_uflow.c create mode 100644 porting/liteos_m/kernel/src/math/__math_uflowf.c create mode 100644 porting/liteos_m/kernel/src/math/__math_xflow.c create mode 100644 porting/liteos_m/kernel/src/math/__math_xflowf.c create mode 100644 porting/liteos_m/kernel/src/math/arm/fabs.c create mode 100644 porting/liteos_m/kernel/src/math/fabs.c create mode 100644 porting/liteos_m/kernel/src/math/floor.c diff --git a/porting/liteos_m/kernel/BUILD.gn b/porting/liteos_m/kernel/BUILD.gn index 891d8f2e..d55251b9 100644 --- a/porting/liteos_m/kernel/BUILD.gn +++ b/porting/liteos_m/kernel/BUILD.gn @@ -59,6 +59,7 @@ static_library(libc) { "src/internal/shgetc.c", "src/locale/__lctrans.c", "src/locale/c_locale.c", + "src/locale/iconv.c", "src/locale/langinfo.c", "src/misc/dirname.c", "src/misc/realpath.c", @@ -110,21 +111,19 @@ static_library(libc) { "src/stdio/stderr.c", "src/stdio/stdin.c", "src/stdio/stdout.c", + "src/stdio/ungetc.c", "src/stdio/vfprintf.c", "src/stdio/vsnprintf.c", "src/stdio/vsprintf.c", "src/stdlib/abs.c", "src/stdlib/atof.c", "src/stdlib/atoi.c", - - #"src/stdlib/strtol.c", - "src/locale/iconv.c", - "src/stdio/ungetc.c", "src/stdlib/atol.c", "src/stdlib/atoll.c", "src/stdlib/bsearch.c", "src/stdlib/llabs.c", "src/stdlib/strtod.c", + "src/stdlib/strtol.c", "src/string/memchr.c", "src/string/memcmp.c", "src/string/memcpy.c", @@ -188,9 +187,21 @@ static_library(libm) { sources = [ "src/math/__fpclassify.c", "src/math/__fpclassifyl.c", + "src/math/__math_divzero.c", + "src/math/__math_divzerof.c", + "src/math/__math_invalid.c", + "src/math/__math_invalidf.c", + "src/math/__math_oflow.c", + "src/math/__math_oflowf.c", + "src/math/__math_uflow.c", + "src/math/__math_uflowf.c", + "src/math/__math_xflow.c", + "src/math/__math_xflowf.c", "src/math/__signbit.c", "src/math/__signbitl.c", + "src/math/arm/fabs.c", "src/math/exp_data.c", + "src/math/floor.c", "src/math/frexp.c", "src/math/frexpl.c", "src/math/log.c", diff --git a/porting/liteos_m/kernel/src/math/__math_divzero.c b/porting/liteos_m/kernel/src/math/__math_divzero.c new file mode 100644 index 00000000..59d21350 --- /dev/null +++ b/porting/liteos_m/kernel/src/math/__math_divzero.c @@ -0,0 +1,6 @@ +#include "libm.h" + +double __math_divzero(uint32_t sign) +{ + return fp_barrier(sign ? -1.0 : 1.0) / 0.0; +} diff --git a/porting/liteos_m/kernel/src/math/__math_divzerof.c b/porting/liteos_m/kernel/src/math/__math_divzerof.c new file mode 100644 index 00000000..ce046f3e --- /dev/null +++ b/porting/liteos_m/kernel/src/math/__math_divzerof.c @@ -0,0 +1,6 @@ +#include "libm.h" + +float __math_divzerof(uint32_t sign) +{ + return fp_barrierf(sign ? -1.0f : 1.0f) / 0.0f; +} diff --git a/porting/liteos_m/kernel/src/math/__math_invalid.c b/porting/liteos_m/kernel/src/math/__math_invalid.c new file mode 100644 index 00000000..17740490 --- /dev/null +++ b/porting/liteos_m/kernel/src/math/__math_invalid.c @@ -0,0 +1,6 @@ +#include "libm.h" + +double __math_invalid(double x) +{ + return (x - x) / (x - x); +} diff --git a/porting/liteos_m/kernel/src/math/__math_invalidf.c b/porting/liteos_m/kernel/src/math/__math_invalidf.c new file mode 100644 index 00000000..357d4b12 --- /dev/null +++ b/porting/liteos_m/kernel/src/math/__math_invalidf.c @@ -0,0 +1,6 @@ +#include "libm.h" + +float __math_invalidf(float x) +{ + return (x - x) / (x - x); +} diff --git a/porting/liteos_m/kernel/src/math/__math_oflow.c b/porting/liteos_m/kernel/src/math/__math_oflow.c new file mode 100644 index 00000000..c85dbf98 --- /dev/null +++ b/porting/liteos_m/kernel/src/math/__math_oflow.c @@ -0,0 +1,6 @@ +#include "libm.h" + +double __math_oflow(uint32_t sign) +{ + return __math_xflow(sign, 0x1p769); +} diff --git a/porting/liteos_m/kernel/src/math/__math_oflowf.c b/porting/liteos_m/kernel/src/math/__math_oflowf.c new file mode 100644 index 00000000..fa7d0620 --- /dev/null +++ b/porting/liteos_m/kernel/src/math/__math_oflowf.c @@ -0,0 +1,6 @@ +#include "libm.h" + +float __math_oflowf(uint32_t sign) +{ + return __math_xflowf(sign, 0x1p97f); +} diff --git a/porting/liteos_m/kernel/src/math/__math_uflow.c b/porting/liteos_m/kernel/src/math/__math_uflow.c new file mode 100644 index 00000000..b90594ae --- /dev/null +++ b/porting/liteos_m/kernel/src/math/__math_uflow.c @@ -0,0 +1,6 @@ +#include "libm.h" + +double __math_uflow(uint32_t sign) +{ + return __math_xflow(sign, 0x1p-767); +} diff --git a/porting/liteos_m/kernel/src/math/__math_uflowf.c b/porting/liteos_m/kernel/src/math/__math_uflowf.c new file mode 100644 index 00000000..94d50f2b --- /dev/null +++ b/porting/liteos_m/kernel/src/math/__math_uflowf.c @@ -0,0 +1,6 @@ +#include "libm.h" + +float __math_uflowf(uint32_t sign) +{ + return __math_xflowf(sign, 0x1p-95f); +} diff --git a/porting/liteos_m/kernel/src/math/__math_xflow.c b/porting/liteos_m/kernel/src/math/__math_xflow.c new file mode 100644 index 00000000..744203c4 --- /dev/null +++ b/porting/liteos_m/kernel/src/math/__math_xflow.c @@ -0,0 +1,6 @@ +#include "libm.h" + +double __math_xflow(uint32_t sign, double y) +{ + return eval_as_double(fp_barrier(sign ? -y : y) * y); +} diff --git a/porting/liteos_m/kernel/src/math/__math_xflowf.c b/porting/liteos_m/kernel/src/math/__math_xflowf.c new file mode 100644 index 00000000..f2c84784 --- /dev/null +++ b/porting/liteos_m/kernel/src/math/__math_xflowf.c @@ -0,0 +1,6 @@ +#include "libm.h" + +float __math_xflowf(uint32_t sign, float y) +{ + return eval_as_float(fp_barrierf(sign ? -y : y) * y); +} diff --git a/porting/liteos_m/kernel/src/math/arm/fabs.c b/porting/liteos_m/kernel/src/math/arm/fabs.c new file mode 100644 index 00000000..f890520a --- /dev/null +++ b/porting/liteos_m/kernel/src/math/arm/fabs.c @@ -0,0 +1,15 @@ +#include + +#if __ARM_PCS_VFP + +double fabs(double x) +{ + __asm__ ("vabs.f64 %P0, %P1" : "=w"(x) : "w"(x)); + return x; +} + +#else + +#include "../fabs.c" + +#endif diff --git a/porting/liteos_m/kernel/src/math/fabs.c b/porting/liteos_m/kernel/src/math/fabs.c new file mode 100644 index 00000000..e8258cfd --- /dev/null +++ b/porting/liteos_m/kernel/src/math/fabs.c @@ -0,0 +1,9 @@ +#include +#include + +double fabs(double x) +{ + union {double f; uint64_t i;} u = {x}; + u.i &= -1ULL/2; + return u.f; +} diff --git a/porting/liteos_m/kernel/src/math/floor.c b/porting/liteos_m/kernel/src/math/floor.c new file mode 100644 index 00000000..14a31cd8 --- /dev/null +++ b/porting/liteos_m/kernel/src/math/floor.c @@ -0,0 +1,31 @@ +#include "libm.h" + +#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 +#define EPS DBL_EPSILON +#elif FLT_EVAL_METHOD==2 +#define EPS LDBL_EPSILON +#endif +static const double_t toint = 1/EPS; + +double floor(double x) +{ + union {double f; uint64_t i;} u = {x}; + int e = u.i >> 52 & 0x7ff; + double_t y; + + if (e >= 0x3ff+52 || x == 0) + return x; + /* y = int(x) - x, where int(x) is an integer neighbor of x */ + if (u.i >> 63) + y = x - toint + toint - x; + else + y = x + toint - toint - x; + /* special case because of non-nearest rounding modes */ + if (e <= 0x3ff-1) { + FORCE_EVAL(y); + return u.i >> 63 ? -1 : 0; + } + if (y > 0) + return x + y - 1; + return x + y; +} -- GitLab