code wiki / _hdl_build / nx_f32_vec_gate.nx
nx_f32_vec_gate.nx source
↩ module page · 61 lines · 3315 B
1// nx_f32_vec_gate.nx -- KAT for the hardware-f32 vec3 PART (R3), built + run through the
2// SOVEREIGN compiler (nx_cc_sovereign now carries f32). Multi-value KAT: a faked/constant
3// f32 implementation cannot produce 32, 25, 5, [0,0,1], 3 AND a signed -4 all at once, so
4// distinct-correct results = real hardware float composing into vec3. exit 0 = GREEN. AUTHOR=ORGAN.
5import "nx_syscalls.nx"
6import "nx_f32_hw.nx"
7import "nx_f32.nx"
8
9func main() -> i64 {
10 let d: i64 = v3_dot(f32_of(1), f32_of(2), f32_of(3), f32_of(4), f32_of(5), f32_of(6))
11 if f32_int(d) != 32 { return 1 } // 4+10+18
12 if f32_int(v3_lensq(f32_of(3), f32_of(4), f32_of(0))) != 25 { return 2 } // 9+16+0
13 if f32_int(f32_sub(f32_of(7), f32_of(2))) != 5 { return 3 } // 7-2
14 let out: *i64 = sys_mmap(24) as *i64
15 v3_cross(f32_of(1), f32_of(0), f32_of(0), f32_of(0), f32_of(1), f32_of(0), out)
16 if f32_int(out[0]) != 0 { return 4 }
17 if f32_int(out[1]) != 0 { return 5 }
18 if f32_int(out[2]) != 1 { return 6 } // x cross y = z
19 if f32_int(f32_div(f32_of(6), f32_of(2))) != 3 { return 7 } // 6/2
20 // signed control: negate one component -> 4+10-18 = -4 (proves real SIGNED float, not magnitude)
21 let dn: i64 = v3_dot(f32_of(1), f32_of(2), f32_neg(f32_of(3)), f32_of(4), f32_of(5), f32_of(6))
22 if f32_int(dn) != (0 - 4) { return 8 }
23
24 // DIFFERENTIAL: hardware SSE f32 (__f32_*) must equal the independent i64 soft-float
25 // IEEE-754 (nx_f32.nx) BIT-FOR-BIT (same binary32 layout). Two implementations agreeing
26 // = no-false-green proof the hardware path is conformant, not just self-consistent.
27 let x: i64 = f32_of(6)
28 let y: i64 = f32_of(7)
29 if __f32_mul(x, y) != nx_f32_mul(x, y) { return 9 } // 42.0f, both paths identical bits
30 if __f32_add(x, y) != nx_f32_add(x, y) { return 10 } // 13.0f
31 let half: i64 = __f32_div(f32_of(1), f32_of(2)) // 0.5f (fractional)
32 if __f32_mul(half, x) != nx_f32_mul(half, x) { return 11 } // 3.0f
33
34 // mat4 KAT (the projection workhorse): identity*v = v; diag(2,3,4,1)*[1,1,1,1] = [2,3,4,1];
35 // diag * identity = diag (exercises m4_mul).
36 let m: *i64 = sys_mmap(128) as *i64
37 let v: *i64 = sys_mmap(32) as *i64
38 let r4: *i64 = sys_mmap(32) as *i64
39 m4_identity(m)
40 v[0] = f32_of(1); v[1] = f32_of(2); v[2] = f32_of(3); v[3] = f32_of(4)
41 m4_vec4(m, v, r4)
42 if f32_int(r4[0]) != 1 { return 12 }
43 if f32_int(r4[1]) != 2 { return 13 }
44 if f32_int(r4[2]) != 3 { return 14 }
45 if f32_int(r4[3]) != 4 { return 15 }
46 m[0] = f32_of(2); m[5] = f32_of(3); m[10] = f32_of(4) // -> diag(2,3,4,1)
47 v[0] = f32_of(1); v[1] = f32_of(1); v[2] = f32_of(1); v[3] = f32_of(1)
48 m4_vec4(m, v, r4)
49 if f32_int(r4[0]) != 2 { return 16 }
50 if f32_int(r4[1]) != 3 { return 17 }
51 if f32_int(r4[2]) != 4 { return 18 }
52 if f32_int(r4[3]) != 1 { return 19 }
53 let mi: *i64 = sys_mmap(128) as *i64
54 let mp: *i64 = sys_mmap(128) as *i64
55 m4_identity(mi)
56 m4_mul(m, mi, mp) // diag * identity = diag
57 if f32_int(mp[0]) != 2 { return 20 }
58 if f32_int(mp[5]) != 3 { return 21 }
59 if f32_int(mp[10]) != 4 { return 22 }
60 return 0
61}