Skip to content

Commit 6d5f8ca

Browse files
yanghuataoxiaoxiang781216
authored andcommitted
libm/openlibm: add math library openlibm support.
add math library openlibm support (1)open menuconfig (2)close math.h:build setup->Customize Header Files->math.h (3) select openlibm:Library Rountines->Select math library->Math Library fram openlibm (4)build Signed-off-by: yanghuatao <[email protected]>
1 parent 2e04d87 commit 6d5f8ca

File tree

6 files changed

+216
-0
lines changed

6 files changed

+216
-0
lines changed

libs/libm/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ config LIBM_NEWLIB
3939
---help---
4040
Math library from Newlib
4141

42+
config LIBM_OPENLIBM
43+
bool "Math library from openlibm"
44+
depends on !ARCH_MATH_H
45+
---help---
46+
Math library from openlibm
47+
4248
config LIBM_TOOLCHAIN
4349
bool "Math library from toolchain"
4450

libs/libm/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ ifeq ($(CONFIG_LIBM),y)
2424
include libm/Make.defs
2525
else ifeq ($(CONFIG_LIBM_NEWLIB),y)
2626
include newlib/Make.defs
27+
else ifeq ($(CONFIG_LIBM_OPENLIBM),y)
28+
include openlibm/Make.defs
2729
endif
2830

2931
BINDIR ?= bin
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
From 147f2e6962c7624920909c3e4a4ef120e6814a66 Mon Sep 17 00:00:00 2001
2+
From: yanghuatao <[email protected]>
3+
Date: Fri, 24 Mar 2023 11:55:02 +0800
4+
Subject: [PATCH 1/2] fix build float_t error: float_t has not been declared
5+
MIME-Version: 1.0
6+
Content-Type: text/plain; charset=UTF-8
7+
Content-Transfer-Encoding: 8bit
8+
9+
VELAPLATFO-6159
10+
11+
libcxx/cmath:335:9: error: ‘::float_t’ has not been declared
12+
13+
(1)open menuconfig (2)close math.h:build setup->Customize Header Files->math.h (2) select openlibm:Library Rountines->Select math library->Math Library fram openlibm (3)build
14+
15+
Signed-off-by: yanghuatao <[email protected]>
16+
Change-Id: Iec6dbcebbe4ef15a96bcebb038f0c64ab39c5af7
17+
---
18+
include/openlibm_math.h | 4 ++--
19+
1 file changed, 2 insertions(+), 2 deletions(-)
20+
21+
diff --git a/openlibm/openlibm/include/openlibm_math.h openlibm/openlibm/include/openlibm_math.h
22+
index 701ad70..988e80c 100644
23+
--- a/openlibm/openlibm/include/openlibm_math.h
24+
+++ openlibm/openlibm/include/openlibm_math.h
25+
@@ -149,8 +149,8 @@ extern const union __nan_un {
26+
: __signbitl(x))
27+
28+
//VBS
29+
-//typedef __double_t double_t;
30+
-//typedef __float_t float_t;
31+
+typedef float float_t;
32+
+typedef double double_t;
33+
#endif /* __ISO_C_VISIBLE >= 1999 */
34+
35+
/*
36+
--
37+
2.39.1
38+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
From 8af59fe95d7c878d96752cdc655d70ffbef28514 Mon Sep 17 00:00:00 2001
2+
From: yanghuatao <[email protected]>
3+
Date: Sat, 25 Mar 2023 11:05:58 +0800
4+
Subject: [PATCH 2/2] add math.h and complex.h to openlibm
5+
6+
VELAPLATFO-6159
7+
8+
openlibm do not have math.h and complex.h, so we add them to openlibm
9+
10+
(1)open menuconfig (2)close math.h:build setup->Customize Header Files->math.h (2) select openlibm:Library Rountines->Select math library->Math Library fram openlibm (3)build
11+
12+
Signed-off-by: yanghuatao <[email protected]>
13+
Change-Id: I0bebef549c3ce7226a190d6a16a347f47014ad0b
14+
---
15+
include/complex.h | 6 ++++++
16+
include/math.h | 6 ++++++
17+
2 files changed, 12 insertions(+)
18+
create mode 100644 include/complex.h
19+
create mode 100644 include/math.h
20+
21+
diff --git a/openlibm/openlibm/include/complex.h openlibm/openlibm/include/complex.h
22+
new file mode 100644
23+
index 0000000..c97e82b
24+
--- /dev/null
25+
+++ openlibm/openlibm/include/complex.h
26+
@@ -0,0 +1,6 @@
27+
+#ifndef OPENLIBM_MATH_COMPLEX_H
28+
+#define OPENLIBM_MATH_COMPLEX_H
29+
+
30+
+#include <openlibm_complex.h>
31+
+
32+
+#endif /* OPENLIBM_MATH_COMPLEX_H */
33+
\ No newline at end of file
34+
diff --git a/openlibm/openlibm/include/math.h openlibm/openlibm/include/math.h
35+
new file mode 100644
36+
index 0000000..0004b77
37+
--- /dev/null
38+
+++ openlibm/openlibm/include/math.h
39+
@@ -0,0 +1,6 @@
40+
+#ifndef OPENLIBM_MATH_MATH_H
41+
+#define OPENLIBM_MATH_MATH_H
42+
+
43+
+#include <openlibm_math.h>
44+
+
45+
+#endif /* !OPENLIBM_MATH_MATH_H */
46+
\ No newline at end of file
47+
--
48+
2.39.1
49+

libs/libm/openlibm/Make.defs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
2+
############################################################################
3+
# libs/libm/openlibm/Make.defs
4+
#
5+
# Licensed to the Apache Software Foundation (ASF) under one or more
6+
# contributor license agreements. See the NOTICE file distributed with
7+
# this work for additional information regarding copyright ownership. The
8+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
9+
# "License"); you may not use this file except in compliance with the
10+
# License. You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17+
# License for the specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
############################################################################
21+
22+
OPENLIBM_VERSION=0.8.1
23+
24+
openlibm-$(OPENLIBM_VERSION).zip:
25+
$(call DOWNLOAD,https://github.com/JuliaMath/openlibm/archive/refs/tags,v$(OPENLIBM_VERSION).zip,openlibm.zip)
26+
27+
openlibm/openlibm: openlibm-$(OPENLIBM_VERSION).zip
28+
$(Q) unzip -o openlibm.zip
29+
$(Q) mv openlibm-$(OPENLIBM_VERSION) openlibm/openlibm
30+
$(Q) patch -p0 < openlibm/0001-fix-build-float_t-error-float_t-has-not-been-declare.patch
31+
$(Q) patch -p0 < openlibm/0002-add-math.h-and-complex.h-to-openlibm.patch
32+
33+
ifeq ($(wildcard openlibm/openlibm/.git),)
34+
distclean::
35+
$(call DELFILE, openlibm.zip)
36+
$(call DELDIR, openlibm/openlibm)
37+
context:: openlibm/openlibm
38+
else
39+
distclean::
40+
context::
41+
endif
42+
43+
# OS-specific stuff
44+
# Get ARCH, it is used to read source code file list form $(ARCH)/Make.files
45+
ifeq ($(CONFIG_ARCH),sim)
46+
ifeq ($(CONFIG_SIM_M32),y)
47+
ARCH = i387
48+
else ifeq ($(CONFIG_HOST_ARM64),y)
49+
ARCH = aarch64
50+
else ifeq ($(CONFIG_HOST_ARM),y)
51+
ARCH = arm
52+
else ifeq ($(CONFIG_HOST_X86),y)
53+
ARCH = i387
54+
else
55+
ARCH = amd64
56+
endif
57+
else ifeq ($(CONFIG_ARCH),risc-v)
58+
ARCH = riscv64
59+
else ifeq ($(CONFIG_ARCH),arm)
60+
ARCH = arm
61+
else ifeq ($(CONFIG_ARCH),arm64)
62+
ARCH = arm64
63+
else ifeq ($(CONFIG_ARCH),x86)
64+
ARCH = i387
65+
else ifeq ($(CONFIG_ARCH),x86_64)
66+
ARCH = amd64
67+
else
68+
ARCH = $(CONFIG_ARCH)
69+
endif
70+
71+
# Get source code lits from Make.files,and append to variable SRCS
72+
# (1) Override CUR_SRCS to xxx_SRCS(for example src_SRCS etc.), then in xxx/Make.files CUR_SRCS is changed to xxx_SRCS.
73+
# (2) Include Make.files
74+
# (3) Get variable xxx_SRCS from Make.files, and append it to variable SRCS
75+
define INC_template
76+
ifneq ($(wildcard $(1)/Make.files),)
77+
override CUR_SRCS = $(2)_SRCS
78+
include $(1)/Make.files
79+
SRCS += $$($(2)_SRCS)
80+
endif
81+
endef
82+
83+
# Determines whether `long double` is the same as `double` on this arch.
84+
# linux x86_64, for instance, `long double` is 80 bits wide, whereas on macOS aarch64,
85+
# `long double` is the same as `double`.
86+
ifneq ($(filter $(ARCH),i387 amd64),) # Add ld80 directory on x86 and x64
87+
$(eval $(call INC_template,openlibm/openlibm/ld80))
88+
VPATH += :openlibm/openlibm/ld80
89+
else ifneq ($(filter $(ARCH),aarch64),) # Add ld128 directory on aarch64
90+
$(eval $(call INC_template,openlibm/openlibm/ld128))
91+
VPATH += :openlibm/openlibm/ld128
92+
endif
93+
94+
$(eval $(call INC_template,openlibm/openlibm/src,src))
95+
$(eval $(call INC_template,openlibm/openlibm/$(ARCH),$(ARCH)))
96+
$(eval $(call INC_template,openlibm/openlibm/bsdsrc,bsdsrc))
97+
98+
VPATH += :openlibm/openlibm/src
99+
VPATH += :openlibm/openlibm/$(ARCH)
100+
VPATH += :openlibm/openlibm/bsdsrc
101+
102+
CFLAGS += ${INCDIR_PREFIX}openlibm/openlibm
103+
CFLAGS += ${INCDIR_PREFIX}openlibm/openlibm/$(ARCH)
104+
CFLAGS += ${INCDIR_PREFIX}openlibm/openlibm/src
105+
CFLAGS += ${DEFINE_PREFIX}__BSD_VISIBLE
106+
107+
AFLAGS += ${INCDIR_PREFIX}openlibm/openlibm
108+
AFLAGS += ${INCDIR_PREFIX}openlibm/openlibm/$(ARCH)
109+
AFLAGS += ${INCDIR_PREFIX}openlibm/openlibm/src
110+
AFLAGS += ${DEFINE_PREFIX}__BSD_VISIBLE
111+
112+
CSRCS := $(sort $(filter %.c,$(SRCS)))
113+
ASRCS := $(sort $(filter %.S,$(SRCS)))
114+
115+
# CSRCS and ASRCS have the same name files, we use .S files,so remove them from CSRCS
116+
CSRCS := $(filter-out $(patsubst %.S,%.c,$(ASRCS)),$(CSRCS))

tools/Config.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,11 @@ ifeq ($(CONFIG_LIBM_NEWLIB),y)
662662
ARCHXXINCLUDES += ${INCSYSDIR_PREFIX}$(TOPDIR)$(DELIM)libs$(DELIM)libm$(DELIM)newlib$(DELIM)include
663663
endif
664664

665+
ifeq ($(CONFIG_LIBM_OPENLIBM),y)
666+
ARCHINCLUDES += ${INCSYSDIR_PREFIX}$(TOPDIR)$(DELIM)libs$(DELIM)libm$(DELIM)openlibm$(DELIM)openlibm$(DELIM)include
667+
ARCHXXINCLUDES += ${INCSYSDIR_PREFIX}$(TOPDIR)$(DELIM)libs$(DELIM)libm$(DELIM)openlibm$(DELIM)openlibm$(DELIM)include
668+
endif
669+
665670
ARCHXXINCLUDES += ${INCSYSDIR_PREFIX}$(TOPDIR)$(DELIM)include
666671

667672
# Convert filepaths to their proper system format (i.e. Windows/Unix)

0 commit comments

Comments
 (0)