nx_nofloat_hw_research_fetch.nx source
↩ module page · 71 lines · 4558 B
1// nx_nofloat_hw_research_fetch.nx -- SOVEREIGN researcher: GROUND the HARDWARE-RUNG-UP exceed in REAL fetched
2// facts (Rule 4). The claim we must ground: on INTEGER-ONLY / NO-FPU hardware (microcontrollers, FPGAs, RISC-V
3// base ISA, edge accelerators) float is a LIABILITY -- it needs a floating-point UNIT or slow software emulation
4// (soft-float), while our no-float Q16 stack runs NATIVELY on the integer ALU. That is where no-float genuinely
5// EXCEEDS (not the GPU/datacenter path, where float wins -- the minority-path asterisk). Sources cover: the FPU
6// (optional), fixed-point arithmetic, MCUs, ARM Cortex-M (M0/M3 = no FPU), RISC-V (integer base + optional F/D),
7// FPGA (float costly), CMSIS-NN / TFLite-Micro (int kernels for edge), int8 edge inference.
8// Mirrors the proven fetcher: sovereign TLS-1.3 + Mozilla CA, idempotent skip-if-have, saves to hw_*.raw.
9// expect_exit: 0
10import "nx_syscalls.nx"
11import "nx_x509_trust_store.nx"
12import "nx_trust_store_load_from_certdata.nx"
13import "nx_https_fetch_follow.nx"
14const K_MAGIC_4194304: i64 = 4194304
15const K_MAGIC_8388608: i64 = 8388608
16
17func df_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
18func df_putn(v: i64) -> i64 {
19 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
20 var m: i64 = v
21 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
22 let d: *u8 = sys_mmap(24); var k: i64 = 0
23 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
24 var j: i64 = k - 1
25 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 }
26 return 0
27}
28func have_file(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
29func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 {
30 if have_file(opath) == 1 { df_puts(opath); df_puts(" [have-skip]\n"); return 1 }
31 let status: *i64 = sys_mmap(8) as *i64
32 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status)
33 df_puts(url); df_puts(" status="); df_putn(status[0]); df_puts(" bytes="); df_putn(n)
34 if n <= 0 { df_puts(" FETCH-FAIL\n"); return 0 }
35 var gz: i64 = 0
36 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } }
37 if gz == 1 { df_puts(" [GZIP-skip]\n"); return 0 }
38 let fd: i64 = sys_openat_wr(opath, 0x1a4)
39 if fd < 0 { df_puts(" SAVE-FAIL\n"); return 0 }
40 sys_write(fd, out, n); sys_close(fd)
41 df_puts(" SAVED\n")
42 return 1
43}
44
45func main() -> i64 {
46 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304)
47 if r <= 0 { df_puts("HW: certdata load failed\n"); return 1 }
48 let store: *TrustStore = r as *TrustStore
49 df_puts("CA roots="); df_putn(trust_store_count(store)); df_puts("\n")
50 let cap: i64 = K_MAGIC_8388608
51 let out: *u8 = sys_mmap(cap)
52 var ok: i64 = 0
53
54 df_puts("== FLOAT IS OPTIONAL HARDWARE (FPU absent on much edge silicon; soft-float = slow) ==\n")
55 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Floating-point_unit" as *u8, "knowledge/fetched/hw_fpu.raw" as *u8, store, out, cap)
56 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Fixed-point_arithmetic" as *u8, "knowledge/fetched/hw_fixedpoint.raw" as *u8, store, out, cap)
57 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Microcontroller" as *u8, "knowledge/fetched/hw_mcu.raw" as *u8, store, out, cap)
58
59 df_puts("== NO-FPU / INTEGER-BASE CPU FAMILIES (where no-float is the native path) ==\n")
60 ok = ok + fetch_save("https://en.wikipedia.org/wiki/ARM_Cortex-M" as *u8, "knowledge/fetched/hw_cortexm.raw" as *u8, store, out, cap)
61 ok = ok + fetch_save("https://en.wikipedia.org/wiki/RISC-V" as *u8, "knowledge/fetched/hw_riscv.raw" as *u8, store, out, cap)
62 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Field-programmable_gate_array" as *u8, "knowledge/fetched/hw_fpga.raw" as *u8, store, out, cap)
63
64 df_puts("== EDGE / TINYML INTEGER INFERENCE (the field already runs no-float on this hardware) ==\n")
65 ok = ok + fetch_save("https://arxiv.org/abs/1801.06601" as *u8, "knowledge/fetched/hw_cmsisnn.raw" as *u8, store, out, cap)
66 ok = ok + fetch_save("https://en.wikipedia.org/wiki/TensorFlow_Lite" as *u8, "knowledge/fetched/hw_tflite.raw" as *u8, store, out, cap)
67 ok = ok + fetch_save("https://en.wikipedia.org/wiki/AI_accelerator" as *u8, "knowledge/fetched/hw_aiaccel.raw" as *u8, store, out, cap)
68
69 df_puts("HW READABLE SOURCES SAVED: "); df_putn(ok); df_puts(" / 9\n")
70 return 0
71}