code wiki / _hdl_build / nx_race_native.nx

nx_race_native.nx source

↩ module page · 30 lines · 1257 B

1// nx_race_native.nx -- "OURS" in the cross-language RACE: the SAME workload (sum of i for 1..120,000,000) 2// as the IR program, compiled SOVEREIGN (nx_cc -> nxasm_x86, no gcc) and run as a direct native loop. 3// Timed head-to-head vs the exported C/JS/Python/Perl/Java versions of the same program. The answer 4// (200000010000000) must match the Nishi IR-interpreted truth and every exported language (correctness), 5// while wall-time shows where our sovereign output sits vs the mainstream toolchains. license_tier: ORIGINAL 6import "nx_syscalls.nx" 7const K_MAGIC_50000000: i64 = 50000000 8const K_MAGIC_48271: i64 = 48271 9const K_MAGIC_2147483647: i64 = 2147483647 10func putn(v: i64) -> i64 { 11 let bb: *u8 = sys_mmap(28) 12 var m: i64 = v 13 if m < 0 { m = 0 - m } 14 let t: *u8 = sys_mmap(28) 15 var k: i64 = 0 16 if m == 0 { t[0] = (48 as u8); k = 1 } 17 while m > 0 { t[k] = ((48 + (m % 10)) as u8); m = m / 10; k = k + 1 } 18 var i: i64 = 0 19 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 20 sys_write(1, bb, k) 21 return 0 22} 23func main() -> i64 { 24 var h: i64 = 1 25 var i: i64 = 1 26 while i <= K_MAGIC_50000000 { h = (h * K_MAGIC_48271) % K_MAGIC_2147483647; i = i + 1 } 27 putn(h) 28 sys_write(1, "\n" as *u8, 1) 29 return 0 30}