diff --git a/porting/liteos_m/kernel/BUILD.gn b/porting/liteos_m/kernel/BUILD.gn index 891d8f2e4d26c9d1eae953681bca9f06a5046c9d..d55251b9d470228b4d3603951346608299e4517b 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 0000000000000000000000000000000000000000..59d2135001ca33e1de10875ca05b361cf455a3ae --- /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 0000000000000000000000000000000000000000..ce046f3e320a99e001f260bb08a46b4775d93ce5 --- /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 0000000000000000000000000000000000000000..177404900d161e4224c1424ec59f08353269d114 --- /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 0000000000000000000000000000000000000000..357d4b121176783974a366e10f68c4d749050cdf --- /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 0000000000000000000000000000000000000000..c85dbf982a0db036a7edf0a1bb32c74de208b185 --- /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 0000000000000000000000000000000000000000..fa7d06208e41da7ad2ba0fbe912af70d4bf82d95 --- /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 0000000000000000000000000000000000000000..b90594aee14e54144ad4c1695a446fbba12395a4 --- /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 0000000000000000000000000000000000000000..94d50f2bf12973f9a1d37ee613cdb7299afc12a4 --- /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 0000000000000000000000000000000000000000..744203c4c817b02c73c21cd89b7e4e9349433498 --- /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 0000000000000000000000000000000000000000..f2c84784f81f8acdcb734f04f220358a26afb617 --- /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 0000000000000000000000000000000000000000..f890520a5cd78d38ee3285aba4e179c730f76768 --- /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 0000000000000000000000000000000000000000..e8258cfdbcf1a751621a69bac02f0f0f9b22b1cf --- /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 0000000000000000000000000000000000000000..14a31cd8c4c549750205369a6fe9e71eec8f71c5 --- /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; +}