BitShuffleBlock: the aarch64 decode uses the caller's scratch instead of a malloc per block

On aarch64 JFJochBitUnshuffleBlock went through bshuf_untrans_bit_elem_NEON, which mallocs and
frees a block-sized temporary for every block, while the caller (JFJochDecompressHperfPtr) already
owns an unused scratch buffer of exactly that size. Call the two NEON stages it wraps
(bshuf_trans_byte_bitrow_NEON, bshuf_shuffle_bit_eightelem_NEON) directly with that scratch.
Same code, same output; x86 is untouched.

Checked byte-identical under qemu-aarch64 against the classic entry point, hperf and the x86
decoders: element sizes 1/2/3/4/8, every block length 8..1040 elements plus 1536..16384, seven
data patterns, and real EIGER2/PILATUS4 bslz4 chunks.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D1G8gJVAy6gp1K5Dz3NE5C
This commit is contained in:
leonarski_fandClaude Opus 5.5 committed 2026-09-27 21:08:41 +02:00
1 parent 59ea3e7348
commit f8e5d0c3fa
1 file changed
+14 -3
+14 -3
View File
@@ -23,13 +23,24 @@
// which a single configure-time answer could not follow.
#if (defined(__ARM_NEON__) || (__ARM_NEON)) && defined(__aarch64__)
// The classic entry points allocate their own block-sized scratch, so the caller's goes unused.
// The two stages of bshuf_untrans_bit_elem_NEON, which bitshuffle_core.c defines but no header
// declares. Calling them directly lets the decode use the caller's scratch instead of the block-sized
// buffer the classic entry point mallocs and frees for every block.
extern "C" {
int64_t bshuf_trans_byte_bitrow_NEON(const void *in, void *out, size_t size, size_t elem_size);
int64_t bshuf_shuffle_bit_eightelem_NEON(const void *in, void *out, size_t size, size_t elem_size);
}
// The classic encode entry point allocates its own block-sized scratch, so the caller's goes unused.
inline int64_t JFJochBitShuffleBlock(char *out, const char *in, char *, size_t size, size_t elem_size) {
return bshuf_trans_bit_elem(in, out, size, elem_size);
}
inline int64_t JFJochBitUnshuffleBlock(char *out, const char *in, char *, size_t size, size_t elem_size) {
return bshuf_untrans_bit_elem(in, out, size, elem_size);
inline int64_t JFJochBitUnshuffleBlock(char *out, const char *in, char *scratch, size_t size, size_t elem_size) {
const int64_t count = bshuf_trans_byte_bitrow_NEON(in, scratch, size, elem_size);
if (count < 0)
return count;
return bshuf_shuffle_bit_eightelem_NEON(scratch, out, size, elem_size);
}
#else