code wiki / (root) / nx_det.nx

nx_det.nx

buildroot/runtime/nx_det.nx

9620 B238 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

syscalls.nx nx_det.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_det_ctx_new nx_det_enter nx_det_fcsr_read nx_det_fcsr_write nx_det_exit nx_det_fcsr_write ↻ nx_det_canonical_nan_f32 nx_det_canonical_nan_f64

structs

102struct NxDetCtx

consts

90const NX_DET_RM_RNE: i64 = 0 // Round to Nearest, ties to Even
91const NX_DET_RM_RTZ: i64 = 1 // Round towards Zero
92const NX_DET_RM_RDN: i64 = 2 // Round Down (towards -inf)
93const NX_DET_RM_RUP: i64 = 3 // Round Up (towards +inf)
94const NX_DET_RM_RMM: i64 = 4 // Round to nearest, ties to Max Magnitude
95const NX_DET_RM_DYN: i64 = 7 // Dynamic (use fcsr frm -- forbidden in det mode)
98const NX_DET_POLICY_RM: i64 = 0 // = RNE
108const NX_DET_CTX_BYTES: i64 = 24
167const NX_DET_F32_QNAN_BITS: i64 = 0x7FC00000
173const NX_DET_F64_QNAN_BITS: i64 = 0x7FF8000000000000

functions

112func nx_det_ctx_new() -> *NxDetCtx
called by 1: main
126func nx_det_fcsr_read() -> i64
called by 1: nx_det_enter
133func nx_det_fcsr_write(v: i64) -> i64
140func nx_det_enter(c: *NxDetCtx) -> i64
151func nx_det_exit(c: *NxDetCtx) -> i64
called by 1: main calls 1: nx_det_fcsr_write
175func nx_det_canonical_nan_f32() -> i64 { return NX_DET_F32_QNAN_BITS }
called by 1: main
176func nx_det_canonical_nan_f64() -> i64 { return NX_DET_F64_QNAN_BITS }
called by 1: main
190func nx_det_fma_f32(a_bits: i64, b_bits: i64, c_bits: i64) -> i64
199func nx_det_fma_f64(a_bits: i64, b_bits: i64, c_bits: i64) -> i64
205func main() -> i64