Skip to content

Support aarch64 (AWS Graviton, Apple Silicon) - #96

Open
lorenzo wants to merge 1 commit into
haskell-works:mainfrom
kronor-io:newhoggy/support-aarch64
Open

Support aarch64 (AWS Graviton, Apple Silicon)#96
lorenzo wants to merge 1 commit into
haskell-works:mainfrom
kronor-io:newhoggy/support-aarch64

Conversation

@lorenzo

@lorenzo lorenzo commented Jul 1, 2026

Copy link
Copy Markdown

Summary

Adds aarch64 support (AWS Graviton on Linux, Apple Silicon on macOS). The C SIMD kernels use a small subset of x86 intrinsics (AVX2 / SSSE3 / BMI2); this PR provides bit-exact NEON / scalar equivalents so the library builds and runs on aarch64. NEON (Advanced SIMD) is baseline on every ARMv8-A core, so no runtime feature detection is required. The x86 build path is unchanged.

Changes

  • cbits/neon_shim.h (new): NEON implementations of the vector intrinsics used (_mm256_cmpeq_epi8, _mm256_movemask_epi8, _mm256_slli/srli_epi64, _mm_shuffle_epi8, _mm_set*, _mm_extract_epi32) and portable scalar implementations of the BMI2 bit-gather ops (_pext_u64/u32, _pdep_u64) and _lzcnt_u64, which have no NEON counterpart.
  • cbits/intrinsics.h: include the NEON shim on aarch64; keep immintrin.h/mmintrin.h on x86.
  • cbits/simd.h: drop the intrinsics.h include — its prototypes use no vector types, and dropping it keeps c2hs (which parses this header via Foreign.chs) from pulling in arm_neon.h, which its C parser cannot handle.
  • cbits/simd-spliced.c: take the vector branch of hw_json_simd_summarise on the NEON path.
  • cbits/simd.c: report the indexing kernels as available on aarch64 (they run on the NEON path).
  • hw-json-simd.cabal: emit the x86 -mavx2/-mbmi2/-msse4.2/-mssse3/-mlzcnt flags only for x86 targets; remove the base < 0 constraint that forced a build failure on ARM.
  • CI: add aarch64 runners (ubuntu-24.04-arm, macos-latest) and key the cabal cache by runner.arch.
  • Version bump to 0.1.2.0 + ChangeLog entry.

Verification

On aarch64 (Apple Silicon):

  • Differential test against x86: a harness drives every shim-affected kernel (hw_json_simd_summarise, the sm_process_chunk / sm_make_ib_op_cl_chunks state machine, sm_write_bp_chunk, and the spliced process_chunk with cross-chunk carries) with identical deterministic inputs, compiled both as arm64 (NEON shim) and x86_64 (real AVX2/BMI2/SSSE3 intrinsics, run under Rosetta). Output is byte-for-byte identical.
  • The hw-json-simd executable produces valid indexes with both the simple and standard methods, including multi-chunk documents; the balanced-parens bit count is consistent with the interesting-bits count, and running balance never underflows.
  • cabal build all and cabal test all pass.

The new aarch64 CI jobs exercise this on Linux (Graviton class) and macOS.

The C SIMD kernels use a small subset of x86 intrinsics (AVX2 / SSSE3 / BMI2).
This adds bit-exact NEON / scalar equivalents so the library builds and runs on
aarch64:

- cbits/neon_shim.h: NEON implementations of the vector intrinsics and scalar
  implementations of the BMI2 bit-gather ops (_pext / _pdep) and _lzcnt.
- cbits/intrinsics.h: include the NEON shim on aarch64; keep immintrin on x86.
- cbits/simd.h: drop the intrinsics.h include (its prototypes use no vector
  types) so c2hs, which parses this header, does not pull in arm_neon.h.
- cbits/simd-spliced.c: take the vector branch of hw_json_simd_summarise on
  the NEON path.
- cbits/simd.c: report the indexing kernels as available on aarch64.
- hw-json-simd.cabal: emit the x86 -m flags only for x86 targets; NEON is
  baseline on ARMv8-A. Remove the base < 0 constraint that blocked ARM.
- CI: add aarch64 Linux and macOS runners; key the cabal cache by runner.arch.

Verified on aarch64: every kernel's output is byte-for-byte identical to the
x86 AVX2/BMI2 build (compared via an x86_64 build run under Rosetta), and the
executable produces valid indexes for both the simple and standard methods.
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