lib.rs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #![crate_name = "compiler_builtins"]
  2. #![crate_type = "rlib"]
  3. #![feature(asm)]
  4. #![feature(core_intrinsics)]
  5. #![feature(linkage)]
  6. #![feature(naked_functions)]
  7. #![cfg_attr(not(test), no_std)]
  8. #![no_builtins]
  9. // TODO(rust-lang/rust#35021) uncomment when that PR lands
  10. // #![feature(rustc_builtins)]
  11. // We disable #[no_mangle] for tests so that we can verify the test results
  12. // against the native compiler-rt implementations of the builtins.
  13. // NOTE cfg(all(feature = "c", ..)) indicate that compiler-rt provides an arch optimized
  14. // implementation of that intrinsic and we'll prefer to use that
  15. // TODO(rust-lang/rust#37029) use e.g. checked_div(_).unwrap_or_else(|| abort())
  16. macro_rules! udiv {
  17. ($a:expr, $b:expr) => {
  18. unsafe {
  19. let a = $a;
  20. let b = $b;
  21. if b == 0 {
  22. ::core::intrinsics::abort()
  23. } else {
  24. ::core::intrinsics::unchecked_div(a, b)
  25. }
  26. }
  27. }
  28. }
  29. macro_rules! sdiv {
  30. ($sty:ident, $a:expr, $b:expr) => {
  31. unsafe {
  32. let a = $a;
  33. let b = $b;
  34. if b == 0 || (b == -1 && a == $sty::min_value()) {
  35. ::core::intrinsics::abort()
  36. } else {
  37. ::core::intrinsics::unchecked_div(a, b)
  38. }
  39. }
  40. }
  41. }
  42. macro_rules! urem {
  43. ($a:expr, $b:expr) => {
  44. unsafe {
  45. let a = $a;
  46. let b = $b;
  47. if b == 0 {
  48. ::core::intrinsics::abort()
  49. } else {
  50. ::core::intrinsics::unchecked_rem(a, b)
  51. }
  52. }
  53. }
  54. }
  55. macro_rules! srem {
  56. ($sty:ty, $a:expr, $b:expr) => {
  57. unsafe {
  58. let a = $a;
  59. let b = $b;
  60. if b == 0 || (b == -1 && a == $sty::min_value()) {
  61. ::core::intrinsics::abort()
  62. } else {
  63. ::core::intrinsics::unchecked_rem(a, b)
  64. }
  65. }
  66. }
  67. }
  68. #[cfg(test)]
  69. #[macro_use]
  70. extern crate quickcheck;
  71. #[cfg(test)]
  72. extern crate core;
  73. #[cfg(test)]
  74. extern crate gcc_s;
  75. #[cfg(test)]
  76. extern crate compiler_rt;
  77. #[cfg(test)]
  78. extern crate rand;
  79. #[cfg(feature = "weak")]
  80. extern crate rlibc;
  81. #[cfg(test)]
  82. #[macro_use]
  83. mod qc;
  84. pub mod int;
  85. pub mod float;
  86. #[cfg(target_arch = "arm")]
  87. pub mod arm;
  88. #[cfg(target_arch = "x86_64")]
  89. pub mod x86_64;