Skip to content

Bug: add exp, exp2, expm1 and cbrt to the fallback simd - #54

Open
ax3l wants to merge 2 commits into
mattkretz:masterfrom
ax3l:topic-fallback-exp
Open

Bug: add exp, exp2, expm1 and cbrt to the fallback simd#54
ax3l wants to merge 2 commits into
mattkretz:masterfrom
ax3l:topic-fallback-exp

Conversation

@ax3l

@ax3l ax3l commented Aug 26, 2026

Copy link
Copy Markdown

vir::stdx's own simd, used where the standard library has no <experimental/simd>, implements most of the Parallelism TS math set but not exp, exp2, expm1 or cbrt. sin, log, log2, erf, pow and hypot are all there, so the gap is easy to miss until portable code calls one of the four.

It showed up building AMReX on macOS, where Apple Clang and libc++ select this simd:

error: no member named 'exp' in namespace 'vir::stdx'

for those four and nothing else. Added with the same SIMD_MATH_1ARG as their neighbours, so they are per-lane like the rest of this fallback.

Second commit adds exponential.cc, mirroring logarithm.cc — these four had no test, which is part of why the hole went unnoticed. It does not compile without the first commit.

vir's own simd, used where the standard library has no
<experimental/simd>, implements most of the Parallelism TS math set but
not these four. sin, cos, log, log2, erf, pow and hypot are all there;
exp is not, which is a surprising hole to land in.

It surfaces as soon as anything portable calls them. AMReX builds on
macOS, where Apple Clang and libc++ select this simd, failed to compile
its amrex::Math SIMD overloads with

  error: no member named 'exp' in namespace 'vir::stdx'

for exp, exp2, expm1 and cbrt, and for nothing else.

They go in with the same SIMD_MATH_1ARG the neighbouring functions use,
so they are per-lane like the rest of this fallback. Nothing here is
about the vector math library: a target that reaches this code has no
libmvec to route to in the first place.

Worth noting where this does NOT belong. The gap is in the simd type
itself, so filling it in vir::vecmath, or in each consumer, would leave
vir::stdx incomplete for everyone calling it directly.
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Comment thread testsuite/tests/exponential.cc Outdated
Comment thread testsuite/tests/exponential.cc Outdated
@ax3l ax3l changed the title simd: add exp, exp2, expm1 and cbrt to the fallback simd Bug: add exp, exp2, expm1 and cbrt to the fallback simd Aug 26, 2026
logarithm.cc covers log, log10, log1p, log2 and logb; math_1arg.cc
covers erf, sqrt and their neighbours. The four functions the previous
commit adds had no test at all, which is part of why the hole went
unnoticed.

Same shape as logarithm.cc. The exponentials get a range that reaches
overflow and underflow from both sides, and the small values are there
for expm1, which exists precisely to stay accurate where exp(x) - 1
cancels. cbrt is tested over the whole range instead, since unlike the
exponentials it is defined for negative arguments.

Without the previous commit this test does not compile, so it does
cover what it claims to.
@ax3l
ax3l force-pushed the topic-fallback-exp branch from 192d8e9 to aae700a Compare August 26, 2026 06:13
@ax3l

ax3l commented Aug 26, 2026

Copy link
Copy Markdown
Author

@mattkretz this is a bug fix (at least on macOS), first seen in #53 and worth running CI on and merging on its own.

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.

1 participant