parse_fp_op_test.nx source
↩ module page · 56 lines · 1822 B
1// parse_fp_op_test.nx -- verify fp_op_for_int op promotion.
2//
3// fp_op_for_int is the helper parse.nx uses to promote integer
4// opcodes (OP_ADD/SUB/MUL/DIV_S) to their F-extension counterparts
5// when either operand is fp-typed. Guards against silent miscompiles
6// that would fire if the table got a new integer op and the promoter
7// didn't update.
8
9import "syscalls.nx"
10import "types.nx"
11import "parse.nx"
12
13func main() -> i64 {
14 // Each of the four arithmetic ops promotes to its fp counterpart.
15 if fp_op_for_int(OP_ADD) != OP_FADD {
16 return __syscall(93, 10, 0, 0, 0, 0, 0)
17 }
18 if fp_op_for_int(OP_SUB) != OP_FSUB {
19 return __syscall(93, 11, 0, 0, 0, 0, 0)
20 }
21 if fp_op_for_int(OP_MUL) != OP_FMUL {
22 return __syscall(93, 12, 0, 0, 0, 0, 0)
23 }
24 if fp_op_for_int(OP_DIV_S) != OP_FDIV {
25 return __syscall(93, 13, 0, 0, 0, 0, 0)
26 }
27
28 // Non-arithmetic ops pass through unchanged.
29 if fp_op_for_int(OP_AND) != OP_AND {
30 return __syscall(93, 20, 0, 0, 0, 0, 0)
31 }
32 if fp_op_for_int(OP_OR) != OP_OR {
33 return __syscall(93, 21, 0, 0, 0, 0, 0)
34 }
35 if fp_op_for_int(OP_XOR) != OP_XOR {
36 return __syscall(93, 22, 0, 0, 0, 0, 0)
37 }
38 if fp_op_for_int(OP_SHL) != OP_SHL {
39 return __syscall(93, 23, 0, 0, 0, 0, 0)
40 }
41 if fp_op_for_int(OP_EQ) != OP_EQ {
42 return __syscall(93, 24, 0, 0, 0, 0, 0)
43 }
44
45 // Remainder doesn't promote (IEEE 754 has no standard 'frem').
46 if fp_op_for_int(OP_REM_S) != OP_REM_S {
47 return __syscall(93, 30, 0, 0, 0, 0, 0)
48 }
49
50 // Unsigned-div also stays integer (fp has no 'unsigned' form).
51 if fp_op_for_int(OP_DIV_U) != OP_DIV_U {
52 return __syscall(93, 31, 0, 0, 0, 0, 0)
53 }
54
55 return 0
56}