_self_host_vdot_full.nx source
↩ module page · 31 lines · 1168 B
1// _self_host_vdot_full.nx -- full vdot [1..16] . [1..16] via self-host.
2// Uses literal hex constants for the packed lanes (avoids the
3// pack4_i16 codegen bug in nx_parse.nx/nx_riscv.nx -- the
4// `expr | (expr << N) | ...` chain currently emits only the first
5// `expr` and drops the rest). Tracked separately.
6//
7// Each pair of i16 lanes per word:
8// lane[0..3] = (1, 2, 3, 4) -> 0x0004000300020001
9// lane[4..7] = (5, 6, 7, 8) -> 0x0008000700060005
10// lane[8..11] = (9,10,11,12) -> 0x000c000b000a0009
11// lane[12..15] = (13,14,15,16) -> 0x00100 0f000e000d
12// dot = sum(i^2 for i=1..16) = 1496. Exit = 1496 % 251 = 241.
13
14import "nx_syscalls.nx"
15
16func main() -> i64 {
17 let a_raw: *u8 = sys_mmap(64)
18 let b_raw: *u8 = sys_mmap(64)
19 let a: *i64 = a_raw as *i64
20 let b: *i64 = b_raw as *i64
21 a[0] = 0x0004000300020001
22 a[1] = 0x0008000700060005
23 a[2] = 0x000c000b000a0009
24 a[3] = 0x0010000f000e000d
25 b[0] = 0x0004000300020001
26 b[1] = 0x0008000700060005
27 b[2] = 0x000c000b000a0009
28 b[3] = 0x0010000f000e000d
29 let s: i64 = __simd_vdot_i16_x16(a as *i64, b as *i64)
30 return s % 251
31}