Skip to content

Commit

Permalink
arm/neon abs: negating INT_MIN is undefined behavior
Browse files Browse the repository at this point in the history
- So cast to unsigned int before flipping sign, and then cast back to a signed int

LLVM 19 is making this more prominant: llvm/llvm-project#82112 (comment)
But this was already visible in earlier clang versions with `-O2` simd-everywhere/simde#901

- gh-actions: resume testing emscripten using the 'tip of tree' ("tot") builds.
- gh-actions: add clang-17 "-O2" build to confirm the fix
  • Loading branch information
mr-c committed Feb 22, 2024
1 parent 453dec2 commit 22a493c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions arm/neon/abs.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ simde_vabsq_s32(simde_int32x4_t a) {
#else
SIMDE_VECTORIZE
for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
r_.values[i] = a_.values[i] < 0 ? -a_.values[i] : a_.values[i];
r_.values[i] = a_.values[i] < 0 ? HEDLEY_STATIC_CAST(int32_t, 0 - HEDLEY_STATIC_CAST(uint32_t, a_.values[i])) : a_.values[i];
}
#endif

Expand Down Expand Up @@ -476,7 +476,7 @@ simde_vabsq_s64(simde_int64x2_t a) {
#else
SIMDE_VECTORIZE
for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
r_.values[i] = a_.values[i] < 0 ? -a_.values[i] : a_.values[i];
r_.values[i] = a_.values[i] < 0 ? HEDLEY_STATIC_CAST(int64_t, 0 - HEDLEY_STATIC_CAST(uint64_t, a_.values[i])) : a_.values[i];
}
#endif

Expand Down

0 comments on commit 22a493c

Please sign in to comment.