interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / tests / compiler / progs / shifts.osc

15 lines · 667 bytes Raw Blame History
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.
8fn shl_i32(x: i32, n: u8) -> i32 { return x << n; }
9fn shr_i8(x: i8, n: i64) -> i8 { return x >> n; }
10fn mix_u64(x: u64, n: i16) -> u64 { return (x << n) ^ (x >> 3) ^ (1 << 63); }
11fn 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}