Skip to content

[VFDLIBM-34] Gate the hypot port on a scalar e_hypot.c equal to StrictMath.hypot in every JIT mode - #136

Open
MaxGekk wants to merge 4 commits into
mainfrom
hypot-scalar-gate
Open

MaxGekk wants to merge 4 commits into
mainfrom
hypot-scalar-gate

Conversation

@MaxGekk

@MaxGekk MaxGekk commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Part of #34: the entry gate for porting hypot, step 1 of its plan, before any vector code.
HypotTest.cHypot is reference/fdlibm-5.3/e_hypot.c in scalar Java, line by line, each statement tagged with its C line; __HI(v) = w replaces the high word and keeps the low word, and lines 80-84 leave ha and hb stale as the C does.
scalarTranscriptionIsStrictMath compares it with StrictMath.hypot through PairBits.matches under MAGNITUDES, so raw bits on every lane but one of two NaNs with different bits, where both results must be a candidate. It also asserts that every way out of the C is taken (ratio return, non-finite, zero b, the three scalings, both sqrt forms, equal high words with b the larger, and each sqrt form after the 2^1022 scaling, where the C reads its stale words).
The inputs are every pair of the special values and of e_hypot.c's high words at three low words, the fuzz's pair draws with wordGaps at +-0x3c00000 and its neighbours and 0, pairs at each scaling word with the other word inside line 63's gap, subnormal and zero b, equal high words, a near 2b, NaNs beside NaNs (random payloads, one bit apart, sign apart), beside infinities and beside finite values, Pythagorean triples scaled across the scalings, random bits, Varka's baseline range and every exponent: 1,243,449 pairs.
scalarTranscriptionIsStrictMathInEveryJitMode runs the same check in a JVM of its own per mode (-Xint, -XX:TieredStopAtLevel=1, -XX:-TieredCompilation, default tiering), started from the test by ProcessBuilder with HypotTest.main, so neither pom.xml nor the fault runs change. It asserts each child had its flag, reports interpreted mode for -Xint and mixed mode for the others, and exited 0; the child exits 1 if any of its three passes has a mismatch, sees no two-NaN lane of distinct candidates or leaves a way out of the C untaken. The children inherit no JAVA_TOOL_OPTIONS, JDK_JAVA_OPTIONS or _JAVA_OPTIONS, time out after 60 s (locally -Xint took 1.3 s, C1 only 0.2 s, C2 only 0.3 s, tiered 0.2 s), and are destroyed on a timeout or interrupt. The candidate each mode returns is printed, not asserted, since it is not specified.
The children do not depend on the vector width, so they run only in a test JVM with no -XX: option, i.e. where vfdlibm.test.jvmArgs is empty: ci.yml's rows "x86 128+256 bits, 512 on AVX-512 runners" and "Arm 128 bits" (once per architecture) and a plain mvn -B verify, dev/release.sh's included; the other rows skip them.
theInputsSeeAChangedTranscription shows the inputs can tell: the transcription with ha and hb refreshed after the 2^1022 scaling, or without line 63's early return, differs from StrictMath. anInfinityBesideANaNIsPositiveInfinity pins line 69.

Why are the changes needed?

#34 makes a scalar transcription that equals StrictMath.hypot the condition for starting the vector port, and the two-NaN contract (AGENTS.md, "Releases") needs evidence that hypot's results on those lanes are among the MAGNITUDES candidates in every JIT tier.
Result: no input differs outside the two-NaN lane, in any mode.
Two-NaN lanes, by StrictMath.hypot (JDK 25.0.5.1, x86-64): -Xint and C1 only returned the second argument's candidate on every lane in every pass; C2 only and default tiering returned the second argument's on 161 lanes of the first pass (before compilation) and the first argument's on every other lane, all later passes included. Neither rule is the C's larger-high-word a, which agrees with PROOFS.md's probe statement.
The transcription's own a + b on those lanes keeps the C's b when interpreted and the C's a when compiled by C1 or C2; it is a candidate in every case.
Changed transcriptions, on 9,500,985 pairs: refreshed words differ on 52,720, no early return on 1,316,919. w >= b at line 95 changed no result on these inputs, so it is not among the variants.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

mvn -B verify passed (all suites and fault runs). HypotTest, HarnessSelfTest and PlantedFaultTest passed again after each round of review fixes.
A larger run, 9,500,985 pairs, two passes, in each mode, all with no mismatch: java <mode flag> --add-modules jdk.incubator.vector -cp target/classes:target/test-classes io.github.vecbricks.vfdlibm.HypotTest 0x100000 2 variants.
No hard-case file for hypot exists yet; the Pythagorean triples are exact cases computed here.
Known nit left: lowWord, fromWords and concat duplicate private helpers of Fuzz and Atan2Test.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 5.5)

Max Gekk added 4 commits November 22, 2026 18:37
…Math.hypot in every JIT mode

HypotTest transcribes e_hypot.c line by line and compares it with
StrictMath.hypot by PairBits under MAGNITUDES, on inputs that take every
return of the C, in this JVM and in one JVM per JIT mode (-Xint, C1 only,
C2 only, default tiering). Two changed transcriptions show the inputs can
tell.

Generated-by: Claude Code (Opus 5.5)
Count every mismatch, keep the equal-word draws finite, run the variants
only when asked, cap the child JVMs' heap, drop the dependency on
Atan2Test, and say what the per-mode run asserts and what it only prints.

Generated-by: Claude Code (Opus 5.5)
The child JVM now fails when a pass sees no two-NaN lane of distinct
candidates or leaves a way out of the C untaken, as the in-process gate
does; runInJvm destroys the child in a finally and reports the output read
before a timeout; cHypot's Javadoc limits the finite-radicand claim to the
C as written.

Generated-by: Claude Code (Opus 5.5)
…e hypot gate

The children inherit no JAVA_TOOL_OPTIONS, JDK_JAVA_OPTIONS or
_JAVA_OPTIONS and must report interpreted or mixed mode as their flag
says; the gate requires both sqrt forms after the 2^1022 scaling, where
the C reads stale words; the children run only in a test JVM with no -XX:
option (the default-width CI rows and a plain verify) and time out after
60 s.

Generated-by: Claude Code (Opus 5.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant