nx_f32x8_probe.nx source
↩ module page · 30 lines · 1221 B
1// nx_f32x8_probe.nx -- test the x86 f32 SIMD primitive __f32x8_dot on nx_cc_known_good.
2//
3// nx_parse.nx:1463 documents __f32x8_dot(a_ptr, b_ptr) = dot of 8 CONTIGUOUS 4-byte f32 -> f32 scalar,
4// x86 AVX2 vmovups+vmulps + hsum. If it works, the f32 side (DiT projections, linear attention) can be SIMD-
5// accelerated (complement to integer vpmaddwd). Golden: dot([1..8],[1..8]) = sum(i^2,1..8) = 204.
6// Note: f32 must be packed as 4-byte f32 in memory (not i64-per-value).
7// license_tier: ORIGINAL
8import "nx_syscalls.nx"
9import "nx_tier.nx"
10import "nx_le.nx"
11import "nx_f32.nx"
12import "nx_f32_div.nx"
13import "nx_f32_cvt.nx"
14
15func main() -> i64 {
16 let a: *u8 = sys_mmap(32) // 8 f32 = 32 bytes
17 let b: *u8 = sys_mmap(32)
18 var i: i64 = 0
19 while i < 8 {
20 let fb: i64 = nx_i32_to_f32(i + 1) // f32 bits of (i+1)
21 nx_le_write_u32(a, i * 4, fb)
22 nx_le_write_u32(b, i * 4, fb)
23 i = i + 1
24 }
25 let s: i64 = __f32x8_dot(a as *i64, b as *i64)
26 let exp: i64 = nx_i32_to_f32(204) // sum(i^2, 1..8) = 204
27 let tol: i64 = nx_f32_div(nx_i32_to_f32(1), nx_i32_to_f32(100))
28 if (nx_f32_sub(s, exp) & 0x7FFFFFFF) >= tol { return 1 }
29 return 0
30}