perf: simd double math binary ops #20875
[P2] Floating-point power operator remains exact-equality checked
Finding: SimdSupportedBinaryOp.POW now routes floating-point ^ expressions through VectorOperators.POW, and the new parity test explicitly allows a two-ULP SIMD-vs-Math delta. This matcher only recognizes function-call spellings such as pow(...); the existing testBinaryMathOperators cases using ^ therefore receive zero tolerance and can fail when C2/SVML produces a permitted non-bit-identical result.
Suggestion: Teach allowedUlpsFor to recognize the binary ^ form when it produces a double, or use parsed-expression metadata, and add a regression case for floating-point power.
🟡 Changes recommended
Update the vector/scalar consistency tolerance for the existing ^ power syntax before merging. The new SIMD POW path permits up to a two-ULP difference, but the tolerance matcher only recognizes function-call forms such as pow(...); floating-point ^ expressions can therefore fail exact-equality assertions.
Reviewed 25 of 25 changed files; findings in 1 file.
Coverage included SIMD processors and factories, expression wiring, SQL registration and tests, benchmarks, documentation, and surrounding consistency tests.
Validation: git apply --check passed. Narrow JDK 25 Vector API smoke checks confirmed operand order, long-to-double conversion, and basic POW/ATAN2/HYPOT behavior. No project tests, builds, installs, or formatters were run.
| Severity | Findings |
| --- | ---: |
| P0 | 0 |
| P1 | 0 |
| P2 | 1 |
| P3 | 0 |
| Total | 1 |
<!-- mergelens:review -->
---
This is an automated review by Codex GPT-5.6-Luna(max)
After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.
🟢 Approval recommended
No actionable issues were found. The prior power-operator tolerance finding is resolved by traversing parsed BinPowExpr nodes and adding dedicated ^ coverage; SIMD dispatch, operand widening, tails, null handling, SQL registration, documentation, benchmarks, and parity tests are consistent across the current diff.
Reviewed 25 of 25 changed files. Validation: git diff --check passed. No tests or builds were run.
<!-- mergelens:review -->
---
This is an automated review by Codex GPT-5.6-Luna(max)
VectorOperators.POW follows the C99 special cases rather than Math.pow: pow(1, NaN) and pow(-1, ±Infinity) return 1.0 instead of NaN. I reproduced this on JDK 25 with SLEEF after C2 warmup (libraryBinaryOp intrinsified). A NaN in a double column is enough to hit it, and it is not the few-ulp drift useVectorMathApi documents. The parity test misses it because the POW domain only has positive finite bases.
Blending NaN back in for those lanes fixes it. I checked this against Math.pow over a 12×12 grid of special values (NaN, ±Infinity, ±0, ±1, negative bases), and the only difference left was 1 ulp:
va.lanewise(VectorOperators.POW, vb)
.blend(Double.NaN, vb.test(VectorOperators.IS_NAN).or(va.abs().eq(1.0).and(vb.test(VectorOperators.IS_INFINITE))))
.intoArray(outValues, i);
The same is needed for the masked tail and the other three POW processors, so a small static helper may be nicer than eight copies. It would also be worth adding NaN, ±Infinity and negative-base cases to SimdVoMathlibParityTest.
DoublePower (the pow() function) now sends long, long through makeLongLongToDouble, so all four double-output combos are SIMD-specialized. Only ^ on two longs stays scalar.
* Exponentiation. VO_MATHLIB code path. {@code VectorOperators.POW} returns a
* {@link jdk.incubator.vector.DoubleVector} only, so the {@code long × long -> long} combo (produced by
* {@code LongMath.pow} for the {@code ^} operator) is not SIMD-specialized here; every double-returning combo is,
* including {@code long × long -> double} for the {@code pow} function.
Cool stuff! Buddy Claude had two comments I think are valuable (one small docs, one around pow() edge-cases) to consider.
🟢 Approval recommended
No actionable issues found. The incremental POW fix restores Math.pow NaN behavior for the relevant C99 corner cases, while the full SIMD wiring, type dispatch, null handling, tails, SQL registration, tests, benchmarks, and documentation remain consistent.
Reviewed 25 of 25 changed files. Updated-head focus covered the 5 files changed since the previous review, then reconciled them with the complete PR diff and surrounding code.
Validation: git diff --check passed. No project tests, builds, installs, or formatters were run.
<!-- mergelens:review -->
---
This is an automated review by Codex GPT-5.6-Luna(max)
The helper lives on SimdDoubleDoublePowProcessor, not SimdPowSpecialCases (reflowed to stay under the line limit):
// NaN. SimdDoubleDoublePowProcessor.withNanFixup patches those lanes, so the SIMD output should match Math.pow
// exactly on this special-value grid. ulp=0 because the Java spec pins these results deterministically.
Checkstyle SingleSpaceSeparator fails on the alignment spaces:
final double[] exps = {nan, nan, inf, inf, -inf, 2.0, nan, inf, -inf, -inf, 2.0, 2.0};
Same checkstyle failure here:
final long[] bases = {1L, -1L, 1L, -1L, 1L, -1L, 2L, 2L, 2L, 3L};
final double[] exps = {nan, nan, inf, inf, -inf, -inf, nan, inf, -inf, 2.0};
Beauty 🐻. Some final small nits.
amaechler
clintropolis
Description
Adds simd wiring for
POWER,ATAN2, andHYPOT(as well as SQL binding for hypot)Benchmarks:
| # | Op | Shape | Scalar (ms/op) | SIMD (ms/op) | Speedup |
|---|---|---|---:|---:|---:|
| 97 | POWER | dd | 45.31 | 39.91 | 1.14× |
| 98 | POWER | dl | 46.79 | 40.30 | 1.16× |
| 99 | POWER | ld | 54.36 | 36.07 | 1.51× |
| 100 | POWER | ll | 55.62 | 36.21 | 1.54× |
| 101 | ATAN2 | dd | 54.39 | 28.79 | 1.89× |
| 102 | ATAN2 | dl | 34.59 | 25.34 | 1.37× |
| 103 | ATAN2 | ld | 42.43 | 25.20 | 1.68× |
| 104 | ATAN2 | ll | 43.22 | 24.83 | 1.74× |
| 105 | HYPOT | dd | 43.98 | 23.42 | 1.88× |
| 106 | HYPOT | dl | 29.60 | 19.61 | 1.51× |
| 107 | HYPOT | ld | 30.43 | 19.59 | 1.55× |
| 108 | HYPOT | ll | 29.31 | 19.64 | 1.49× |