code wiki / (root) / _self_host_li_boundary_test.nx

_self_host_li_boundary_test.nx source

↩ module page · 59 lines · 1967 B

1// Boundary smoke for nxasm parse_li -- exercises corner cases at 2// every immediate-width boundary so a future regression in the 3// 3-tier expansion (12-bit / 32-bit / 64-bit) fires immediately. 4// 5// Born from the silent-truncation bug (2026-05-16): parse_li used 6// to mask any immediate to 12 bits, mangling 0x0001000100010001 7// into 1 and breaking every packed-data SIMD smoke. This pins 8// the BOUNDARIES so any drift in expansion logic surfaces with 9// a precise case number. 10 11import "nx_syscalls.nx" 12 13func main() -> i64 { 14 // Test 1: +2047 -- max 12-bit signed. Should use single addi. 15 let a: i64 = 2047 16 if a != 2047 { return 1 } 17 18 // Test 2: -2048 -- min 12-bit signed. Should use single addi. 19 let b: i64 = -2048 20 if b != -2048 { return 2 } 21 22 // Test 3: 2048 -- needs 32-bit form (lui + addi). 23 let c: i64 = 2048 24 if c != 2048 { return 3 } 25 26 // Test 4: -2049 -- needs 32-bit form. 27 let d: i64 = -2049 28 if d != -2049 { return 4 } 29 30 // Test 5: INT32_MAX = 2147483647. Last value in 32-bit form. 31 let e: i64 = 2147483647 32 if e != 2147483647 { return 5 } 33 34 // Test 6: INT32_MIN = -2147483648. 35 let f: i64 = -2147483648 36 if f != -2147483648 { return 6 } 37 38 // Test 7: 2147483648 = INT32_MAX + 1. Needs 64-bit form. 39 let g: i64 = 2147483648 40 if g != 2147483648 { return 7 } 41 42 // Test 8: -2147483649 = INT32_MIN - 1. Needs 64-bit form. 43 let h: i64 = -2147483649 44 if h != -2147483649 { return 8 } 45 46 // Test 9: The original repro value -- 0x0001000100010001 47 // (packed-i16 lanes of 1). 281479271743489. 48 let p: i64 = 281479271743489 49 if p != 281479271743489 { return 9 } 50 if (p & 0xFFFF) != 1 { return 19 } 51 if (p >> 48) != 1 { return 29 } 52 53 // Test 10: A high-bit-set value: 0x8000000000000000 = INT64_MIN. 54 // We use a near-min that NishiLang can express as a literal. 55 let m: i64 = -1000000000000 56 if m != -1000000000000 { return 10 } 57 58 return 0 59}