Repository navigation
crc: avoid x18 in crc32_iscsi_x6 and enable it on macOS - #478
cielavenir wants to merge 3 commits into
Conversation
x18 is the AAPCS64 platform register. It is reserved on Apple and Windows, and holds the shadow call stack pointer when built with -fsanitize=shadow-call-stack. crc32_iscsi_x6 used it as a scratch data register without saving it. Use x27 instead, which push_stack/pop_stack already save and restore but which was otherwise unused, so there is no extra cost. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Taiju Yamada <tyamada@bi.a.u-tokyo.ac.jp>
Now that crc32_iscsi_x6 no longer clobbers x18, make it build on Apple by following the same conventions as the other aarch64 CRC files: cdecl() for the symbol name, @PAGE/@PAGEOFF relocations, and .type/.size only on ELF. Select it on Apple when both CRC32 and PMULL are available, matching the Linux dispatch order. The SVE2 fusion path stays Linux-only since Apple cores lack SVE2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Taiju Yamada <tyamada@bi.a.u-tokyo.ac.jp>
|
https://github.com/cielavenir/isa-l/actions/runs/44453899851 will show macOS run |
|
The
Local median throughput, decimal GB/s:
Method: an Apple Silicon system, compiled with Measurement limitation: these results are not CPU-pinned; core placement and frequency were not fixed. |
crc32_iscsi_x6 entered its 6-lane loop only for LEN > 1024, but one iteration consumes exactly 1024 bytes and the loop itself continues while LEN >= 1024. A 1024-byte buffer therefore fell back to the serial crc32cx loop, at roughly 40% of the parallel throughput. Use blo instead of bls so LEN == 1024 takes the parallel path. This affects Linux as well, where x6 is already dispatched. Reported-by: liuqinfei Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Taiju Yamada <tyamada@bi.a.u-tokyo.ac.jp>
|
Thanks for testing this so carefully! 1. 1024-byte threshold: fixed in 9af3609 ( 2. refl_pmull comparison: I benchmarked all kernels with direct calls from one executable on the GitHub Median throughput, decimal GB/s (x6 includes the
On M1, x6 is equal to or faster than I'd suggest keeping x6 as the Apple default in this PR, since it is a strict improvement over Limitation: the runner is a shared VM (3 vCPUs, no core pinning), so absolute numbers are lower than bare metal and should be taken as indicative. Side note, unrelated to this PR: the same benchmark on the Neoverse N2 results (
|
| Bytes | crc_ext | 3crc_fold | refl_pmull | x6 | dispatched |
|---|---|---|---|---|---|
| 64 | 18.10 | 16.70 | 3.84 | 14.85 | 13.60 |
| 128 | 23.17 | 23.26 | 6.66 | 21.64 | 19.74 |
| 256 | 24.98 | 25.19 | 10.96 | 25.46 | 24.93 |
| 512 | 26.04 | 26.26 | 16.13 | 26.23 | 25.98 |
| 1000 | 26.30 | 26.60 | 7.43 | 26.72 | 26.66 |
| 1023 | 26.28 | 26.20 | 5.61 | 26.29 | 26.26 |
| 1024 | 26.63 | 26.01 | 18.19 | 23.54 | 23.34 |
| 1025 | 26.42 | 25.82 | 17.87 | 23.55 | 23.28 |
| 2048 | 26.92 | 26.16 | 18.96 | 24.22 | 24.14 |
| 4096 | 27.01 | 26.14 | 19.35 | 24.70 | 24.55 |
| 8192 | 27.07 | 26.19 | 19.54 | 24.89 | 24.88 |
| 65536 | 27.06 | 26.14 | 19.71 | 25.03 | 25.00 |
| 1048576 | 26.84 | 25.92 | 19.50 | 24.60 | 24.61 |
|
LGTM for the current scope. The In my local comparisons using both fixed independent seeds and chained CRC seeds, x6 appeared to have an advantage over One detail that may be worth double-checking is whether the benchmark uses a fixed seed on each call or feeds the previous CRC result into the next call. ISA-L's existing I agree that selecting |
Summary
crc32_iscsi_x6(added in b60f302) uses x18 as a scratch register (crc0_data8) without saving it. x18 is the AAPCS64 platform register: it is reserved on Apple and Windows, and holds the shadow call stack pointer under-fsanitize=shadow-call-stack. That is also why the file is wrapped in#ifndef __APPLE__.push_stack/pop_stackalready save/restore x27, and it was otherwise unused, so there is no extra cost.__APPLE__guard and follow the existing aarch64 CRC conventions (cdecl(),@PAGE/@PAGEOFF,.type/.sizeonly on ELF). The Apple dispatcher selects it when both CRC32 and PMULL are present, matching the Linux order. The SVE2 fusion path stays Linux-only (no SVE2 on Apple cores; it also uses x18/x29).Testing
crc32_iscsi_x6.Sassembles with clang 19 forarm64-apple-macos13andaarch64-linux-gnu; objdump shows no x18/w18 use.crc32_iscsitests on themacos-15(arm64) GitHub runner.Performance on Apple M1
crc32_iscsi_perf(8 KB, warm cache) on themacos-15GitHub runner (Apple M1 (Virtual), 3 vCPUs, CRC32 + PMULL, no SVE). The same job buildsmaster(af6a939, which dispatches tocrc32_iscsi_3crc_foldon Apple) in a git worktree and this branch (crc32_iscsi_x6), then runs them alternately for 5 rounds (run).3crc_fold)x6)Both produce the same CRC. The runner is a shared VM, so treat the numbers as indicative.
🤖 Generated with Claude Code