code wiki / _hdl_build / nx_race_native.nx
nx_race_native.nx source
↩ module page · 50 lines · 3192 B
1// nx_race_native.nx -- "OURS" in the cross-language RACE: the SAME workload as the IR program, compiled
2// SOVEREIGN (nx_cc -> nxasm_x86, no gcc) and run as a direct native loop. Timed head-to-head vs the
3// exported C/JS/Python/Perl/Java versions. The answer must match the Nishi IR-interpreted truth and every
4// exported language (correctness); wall-time shows where our output sits vs mainstream toolchains.
5// license_tier: ORIGINAL
6//
7// ⚠⚠HEADER CORRECTED 2026-08-14 -- IT DESCRIBED A DIFFERENT PROGRAM THAN THE ONE BELOW, THREE WAYS:
8// it claimed the workload was "sum of i for 1..120,000,000"; the code runs a 50,000,000-iteration LEHMER
9// step, not a sum; and the quoted answer 200000010000000 is the sum 1..20,000,000 (n(n+1)/2), matching
10// NEITHER. For a benchmark whose entire claim is that every language runs THE SAME WORKLOAD, a stale
11// header is not cosmetic: anyone porting from the comment implements a different program and the race
12// silently compares two workloads.
13// ★★★A CROSS-LANGUAGE BENCHMARK'S HEADER IS PART OF ITS CONTRACT, AND A CONTRACT THAT DISAGREES WITH THE
14// CODE IS WORSE THAN NO CONTRACT -- THE READER TRUSTS IT PRECISELY BECAUSE IT IS SPECIFIC.
15// ★THE CORRECT ANSWER, MEASURED 2026-08-14 BY RUNNING IT: 668950819 (seed h=1, RN_ITERS Lehmer steps).
16// The old header quoted 200000010000000, which is the sum 1..20,000,000 and matches nothing this program
17// computes. A stated answer is the ONLY part of a cross-language contract a port can actually check
18// itself against, so a wrong one is worse than none: it certifies a mismatched port as correct.
19// ⚠OWED: the exported C/JS/Python/Perl/Java ports must be read to confirm they run THIS loop (same
20// multiplier, same modulus, same iteration count) and produce 668950819. Until that is checked the
21// race's comparability is asserted, not proven -- and this header is no longer the evidence for it.
22import "nx_syscalls.nx"
23// ★THE MINIMAL STANDARD (Park-Miller / Lehmer) GENERATOR, AND IT IS A MATCHED SET SHARED WITH EVERY PORT.
24// These were K_MAGIC_48271 and K_MAGIC_2147483647 -- named for their digits, which hides both that they
25// are a PUBLISHED pair (x = 48271*x mod 2^31-1, the revised MINSTD multiplier; 16807 was the original)
26// and that every exported language must use the IDENTICAL pair or the race compares different programs.
27const RN_ITERS: i64 = 50000000 // loop count -- shared with every exported port
28const RN_MINSTD_MULT: i64 = 48271 // Park-Miller revised multiplier
29const RN_MINSTD_MOD: i64 = 2147483647 // 2^31 - 1, Mersenne prime modulus
30func putn(v: i64) -> i64 {
31 let bb: *u8 = sys_mmap(28)
32 var m: i64 = v
33 if m < 0 { m = 0 - m }
34 let t: *u8 = sys_mmap(28)
35 var k: i64 = 0
36 if m == 0 { t[0] = (48 as u8); k = 1 }
37 while m > 0 { t[k] = ((48 + (m % 10)) as u8); m = m / 10; k = k + 1 }
38 var i: i64 = 0
39 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 }
40 sys_write(1, bb, k)
41 return 0
42}
43func main() -> i64 {
44 var h: i64 = 1
45 var i: i64 = 1
46 while i <= RN_ITERS { h = (h * RN_MINSTD_MULT) % RN_MINSTD_MOD; i = i + 1 }
47 putn(h)
48 sys_write(1, "\n" as *u8, 1)
49 return 0
50}