Skip to content

0.5.3 --- an image is entered in its convention's floating-point state - #33

Merged
Sunrisepeak merged 1 commit into
mainfrom
openkal-0.24.4
Nov 7, 2026
Merged

Sunrisepeak merged 1 commit into
mainfrom
openkal-0.24.4

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

An ok image is entered in its convention's floating-point state (SPEC 12.2), on every system.

The defect. A thread of Windows begins with the x87 at double precision (control word 0x027F); Linux and macOS begin at extended precision (0x037F), the System V state. okrun entered an image without establishing the state, so a C library in the image that computes in long double read decimal numbers otherwise: openkal-musl's strtod("0.4") gave 0x1.99999999998p-2 instead of 0x1.999999999999ap-2 (measured on x86_64-openkal under both control words). It surfaced as a JSON number comparison that failed only on Windows.

The change.

  • run/src/image_abi.h: okrun_fp_enter and okrun_fp_leave — on x86-64 the x87 control word 0x037F and MXCSR 0x1F80, on AArch64 FPCR zero; each writes only a word that differs.
  • The runner establishes the state at the entry, around initialisers and finalisers (a library's run on the opening program's thread, whose state is restored), and in each context the image starts.
  • okrun_call_enter / okrun_call_leave (okrun.h, openkal.run): a binding makes each call from a program of the system in the image's state and restores the caller's after it; openkal-bind generates the pair around every call.
  • examples/fpstate: the state at the entry and in a context, checked on each system. examples/bind: the caller sets the x87 to Windows' precision, the library reports the convention's, and the caller's word is restored.
  • 0.5.3 for the archive's four packages; README and docs/bind.md.

The SPEC row that states the state is mcpplibs/openkal's (a companion pull request).

Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com>
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