Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libm/libmcs: add math library libmcs support #9125

Merged
merged 1 commit into from Apr 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions libs/libm/Kconfig
Expand Up @@ -39,6 +39,13 @@ config LIBM_NEWLIB
---help---
Math library from Newlib

config LIBM_LIBMCS
bool "Math library from LibmCS"
depends on !ARCH_MATH_H
depends on ALLOW_BSD_COMPONENTS
---help---
Math library from libmcs

config LIBM_OPENLIBM
bool "Math library from openlibm"
depends on !ARCH_MATH_H
Expand All @@ -60,3 +67,7 @@ endif
if LIBM_NEWLIB
source "libs/libm/newlib/Kconfig"
endif

if LIBM_LIBMCS
source "libs/libm/libmcs/Kconfig"
endif
2 changes: 2 additions & 0 deletions libs/libm/Makefile
Expand Up @@ -24,6 +24,8 @@ ifeq ($(CONFIG_LIBM),y)
include libm/Make.defs
else ifeq ($(CONFIG_LIBM_NEWLIB),y)
include newlib/Make.defs
else ifeq ($(CONFIG_LIBM_LIBMCS),y)
include libmcs/Make.defs
else ifeq ($(CONFIG_LIBM_OPENLIBM),y)
include openlibm/Make.defs
endif
Expand Down
@@ -0,0 +1,68 @@
From 84a14af9f858606a42fbdcd1f04af102594293d3 Mon Sep 17 00:00:00 2001
From: yanghuatao <yanghuatao@xiaomi.com>
Date: Thu, 23 Mar 2023 09:43:19 +0800
Subject: [PATCH 1/3] fix build error: remove unused file fenv.h

VELAPLATFO-6159

fenv.h is unused, remove it or will have conflict with quickjs.c`s fenv.h

(1)open menuconfig (2)close math.h:build setup->Customize Header Files->math.h (2) select libmcs:Library Rountines->Select math library->Math Library fram LibmCS (3)build

Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
Change-Id: I70496ce82ff2f9de9016f5c829daf9982fa32d45
---
libmcs/libmcs/libm/include/fenv.h | 41 -----------------------------------------
1 file changed, 41 deletions(-)
delete mode 100644 libm/include/fenv.h

diff --git a/libmcs/libmcs/libm/include/fenv.h libmcs/libmcs/libm/include/fenv.h
deleted file mode 100644
index 169c85627..000000000
--- a/libmcs/libmcs/libm/include/fenv.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* SPDX-License-Identifier: GTDGmbH */
-/* Copyright 2020-2021 by GTD GmbH. */
-
-#ifndef LIBMCS_FENV_H
-#define LIBMCS_FENV_H
-
-#error fenv.h/fenv.c shall not be used as is. They have no functionality \
- other than returning an error value and providing prototypes. \
- If you, the user, want to use fenv you will have to implement the \
- features yourself (or copy them from somewhere). We can not \
- provide these functionalities for you as their implementation is \
- highly platform dependant.
-
-#ifdef __cplusplus
-extern "C"{
-#endif
-
-/* Floating-point Exceptions */
-extern int feclearexcept(int);
-extern int feraiseexcept(int);
-extern int fegetexceptflag(fexcept_t *, int);
-extern int fesetexceptflag(const fexcept_t *, int);
-
-/* Rounding Direction */
-extern int fegetround();
-extern int fesetround(int);
-
-/* Entire Environment */
-extern int fegetenv(fenv_t *);
-extern int fesetenv(const fenv_t *);
-extern int feholdexcept(fenv_t *);
-extern int feupdateenv(const fenv_t *);
-
-/* Other */
-extern int fetestexcept(int);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* !LIBMCS_FENV_H */
--
2.39.1

@@ -0,0 +1,45 @@
From 462db92b2ce6645876f90fd7b6dfc423c965cc6d Mon Sep 17 00:00:00 2001
From: yanghuatao <yanghuatao@xiaomi.com>
Date: Thu, 23 Mar 2023 09:47:17 +0800
Subject: [PATCH 2/3] fix build error: do not include config.h

VELAPLATFO-6159

config.h is generated by confugure, we do not need it

(1)open menuconfig (2)close math.h:build setup->Customize Header Files->math.h (2) select libmcs:Library Rountines->Select math library->Math Library fram LibmCS (3)build

Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
Change-Id: I2d6efed47a8addee7624cbb972fb2ca914c1684c
---
libmcs/libmcs/libm/include/complex.h | 1 -
libmcs/libmcs/libm/include/math.h | 1 -
2 files changed, 2 deletions(-)

diff --git a/libmcs/libmcs/libm/include/complex.h libmcs/libmcs/libm/include/complex.h
index ab30ac979..5a2ba59ac 100644
--- a/libmcs/libmcs/libm/include/complex.h
+++ libmcs/libmcs/libm/include/complex.h
@@ -15,7 +15,6 @@
extern "C"{
#endif

-#include "config.h"
#include "internal_config.h"

#ifndef __LIBMCS_WANT_COMPLEX
diff --git a/libmcs/libmcs/libm/include/math.h libmcs/libmcs/libm/include/math.h
index 1bb0e4bab..b0f6427df 100644
--- a/libmcs/libmcs/libm/include/math.h
+++ libmcs/libmcs/libm/include/math.h
@@ -5,7 +5,6 @@
extern "C"{
#endif

-#include "config.h"
#include "internal_config.h"

/*
--
2.39.1

@@ -0,0 +1,87 @@
From 6efff584737164533272e8888e945c60b671139c Mon Sep 17 00:00:00 2001
From: yanghuatao <yanghuatao@xiaomi.com>
Date: Thu, 23 Mar 2023 09:54:59 +0800
Subject: [PATCH 3/3] fix build error: INFINITY error in quickjs.c

VELAPLATFO-6159

quickjs/quickjs.c:40035:45: error: initializer element is not constant 40035 | JS_PROP_DOUBLE_DEF("POSITIVE_INFINITY", INFINITY, 0 )

(1)open menuconfig (2)close math.h:build setup->Customize Header Files->math.h (2) select libmcs:Library Rountines->Select math library->Math Library fram LibmCS (3)build

Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
Change-Id: I6d70b7152e047b893429f49abc3c6c0e191735a4
---
libmcs/libmcs/Makefile.in | 1 -
.../2000_misc_internal.rst | 1 -
libmcs/libmcs/libm/common/tools.c | 7 -------
libmcs/libmcs/libm/include/math.h | 12 ++++++------
4 files changed, 6 insertions(+), 15 deletions(-)
delete mode 100644 libm/common/tools.c

diff --git a/libmcs/libmcs/Makefile.in libmcs/libmcs/Makefile.in
index 6e3bca4c1..a12073c6f 100644
--- a/libmcs/libmcs/Makefile.in
+++ libmcs/libmcs/Makefile.in
@@ -81,7 +81,6 @@ CSRC = libm/complexd/cabsd.c \
libm/complexf/internal/ctrigf.c

SRC = libm/common/signgam.c \
- libm/common/tools.c \
libm/mathd/acosd.c \
libm/mathd/acoshd.c \
libm/mathd/asind.c \
diff --git a/libmcs/libmcs/doc/sdd/5_Software_Design/4_Software_Component_Design_Aspects_Of_Each_Component/2000_misc_internal.rst libmcs/libmcs/doc/sdd/5_Software_Design/4_Software_Component_Design_Aspects_Of_Each_Component/2000_misc_internal.rst
index da1dd536b..f6bda14da 100644
--- a/libmcs/libmcs/doc/sdd/5_Software_Design/4_Software_Component_Design_Aspects_Of_Each_Component/2000_misc_internal.rst
+++ libmcs/libmcs/doc/sdd/5_Software_Design/4_Software_Component_Design_Aspects_Of_Each_Component/2000_misc_internal.rst
@@ -28,7 +28,6 @@ Source Code Files
^^^^^^^^^^^^^^^^^

* libm/common/tools.h
-* libm/common/tools.c

References
^^^^^^^^^^
diff --git a/libmcs/libmcs/libm/common/tools.c libmcs/libmcs/libm/common/tools.c
deleted file mode 100644
index 652dfe9f3..000000000
--- a/libmcs/libmcs/libm/common/tools.c
+++ /dev/null
@@ -1,7 +0,0 @@
-/* SPDX-License-Identifier: GTDGmbH */
-/* Copyright 2020-2021 by GTD GmbH. */
-
-#include "tools.h"
-
-const float __inff = 1.0f/0.0f;
-const double __infd = 1.0/0.0;
diff --git a/libmcs/libmcs/libm/include/math.h libmcs/libmcs/libm/include/math.h
index b0f6427df..8cfb61f6b 100644
--- a/libmcs/libmcs/libm/include/math.h
+++ libmcs/libmcs/libm/include/math.h
@@ -35,15 +35,15 @@ typedef double double_t;
#define M_SQRT2 1.41421356237309504880
#define M_SQRT1_2 0.70710678118654752440

-#define HUGE_VAL (__infd)
-#define HUGE_VALF (__inff)
+#ifndef _HUGE_ENUF
+#define _HUGE_ENUF (1e+300) /* _HUGE_ENUF*_HUGE_ENUF must overflow */
+#endif
+
+#define HUGE_VAL ((double)(_HUGE_ENUF * _HUGE_ENUF))
+#define HUGE_VALF ((float)(_HUGE_ENUF * _HUGE_ENUF))
#define HUGE_VALL ((long double) HUGE_VAL)
#define INFINITY HUGE_VALF

-/* Global constants that contain infinities. */
-extern const float __inff;
-extern const double __infd;
-
#define NAN (nanf(""))

#define FP_NAN 0
--
2.39.1

10 changes: 10 additions & 0 deletions libs/libm/libmcs/Kconfig
@@ -0,0 +1,10 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

config LIBM_LIBMCS_WANT_COMPLEX
bool "libmcs complex support"
default y
---help---
complex support, will use complex.h