]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/lower_128bit_test.rs
e8c8412db80efdae0d258ea93fc5c3ae728b7260
[rust.git] / src / test / mir-opt / lower_128bit_test.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // asmjs can't even pass i128 as arguments or return values, so ignore it.
12 // this will hopefully be fixed by the LLVM 5 upgrade (#43370)
13 // ignore-asmjs
14 // ignore-emscripten
15
16 // compile-flags: -Z lower_128bit_ops -C debug_assertions=no
17
18 #![feature(i128_type)]
19
20 fn test_signed(mut x: i128) -> i128 {
21     x += 1;
22     x -= 2;
23     x *= 3;
24     x /= 4;
25     x %= 5;
26     x <<= 6;
27     x >>= 7;
28     x
29 }
30
31 fn test_unsigned(mut x: u128) -> u128 {
32     x += 1;
33     x -= 2;
34     x *= 3;
35     x /= 4;
36     x %= 5;
37     x <<= 6;
38     x >>= 7;
39     x
40 }
41
42 fn main() {
43     assert_eq!(test_signed(-222), -1);
44     assert_eq!(test_unsigned(200), 2);
45 }
46
47 // END RUST SOURCE
48
49 // START rustc.test_signed.Lower128Bit.after.mir
50 //     _1 = const compiler_builtins::int::addsub::rust_i128_add(_1, const 1i128) -> bb7;
51 //     ...
52 //     _1 = const compiler_builtins::int::sdiv::rust_i128_div(_1, const 4i128) -> bb8;
53 //     ...
54 //     _1 = const compiler_builtins::int::sdiv::rust_i128_rem(_1, const 5i128) -> bb11;
55 //     ...
56 //     _1 = const compiler_builtins::int::mul::rust_i128_mul(_1, const 3i128) -> bb5;
57 //     ...
58 //     _1 = const compiler_builtins::int::addsub::rust_i128_sub(_1, const 2i128) -> bb6;
59 //     ...
60 //     _11 = const 7i32 as u32 (Misc);
61 //     _1 = const compiler_builtins::int::shift::rust_i128_shr(_1, move _11) -> bb9;
62 //     ...
63 //     _12 = const 6i32 as u32 (Misc);
64 //     _1 = const compiler_builtins::int::shift::rust_i128_shl(_1, move _12) -> bb10;
65 // END rustc.test_signed.Lower128Bit.after.mir
66
67 // START rustc.test_unsigned.Lower128Bit.after.mir
68 //     _1 = const compiler_builtins::int::addsub::rust_u128_add(_1, const 1u128) -> bb5;
69 //     ...
70 //     _1 = const compiler_builtins::int::udiv::rust_u128_div(_1, const 4u128) -> bb6;
71 //     ...
72 //     _1 = const compiler_builtins::int::udiv::rust_u128_rem(_1, const 5u128) -> bb9;
73 //     ...
74 //     _1 = const compiler_builtins::int::mul::rust_u128_mul(_1, const 3u128) -> bb3;
75 //     ...
76 //     _1 = const compiler_builtins::int::addsub::rust_u128_sub(_1, const 2u128) -> bb4;
77 //     ...
78 //     _5 = const 7i32 as u32 (Misc);
79 //     _1 = const compiler_builtins::int::shift::rust_u128_shr(_1, move _5) -> bb7;
80 //     ...
81 //     _6 = const 6i32 as u32 (Misc);
82 //     _1 = const compiler_builtins::int::shift::rust_u128_shl(_1, move _6) -> bb8;
83 // END rustc.test_unsigned.Lower128Bit.after.mir