omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / tests / compiler / progs / shifts.osc
| 1 | // entry: shl_i32 shr_i8 mix_u64 rot_u32 |
| 2 | // expect-run: shl_i32 1 30 -> 1073741824 |
| 3 | // expect-run: shl_i32 1 31 -> trap=OVERFLOW |
| 4 | // expect-run: shl_i32 1 32 -> trap=SHIFT |
| 5 | // expect-run: shr_i8 18446744073709551488 7 -> 18446744073709551615 |
| 6 | // shifts with amounts of any integer type; amount >= width traps SHIFT, |
| 7 | // signed << that loses bits traps OVERFLOW. |
| 8 | fn shl_i32(x: i32, n: u8) -> i32 { return x << n; } |
| 9 | fn shr_i8(x: i8, n: i64) -> i8 { return x >> n; } |
| 10 | fn mix_u64(x: u64, n: i16) -> u64 { return (x << n) ^ (x >> 3) ^ (1 << 63); } |
| 11 | fn rot_u32(x: u32, n: u32) -> u32 { |
| 12 | let k: u32 = n % 32; |
| 13 | if k == 0 { return x; } |
| 14 | return (x << k) | (x >> (32 - k)); |
| 15 | } |