Skip to content

Commit 45a683a

Browse files
committed
Masked tail variants of the addition with five sizes on the i7-12700H
vectorMaskedTail was about 30 percent slower than vector with 100,003 elements but not with 1,003. This run adds 103 and 10,003 elements to see where the gap starts: up to 10,003 elements, vectorMaskedTail stays within 25 percent of vector (918 against 913 ns/op at 10,003), and only with 100,003 elements is it clearly slower (14,075 against 10,329 ns/op).
1 parent 1d76a57 commit 45a683a

3 files changed

Lines changed: 2218 additions & 0 deletions

File tree

‎results/12th-gen-intel-core-i7-12700h-x64/benchmarks/supplementary/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The machine is a laptop with a 12th Gen Intel Core i7-12700H (AVX2, no AVX-512,
1515
| `add-masked-tail-with-and-without-tail` | `AddBenchmark.vector` and `vectorMaskedTail` with 100,000, 100,003 and 100,008 elements. Without a tail (100,000 and 100,008), both are equally fast; only with the masked tail (100,003) is `vectorMaskedTail` consistently slower, in all forks of all four runs at this size (13.0 to 14.0 µs). A single masked iteration should cost nanoseconds, not about 3 µs; the cause could not be determined, since WSL2 exposes no hardware performance counters |
1616
| `add-alignment-sweep` | `AddAlignmentBenchmark.vectorAfterHead` with `head` = 0 to 7 and `AddBenchmark.scalar`, with 1,000 and 100,000 elements, with `-XX:-UseCompactObjectHeaders -XX:ObjectAlignmentInBytes=32`. With these flags, every float array starts 16 bytes after a 32-byte boundary, and `vectorAfterHead` starts the vector loop only after `head` scalar elements, which shifts all vector accesses by `head` × 4 bytes; `head` = 4 puts them on 32-byte boundaries, the width of the AVX2 vectors |
1717
| `add-scalar-12-byte-offset` | `AddBenchmark.scalar` with 1,000 and 100,000 elements and `-XX:ObjectAlignmentInBytes=32` with compact object headers (the default), which puts the first element of every float array 12 bytes after a 32-byte boundary instead of 16. The auto-vectorized loop stays as fast (32.4 ns/op with 1,000 elements, against 32.6 in `add-alignment-sweep`), because C2 adapts its scalar pre-loop to the offset (see `../../jit/assembly/README.md`) |
18+
| `add-masked-tail-sizes` | `AddBenchmark.vector`, `vectorMasked` and `vectorMaskedTail` with 7, 103, 1,003, 10,003 and 100,003 elements, all sizes with a partial last vector, to see whether `vectorMaskedTail` is slower than `vector` only with 100,003 elements |
1819

1920
`vectorMasked` was about three times slower than `vector` with 1,003 elements, so a short diagnostic run with `-XX:+PrintIntrinsics` followed; `masked-tail-intrinsics.txt` holds the lines of intrinsics C2 could not inline (marked `**`), with their counts.
2021

@@ -35,6 +36,7 @@ $JMH -rff add-masked-tail-with-and-without-tail.json 'AddBenchmark\.(vector|vect
3536
$JMH -rff add-alignment-sweep.json 'AddAlignmentBenchmark\.|AddBenchmark\.scalar$' -p size=1000,100000 \
3637
-jvmArgsAppend "-XX:-UseCompactObjectHeaders -XX:ObjectAlignmentInBytes=32"
3738
$JMH -rff add-scalar-12-byte-offset.json 'AddBenchmark\.scalar$' -p size=1000,100000 -jvmArgsAppend "-XX:ObjectAlignmentInBytes=32"
39+
$JMH -rff add-masked-tail-sizes.json 'AddBenchmark\.(vector|vectorMasked|vectorMaskedTail)$' -p size=7,103,1003,10003,100003
3840
3941
$JMH 'AddBenchmark\.vectorMasked$' -p size=1003 -f 1 -wi 3 -i 1 \
4042
-jvmArgsAppend "-XX:+UnlockDiagnosticVMOptions -XX:+PrintIntrinsics" 2>&1 \

0 commit comments

Comments
 (0)