Skip to content

Fix arm64 NEON dispatch to use the existing shared wrappers - #2

Open
thomasahle wants to merge 1 commit into
jbapple:mainfrom
thomasahle:fix-neon-dispatch
Open

thomasahle wants to merge 1 commit into
jbapple:mainfrom
thomasahle:fix-neon-dispatch

Conversation

@thomasahle

Copy link
Copy Markdown

Fixes #1.

example.cpp fails to compile on arm64 because the NEON dispatch instantiates V2Neon, V3Neon, and V4Neon, while the shared SSE2/NEON wrappers are declared as V2Sse2, V3Sse2, and V4Sse2.

Use the same SSE2-or-NEON guard for the dispatch as for those wrapper declarations, and remove the duplicate branch that references undeclared functions. The existing arm64 BlockWrapper128 continues to execute NEON operations. The header change is one guard edit and deletion of the obsolete branch; the hash implementations and x86 dispatch remain unchanged.

Add check-dispatch.cpp, a standalone test in the style of the existing consistency checker. It reads entropy arrays and input bytes from a simple text stream and emits all returned words from HalftimeHashStyle64/128/256/512 and advanced::V1<3> through V4<3>. Compile it with -DHALFTIME_TEST_SCALAR to select the header's existing scalar fallback; that test-only option undefines the architecture feature macros before including the header. The normal build uses native dispatch without aliases or header substitutions.

Verified against upstream commit caf7924ceab4721f4e0cc33442b185558ba7f1c4:

  • Apple M2 Pro, macOS 27.0, Apple clang 17.0.0 (clang-1700.6.4.2): the stock example fails with 12 undeclared-name diagnostics; the fixed example compiles and runs with -std=c++17 -O2, both with default target flags and -march=armv8-a+crypto.
  • The same explicit JSON vectors were read on the Mac and an Intel Xeon Platinum 8375C running Linux with GCC 11.5.0. There are 4,609 random byte inputs: one at every length 0–4,096, plus 512 randomly selected lengths. Each selects one of 64 random entropy arrays, each containing the public kEntropyBytesNeeded / sizeof(uint64_t) allocation of 8,866 words. The JSON stores the actual entropy words and input bytes, not just seeds.
  • Mac NEON/default, NEON/crypto, and forced scalar match Xeon scalar, SSE2, AVX2, and AVX-512. Each configuration was tested at -O2 both with and without -fwrapv, for 14 builds total. All 73,744 returned 64-bit words per build match byte-for-byte: 36,872 API calls per build, zero mismatches. Both canonical hex streams and their decoded little-endian bytes were compared.

Vector JSON SHA-256: c731f2e7565e5798dafa9c7ecf5c43ed9807ec0254a062e7385a0d1c2287d8d1.

Common output-stream SHA-256: 554f8550a4aefd9badd87131998fe2b8993b153c3141a71862c24041fb05342f.

Reproduction scripts, vectors, exact compiler commands, dispatch reports, outputs from both hosts, and the complete comparison are in the accompanying verification directory. The larger vector corpus and verification artifacts are outside the source patch. The Mac runs were sequential correctness checks, with no timing benchmark.

The shared TabulateAfter out-of-bounds array subscript remains a separate portability defect. Existing signed lane sums motivated the additional -fwrapv runs. These results establish equality for the tested builds and vectors; they do not establish that the existing header is free of undefined behavior. Homebrew GNU g++ 14.2.0 on arm64 still fails on existing NEON vector conversions and local SDK declarations; this change specifically fixes the dispatch-name failure reproduced with Apple clang 17.

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.

arm64 NEON dispatch references undeclared V2Neon/V3Neon/V4Neon

1 participant