Skip to content

Support aarch64 / arm architectures (e.g. AWS Graviton) - #76

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

Support aarch64 / arm architectures (e.g. AWS Graviton)#76
lorenzo wants to merge 1 commit into
haskell-works:mainfrom
kronor-io:newhoggy/support-aarch64

Conversation

@lorenzo

@lorenzo lorenzo commented Jun 30, 2026

Copy link
Copy Markdown

Summary

Adds support for non-x86 architectures (notably aarch64 / arm, e.g. AWS Graviton on Linux). Previously the package forced a build failure on ARM via an unsatisfiable base < 0 constraint, because the C sources and compiler flags assumed x86 SIMD intrinsics.

On non-x86 targets the library now builds and runs using the existing pure-Haskell Stock implementations (the dispatch in Comparison/Logical already falls back to Stock whenever avx2Enabled is False). x86 behaviour is unchanged.

Changes

  • hw-simd.cabal: only emit the x86 instruction-set flags (-mavx2, -mbmi2, -msse4.2) when building for an x86 target (arch(x86_64) || arch(i386)); remove the base < 0 ARM block.
  • cbits/simd_avx2.c: guard the x86 intrinsic includes (immintrin.h, mmintrin.h) behind AVX2_ENABLED. The function bodies were already guarded by AVX2_ENABLED, so on non-x86 they compile to no-ops.
  • cbits/simd_sse2.c: guard the (unbound) sse_cmpeq8 and its intrinsic includes behind __x86_64__ / __i386__. This function is not bound from Haskell.
  • CI: add an ubuntu-24.04-arm runner and disambiguate the cabal-cache archive-uri by runner.arch (x86_64 and aarch64 Linux otherwise share runner.os == Linux).
  • Version bump to 0.1.3.0 + ChangeLog entry.

Verification

Built and tested locally on aarch64:

  • cabal build lib:hw-simd — succeeds.
  • cabal test all — both suites pass (hw-simd-test hspec/hedgehog: 3 examples, 0 failures; doctest: pass).
  • The +bmi2-flagged sibling deps (bits-extra, hw-rankselect*) also build on aarch64, so the dependency chain is Graviton-ready.

Notes / follow-up

This PR provides functional (correct, scalar) support on ARM via the Stock path. Actual ARM SIMD acceleration (NEON implementations behind a neon flag, mirroring the AVX2 structure) is left as a possible follow-up.

The package previously forced a build failure on non-x86 architectures via
an unsatisfiable `base < 0` constraint, because the C sources and compiler
flags assumed x86 SIMD intrinsics.

This makes the library build and run on aarch64 / arm, falling back to the
pure-Haskell "Stock" implementations:

- cabal: only emit the x86 instruction-set flags (-mavx2, -mbmi2, -msse4.2)
  when building for an x86 target (arch(x86_64) || arch(i386)); remove the
  `base < 0` block.
- cbits/simd_avx2.c: guard the x86 intrinsic includes behind AVX2_ENABLED
  (the function bodies were already so guarded, so they become no-ops).
- cbits/simd_sse2.c: guard the unbound sse_cmpeq8 and its intrinsic includes
  behind __x86_64__ / __i386__.
- CI: add an ubuntu-24.04-arm runner and disambiguate the cabal-cache key by
  runner.arch (x86_64 and aarch64 Linux otherwise share runner.os).

Verified on aarch64: library builds and the hspec/hedgehog test suite passes.
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