compression: use the NEON bitshuffle on aarch64
bitshuffle_hperf is an x86-only implementation - its entire vector body sits behind __i386__/__x86_64__, so on aarch64 every entry point compiles down to the scalar fallback. Measured against its own SIMD path that costs 8.3x on encode and 3.8x on decode, and it is the transform behind every compressed image the writer produces and every one the reader, preview and XDS plugin take apart again. The classic bitshuffle vendored beside it does have an aarch64 NEON path, and is already compiled into the same target, so this costs nothing new. BitShuffleBlock.h picks bshuf_trans_bit_elem/bshuf_untrans_bit_elem there and keeps bitshuf_encode_block / bitshuf_decode_block everywhere else, where hperf is about twice classic SSE2 and remains the better choice. The expected aarch64 gain is ~2.5x encode / ~1.7x decode: classic NEON is 128-bit and carries an extra pass, so it recovers part of the gap rather than all of it. The condition mirrors USEARMNEON in bitshuffle_core.c exactly, because with NEON off the classic scalar path is slower than hperf's and must not be selected. Swapping implementations is only safe while the two agree bit for bit - otherwise an ARM build would write files an x86 build could not read. They do: verified byte-identical output and mutual cross-decoding for elem_size 1/2/4/8 over block sizes from 8 to 65536 elements. Both are always compiled in, so the new test holds them to it on every architecture, not just the one that would notice. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <catch2/catch_all.hpp>
|
||||
#include <bitshuffle/bitshuffle.h>
|
||||
#include <bitshuffle_hperf/bitshuffle.h>
|
||||
#include <zstd.h>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
@@ -317,6 +318,35 @@ TEST_CASE("Bitshuffle_ZSTD","[ZSTD]") {
|
||||
|
||||
REQUIRE(memcmp(image.data(), decompressed.data(), RAW_MODULE_SIZE*sizeof(uint32_t)) == 0);
|
||||
}
|
||||
|
||||
// BitShuffleBlock.h picks between the two vendored bitshuffle implementations by architecture:
|
||||
// bitshuffle_hperf on x86, the classic one on aarch64, where only the latter has SIMD. That is only
|
||||
// safe as long as the two agree bit for bit - otherwise an ARM build would write files an x86 build
|
||||
// cannot read. Both are always compiled in, so this holds them to it on every architecture.
|
||||
TEST_CASE("Bitshuffle_hperf_matches_classic","[ZSTD]") {
|
||||
for (size_t elem_size : {1, 2, 4, 8}) {
|
||||
// Element counts the compressor actually produces (128 kB / 16 kB blocks), plus the
|
||||
// smallest legal block and a short trailing one.
|
||||
const size_t sizes[] = {8, 64, 16384 / elem_size, 131072 / elem_size};
|
||||
for (size_t size : sizes) {
|
||||
std::vector<char> image(size * elem_size), hperf(size * elem_size),
|
||||
classic(size * elem_size), scratch(size * elem_size), decoded(size * elem_size);
|
||||
std::mt19937 gen(1234);
|
||||
for (auto &c : image)
|
||||
c = static_cast<char>(gen() & 0xff);
|
||||
|
||||
REQUIRE(bitshuf_encode_block(hperf.data(), image.data(), scratch.data(), size, elem_size) >= 0);
|
||||
REQUIRE(bshuf_trans_bit_elem(image.data(), classic.data(), size, elem_size) >= 0);
|
||||
REQUIRE(hperf == classic);
|
||||
|
||||
// Each implementation must also decode what the other wrote.
|
||||
REQUIRE(bitshuf_decode_block(decoded.data(), classic.data(), scratch.data(), size, elem_size) >= 0);
|
||||
REQUIRE(decoded == image);
|
||||
REQUIRE(bshuf_untrans_bit_elem(hperf.data(), decoded.data(), size, elem_size) >= 0);
|
||||
REQUIRE(decoded == image);
|
||||
}
|
||||
}
|
||||
}
|
||||
// ---- BSHUF_ZSTD_RLE_HUFF (RLE runs + adaptive Huffman literals, standard zstd frame) ----
|
||||
// Round-trips through JFJochDecompress (which calls stock ZSTD_decompress per block) and checks
|
||||
// the output never exceeds the advertised worst-case size. Run on good and adversarial data to
|
||||
|
||||
Reference in New Issue
Block a user