nx_det.nx
buildroot/runtime/nx_det.nx
about
nx_det.nx -- deterministic floating-point execution mode.
WHY THIS EXISTS (Phase R2 capability lever, 2026-04-24):
Same .nx source must produce the same bits of output on every
host that runs it -- x86 laptop, RV64 Milk-V, NishiOS silicon,
browser WASM. This is a capability V8 / WASM / gcc STRUCTURALLY
cannot provide because each chooses its own IEEE 754 defaults
(rounding mode, subnormal handling, contract-affine math, FMA
fusion) and each sees its own platform's ISA-specific quirks.
Bit-exact determinism unlocks, in order:
1. Reproducible F6 manifests across heterogeneous build hosts
2. Replay debugging (record input nondeterminism, replay exactly)
3. Lockstep multiplayer (Carthago V3 ask; NGE future)
4. Formal verification at the binary level (seL4 path)
5. Supply-chain attestation of FP-heavy numeric code
We own the code path from source to silicon, so we pin every
FP knob that the standard leaves flexible. Managed platforms
cannot do this because they don't control the ISA or the JIT.
WHAT THIS MODULE PROVIDES:
nx_det_enter() Enter deterministic mode. Sets:
* rounding mode = round-to-nearest-even
* subnormals flushed to zero = NO
(accept slower runtime, forbid
flush-to-zero platform quirk)
* NaN handling = quiet propagation, no
trap; NaN payload canonicalised
* contract-affine math = OFF (no fused
multiply-add unless nx_det_fma called)
* exception flags cleared
nx_det_exit() Restore whatever FP state the caller had.
nx_det_with(block) Scope block in deterministic mode; auto
restore on return. Convention wrapper.
dependencies 1 imports · 0 importers
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 102 | struct NxDetCtx |
consts
| 90 | const NX_DET_RM_RNE: i64 = 0 // Round to Nearest, ties to Even |
| 91 | const NX_DET_RM_RTZ: i64 = 1 // Round towards Zero |
| 92 | const NX_DET_RM_RDN: i64 = 2 // Round Down (towards -inf) |
| 93 | const NX_DET_RM_RUP: i64 = 3 // Round Up (towards +inf) |
| 94 | const NX_DET_RM_RMM: i64 = 4 // Round to nearest, ties to Max Magnitude |
| 95 | const NX_DET_RM_DYN: i64 = 7 // Dynamic (use fcsr frm -- forbidden in det mode) |
| 98 | const NX_DET_POLICY_RM: i64 = 0 // = RNE |
| 108 | const NX_DET_CTX_BYTES: i64 = 24 |
| 167 | const NX_DET_F32_QNAN_BITS: i64 = 0x7FC00000 |
| 173 | const NX_DET_F64_QNAN_BITS: i64 = 0x7FF8000000000000 |
functions
| 112 | func nx_det_ctx_new() -> *NxDetCtx called by 1: main |
| 126 | func nx_det_fcsr_read() -> i64 called by 1: nx_det_enter |
| 133 | func nx_det_fcsr_write(v: i64) -> i64 |
| 140 | func nx_det_enter(c: *NxDetCtx) -> i64 |
| 151 | func nx_det_exit(c: *NxDetCtx) -> i64 |
| 175 | func nx_det_canonical_nan_f32() -> i64 { return NX_DET_F32_QNAN_BITS } called by 1: main |
| 176 | func nx_det_canonical_nan_f64() -> i64 { return NX_DET_F64_QNAN_BITS } called by 1: main |
| 190 | func nx_det_fma_f32(a_bits: i64, b_bits: i64, c_bits: i64) -> i64 |
| 199 | func nx_det_fma_f64(a_bits: i64, b_bits: i64, c_bits: i64) -> i64 |
| 205 | func main() -> i64 |