Files
aji/tests/conformance/phase0/accept/all_integer_widths.air
T
dev 1f5008bb37 interp: deterministic interpreter, aji run, run tests (P0-11, P0-12)
- src/interp/machine.zig: format-0 interpreter on the air64 target;
  checked/wrapping arithmetic, shifts, casts, aggregates, calls with a
  1024-frame limit, traps as records with T0xxx codes
- aji run: prints one JSON run record; exit code 4 on trap
- conformance runner: `expect: run` with `result:`/`trap:`, every run
  executed twice and compared byte-for-byte; header keys must be single
  lowercase words
- Phase 0 corpus: 3 accept, 19 reject, 15 run tests (41 total)
2026-10-04 12:28:27 +03:00

213 lines
4.2 KiB
LLVM

; Checked and wrapping arithmetic on every integer type.
; expect: accept
; phase: 0
; spec: docs/spec/07a-air-instructions.md
module test.all_integer_widths
air 0
lang 0.1
features []
fn @f_u8(%a: u8, %b: u8) -> u8
effects []
entry:
%s = add.checked.u8 %a, %b
%d = sub.wrap.u8 %s, %b
%m = mul.wrap.u8 %d, %a
%q = div.checked.u8 %m, %b
%r = rem.checked.u8 %q, %b
%x = xor.u8 %r, %a
%l = shl.u8 %x, %b
%c = lt.u8 %l, %a
cbr %c, @yes(), @no()
yes:
ret %l
no:
ret %a
fn @f_u16(%a: u16, %b: u16) -> u16
effects []
entry:
%s = add.checked.u16 %a, %b
%d = sub.wrap.u16 %s, %b
%m = mul.wrap.u16 %d, %a
%q = div.checked.u16 %m, %b
%r = rem.checked.u16 %q, %b
%x = xor.u16 %r, %a
%l = shl.u16 %x, %b
%c = lt.u16 %l, %a
cbr %c, @yes(), @no()
yes:
ret %l
no:
ret %a
fn @f_u32(%a: u32, %b: u32) -> u32
effects []
entry:
%s = add.checked.u32 %a, %b
%d = sub.wrap.u32 %s, %b
%m = mul.wrap.u32 %d, %a
%q = div.checked.u32 %m, %b
%r = rem.checked.u32 %q, %b
%x = xor.u32 %r, %a
%l = shl.u32 %x, %b
%c = lt.u32 %l, %a
cbr %c, @yes(), @no()
yes:
ret %l
no:
ret %a
fn @f_u64(%a: u64, %b: u64) -> u64
effects []
entry:
%s = add.checked.u64 %a, %b
%d = sub.wrap.u64 %s, %b
%m = mul.wrap.u64 %d, %a
%q = div.checked.u64 %m, %b
%r = rem.checked.u64 %q, %b
%x = xor.u64 %r, %a
%l = shl.u64 %x, %b
%c = lt.u64 %l, %a
cbr %c, @yes(), @no()
yes:
ret %l
no:
ret %a
fn @f_u128(%a: u128, %b: u128) -> u128
effects []
entry:
%s = add.checked.u128 %a, %b
%d = sub.wrap.u128 %s, %b
%m = mul.wrap.u128 %d, %a
%q = div.checked.u128 %m, %b
%r = rem.checked.u128 %q, %b
%x = xor.u128 %r, %a
%l = shl.u128 %x, %b
%c = lt.u128 %l, %a
cbr %c, @yes(), @no()
yes:
ret %l
no:
ret %a
fn @f_usize(%a: usize, %b: usize) -> usize
effects []
entry:
%s = add.checked.usize %a, %b
%d = sub.wrap.usize %s, %b
%m = mul.wrap.usize %d, %a
%q = div.checked.usize %m, %b
%r = rem.checked.usize %q, %b
%x = xor.usize %r, %a
%l = shl.usize %x, %b
%c = lt.usize %l, %a
cbr %c, @yes(), @no()
yes:
ret %l
no:
ret %a
fn @f_i8(%a: i8, %b: i8) -> i8
effects []
entry:
%s = add.checked.i8 %a, %b
%d = sub.wrap.i8 %s, %b
%m = mul.wrap.i8 %d, %a
%q = div.checked.i8 %m, %b
%r = rem.checked.i8 %q, %b
%x = xor.i8 %r, %a
%l = shl.i8 %x, %b
%c = lt.i8 %l, %a
cbr %c, @yes(), @no()
yes:
ret %l
no:
ret %a
fn @f_i16(%a: i16, %b: i16) -> i16
effects []
entry:
%s = add.checked.i16 %a, %b
%d = sub.wrap.i16 %s, %b
%m = mul.wrap.i16 %d, %a
%q = div.checked.i16 %m, %b
%r = rem.checked.i16 %q, %b
%x = xor.i16 %r, %a
%l = shl.i16 %x, %b
%c = lt.i16 %l, %a
cbr %c, @yes(), @no()
yes:
ret %l
no:
ret %a
fn @f_i32(%a: i32, %b: i32) -> i32
effects []
entry:
%s = add.checked.i32 %a, %b
%d = sub.wrap.i32 %s, %b
%m = mul.wrap.i32 %d, %a
%q = div.checked.i32 %m, %b
%r = rem.checked.i32 %q, %b
%x = xor.i32 %r, %a
%l = shl.i32 %x, %b
%c = lt.i32 %l, %a
cbr %c, @yes(), @no()
yes:
ret %l
no:
ret %a
fn @f_i64(%a: i64, %b: i64) -> i64
effects []
entry:
%s = add.checked.i64 %a, %b
%d = sub.wrap.i64 %s, %b
%m = mul.wrap.i64 %d, %a
%q = div.checked.i64 %m, %b
%r = rem.checked.i64 %q, %b
%x = xor.i64 %r, %a
%l = shl.i64 %x, %b
%c = lt.i64 %l, %a
cbr %c, @yes(), @no()
yes:
ret %l
no:
ret %a
fn @f_i128(%a: i128, %b: i128) -> i128
effects []
entry:
%s = add.checked.i128 %a, %b
%d = sub.wrap.i128 %s, %b
%m = mul.wrap.i128 %d, %a
%q = div.checked.i128 %m, %b
%r = rem.checked.i128 %q, %b
%x = xor.i128 %r, %a
%l = shl.i128 %x, %b
%c = lt.i128 %l, %a
cbr %c, @yes(), @no()
yes:
ret %l
no:
ret %a
fn @f_isize(%a: isize, %b: isize) -> isize
effects []
entry:
%s = add.checked.isize %a, %b
%d = sub.wrap.isize %s, %b
%m = mul.wrap.isize %d, %a
%q = div.checked.isize %m, %b
%r = rem.checked.isize %q, %b
%x = xor.isize %r, %a
%l = shl.isize %x, %b
%c = lt.isize %l, %a
cbr %c, @yes(), @no()
yes:
ret %l
no:
ret %a