compiler-builtins-zynq/src/lib.rs

89 lines
1.8 KiB
Rust
Raw Normal View History

2016-08-08 04:58:05 +08:00
#![allow(unused_features)]
2016-08-13 16:51:54 +08:00
#![no_std]
2016-08-08 04:58:05 +08:00
#![feature(asm)]
#![feature(core_intrinsics)]
#![feature(naked_functions)]
// TODO(rust-lang/rust#35021) uncomment when that PR lands
// #![feature(rustc_builtins)]
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-08-11 08:12:37 +08:00
#[cfg(test)]
#[macro_use]
extern crate quickcheck;
2016-08-08 04:58:05 +08:00
#[cfg(target_arch = "arm")]
pub mod arm;
2016-08-13 16:51:54 +08:00
pub mod udiv;
pub mod mul;
pub mod shift;
2016-08-11 12:28:15 +08:00
/// Trait for some basic operations on integers
trait Int {
2016-08-13 16:51:54 +08:00
fn bits() -> u32;
2016-08-11 12:28:15 +08:00
}
// TODO: Once i128/u128 support lands, we'll want to add impls for those as well
impl Int for u32 {
2016-08-13 16:51:54 +08:00
fn bits() -> u32 {
32
}
2016-08-11 12:28:15 +08:00
}
impl Int for i32 {
2016-08-13 16:51:54 +08:00
fn bits() -> u32 {
32
}
2016-08-11 12:28:15 +08:00
}
impl Int for u64 {
2016-08-13 16:51:54 +08:00
fn bits() -> u32 {
64
}
2016-08-11 12:28:15 +08:00
}
impl Int for i64 {
2016-08-13 16:51:54 +08:00
fn bits() -> u32 {
64
}
2016-08-11 12:28:15 +08:00
}
/// Trait to convert an integer to/from smaller parts
trait LargeInt {
type LowHalf;
type HighHalf;
fn low(self) -> Self::LowHalf;
fn high(self) -> Self::HighHalf;
fn from_parts(low: Self::LowHalf, high: Self::HighHalf) -> Self;
}
// TODO: Once i128/u128 support lands, we'll want to add impls for those as well
impl LargeInt for u64 {
type LowHalf = u32;
type HighHalf = u32;
fn low(self) -> u32 {
self as u32
}
fn high(self) -> u32 {
(self >> 32) as u32
}
fn from_parts(low: u32, high: u32) -> u64 {
low as u64 | ((high as u64) << 32)
}
}
impl LargeInt for i64 {
type LowHalf = u32;
type HighHalf = i32;
fn low(self) -> u32 {
self as u32
}
fn high(self) -> i32 {
(self >> 32) as i32
}
fn from_parts(low: u32, high: i32) -> i64 {
low as i64 | ((high as i64) << 32)
}
}