Bug: add exp, exp2, expm1 and cbrt to the fallback simd - #54
Open
ax3l wants to merge 2 commits into
Open
Conversation
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.
Not up to standards ⛔
|
ax3l
commented
Aug 26, 2026
ax3l
commented
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
force-pushed
the
topic-fallback-exp
branch
from
August 26, 2026 06:13
192d8e9 to
aae700a
Compare
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
vir::stdx's own simd, used where the standard library has no<experimental/simd>, implements most of the Parallelism TS math set but notexp,exp2,expm1orcbrt.sin,log,log2,erf,powandhypotare 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:
for those four and nothing else. Added with the same
SIMD_MATH_1ARGas their neighbours, so they are per-lane like the rest of this fallback.Second commit adds
exponential.cc, mirroringlogarithm.cc— these four had no test, which is part of why the hole went unnoticed. It does not compile without the first commit.