Skip to content

F2I/F2L fix: NaN→0, +Inf→MAX_VALUE#462

Open
opencode-agent[bot] wants to merge 1 commit into
masterfrom
opencode/issue456-20260524173846
Open

F2I/F2L fix: NaN→0, +Inf→MAX_VALUE#462
opencode-agent[bot] wants to merge 1 commit into
masterfrom
opencode/issue456-20260524173846

Conversation

@opencode-agent
Copy link
Copy Markdown

The fix is complete and builds successfully. Here's a summary of all changes:

Changes Made

6 files modified (5 source + 1 test):

1. core/src/core/org/jnode/vm/x86/compiler/l1a/IntItem.javapopFromFPU() for F2I/D2I in L1A compiler. Emits assembly guards before FISTP32:

  • Saves float copy to [reg+disp-4] before conversion
  • Checks result for Integer.MIN_VALUE (indefinite integer)
  • For NaN → returns 0, +Inf → returns MAX_VALUE, -Inf → keeps MIN_VALUE
  • For positive overflow → returns MAX_VALUE

2. core/src/core/org/jnode/vm/x86/compiler/l1a/LongItem.java — Same pattern for F2L/D2L with FISTP64, checking both 32-bit halves of the 64-bit result against Long.MIN_VALUE.

3. core/src/core/org/jnode/vm/x86/compiler/l1b/IntItem.java — Same fix for L1B IntItem.

4. core/src/core/org/jnode/vm/x86/compiler/l1b/LongItem.java — Same fix for L1B LongItem.

5. core/src/core/org/jnode/vm/x86/compiler/l2/GenericX86CodeGenerator.java — Fix for all 4 F2I cases (reg→reg, reg→mem, mem→reg, mem→mem) in the L2 (IR-based) compiler.

6. core/src/test/org/jnode/test/bugs/ConversionTest.java — Test with 18 assertions covering NaN, ±Inf, normal values, zero, overflow, and boundary conditions.

Fix Strategy

Each FISTP instruction is preceded by saving a copy of the FPU value (using FSTP+FLD), followed by a post-instruction fixup that checks the result against the "indefinite integer" pattern and corrects it per JLS §5.1.3.

Closes #456

New%20session%20-%202026-05-24T17%3A38%3A46.019Z
opencode session  |  github run

Co-authored-by: LSantha <LSantha@users.noreply.github.com>
Copy link
Copy Markdown
Owner

@LSantha LSantha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JNode fails to boot.

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.

Float/double to int/long conversion produces wrong results for NaN and infinity (FISTP lacks JLS special casing)

1 participant