Skip to content

math: extend non-glibc guard to Clang and add exp10 guard#1400

Merged
mr-c merged 1 commit intosimd-everywhere:masterfrom
kjg0724:fix/roundeven-exp10-clang-non-glibc
Mar 30, 2026
Merged

math: extend non-glibc guard to Clang and add exp10 guard#1400
mr-c merged 1 commit intosimd-everywhere:masterfrom
kjg0724:fix/roundeven-exp10-clang-non-glibc

Conversation

@kjg0724
Copy link
Copy Markdown
Contributor

@kjg0724 kjg0724 commented Mar 30, 2026

Follow-up to #1398, addressing two remaining issues reported in #1396.

1. Clang on non-AArch64 targets

The previous fix guarded __builtin_roundeven for GCC 10+ only, based
on the assumption that Clang always lowers it to an inline
llvm.roundeven.* intrinsic. That is only true on AArch64 (FRINTN).
On x86 without SSE4.1, powerpc, sparc, i386, and others, Clang emits
a roundeven()/roundevenf() libm call — same failure mode as GCC.

Fix: drop the compiler-specific check and apply the glibc >= 2.25 guard
to all compilers. Non-glibc platforms fall through to the existing
portable inline fallback.

2. __builtin_exp10 / __builtin_exp10f

exp10() is a GNU extension present only in glibc. On musl and other
non-glibc libcs the symbol is absent, producing the same class of link
error. The existing fallback (simde_math_pow(10.0, v)) is correct;
it just needs to be activated on non-glibc platforms.

Closes #1396.

The previous fix (simd-everywhere#1398) guarded __builtin_roundeven only for GCC 10+,
assuming Clang always lowers it to an inline llvm.roundeven.* intrinsic.
That assumption is wrong: Clang emits a roundeven()/roundevenf() libm
call on targets without a native rounding instruction (x86 without
SSE4.1, powerpc, sparc, i386, etc.).  On non-glibc systems (musl,
OpenBSD, FreeBSD, MinGW) the symbol is absent, causing:

  undefined reference to 'roundevenf'

Fix: drop the GCC-only restriction and apply the glibc >= 2.25 guard to
all compilers.  Non-glibc platforms fall through to the existing portable
inline fallback.

Also guard __builtin_exp10 / __builtin_exp10f: exp10() is a GNU
extension present only in glibc, so the builtin produces the same class
of link error on musl and other non-glibc libcs.  The fallback
simde_math_pow(10.0, v) / simde_math_powf(10.0f, v) is already present
and correct.

Reported by brad0 in issue simd-everywhere#1396.
@kjg0724 kjg0724 force-pushed the fix/roundeven-exp10-clang-non-glibc branch from 7a291da to e6f8243 Compare March 30, 2026 01:39
@brad0
Copy link
Copy Markdown

brad0 commented Mar 30, 2026

arm64$ cat /tmp/test.c
double foo1(double x) {
    return __builtin_roundeven(x);
}

float foo2(float x) {
    return __builtin_roundevenf(x);
}

long foo3(long x) {
    return __builtin_roundevenl(x);
}
arm64$ /usr/local/bin/clang-19 -target aarch64-unknown-openbsd -O2 -c test.c -o test.o
arm64$ nm -u test.o
arm64$ /usr/local/bin/clang-19 -target powerpc-unknown-openbsd -O2 -c test.c -o test.o
arm64$ nm -u test.o
roundeven
roundevenf
arm64$ /usr/local/bin/clang-19 -target powerpc64-unknown-openbsd -O2 -c test.c -o test.o
arm64$ nm -u test.o
.TOC.
roundeven
roundevenf
arm64$ /usr/local/bin/clang-19 -target mips64-unknown-openbsd -O2 -c test.c -o test.o
arm64$ nm -u test.o
roundeven
roundevenf
arm64$ /usr/local/bin/clang-21 -target amd64-unknown-openbsd -O2 -c test.c -o test.o
arm64$ nm -u test.o
roundeven
roundevenf

@brad0
Copy link
Copy Markdown

brad0 commented Mar 30, 2026

Thanks. I'll take this for a spin and test on the various archs OpenBSD / FreeBSD.

@brad0
Copy link
Copy Markdown

brad0 commented Mar 30, 2026

Build tested and tests run on OpenBSD/ FreeBSD amd64 with GCC and Clang. Build tests and tests run on OpenBSD aarch64 with Clang.

This also closes #1014

@mr-c mr-c linked an issue Mar 30, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Collaborator

@mr-c mr-c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @kjg0724 !

@mr-c
Copy link
Copy Markdown
Collaborator

mr-c commented Mar 30, 2026

@brad0 @kjg0724 PR(s) with additional CI configuration (non-Github Actions preferred) that would have caught some of these issues would be very welcome.

@brad0 thank you for the manual testing!

@mr-c mr-c merged commit cb5b957 into simd-everywhere:master Mar 30, 2026
131 of 132 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ld: error: undefined reference: roundevenf Several tests fail on FreeBSD with clang-15

3 participants