2016-10-11 08:05:21 +08:00
|
|
|
#![cfg_attr(not(stage0), deny(warnings))]
|
2016-10-11 05:45:24 +08:00
|
|
|
#![cfg_attr(not(test), no_std)]
|
2016-12-12 05:18:43 +08:00
|
|
|
#![cfg_attr(feature = "compiler-builtins", compiler_builtins)]
|
2016-10-11 05:43:38 +08:00
|
|
|
#![crate_name = "compiler_builtins"]
|
|
|
|
#![crate_type = "rlib"]
|
2016-10-11 08:05:21 +08:00
|
|
|
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
|
|
|
|
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
|
|
|
html_root_url = "https://doc.rust-lang.org/nightly/",
|
|
|
|
html_playground_url = "https://play.rust-lang.org/",
|
|
|
|
test(attr(deny(warnings))))]
|
2016-08-08 04:58:05 +08:00
|
|
|
#![feature(asm)]
|
2016-10-11 05:45:24 +08:00
|
|
|
#![feature(compiler_builtins)]
|
2016-08-16 10:08:04 +08:00
|
|
|
#![feature(core_intrinsics)]
|
2016-08-08 04:58:05 +08:00
|
|
|
#![feature(naked_functions)]
|
2016-10-11 08:05:21 +08:00
|
|
|
#![feature(staged_api)]
|
2017-01-04 08:42:57 +08:00
|
|
|
#![feature(i128_type)]
|
2017-01-04 09:42:03 +08:00
|
|
|
#![feature(repr_simd)]
|
|
|
|
#![feature(abi_unadjusted)]
|
|
|
|
#![allow(unused_features)]
|
2016-08-14 01:16:52 +08:00
|
|
|
#![no_builtins]
|
2016-10-11 08:45:34 +08:00
|
|
|
#![unstable(feature = "compiler_builtins_lib",
|
2016-10-11 08:05:21 +08:00
|
|
|
reason = "Compiler builtins. Will never become stable.",
|
|
|
|
issue = "0")]
|
2016-08-08 04:58:05 +08:00
|
|
|
|
2016-08-13 16:51:54 +08:00
|
|
|
// We disable #[no_mangle] for tests so that we can verify the test results
|
|
|
|
// against the native compiler-rt implementations of the builtins.
|
|
|
|
|
2016-09-27 04:55:11 +08:00
|
|
|
// NOTE cfg(all(feature = "c", ..)) indicate that compiler-rt provides an arch optimized
|
|
|
|
// implementation of that intrinsic and we'll prefer to use that
|
|
|
|
|
2016-10-08 06:48:37 +08:00
|
|
|
// TODO(rust-lang/rust#37029) use e.g. checked_div(_).unwrap_or_else(|| abort())
|
2016-10-07 23:17:44 +08:00
|
|
|
macro_rules! udiv {
|
|
|
|
($a:expr, $b:expr) => {
|
|
|
|
unsafe {
|
|
|
|
let a = $a;
|
|
|
|
let b = $b;
|
|
|
|
|
|
|
|
if b == 0 {
|
2016-10-08 06:48:37 +08:00
|
|
|
::core::intrinsics::abort()
|
2016-10-07 23:17:44 +08:00
|
|
|
} else {
|
2016-10-08 06:48:37 +08:00
|
|
|
::core::intrinsics::unchecked_div(a, b)
|
2016-10-07 23:17:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! sdiv {
|
|
|
|
($sty:ident, $a:expr, $b:expr) => {
|
|
|
|
unsafe {
|
|
|
|
let a = $a;
|
|
|
|
let b = $b;
|
|
|
|
|
|
|
|
if b == 0 || (b == -1 && a == $sty::min_value()) {
|
2016-10-08 06:48:37 +08:00
|
|
|
::core::intrinsics::abort()
|
2016-10-07 23:17:44 +08:00
|
|
|
} else {
|
2016-10-08 06:48:37 +08:00
|
|
|
::core::intrinsics::unchecked_div(a, b)
|
2016-10-07 23:17:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! urem {
|
|
|
|
($a:expr, $b:expr) => {
|
|
|
|
unsafe {
|
|
|
|
let a = $a;
|
|
|
|
let b = $b;
|
|
|
|
|
|
|
|
if b == 0 {
|
2016-10-08 06:48:37 +08:00
|
|
|
::core::intrinsics::abort()
|
2016-10-07 23:17:44 +08:00
|
|
|
} else {
|
2016-10-08 06:48:37 +08:00
|
|
|
::core::intrinsics::unchecked_rem(a, b)
|
2016-10-07 23:17:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! srem {
|
|
|
|
($sty:ty, $a:expr, $b:expr) => {
|
|
|
|
unsafe {
|
|
|
|
let a = $a;
|
|
|
|
let b = $b;
|
|
|
|
|
|
|
|
if b == 0 || (b == -1 && a == $sty::min_value()) {
|
2016-10-08 06:48:37 +08:00
|
|
|
::core::intrinsics::abort()
|
2016-10-07 23:17:44 +08:00
|
|
|
} else {
|
2016-10-08 06:48:37 +08:00
|
|
|
::core::intrinsics::unchecked_rem(a, b)
|
2016-10-07 23:17:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-05 22:08:56 +08:00
|
|
|
// Hack for LLVM expectations for ABI on windows
|
|
|
|
#[cfg(all(windows, target_pointer_width="64"))]
|
|
|
|
#[repr(simd)]
|
|
|
|
pub struct U64x2(u64, u64);
|
|
|
|
|
|
|
|
#[cfg(all(windows, target_pointer_width="64"))]
|
|
|
|
fn conv(i: u128) -> U64x2 {
|
|
|
|
use int::LargeInt;
|
|
|
|
U64x2(i.low(), i.high())
|
|
|
|
}
|
|
|
|
|
2017-01-05 22:23:45 +08:00
|
|
|
#[cfg(all(windows, target_pointer_width="64"))]
|
|
|
|
fn sconv(i: i128) -> U64x2 {
|
|
|
|
use int::LargeInt;
|
|
|
|
let j = i as u128;
|
|
|
|
U64x2(j.low(), j.high())
|
|
|
|
}
|
|
|
|
|
2016-08-11 08:12:37 +08:00
|
|
|
#[cfg(test)]
|
2017-01-27 05:17:23 +08:00
|
|
|
#[cfg_attr(target_arch = "arm", macro_use)]
|
2016-08-11 08:12:37 +08:00
|
|
|
extern crate quickcheck;
|
2016-08-08 04:58:05 +08:00
|
|
|
|
2016-08-14 05:58:44 +08:00
|
|
|
#[cfg(test)]
|
|
|
|
extern crate core;
|
|
|
|
|
2016-09-17 04:53:14 +08:00
|
|
|
#[cfg(test)]
|
|
|
|
extern crate gcc_s;
|
|
|
|
|
2016-09-27 13:22:10 +08:00
|
|
|
#[cfg(test)]
|
|
|
|
extern crate compiler_rt;
|
|
|
|
|
2016-09-22 10:38:06 +08:00
|
|
|
#[cfg(test)]
|
|
|
|
extern crate rand;
|
|
|
|
|
2016-09-27 13:22:10 +08:00
|
|
|
#[cfg(test)]
|
|
|
|
#[macro_use]
|
|
|
|
mod qc;
|
|
|
|
|
2016-08-18 04:50:24 +08:00
|
|
|
pub mod int;
|
2016-08-18 04:51:37 +08:00
|
|
|
pub mod float;
|
2016-08-18 04:50:24 +08:00
|
|
|
|
2016-12-18 12:01:47 +08:00
|
|
|
#[cfg(feature = "mem")]
|
|
|
|
pub mod mem;
|
|
|
|
|
2016-08-08 04:58:05 +08:00
|
|
|
#[cfg(target_arch = "arm")]
|
|
|
|
pub mod arm;
|
|
|
|
|
2016-08-17 06:46:46 +08:00
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
pub mod x86_64;
|