bigint.nx source
↩ module page · 39 lines · 1506 B
1// bigint.nx -- KAT GATE for the multi-precision integer primitives (syscalls.nx import chain).
2//
3// 2026-07-09: the bi_* primitives moved to nx_bigint_lib.nx (importable, zero-imports) -- this twin and
4// nx_bigint.nx were code-identical and BOTH carried main(), making the primitives unimportable into any
5// main-bearing binary. This file keeps the ORIGINAL smoke battery as the standing gate on the syscalls.nx
6// chain (the syscall-module duality's other side); nx_bigint.nx gates the nx_syscalls chain. Consumers
7// import nx_bigint_lib.nx. expect_exit: 0 license_tier: ORIGINAL
8import "syscalls.nx"
9import "nx_bigint_lib.nx"
10
11// Compile+run smoke: the original KAT battery (returns nonzero identifying the failing check).
12func main() -> i64 {
13 let a: *i64 = (sys_mmap(32) as i64) as *i64
14 let b: *i64 = (sys_mmap(32) as i64) as *i64
15 let r: *i64 = (sys_mmap(32) as i64) as *i64
16 bi_zero(a, 4); bi_zero(b, 4)
17 a[0] = 1
18 b[0] = 1
19 bi_add(r, a, b, 4)
20 if r[0] != 2 { return 1 }
21 if r[1] != 0 { return 2 }
22
23 // 2 * 3 = 6.
24 a[0] = 2; b[0] = 3
25 bi_mul(r, a, 4, b, 4)
26 if r[0] != 6 { return 3 }
27
28 // Byte round-trip: 0xDEADBEEF.
29 let buf: *u8 = sys_mmap(8)
30 buf[0] = 0xDE; buf[1] = 0xAD; buf[2] = 0xBE; buf[3] = 0xEF
31 bi_from_bytes_be(r, 4, buf, 4)
32 if (r[0] & 0xFFFFFFFF) != 0xDEADBEEF { return 4 }
33
34 let out: *u8 = sys_mmap(8)
35 bi_to_bytes_be(out, 4, r, 4)
36 if out[0] != 0xDE { return 5 }
37 if out[3] != 0xEF { return 6 }
38 return 0
39}