_self_host_vdot_test.nx source
↩ module page · 39 lines · 1364 B
1// _self_host_vdot_test.nx -- proves the self-host can emit
2// __simd_vdot_i16_x16 end-to-end through NishiLang only.
3//
4// Build path (NO new C code added -- only existing C anchor):
5// nxc2.exe (one-time bootstrap) -> nxc.elf (the self-host)
6// nxc.elf compiles THIS file using its new __simd_vdot_i16_x16
7// parse builtin + IR builder + RV-V codegen.
8// Result: an RV-V program that runs on qemu and exits with the
9// dot product as its return code.
10//
11// dot([1..16] . [1..16]) = sum(i^2 for i=1..16) = 1496. Doesn't
12// fit in u8 exit code (max 255), so we mod by 251 (next prime
13// below 256) and exit with that. 1496 % 251 = 241.
14
15import "nx_syscalls.nx"
16
17func pack4_i16(a: i64, b: i64, c: i64, d: i64) -> i64 {
18 return (a & 0xFFFF)
19 | ((b & 0xFFFF) << 16)
20 | ((c & 0xFFFF) << 32)
21 | ((d & 0xFFFF) << 48)
22}
23
24func main() -> i64 {
25 let a_raw: *u8 = sys_mmap(64)
26 let b_raw: *u8 = sys_mmap(64)
27 let a: *i64 = a_raw as *i64
28 let b: *i64 = b_raw as *i64
29 a[0] = pack4_i16(1, 2, 3, 4)
30 a[1] = pack4_i16(5, 6, 7, 8)
31 a[2] = pack4_i16(9, 10, 11, 12)
32 a[3] = pack4_i16(13, 14, 15, 16)
33 b[0] = pack4_i16(1, 2, 3, 4)
34 b[1] = pack4_i16(5, 6, 7, 8)
35 b[2] = pack4_i16(9, 10, 11, 12)
36 b[3] = pack4_i16(13, 14, 15, 16)
37 let s: i64 = __simd_vdot_i16_x16(a as *i64, b as *i64)
38 return s % 251
39}