Repository navigation
Keep ParparVM integer division from trapping on x86 - #6025
Conversation
A translated idiv/irem/ldiv/lrem was a raw C / or %, which is undefined for a zero divisor and for MIN_VALUE / -1. arm64's sdiv answers both without trapping; x86's idiv raises SIGFPE and kills the process (native Windows and Linux, x86 servers running the backend). Route them through static inline helpers in cn1_globals.h that answer what arm64 already answers -- x/0 == 0, x%0 == x, MIN/-1 == MIN, MIN%-1 == 0 -- so devices see no change. One unsigned compare covers both edge divisors and folds away for constant divisors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
βΉοΈ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with π while any review is running, comments if it has suggestions, and reacts with π once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: βΉοΈ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with π. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Cloudflare Preview
|
|
Compared 206 screenshots: 206 matched. |
β Continuous Quality ReportTest & Coverage
Static Analysis
Generated automatically by the PR CI workflow. |
|
Compared 185 screenshots: 185 matched. Benchmark ResultsDetailed Performance Metrics
|
|
Compared 185 screenshots: 185 matched. Benchmark ResultsDetailed Performance Metrics
ParparVM vs HotSpot (JDK 25): Windows x64Runner CPU: AMD64 Family 25 Model 1 Stepping 1, AuthenticAMD (baseline Ratios are ParparVM / JDK 25: below 1.00x ParparVM is faster (time) or smaller (RAM). Median of 5 interleaved, paired rounds; every run's output was verified. A ratio more than 15% (time) / 15% (RAM) away from its baseline in
Result: no regression |
Problem
ParparVM translated
idiv/irem/ldiv/lreminto a raw C/or%. In C both are undefined for a zero divisor and forMIN_VALUE / -1(the quotient does not fit), and-fwrapvonly covers+ - *. What happens is up to the CPU:sdiv)idiv)7 / 0,7 % 00,7MIN / -1,MIN % -1MIN,0So native Windows/Linux builds and x86 servers running the backend crash outright, while arm64 keeps going. On the backend that is a remote crash whenever a divisor comes from a request.
Fix
Integer division and remainder go through four
static inlinehelpers incn1_globals.h(cn1IntDiv,cn1IntRem,cn1LongDiv,cn1LongRem), used by both the stack form (BasicInstruction, theBC_*macros) and the inline-expression form (ArithmeticExpression).They do not throw
ArithmeticException. They answer what arm64 hardware already answers, so iOS devices see no behaviour change and every target now agrees:x/0 == 0,x%0 == x,MIN/-1 == MIN,MIN%-1 == 0.Cost: one unsigned compare,
(uint32_t)b + 1u <= 1u, which is true only for 0 and -1. From the-O2assembly:/ 10,% 7) fold the check away entirely, so the code is the same multiply-shift as before;cmp/jaon x86, and on arm64 clang makes it branch-free (sdiv+csel).Tests
BytecodeInstructionIntegrationTest's fixture gainsdivisionEdges(): 13 int/long checks in both the expression and the stack form. The divisors are read from heap fields so clang cannot constant-fold them. The test asserts the exact result line (RESULT=9000, a zero failure bitmask) and that the generated C uses the helpers./and%it fails with exit 136 (SIGFPE). The Linux CI runners are x86, so the test bites there.ByteCodeTranslator: 0 findings.π€ Generated with Claude Code