code wiki / (root) / nx_simd_probe2.nx

nx_simd_probe2.nx source

↩ module page · 36 lines · 1428 B

1// nx_simd_probe2.nx -- verify the POINTER-FORM __simd_vdot_i16_x16 compiles AND computes on x86. 2// 3// The vload form (__simd_vload_i16_x16) is unhandled by nx_cc_known_good, but the pointer form 4// __simd_vdot_i16_x16(ptr_a, ptr_b) compiles (2512 lines .s). This confirms it also COMPUTES correctly: 5// dot([1..16],[1..16]) = sum(i^2 for i=1..16) = 1496. run-exit=0 => SIMD is USABLE via the pointer form. 6// license_tier: ORIGINAL 7import "nx_syscalls.nx" 8import "nx_tier.nx" 9const K_MAGIC_1496: i64 = 1496 10 11func sp2_pack(a: i64, b: i64, c: i64, d: i64) -> i64 { 12 return (a & 0xFFFF) | ((b & 0xFFFF) << 16) | ((c & 0xFFFF) << 32) | ((d & 0xFFFF) << 48) 13} 14 15func main() -> i64 { 16 let a: *i64 = sys_mmap(64) as *i64 17 let b: *i64 = sys_mmap(64) as *i64 18 a[0] = sp2_pack(1, 2, 3, 4) 19 a[1] = sp2_pack(5, 6, 7, 8) 20 a[2] = sp2_pack(9, 10, 11, 12) 21 a[3] = sp2_pack(13, 14, 15, 16) 22 b[0] = a[0] 23 b[1] = a[1] 24 b[2] = a[2] 25 b[3] = a[3] 26 let s: i64 = __simd_vdot_i16_x16(a as *i64, b as *i64) 27 if s != K_MAGIC_1496 { return 1 } // sum(1..16)^2 = K_MAGIC_1496 28 29 // second check: all-ones dot = 16 (guards against a constant-1496 stub) 30 let one: i64 = 0x0001000100010001 31 a[0] = one; a[1] = one; a[2] = one; a[3] = one 32 b[0] = one; b[1] = one; b[2] = one; b[3] = one 33 let s2: i64 = __simd_vdot_i16_x16(a as *i64, b as *i64) 34 if s2 != 16 { return 2 } 35 return 0 36}