Repository navigation
Use a counter-mode generator for random bytes on AArch64 and x86-64 - #116133
Conversation
src/Functions/FunctionsRandom.cpp had exactly one dispatch test, "#if !defined(__AVX2__)", with no #elif and no __aarch64__ anywhere in the file. Every non-AVX2 target therefore took the scalar arm: four LinearCongruentialGenerator chains at 16 bytes per iteration. x86 takes the AVX2 arm (16 chains as four UInt64x4, 128 bytes per iteration) by default, since ClickHouse#90043 made x86-64-v3 the default x86 target. randomFixedString(10) over 100M rows is 1.5359x slower on ARM than on AMD as a result, recomputed from performance-CI history. RandImpl::execute is the single random-byte source for rand, rand64, randConstant, randomString, randomFixedString, generateUUIDv4, generateUUIDv7 and dateTimeToUUIDv7, so one arm reaches all of them. The reason this was never simply vectorised on ARM is architectural: AArch64 NEON has no 64-bit-lane integer multiply, so the LCG recurrence cannot be vectorised there. Confirmed at instruction level with clang-22 under the project's ARM flags: uint64x2 * uint64x2 becomes extract both lanes to GPRs, scalar multiply, reinsert, while uint32x4 * uint32x4 is a single mul v0.4s. x86 has the same architectural hole but LLVM auto-emits the three-partial-product decomposition, which is why the AVX2 arm can write a portable "gens * a + c". Measuring loop-body instructions per generated byte, every LCG-preserving vector design for ARM is slower than today's scalar arm: 0.46x for the portable 64x64 decomposition at both two and four 64-bit lanes (16 GPR/vector transfers per iteration), 0.93x for a split-state (lo32, hi32) form. Widening the scalar chain count is not the portable answer either, since it regresses a shipped configuration: x86-64-v2 goes from 13.85 to 10.56 GB/s at eight chains, 0.76x. So the generator has to change on ARM and it has to use a different execution unit. This adds an additive "#elif defined(__aarch64__) && defined(__ARM_FEATURE_AES)" arm holding ARS, reduced-round AES in counter mode, from Salmon et al., "Parallel Random Numbers: As Easy as 1, 2, 3", SC'11: five AES rounds per 16-byte block, eight counter blocks in flight to cover AES latency, and round keys drawn from a Weyl sequence so there is no key schedule inside the loop. AESE/AESMC issue on the cryptographic pipe rather than competing for the integer multiply unit. The gating needs no runtime dispatch. cmake/cpu_features.cmake:53 passes -march=armv8.2-a+simd+crypto+dotprod+ssbs+rcpc+bf16 for the AArch64 server profile and clang defines __ARM_FEATURE_AES under those flags; under the compat profile (NO_ARMV81_OR_HIGHER, -march=armv8+crc at :20) it does not, so that build keeps the scalar arm. Both measured. x86 is unaffected by construction: the new arm is inserted before the existing two, so their bodies are untouched and each x86 build still selects the arm it selects today. Verified rather than asserted. RandImpl::execute assembly is byte-identical pre-fix and post-fix at -march=x86-64-v3 (the AVX2 arm, 30 vpmuludq), at -march=x86-64-v2 (the scalar arm), on ppc64le, and on the AArch64 compat profile; only the AArch64 server profile changes, from 16 mul and 4 madd with zero cryptographic instructions to 45 aese and 36 aesmc, which is five rounds times eight blocks plus five for the tail. Whole-translation-unit assembly on the four unchanged targets differs only in debug line tables and is identical once those are stripped. The generated stream changes on AArch64. That is not a new property: the scalar and AVX2 arms already produce different sequences from each other, using a different chain count, a different subset of the seed array and a different bit selection. rand declares isDeterministic() == false and is reseeded from randomSeed() on every call, so no caller may depend on the exact sequence. Correctness of the new arm was checked on an ARM binary under qemu-aarch64-static, running the same eight-block interleaved loop, with a liveness control beside each assertion: the overwrite past size peaks at exactly PADDING_FOR_SIMD - 1 = 63 bytes and never exceeds it, size == 0 writes nothing, two complementary pre-fills agree on every byte in [0, size) for sizes 1 to 600, and the four-byte randConstant call yields 64 distinct values across 64 seeds. Distribution over 64 MiB against the scalar arm: byte-histogram chi-square 200.2 against 280.8 for 255 degrees of freedom, worst per-bit deviation 0.000324 against 0.000237, 16-bit-word chi-square 65647.9 against 65655.6 for 65535 degrees of freedom. A negative control of the same output with the top bit of each byte cleared is rejected by all three statistics, so the screen discriminates. UBSAN with -fno-sanitize-recover=all is clean. Throughput was never read from qemu, which interprets each SIMD operation. Two documentation defects are corrected alongside. rand.cpp, rand64.cpp and FunctionsRandom.h described the generator as a linear congruential generator, which is already imprecise given that the two existing arms differ, and is untrue on the AArch64 server profile after this change; the descriptions now name the property, that the generator is non-cryptographic and predictable from its initial state, rather than the algorithm. FunctionsRandom.h also documented the overwrite contract as 15 bytes, while the AVX2 arm has required PADDING_FOR_SIMD - 1 = 63 since it was written. Every call site is backed by a PaddedPODArray, whose pad_right is exactly PADDING_FOR_SIMD - 1, so nothing was unsafe; the comment was wrong. The design and the AArch64 A/B measurements in the linked issue are egor-click's work. On a 32-core Neoverse-V2 he measured two independent interleaved sessions of 21 runs per side: 29.86% and 30.12% wall-clock reductions across the four affected performance-CI queries, plus rand() 1.1004x, rand64() 1.1561x and generateUUIDv4() 1.1241x out of sample. He also discloses a 3.98% regression on small buffers, at max_block_size=64 where the six round keys and three seed derivations are not amortised, and deliberately declines a size threshold for it on the grounds that a size-conditional branch shaped around the benchmark that exposed the cost is the wrong shape for this file. Closes: ClickHouse#116077
Internal second-model review (1 finding, adjudicated)Independent cold review of this diff plus a second-model pass, adjudicated against the
Also checked and found clean, recorded because each was a plausible blocker for this class of change:
Session id: cron:clickhouse-review-slot-11:20260824-140300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20260824-131300 |
|
Workflow [PR], commit [3fdcc79] Summary: ❌
AI ReviewSummaryThis PR replaces the old random-byte generator with ARS on AArch64 and adds VAES-based x86 paths selected at runtime. The AArch64 part looks coherent, but the new x86 dispatch still has two material gaps: the optimization disappears entirely from Findings
Final VerdictChanges needed before merge. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 72/124 (58.06%) · Uncovered code |
|
cc @Ergus @Algunenano, could you review this? |
CI finish ledger - 4d88123Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260824-160000 |
Build (arm_tidy) failed on this branch with two clang-tidy errors (-warnings-as-errors) at the two loops in RandImpl::execute that iterate the whole `state` array using the index only: FunctionsRandom.cpp:129:13: error: use range-based for loop instead FunctionsRandom.cpp:131:9: error: use range-based for loop instead Both are full traversals of `state` where the index is used exclusively to subscript that one array, so a range-based for expresses them directly. The two neighbouring loops keep their index because they use `i` arithmetically (as the per-block counter offset and as the store displacement), which is also why clang-tidy did not flag them. Verified by cross-running clang-tidy-22 on the single translation unit at the arm_tidy target and flags (aarch64-linux-gnu, -march=armv8.2-a+simd+crypto+dotprod+ssbs+rcpc+bf16, Debug): 2 diagnostics before, 0 after, with the full .clang-tidy configuration and no other diagnostic in the file. arm_darwin behaves the same (2 before, 0 after); arm_v80compat and x86-64 are unaffected because they select a different arm. The change is codegen-neutral where it matters: at -O3, the shipped AArch64 profile, the disassembly of RandImpl::execute is byte-identical before and after (45 aese / 36 aesmc / 29 eor either way). A control that changes `blocks` from 8 to 4 moves that comparison (25 aese / 20 aesmc), so the identity is a measurement rather than a blind compare. The correctness and distribution harness, built in both loop shapes and run under qemu-aarch64, produces byte-identical output and passes all 7 checks with its biased control still failing as designed.
01276_random_string and 01277_random_fixed_string were the coverage this branch's new AArch64 arm relies on, but their oracle could not fail the way it was read as failing. `GROUP BY byte` only creates a row for a byte value that actually occurs, so `SELECT DISTINCT c > 30000` says "every byte value that appeared, appeared often" and says nothing about how many appeared. A generator emitting one constant byte produces a single group of 10000000 and returns `1`, exactly like a healthy one. Measured against the shipped binary, substituting a constant-byte generator of the same width into each test: the old oracle passes the mutant in both files, the new `count() = 256 AND min(c) > 30000` form fails it in both. A partial mutant restricted to 128 distinct values also passes the old form and fails the new one, so the added term discriminates diversity and not merely the one-value extreme. The healthy generator returns 256 groups, so the references are unchanged and both tests still print `1`. `ORDER BY byte` is dropped because the aggregate no longer depends on row order. The memory pins stay: these queries exist to hold `randomString` and `randomFixedString` under 600Mi, and the strengthened form was re-measured inside that cap over five runs.
Algunenano
left a comment
There was a problem hiding this comment.
Some things to consider for follow-ups:
- For AVX2 we can also derive one seed and fan it out with a Weyl sequence the way the PR already does for round keys. This would reduce setup cost noticeably.
- We should consider adding VAES as a x86 target (via dynamic dispatch)
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units226 translation units recompiled, 1380 s compile time in total, 226 of them have a recent master baseline. |
|
📊 Cloud Performance Report ✅ AI verdict: This PR only rewrites the rand()/rand64() number generator (switching to AES-based ARS on capable CPUs) plus a CPU-feature-detection enum; it does not touch the query-execution path that ClickBench exercises, and none of the ClickBench queries call random functions. The six flagged queries all moved +9.5% to +17.3% in the same direction with CPU time rising in step, a uniform pattern that indicates run-to-run environment variance rather than a real regression. The two provisional regressions (Q16, Q17) are downgraded to not_sure on that basis, and the remaining four were already correctly held within master's variance band. No plausible PR-attributable regression was found. clickbenchFlagged queries (6 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
CI finish ledger - e9a215cEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Not caused by this PR. I read This PR changes only the AArch64 random-bytes generator: four files under
Session id: cron:our-pr-ci-monitor:20260824-220000 |
| -- that memory again. Do not drop `max_block_size`: both peaks scale with it, so without the pin | ||
| -- a cap loose enough for a high draw stops catching a revert on a low one. | ||
| SELECT DISTINCT c > 30000 FROM (SELECT arrayJoin(reinterpret(randomString(100), 'Array(UInt8)')) AS byte, count() AS c FROM numbers(100000) GROUP BY byte ORDER BY byte) SETTINGS max_memory_usage = '600Mi', max_block_size = 65409; | ||
| -- `count() = 256` is load-bearing: `GROUP BY byte` only creates a row for a byte value that occurs, |
There was a problem hiding this comment.
@groeneai Undo the changes in this test and in 01277_random_fixed_string.sql.
There was a problem hiding this comment.
Reverted in a55fc14; both files are byte-identical to master again.
One note in case you want it kept elsewhere: the restored oracle is SELECT DISTINCT c > 30000 over GROUP BY byte, and GROUP BY only creates a group for a byte value that occurs, so it also returns 1 for a generator emitting one byte 10,000,000 times (checked with a constant-byte mutant). That weakness is pre-existing on master, not introduced here.
| * rand - values from the range 0 .. 2^32 - 1. | ||
| * rand64 - values from the range 0 .. 2^64 - 1. | ||
| * | ||
| * Which generator produces those bytes is selected per target at compile time, so the |
| } | ||
|
|
||
| #if !defined(__AVX2__) | ||
| #if defined(__aarch64__) && defined(__ARM_FEATURE_AES) |
There was a problem hiding this comment.
@groeneai Replace the AES-based implementation by a vectorized linear congruential generator, even if it's slightly slower.
There was a problem hiding this comment.
First, a correction to my own comment in this file. It says synthesising a 64x64 product from vmull_u32 "costs more instructions per generated byte than the scalar MADD it would replace, and measures slower". That is not supported for the shape you are asking for.
Measured, clang-22, -O3 -DNDEBUG, --target=aarch64-linux-gnu -march=armv8.2-a+simd+crypto+crc, inner-loop instructions per output byte:
| variant | insns/byte |
|---|---|
| today's scalar arm, 4 chains | 0.8125 |
| all-NEON split-state exact LCG, 16 chains | 0.7656 |
| ARS as in this PR, main loop | 0.8750 |
A vectorized LCG keeping the exact current = current * a + c is viable: hold the 64-bit state as (lo, hi) in uint32x4_t, partial products via vmlaq_u32, carry from vmull_u32/vmull_high_u32 + vuzp2q_u32, emit bits 16..47 as today. It needs no __ARM_FEATURE_AES gate, so unlike ARS it would also speed up arm_v80compat. My earlier numbers used a portable operator* decomposition, which lowers to extract-to-GPR/multiply/reinsert (16 transfers per iteration); that is not this shape.
Two caveats:
- Instruction counts cannot rank these two: AESE/AESMC issue on the crypto pipe, MUL/MLA on the integer-vector pipes. I have no ARM host, so only this PR's
Performance Comparison (aarch64)job can settle it. - Avoid the 32-bit-lane form (one
mla v.4s, 0.3750 insns/byte). With a 32-bit state the output is the state, so the>> 16that drops the weak low bits is unavailable and bit k has period 2^(k+1). Measured: bit 00101..., bit 1 period 4, bit 2 period 8, sorand() % 2would strictly alternate.
Shall I push the 16-chain split-state arm so the ARM perf job compares it against ARS directly? If you want the LCG regardless of that result, I will do that instead.
|
@Algunenano Sorry, I didn't see that you assigned already. The current ARM-NEON implementation uses AES instructions. To keep the complexity low, I guess it makes sense to use (vectorized) linear congruential generation on ARM as well? |
|
Stress test failure related to missing cancellation: Fixed here |
Three review asks from @rschu1ze on ClickHouse#116133: - Undo the changes in 01276_random_string.sql and 01277_random_fixed_string.sql. Both files are now byte-identical to master again. - Remove the added note in FunctionsRandom.h about the generator being selected per target. - Retain the original "must be 15-bytes padded" comment on RandImpl::execute. The overwrite bound the reverted comment described is unchanged by this revert: the AVX2 arm has required PADDING_FOR_SIMD - 1 = 63 bytes of padding since it was written, and every caller's PaddedPODArray supplies at least that. The comment understating it as 15 predates this PR and is left as it was. The generator question raised in the fourth review comment is answered in the thread and is not addressed by this commit.
I trusted @groeneai 's assumptions, but it seems that it comes from @egor-click 's initial issue as it's not measuring runtime, just instructions. I don't think @groeneai has an ARM machine, so probably giving it these kind of issues does not make any sense. It can't iterate |
|
I've been having a look and testing a VAES implementation and it seems we get a 2x in some cases so it's worth the extra complexity: So I think it's ok to use it for for x86 (when supported) and for NEON (always since we always have AES). I'll add it here |
yeah, my bot had arm machine to test this, performance comparison also looks good for ARM as far as i can see |
The x86-64 arm of `RandImpl::execute` is already vectorised, unlike the AArch64 one, but AES still generates bytes faster than the linear congruential generator does: `VAESENC` retires two AES blocks per instruction on the cryptographic pipe, while the generator competes for the vector multiply ports. So add ARS on VAES as a second x86-64 arm, selected at runtime. VAES is not part of any microarchitecture level - Zen 3 has it with no AVX-512 at all, and Intel only from Ice Lake onwards - so neither `x86_64_v4` nor `x86_64_icelake` describes the CPUs that have it, and `TargetArch` gets a feature bit of its own. The constants and the seeding are shared with the AArch64 arm through `ArsParams`. Only the round itself differs, because the two instruction sets order the key addition differently. Generator throughput against the arm it falls back to, at one default block of `randomFixedString(10)`, single thread and then saturating every core: Zen 4 (Ryzen 9 7950X3D) 1.94x / 2.00x Sapphire Rapids (Xeon 8488C) 2.07x / 1.84x Ice Lake (Xeon 8375C) 1.94x / 1.73x Zen 3 (EPYC 7R13) 1.47x / 1.37x End to end on Zen 4, best of 7: `randomFixedString(10)` over 400M rows 1.384x, `generateUUIDv4` 1.397x, `rand64` 1.345x.
|
I've updated the PR to implement ARS with VAES for x86, both for x86v4 and v3, via dynamic dispatching. Linear congruential generator is kept for systems without AES. @groeneai Could you review the changes please? |
|
Reviewed I have no ARM host, but I do have VAES here, on a Xeon 6975P-C, which is the Granite Rapids row of your table, so I checked the parts that are measurable rather than only reading them. Dispatch. Verified live rather than by inspection: with breakpoints on all three arms, a Bounds. Both arms write at most 63 bytes past Output. Over 64 MiB per arm, byte chi2 is 236.2 against 255 dof, no bitwise period up to 32 in any bit position, and all 40960 blocks inside one 640 KiB call are distinct. Sizes 1..300 fully overwrite Throughput, best of 9, pinned, against the LCG arm they fall back to: at 640 KiB 2.32x for the 256-bit arm and 2.99x for the 512-bit one; at 8 MiB 1.80x and 1.72x, so 512-vs-256 is 0.96x. Your table says 2.07x and 2.98x for Granite Rapids and your caveat says 0.96x at 8 MB there, so both reproduce, including the Intel crossover. The finding. The suite cannot detect a broken ARS arm. If I replace the five AES rounds in That gap is not introduced by your commit, but it becomes more relevant with it, because which arm runs is now a runtime property, and |
|
Two automated findings landed on The The I measured the crossover here, on Granite Rapids, arms interleaved within each rep so drift hits both equally, median of 15 per-rep ratios (512 over 256): So it reproduces, but it starts around 4 MiB rather than at the 8 MB your comment cites, and it then stays flat out to 32 MiB. Worth noting the earlier onset makes the affected width range wider than the comment suggests: Whether that deserves a size threshold in the dispatcher is your call, and my earlier point stands that I cannot rank these two arms on Ice Lake or Sapphire Rapids myself. |
|
thanks @Algunenano ! |
CI finish ledger - 3fdcc79Every failure below has an owner.
Not reachable from this diff, which touches only Session id: cron:our-pr-ci-monitor:20260825-223000 |
bf256b0
A stress test hung on a fuzzed `h3PolygonToCellsWithContainment` query whose polygon had a vertex at latitude -1.7976931348623157e308. It spent about 45 minutes inside one H3 call, observing neither `max_execution_time` nor `KILL QUERY`. Two causes. H3 picks the coarse resolution for its size estimate by dividing the polygon's bounding box area by the average cell area, and a vertex off the sphere makes that area negative, so the reduction never triggers and the estimate counts every cell of a polygon covering much of the globe: 2.6e8 cells at resolution 9. And the cells of one polygon were filled inside a single H3 call, so the only cancellation checkpoint was between rows. Vertices are now rejected unless longitude is in -180..180 and latitude in -90..90 degrees, and the cells are enumerated one at a time through H3's cell iterator, charging the shared `CancellationBudget` per cell. Both functions share one implementation now, which also drops the staging buffer the results were copied through. `h3PolygonToCells` had the same shape, plus H3's legacy algorithm allocating two estimate-sized buffers outside the memory tracker. It goes through the same iterator with `CONTAINMENT_CENTER`, the containment rule its own H3 source documents for itself. On a 20 by 20 degree box at resolution 9 it returns the same 58823612 cells in 0.64 s instead of 47 s, with 1.35 GB of peak RSS instead of 4.5 GB. Measured on a release build: a valid 20000-vertex polygon at resolution 10 took 7.5 s per row for the first function and 29 s for the second, and both now stop 1.1 s after a 1 s deadline. Clean under MSan and TSan. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=116133&sha=e9a215c284fb7445939babacac5b3783e3501669&name_0=PR&name_1=Stress%20test%20%28arm_debug%29 ClickHouse#116133 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>


Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Speed up random data generation.
rand,rand64,randConstant,randomString,randomFixedString,generateUUIDv4,generateUUIDv7anddateTimeToUUIDv7now generate bytes with ARS (reduced-round AES in counter mode) wherever the CPU has AES instructions: on AArch64 chosen at build time, on x86-64 chosen at run time when VAES is present. Targets and CPUs without those instructions keep the previous generator unchanged.Description
Closes: #116077
FunctionsRandom.cpphad one dispatch test,#if !defined(__AVX2__), so all of AArch64 took thescalar four-chain LCG at 16 bytes per iteration while x86-64 took the AVX2 arm at 128. Since
#90043 made
x86-64-v3the default x86 target, that is what every default build gets.randomFixedString(10)over 100M rows is 1.5359x slower on ARM than AMD as a result.It was never simply vectorised because AArch64 NEON has no 64-bit-lane integer multiply. I
confirmed that with clang-22:
uint64x2 * uint64x2becomes extract-to-GPR, scalar multiply,reinsert, and every LCG-preserving vector design I measured lands at 0.46x-0.93x of the scalar
arm. Widening the scalar chain count is not portable either:
x86-64-v2goes to 0.76x.So this adds an
#elif defined(__aarch64__) && defined(__ARM_FEATURE_AES)arm using ARS (Salmonet al., "Parallel Random Numbers: As Easy as 1, 2, 3", SC'11), which issues on the cryptographic
pipe instead of the integer multiply unit. AES is unconditional in the AArch64 server profile
(
cpu_features.cmake:53passes+crypto) and clang defines__ARM_FEATURE_AESthere but notunder compat, so no runtime dispatch is needed and the compat build keeps the scalar arm.
The design and the ARM measurements are @ egor-click's, from #116077: two interleaved 21-run
Neoverse-V2 sessions, 29.86% and 30.12% wall-clock reduction across the four affected
performance-CI queries, and
rand()1.1004x,rand64()1.1561x,generateUUIDv4()1.1241x. Healso discloses 3.98% slower small buffers (
max_block_size=64, where the round keys are notamortised) and adds no size threshold. I have no ARM host, so the authoritative number here is
this PR's own
Performance Comparison (aarch64)job.Also corrects two documentation gaps: three sites called the generator a "linear congruential
generator", already imprecise since the arms differ. The
FunctionsRandom.hoverwrite contract isrestored to
PADDING_FOR_SIMD - 1after being reverted per review - "15 bytes" was only everaccurate for the scalar arm, the AVX2 arm has required 63 since it was written, and both new x86
arms measure exactly 63.
x86-64
The same conclusion holds on x86-64 for a different reason. There the LCG arm is already vectorised, so the AArch64 rationale does not apply - but AES still generates bytes faster, because
VAESENCretires several AES blocks per instruction on the cryptographic pipe while the generator competes for the multiply ports.VAES belongs to no x86-64 microarchitecture level - Zen 3 has it with no AVX-512 at all, Intel only from Ice Lake - so the build flags cannot imply it and it needs runtime dispatch.
TargetArchgains anx86_64_vaesbit, andRandImpl::executebecomes: VAES andx86-64-v4-> ARS over 512-bitVAESENC; VAES only -> ARS over 256-bitVAESENC(Zen 3); no VAES -> the existing AVX2 LCG arm, untouched. The two conditions together also keep AES off Skylake-SP and Cascade Lake, which arex86-64-v4but have no VAES, and which are the parts where 512-bit code costs the most in clock frequency.Generator throughput against the LCG arm, single thread, one default block of
randomFixedString(10):End to end on Zen 4, best of 7 against a binary built from the same tree with only this arm reverted:
randomFixedString(10)over 400M rows 1.38x,generateUUIDv41.40x,rand641.35x. The 512-bit tier adds a further ~6% on top of that - well under its generator ratio, because generation is no longer the dominant cost once it is already twice as fast.One caveat, recorded in the code: on Intel a call of a few MB or more makes the 512-bit arm slower than the 256-bit one, 0.79x at 8 MB on Ice Lake and 0.80x on Sapphire Rapids, while AMD shows no crossover. It is not the memory system running out of bandwidth - that would make the two converge, not invert - and a frequency effect fits better. One default block is 640 KiB, so no size threshold was added.
x86-64 validation
Both arms verified against an independent scalar ARS-5 reference, block by block, over 609 sizes (1..600 plus block boundaries to 640 KiB): output matches the reference, the 256-bit and 512-bit arms produce byte-identical streams for the same key and counter, and neither writes more than
PADDING_FOR_SIMD - 1bytes pastsize- both peak at exactly 63.Codegen checked per section: the dispatcher contains no VAES and no AVX-512, so it stays legal without either;
executeArscontains nozmmor mask registers, so it stays legal on Zen 3;executeArs512has the expectedvaesenc/vaesenclastcounts. 69 stateless tests covering the eight affected functions pass, with two pre-existing ZooKeeper/replication failures that reproduce against an unmodified binary.Not covered locally: the 256-bit arm needs a CPU with VAES but no AVX-512, so every local run took the 512-bit path. No sanitizer run either - the 512-bit tail store lands exactly on the padding boundary, so the ASan job is the meaningful check.
Validation (AArch64)
clang-22 (the CI pin), project flags from this tree.
RandImpl::executecodegen:x86-64-v3(AVX2 arm)37bb61e6, 30vpmuludqx86-64-v2(scalar arm)175224d4adfa0eedarmv8+crc9b7a9430, 0aesearmv8.2-a+crypto9b7a9430, 0aeseaese, 36aesmc45
aese= 5 rounds x 8 blocks + 5 tail. Whole-TU assembly on the unchanged targets differs onlyin debug line tables.
__ARM_FEATURE_AESmeasured defined under the server profile, undefinedunder compat, and defined for
aarch64-apple-darwinwith no-marchat all, so that build takesthe new arm too. The arm compiles clean under
-Weverything -Werror.ARM binary under
qemu-aarch64-static, running the exact loop from the patch, each assertionpaired with a liveness control: overwrite worst case exactly 63 bytes past
sizeand never more,size == 0writes nothing, two complementary pre-fills agree on every byte in[0, size)forsizes 1..600, and the 4-byte
randConstantcall gives 64 distinct values. Distribution over64 MiB:
The control is ARS output with the top bit of each byte cleared; all three reject it. UBSAN with
-fno-sanitize-recover=allis clean.x86-64 is no longer unchanged; see the x86-64 section above. 27 of the 31 stateless tests touching the eight affected functions pass; the 4 failures need
ZooKeeper or a cluster, and reproduce against the unmodified binary.
Workflow [PR]
Sync PR [sync-upstream/pr/116133]
Version info
26.9.1.123(included in26.9and later)