Skip to content

[VFDLIBM-139] Assert the width, no FMA and no call in the C2 code of exp's arms - #141

Merged
MaxGekk merged 9 commits into
mainfrom
asm-check-exp
Nov 22, 2026
Merged

MaxGekk merged 9 commits into
mainfrom
asm-check-exp

Conversation

@MaxGekk

@MaxGekk MaxGekk commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Part of #139: step 1 for exp, and the census of step 2 for exp.

dev/hsdis-build.sh builds hsdis into target/hsdis from two files of the jdk-25-ga tag (hsdis-capstone.c, hsdis.h), fetched alone with pinned SHA-256s, against Capstone 5; it builds the pinned Capstone 5.0.7 from source when the system's is not 5, and passes only if HotSpot then prints a real [Disassembly] (and no hsdis of the JDK's own shadows it).

ExpAsmProbe runs each exp arm (finish and blended, unmasked and masked, and expRare with expCore) in an ExpBenchmark-shaped loop, one JVM per VectorWidth, under -Xbatch, the row's -XX options, the forced inline and CompileCommand=print on its loops.

AsmCheck parses the last standard C2 nmethod of each loop, from entry point to stubs, in Intel syntax, and holds the rules: every byte and line read; packed-double arithmetic on the width's registers only and no scalar double arithmetic; no FMA of any form; no call but uncommon traps and the entry barrier; no StrictMath or FdLibm frame.

ExpAsmTest applies them at 128, 256, 512 bits and the preferred species, and prints the census as Markdown rows; at 128 bits on x86 the call rule is not asserted, since no two-lane mask lowers there and the arms run the Java fallback.

The test skips with its reason when the host is not Linux x86-64, when no hsdis is found, when the JDK has one of its own, and when one is found but HotSpot printed no disassembly; VFDLIBM_ASM_REQUIRED=true turns the last three into failures.

AsmCheckSelfTest feeds crafted disassembly in HotSpot's real line shapes: a clean body passes, and an FMA, a narrow or scalar body, a call, undecoded bytes, an unread line and a StrictMath frame each fail their rule; a hex dump, a C1 compile and an OSR compile parse to nothing.

ci.yml: the three x86 rows of build run dev/hsdis-build.sh on every run, no cache, and set VFDLIBM_ASM_REQUIRED=true; the Arm row skips the check.

SKILLS.md, "The assembly check": the rules, what was learned, and the census per arm, width and AVX level from the laptop; AGENTS.md gets a Build-and-test entry.

Nits left from review, not fixed:

  • Capstone's SHA-256 is pinned on GitHub's generated tag archive, whose bytes GitHub does not promise; a change would fail the build loudly, on every x86 row.
  • Each x86 row fetches three files from GitHub per run; a network failure past curl's retries fails the row.
  • dev/hsdis-build.sh --check disassembles a trivial int method, so it passes a Capstone 4 hsdis; the test then fails on its undecoded bytes, with a message naming Capstone.
  • VFDLIBM_HSDIS_DIR pointed at a binutils hsdis runs the rules on a format they were not written for (unread lines would mostly report it).
  • -XX options that stop C2 (TieredStopAtLevel=1) reach the probe too; the test then fails with "no standard C2 compile", naming the options.
  • The C1 compiles in the probe's output hold StrictMath.exp's inlined wrapper and a call into FdLibm; they are not read, and only a failure prints their tail.

Why are the changes needed?

Nothing read the instructions C2 emits: no FMA was a promise and the vector width was inferred from allocation.

The check found a real case on its first run: a loop calling expCore then expRare on one vector calls expRare (refused for NodeCountInliningCutoff) and boxes; ExpBenchmark's order, expRare first, inlines both.

Ubuntu 24.04's Capstone 4.0.2, which ubuntu-latest has, printed exp's AVX-512 bodies with .byte 0x62 and garbage including a call, which is why the script builds Capstone 5 and the check fails on undecoded bytes.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

mvn -B verify on the laptop (AVX-512).

mvn -q test -Dtest='ExpAsmTest,AsmCheckSelfTest' with -Dvfdlibm.test.jvmArgs empty, -XX:UseAVX=2 -XX:MaxVectorSize=32 and -XX:MaxVectorSize=16: every arm passes at every width; no FMA in any arm.

The skip paths by hand: VFDLIBM_HSDIS_DIR at an empty directory (not found), at a file that is not a library (found but not loaded), and the latter with VFDLIBM_ASM_REQUIRED=true (fails).

In an ubuntu:24.04 container: dev/hsdis-build.sh built Capstone 5.0.7 and hsdis, and the probe's counts matched the laptop's; hsdis on the system's Capstone 4.0.2 gave 19 to 43 undecoded lines per arm, which the new rule reports.

The branch passed seven code-review rounds at high; the last commit before the rebase (no hsdis cache, comment lines before the first instruction, a doc fix) and the rebase onto main were not reviewed before this pull request was opened.

No timing claim: the census is instruction counts on the laptop, not a headline.

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

Generated-by: Claude Code (Opus 5.5)

Max Gekk added 9 commits November 22, 2026 23:28
…exp's arms

dev/hsdis-build.sh builds hsdis into target/hsdis from two pinned files of
jdk-25-ga against Capstone 5 (built from a pinned release when the
system's is older) and checks that HotSpot disassembles with it. hsdis
is a tool: its source and binary are never committed.

ExpAsmProbe runs each exp arm in a loop, one JVM per width, under
-Xbatch with the body forced inline and CompileCommand=print; AsmCheck
parses the last standard C2 nmethod and holds the rules (every byte
decoded, packed-double arithmetic on the width's registers, no FMA, no
call but uncommon traps and the entry barrier, no StrictMath frame).
ExpAsmTest applies them at each width, skipping with its reason without
hsdis; AsmCheckSelfTest shows each rule failing. CI's x86 rows build
hsdis and require the check. SKILLS.md holds the rules, the lessons and
the laptop's census.

Part of #139.

Generated-by: Claude Code (Opus 5.5)
…dis, cached hsdis in CI

Generated-by: Claude Code (Opus 5.5)
…ion arguments, rewrap

Generated-by: Claude Code (Opus 5.5)
…n, key the cache on the image, skip on a JDK's own hsdis

Generated-by: Claude Code (Opus 5.5)
… reads, refuse a JDK's own hsdis in the script

Generated-by: Claude Code (Opus 5.5)
…is in the JDK too, name a missing JDK

Generated-by: Claude Code (Opus 5.5)
Generated-by: Claude Code (Opus 5.5)
… dump is not read, cache the library alone

Generated-by: Claude Code (Opus 5.5)
…es; correct the C1 note

Generated-by: Claude Code (Opus 5.5)
@MaxGekk
MaxGekk merged commit b283273 into main Nov 22, 2026
14 checks passed
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