Repository navigation
Conversation
|
I've asked a coding agent to review the diff: I reviewed the diff and found one blocking issue: the NEON path doesn't compile on 32-bit ARM with NEON enabled. The rest of the logic looks correct. The CI only covers macOS arm64, Linux x64 and Windows x64, so it can't catch this. Blocking: armv7 + NEON build failure Because Node.js vendors nbytes, this would break Node.js' armv7 builds that have NEON enabled. I haven't checked which official or distro armv7 configs actually turn NEON on. The simplest fix is to only take the NEON path on 64-bit: #if defined(__aarch64__) || defined(_M_ARM64)Alternatively, keep armv7 NEON and replace the I ran the x86 and aarch64 syntax checks too, but they were inconclusive: zig failed with a cache-rename error before reporting anything about the source. Non-blocking
|
|
alright, makes sense, i completely overlooked the armv7 thing. Thanks for running it @aduh95! armv7 + NEON (blocking): fixed in d0915f8. NEON now only kicks in on
Short inputs: fair point, 6ffc50b skips the call entirely when
The leftover ~0.5 ns below 16 bytes is most likely the extra length check, kinda nothing next to the ~100 ns a Public header: moved to
Benchmarks: the lib and node CI for armv7 / Windows ARM64: agree it's deffo a gap. I'd rather do it in a follow-up PR (cross-compile job, maybe qemu for armv7) so this one stays focused, if that works for you. Otherwise just lmk and i'll do it here, it's my first time contributing to this project so I'll gladly adapt to anything 😄. |
Fixes #19
Decodes hex in 16-byte output blocks with NEON on
arm64and SSE2 onx86-64.In
node, at least by my measurements 🤞, this makesBuffer.from(hex)3.3x faster at 1 KiB and
buf.write(str, 'hex')3.9x faster at 2 KiB,with byte-identical output .
How
HexDecode<T>with a one-byteTfirst calls the new out-of-lineHexDecodeBlocks(), then the existing scalar loop continues from where itstopped. Intrinsics stay out of the public header.
nibbles with arithmetic, then validates them with one single horizontal check:
vminvq_u8on NEON,_mm_movemask_epi8on SSE2.block and returns at the exact invalid pair, so we ensure that truncation
semantics are unchanged.
_mm_min_epu8, and nibble pairs arecombined with 16-bit shifts and
_mm_packus_epi16.HexDecodeBlocks()returns 0 and decoding is fullyscalar, as before.
Results
Library (
nbytes::HexDecode, one-byte input, out-of-line, median of 9batches × 2 interleaved runs, M1 Pro,
-O3):*
x86-64build run under Rosetta 2. Treat the absolute numbers as indicative;the ratios hold.
Node.js (
mainat768315cfwith this patch applied todeps/nbytes,benchmark/compare.js --runs 20, Welch t-test):buffers/buffer-hex-encode.js len=64(this benchmark measuresBuffer.from(hex))buffers/buffer-hex-encode.js len=1024buffers/buffer-write-string.js len=2048 encoding=hex... args=offset... args=offset+lengthbuffers/buffer-write-string-short.js encoding=hex len=1/8/16Testing
tests/basic.cppcompare against an independent referencedecoder:
blocks);
ctestpasses 11/11 on arm64 (NEON) and x86-64 (SSE2,-DCMAKE_OSX_ARCHITECTURES=x86_64).new tests fail.
Buffer.from(hex)/buf.write(hex)matches
mainexactly (invalid bytes, two-byte strings, offsets, oddlengths);
test/parallelpasses, excepttest-node-runandtest-snapshot-warning,which fail the same way on unpatched
mainin my environment.clang-formatat version 17.Repro (library):
Repro (Node.js, with the patch in
deps/nbytes):