lib.rs 820 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #![allow(unused_features)]
  2. #![cfg_attr(not(test), no_std)]
  3. #![feature(asm)]
  4. #![feature(core_intrinsics)]
  5. #![feature(naked_functions)]
  6. // TODO(rust-lang/rust#35021) uncomment when that PR lands
  7. // #![feature(rustc_builtins)]
  8. #[cfg(test)]
  9. extern crate core;
  10. use core::mem;
  11. #[cfg(target_arch = "arm")]
  12. pub mod arm;
  13. #[cfg(test)]
  14. mod test;
  15. const CHAR_BITS: usize = 8;
  16. macro_rules! absv_i2 {
  17. ($intrinsic:ident : $ty:ty) => {
  18. #[no_mangle]
  19. pub extern "C" fn $intrinsic(x: $ty) -> $ty {
  20. let n = mem::size_of::<$ty>() * CHAR_BITS;
  21. if x == 1 << (n - 1) {
  22. panic!();
  23. }
  24. let y = x >> (n - 1);
  25. (x ^ y) - y
  26. }
  27. }
  28. }
  29. absv_i2!(__absvsi2: i32);
  30. absv_i2!(__absvdi2: i64);
  31. // TODO(rust-lang/35118)?
  32. // absv_i2!(__absvti2, i128);