Skip to content

Commit

Permalink
libm/newlib: Add arch-specific source code first to CSRCS
Browse files Browse the repository at this point in the history
Source code under `newlib/newlib/newlib/libm/machine/$(ARCH)/*.c`
should be added before common source code from `../../common/*.c`.
Take `newlib/newlib/newlib/libm/machine/riscv/s_fma.c` as an
example:

```

double
fma (double x, double y, double z)
{
        double result;
        asm ("fmadd.d %0, %1, %2, %3" : "=f" (result) : "f" (x), "f" (y), "f" (z));
        return result;
}

```

Note that the common `s_fma.c` will be included by the source file
directly. The order of adding the files to CSRCS matters here.

Although the CMake-based build system does not have the same build
problem of including the a source-file with the same in the wrong
order, this commit also changes the order of inclusion for CMake
too to keep it consistent.
  • Loading branch information
tmedicci authored and xiaoxiang781216 committed Dec 3, 2024
1 parent 80dd961 commit 5456668
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
5 changes: 3 additions & 2 deletions libs/libm/newlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ if(CONFIG_LIBM_NEWLIB)
set(ARCH_DIR ${CONFIG_ARCH})
endif()

file(GLOB_RECURSE COMMON_CSRCS ${NEWLIB_DIR}/newlib/libm/common/*.c)
file(GLOB_RECURSE COMPLEX_CSRCS ${NEWLIB_DIR}/newlib/libm/complex/*.c)
file(GLOB_RECURSE ARCH_CSRCS
${NEWLIB_DIR}/newlib/libm/machine/${ARCH_DIR}/*.c)

file(GLOB_RECURSE COMMON_CSRCS ${NEWLIB_DIR}/newlib/libm/common/*.c)
file(GLOB_RECURSE COMPLEX_CSRCS ${NEWLIB_DIR}/newlib/libm/complex/*.c)

if(CONFIG_ARCH_X86_64)
file(GLOB_RECURSE ARCH_CSRCS ${NEWLIB_DIR}/newlib/libm/fenv/*.c)
endif()
Expand Down
15 changes: 7 additions & 8 deletions libs/libm/newlib/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ $(TOPDIR)/include/newlib: newlib/newlib

context:: $(TOPDIR)/include/newlib

CSRCS += $(wildcard newlib/newlib/newlib/libm/common/*.c)
CSRCS += $(wildcard newlib/newlib/newlib/libm/complex/*.c)

VPATH += :newlib/newlib/newlib/libm/common
VPATH += :newlib/newlib/newlib/libm/complex
DEPPATH += --dep-path newlib/newlib/newlib/libm/common
DEPPATH += --dep-path newlib/newlib/newlib/libm/complex

ifeq ($(CONFIG_ARCH_ARM),y)
ARCH = arm
else ifeq ($(CONFIG_ARCH_ARM64),y)
Expand All @@ -88,6 +80,13 @@ CSRCS += $(wildcard newlib/newlib/newlib/libm/machine/$(ARCH)/*.c)
VPATH += :newlib/newlib/newlib/libm/machine/$(ARCH)
DEPPATH += --dep-path newlib/newlib/newlib/libm/machine/$(ARCH)

CSRCS += $(wildcard newlib/newlib/newlib/libm/common/*.c)
CSRCS += $(wildcard newlib/newlib/newlib/libm/complex/*.c)

VPATH += :newlib/newlib/newlib/libm/common
VPATH += :newlib/newlib/newlib/libm/complex
DEPPATH += --dep-path newlib/newlib/newlib/libm/common
DEPPATH += --dep-path newlib/newlib/newlib/libm/complex

ifeq ($(CONFIG_ARCH_X86_64),y)
CSRCS += $(wildcard newlib/newlib/newlib/libm/fenv/*.c)
Expand Down

0 comments on commit 5456668

Please sign in to comment.