_self_host_lane_binops_test.nx source
↩ module page · 65 lines · 2540 B
1// Per-lane vmin/vmax/vadd/vsub/vmul for i16x16 -- one smoke each.
2// Verifies via reduce after.
3// Returns 0 on full PASS, case# on first failure.
4
5import "nx_syscalls.nx"
6
7func main() -> i64 {
8 let a_raw: *u8 = sys_mmap(64)
9 let b_raw: *u8 = sys_mmap(64)
10 let o_raw: *u8 = sys_mmap(64)
11 let a: *i64 = a_raw as *i64
12 let b: *i64 = b_raw as *i64
13 let o: *i64 = o_raw as *i64
14
15 // a = [1,2,3,4, 5,6,7,8, 9,10,11,12, 13,14,15,16]
16 a[0] = 0x0004000300020001
17 a[1] = 0x0008000700060005
18 a[2] = 0x000c000b000a0009
19 a[3] = 0x0010000f000e000d
20 // b = [16,15,...,1] (reverse order)
21 b[0] = 0x000d000e000f0010
22 b[1] = 0x0009000a000b000c
23 b[2] = 0x0005000600070008
24 b[3] = 0x0001000200030004
25
26 // Test 1: vmin lanewise. min(1,16)=1, min(16,1)=1.
27 // Whole vec min = min(a,b) per-lane all <= 8. vreduce_min = 1.
28 let d1: i64 = __simd_vmin_lane_i16_x16(a as *i64, b as *i64, o as *i64)
29 let r1: i64 = __simd_vreduce_min_i16_x16(o as *i64)
30 if r1 != 1 { return 1 }
31
32 // Test 2: vmax lanewise. max(1,16)=16, max(2,15)=15, ...max(8,9)=9.
33 // Then lanes 9..16 paired with 8..1 also produce 9..16. Max overall = 16.
34 let d2: i64 = __simd_vmax_lane_i16_x16(a as *i64, b as *i64, o as *i64)
35 let r2: i64 = __simd_vreduce_max_i16_x16(o as *i64)
36 if r2 != 16 { return 2 }
37
38 // Test 3: vadd lanewise. a + b = (17,17,...17) every lane.
39 // vreduce_max = 17.
40 let d3: i64 = __simd_vadd_lane_i16_x16(a as *i64, b as *i64, o as *i64)
41 let r3: i64 = __simd_vreduce_max_i16_x16(o as *i64)
42 if r3 != 17 { return 3 }
43 // Confirm: vreduce_min also = 17.
44 let r3b: i64 = __simd_vreduce_min_i16_x16(o as *i64)
45 if r3b != 17 { return 13 }
46
47 // Test 4: vsub lanewise. a - b = (1-16, 2-15, 3-14, ..., 16-1)
48 // = (-15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15)
49 // vreduce_min = -15, vreduce_max = 15.
50 let d4: i64 = __simd_vsub_lane_i16_x16(a as *i64, b as *i64, o as *i64)
51 let r4: i64 = __simd_vreduce_min_i16_x16(o as *i64)
52 if r4 != -15 { return 4 }
53 let r4b: i64 = __simd_vreduce_max_i16_x16(o as *i64)
54 if r4b != 15 { return 14 }
55
56 // Test 5: vmul lanewise. a * b = (16, 30, 42, 52, 60, 66, 70, 72,
57 // 72, 70, 66, 60, 52, 42, 30, 16). max = 72.
58 let d5: i64 = __simd_vmul_lane_i16_x16(a as *i64, b as *i64, o as *i64)
59 let r5: i64 = __simd_vreduce_max_i16_x16(o as *i64)
60 if r5 != 72 { return 5 }
61 let r5b: i64 = __simd_vreduce_min_i16_x16(o as *i64)
62 if r5b != 16 { return 15 }
63
64 return 0
65}