Skip to content

Commit 6447353

Browse files
committed
Alignment sweep of the Vector API addition on the M5 Pro
With every array on a 16-byte boundary, the vector loop is as fast as the auto-vectorized scalar loop only when it starts after 0 or 4 scalar elements, i.e. when its loads and stores are 16-byte aligned: 43.7 and 46.7 ns for 1,000 elements against 45.1 ns. Every other start takes 53 to 59 ns.
1 parent b60f495 commit 6447353

3 files changed

Lines changed: 2673 additions & 0 deletions

File tree

‎results/apple-m5-pro-arm64/benchmarks/supplementary/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Run on 2026-11-15 right after the main run in `../results.json`, on the same mac
1010
| `add-masked-tail-allocations.txt` | Where `vectorMasked` with 1,003 elements allocates: Java Flight Recorder allocation samples, grouped by class and stack. The objects come from `fromArray()` on the in-range path (`FloatVector.java` line 2895 in JDK 27), i.e. also in the iterations with a full mask, and from `add()` |
1111
| `add-masked-tail-variants` | `AddBenchmark.vector`, `vectorMasked` and `vectorMaskedTail` with 7, 1,000, 1,003 and 100,003 elements, with the GC profiler. `vectorMaskedTail` (added on the i7-12700H) keeps the main loop unmasked and masks only the one partial iteration at the end. On NEON that iteration allocates 176 bytes with 1,003 elements and costs about 35 ns; the main loop stays free of allocations |
1212
| `add-masked-tail-with-and-without-tail` | `AddBenchmark.vector` and `vectorMaskedTail` with 100,000, 100,003 and 100,008 elements, with the GC profiler: only 100,003 needs a masked tail, and only there does `vectorMaskedTail` allocate (240 bytes per call) |
13+
| `add-alignment-sweep` | `AddAlignmentBenchmark.vectorAfterHead` with a head of 0 to 7 scalar elements before the vector loop, and `AddBenchmark.scalar`, with 1,000 and 100,000 elements, under `-XX:-UseCompactObjectHeaders -XX:ObjectAlignmentInBytes=16`. Every array then starts at a 16-byte boundary, so the vector accesses are 16-byte aligned for a head of 0 and 4 only. Exactly these two are as fast as the scalar loop; all other heads take about 20 % longer |
1314
| `add-16-byte-aligned-arrays` | `AddBenchmark.scalar` and `vector` with `-XX:-UseCompactObjectHeaders -XX:ObjectAlignmentInBytes=16`, which puts the first element of every array on a 16-byte boundary |
1415

1516
Commands, run from the repository root after `scripts/run-benchmarks.sh` had built the benchmarks:
@@ -22,6 +23,8 @@ $JMH -rff dot-product-dependency-chains.json 'DotProductBenchmark\.'
2223
$JMH -rff add-masked-tail-variants.json 'AddBenchmark\.(vector|vectorMasked|vectorMaskedTail)$' -p size=7,1000,1003,100003 -prof gc
2324
$JMH -rff add-masked-tail-with-and-without-tail.json 'AddBenchmark\.(vector|vectorMaskedTail)$' -p size=100000,100003,100008 -prof gc
2425
$JMH -rff add-masked-tail.json 'AddBenchmark\.(vector|vectorMasked)$' -p size=1003,100003 -prof gc
26+
$JMH -rff add-alignment-sweep.json 'AddAlignmentBenchmark\.|AddBenchmark\.scalar$' -p size=1000,100000 \
27+
-jvmArgsAppend "-XX:-UseCompactObjectHeaders -XX:ObjectAlignmentInBytes=16"
2528
$JMH -rff add-16-byte-aligned-arrays.json 'AddBenchmark\.(scalar|vector)$' -p size=1000,100000 \
2629
-jvmArgsAppend "-XX:-UseCompactObjectHeaders -XX:ObjectAlignmentInBytes=16"
2730
```

0 commit comments

Comments
 (0)