]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/i128-ffi.rs
rustdoc: Hide `self: Box<Self>` in list of deref methods
[rust.git] / src / test / run-pass / i128-ffi.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 // MSVC doesn't support 128 bit integers, and other Windows
12 // C compilers have very inconsistent views on how the ABI
13 // should look like.
14
15 // ignore-windows
16
17 // Ignore 32 bit targets:
18 // ignore-x86, ignore-arm
19
20 // ignore-emscripten
21
22 #![feature(i128_type)]
23
24 #[link(name = "rust_test_helpers", kind = "static")]
25 extern "C" {
26     fn identity(f: u128) -> u128;
27     fn square(f: i128) -> i128;
28     fn sub(f: i128, f: i128) -> i128;
29 }
30
31 fn main() {
32     unsafe {
33         let a = 0x734C_C2F2_A521;
34         let b = 0x33EE_0E2A_54E2_59DA_A0E7_8E41;
35         let b_out = identity(b);
36         assert_eq!(b, b_out);
37         let a_square = square(a);
38         assert_eq!(b, a_square as u128);
39         let k = 0x1234_5678_9ABC_DEFF_EDCB_A987_6543_210;
40         let k_d = 0x2468_ACF1_3579_BDFF_DB97_530E_CA86_420;
41         let k_out = sub(k_d, k);
42         assert_eq!(k, k_out);
43     }
44 }