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` #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 2158ac7 commit c200c16
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ jobs:
run: |
git clone https://github.com/emscripten-core/emsdk.git /opt/emsdk
cd /opt/emsdk
./emsdk install 4e7eadf19c76c143e522b535254eb99a9b34fd6d
./emsdk activate 4e7eadf19c76c143e522b535254eb99a9b34fd6d
./emsdk install tot
./emsdk activate tot
source emsdk_env.sh
- name: Install v8
run: |
Expand Down Expand Up @@ -532,6 +532,9 @@ jobs:
distro: ubuntu-22.04
arch_flags: -ffast-math -Wno-unsafe-buffer-usage
ccache: 'true'
- version: "17"
distro: ubuntu-22.04
arch_flags: -march=native -Wno-unsafe-buffer-usage -O2
runs-on: ${{ matrix.distro }}
env:
CFLAGS: ${{ matrix.arch_flags }} -Wall -Weverything -Werror -fno-lax-vector-conversions
Expand Down
17 changes: 17 additions & 0 deletions docker/cross-files/i686-gcc-14.cross
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[binaries]
c = 'i686-linux-gnu-gcc-14'
cpp = 'i686-linux-gnu-g++-14'
ar = 'i686-linux-gnu-ar'
strip = 'i686-linux-gnu-strip'
objcopy = 'i686-linux-gnu-objcopy'
ld = 'i686-linux-gnu-ld'

[properties]
c_args = ['-Wextra', '-Werror', '-march=prescott']
cpp_args = ['-Wextra', '-Werror', '-march=prescott']

[host_machine]
system = 'linux'
cpu_family = 'x86'
cpu = 'prescott'
endian = 'little'
4 changes: 2 additions & 2 deletions simde/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 c200c16

Please sign in to comment.