lib.rs 2.8 KB

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