lib.rs 2.8 KB

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