| 1 |
macro_rules! force_eval { |
| 2 |
($e:expr) => { |
| 3 |
unsafe { ::core::ptr::read_volatile(&$e) } |
| 4 |
}; |
| 5 |
} |
| 6 |
|
| 7 |
#[cfg(not(debug_assertions))] |
| 8 |
macro_rules! i { |
| 9 |
($array:expr, $index:expr) => { |
| 10 |
unsafe { *$array.get_unchecked($index) } |
| 11 |
}; |
| 12 |
($array:expr, $index:expr, = , $rhs:expr) => { |
| 13 |
unsafe { |
| 14 |
*$array.get_unchecked_mut($index) = $rhs; |
| 15 |
} |
| 16 |
}; |
| 17 |
($array:expr, $index:expr, += , $rhs:expr) => { |
| 18 |
unsafe { |
| 19 |
*$array.get_unchecked_mut($index) += $rhs; |
| 20 |
} |
| 21 |
}; |
| 22 |
($array:expr, $index:expr, -= , $rhs:expr) => { |
| 23 |
unsafe { |
| 24 |
*$array.get_unchecked_mut($index) -= $rhs; |
| 25 |
} |
| 26 |
}; |
| 27 |
($array:expr, $index:expr, &= , $rhs:expr) => { |
| 28 |
unsafe { |
| 29 |
*$array.get_unchecked_mut($index) &= $rhs; |
| 30 |
} |
| 31 |
}; |
| 32 |
($array:expr, $index:expr, == , $rhs:expr) => { |
| 33 |
unsafe { *$array.get_unchecked_mut($index) == $rhs } |
| 34 |
}; |
| 35 |
} |
| 36 |
|
| 37 |
#[cfg(debug_assertions)] |
| 38 |
macro_rules! i { |
| 39 |
($array:expr, $index:expr) => { |
| 40 |
*$array.get($index).unwrap() |
| 41 |
}; |
| 42 |
($array:expr, $index:expr, = , $rhs:expr) => { |
| 43 |
*$array.get_mut($index).unwrap() = $rhs; |
| 44 |
}; |
| 45 |
($array:expr, $index:expr, -= , $rhs:expr) => { |
| 46 |
*$array.get_mut($index).unwrap() -= $rhs; |
| 47 |
}; |
| 48 |
($array:expr, $index:expr, += , $rhs:expr) => { |
| 49 |
*$array.get_mut($index).unwrap() += $rhs; |
| 50 |
}; |
| 51 |
($array:expr, $index:expr, &= , $rhs:expr) => { |
| 52 |
*$array.get_mut($index).unwrap() &= $rhs; |
| 53 |
}; |
| 54 |
($array:expr, $index:expr, == , $rhs:expr) => { |
| 55 |
*$array.get_mut($index).unwrap() == $rhs |
| 56 |
}; |
| 57 |
} |
| 58 |
|
| 59 |
// Temporary macro to avoid panic codegen for division (in debug mode too). At |
| 60 |
// the time of this writing this is only used in a few places, and once |
| 61 |
// rust-lang/rust#72751 is fixed then this macro will no longer be necessary and |
| 62 |
// the native `/` operator can be used and panics won't be codegen'd. |
| 63 |
#[cfg(any(debug_assertions, not(feature = "unstable")))] |
| 64 |
macro_rules! div { |
| 65 |
($a:expr, $b:expr) => { |
| 66 |
$a / $b |
| 67 |
}; |
| 68 |
} |
| 69 |
|
| 70 |
#[cfg(all(not(debug_assertions), feature = "unstable"))] |
| 71 |
macro_rules! div { |
| 72 |
($a:expr, $b:expr) => { |
| 73 |
unsafe { core::intrinsics::unchecked_div($a, $b) } |
| 74 |
}; |
| 75 |
} |
| 76 |
|
| 77 |
macro_rules! llvm_intrinsically_optimized { |
| 78 |
(#[cfg($($clause:tt)*)] $e:expr) => { |
| 79 |
#[cfg(all(feature = "unstable", $($clause)*))] |
| 80 |
{ |
| 81 |
if true { // thwart the dead code lint |
| 82 |
$e |
| 83 |
} |
| 84 |
} |
| 85 |
}; |
| 86 |
} |
| 87 |
|
| 88 |
// Public modules |
| 89 |
mod acos; |
| 90 |
mod acosf; |
| 91 |
mod acosh; |
| 92 |
mod acoshf; |
| 93 |
mod asin; |
| 94 |
mod asinf; |
| 95 |
mod asinh; |
| 96 |
mod asinhf; |
| 97 |
mod atan; |
| 98 |
mod atan2; |
| 99 |
mod atan2f; |
| 100 |
mod atanf; |
| 101 |
mod atanh; |
| 102 |
mod atanhf; |
| 103 |
mod cbrt; |
| 104 |
mod cbrtf; |
| 105 |
mod ceil; |
| 106 |
mod ceilf; |
| 107 |
mod copysign; |
| 108 |
mod copysignf; |
| 109 |
mod cos; |
| 110 |
mod cosf; |
| 111 |
mod cosh; |
| 112 |
mod coshf; |
| 113 |
mod erf; |
| 114 |
mod erff; |
| 115 |
mod exp; |
| 116 |
mod exp10; |
| 117 |
mod exp10f; |
| 118 |
mod exp2; |
| 119 |
mod exp2f; |
| 120 |
mod expf; |
| 121 |
mod expm1; |
| 122 |
mod expm1f; |
| 123 |
mod fabs; |
| 124 |
mod fabsf; |
| 125 |
mod fdim; |
| 126 |
mod fdimf; |
| 127 |
mod floor; |
| 128 |
mod floorf; |
| 129 |
mod fma; |
| 130 |
mod fmaf; |
| 131 |
mod fmax; |
| 132 |
mod fmaxf; |
| 133 |
mod fmin; |
| 134 |
mod fminf; |
| 135 |
mod fmod; |
| 136 |
mod fmodf; |
| 137 |
mod frexp; |
| 138 |
mod frexpf; |
| 139 |
mod hypot; |
| 140 |
mod hypotf; |
| 141 |
mod ilogb; |
| 142 |
mod ilogbf; |
| 143 |
mod j0; |
| 144 |
mod j0f; |
| 145 |
mod j1; |
| 146 |
mod j1f; |
| 147 |
mod jn; |
| 148 |
mod jnf; |
| 149 |
mod ldexp; |
| 150 |
mod ldexpf; |
| 151 |
mod lgamma; |
| 152 |
mod lgamma_r; |
| 153 |
mod lgammaf; |
| 154 |
mod lgammaf_r; |
| 155 |
mod log; |
| 156 |
mod log10; |
| 157 |
mod log10f; |
| 158 |
mod log1p; |
| 159 |
mod log1pf; |
| 160 |
mod log2; |
| 161 |
mod log2f; |
| 162 |
mod logf; |
| 163 |
mod modf; |
| 164 |
mod modff; |
| 165 |
mod nextafter; |
| 166 |
mod nextafterf; |
| 167 |
mod pow; |
| 168 |
mod powf; |
| 169 |
mod remainder; |
| 170 |
mod remainderf; |
| 171 |
mod remquo; |
| 172 |
mod remquof; |
| 173 |
mod rint; |
| 174 |
mod rintf; |
| 175 |
mod round; |
| 176 |
mod roundf; |
| 177 |
mod scalbn; |
| 178 |
mod scalbnf; |
| 179 |
mod sin; |
| 180 |
mod sincos; |
| 181 |
mod sincosf; |
| 182 |
mod sinf; |
| 183 |
mod sinh; |
| 184 |
mod sinhf; |
| 185 |
mod sqrt; |
| 186 |
mod sqrtf; |
| 187 |
mod tan; |
| 188 |
mod tanf; |
| 189 |
mod tanh; |
| 190 |
mod tanhf; |
| 191 |
mod tgamma; |
| 192 |
mod tgammaf; |
| 193 |
mod trunc; |
| 194 |
mod truncf; |
| 195 |
|
| 196 |
// Use separated imports instead of {}-grouped imports for easier merging. |
| 197 |
pub use self::acos::acos; |
| 198 |
pub use self::acosf::acosf; |
| 199 |
pub use self::acosh::acosh; |
| 200 |
pub use self::acoshf::acoshf; |
| 201 |
pub use self::asin::asin; |
| 202 |
pub use self::asinf::asinf; |
| 203 |
pub use self::asinh::asinh; |
| 204 |
pub use self::asinhf::asinhf; |
| 205 |
pub use self::atan::atan; |
| 206 |
pub use self::atan2::atan2; |
| 207 |
pub use self::atan2f::atan2f; |
| 208 |
pub use self::atanf::atanf; |
| 209 |
pub use self::atanh::atanh; |
| 210 |
pub use self::atanhf::atanhf; |
| 211 |
pub use self::cbrt::cbrt; |
| 212 |
pub use self::cbrtf::cbrtf; |
| 213 |
pub use self::ceil::ceil; |
| 214 |
pub use self::ceilf::ceilf; |
| 215 |
pub use self::copysign::copysign; |
| 216 |
pub use self::copysignf::copysignf; |
| 217 |
pub use self::cos::cos; |
| 218 |
pub use self::cosf::cosf; |
| 219 |
pub use self::cosh::cosh; |
| 220 |
pub use self::coshf::coshf; |
| 221 |
pub use self::erf::erf; |
| 222 |
pub use self::erf::erfc; |
| 223 |
pub use self::erff::erfcf; |
| 224 |
pub use self::erff::erff; |
| 225 |
pub use self::exp::exp; |
| 226 |
pub use self::exp10::exp10; |
| 227 |
pub use self::exp10f::exp10f; |
| 228 |
pub use self::exp2::exp2; |
| 229 |
pub use self::exp2f::exp2f; |
| 230 |
pub use self::expf::expf; |
| 231 |
pub use self::expm1::expm1; |
| 232 |
pub use self::expm1f::expm1f; |
| 233 |
pub use self::fabs::fabs; |
| 234 |
pub use self::fabsf::fabsf; |
| 235 |
pub use self::fdim::fdim; |
| 236 |
pub use self::fdimf::fdimf; |
| 237 |
pub use self::floor::floor; |
| 238 |
pub use self::floorf::floorf; |
| 239 |
pub use self::fma::fma; |
| 240 |
pub use self::fmaf::fmaf; |
| 241 |
pub use self::fmax::fmax; |
| 242 |
pub use self::fmaxf::fmaxf; |
| 243 |
pub use self::fmin::fmin; |
| 244 |
pub use self::fminf::fminf; |
| 245 |
pub use self::fmod::fmod; |
| 246 |
pub use self::fmodf::fmodf; |
| 247 |
pub use self::frexp::frexp; |
| 248 |
pub use self::frexpf::frexpf; |
| 249 |
pub use self::hypot::hypot; |
| 250 |
pub use self::hypotf::hypotf; |
| 251 |
pub use self::ilogb::ilogb; |
| 252 |
pub use self::ilogbf::ilogbf; |
| 253 |
pub use self::j0::j0; |
| 254 |
pub use self::j0::y0; |
| 255 |
pub use self::j0f::j0f; |
| 256 |
pub use self::j0f::y0f; |
| 257 |
pub use self::j1::j1; |
| 258 |
pub use self::j1::y1; |
| 259 |
pub use self::j1f::j1f; |
| 260 |
pub use self::j1f::y1f; |
| 261 |
pub use self::jn::jn; |
| 262 |
pub use self::jn::yn; |
| 263 |
pub use self::jnf::jnf; |
| 264 |
pub use self::jnf::ynf; |
| 265 |
pub use self::ldexp::ldexp; |
| 266 |
pub use self::ldexpf::ldexpf; |
| 267 |
pub use self::lgamma::lgamma; |
| 268 |
pub use self::lgamma_r::lgamma_r; |
| 269 |
pub use self::lgammaf::lgammaf; |
| 270 |
pub use self::lgammaf_r::lgammaf_r; |
| 271 |
pub use self::log::log; |
| 272 |
pub use self::log10::log10; |
| 273 |
pub use self::log10f::log10f; |
| 274 |
pub use self::log1p::log1p; |
| 275 |
pub use self::log1pf::log1pf; |
| 276 |
pub use self::log2::log2; |
| 277 |
pub use self::log2f::log2f; |
| 278 |
pub use self::logf::logf; |
| 279 |
pub use self::modf::modf; |
| 280 |
pub use self::modff::modff; |
| 281 |
pub use self::nextafter::nextafter; |
| 282 |
pub use self::nextafterf::nextafterf; |
| 283 |
pub use self::pow::pow; |
| 284 |
pub use self::powf::powf; |
| 285 |
pub use self::remainder::remainder; |
| 286 |
pub use self::remainderf::remainderf; |
| 287 |
pub use self::remquo::remquo; |
| 288 |
pub use self::remquof::remquof; |
| 289 |
pub use self::rint::rint; |
| 290 |
pub use self::rintf::rintf; |
| 291 |
pub use self::round::round; |
| 292 |
pub use self::roundf::roundf; |
| 293 |
pub use self::scalbn::scalbn; |
| 294 |
pub use self::scalbnf::scalbnf; |
| 295 |
pub use self::sin::sin; |
| 296 |
pub use self::sincos::sincos; |
| 297 |
pub use self::sincosf::sincosf; |
| 298 |
pub use self::sinf::sinf; |
| 299 |
pub use self::sinh::sinh; |
| 300 |
pub use self::sinhf::sinhf; |
| 301 |
pub use self::sqrt::sqrt; |
| 302 |
pub use self::sqrtf::sqrtf; |
| 303 |
pub use self::tan::tan; |
| 304 |
pub use self::tanf::tanf; |
| 305 |
pub use self::tanh::tanh; |
| 306 |
pub use self::tanhf::tanhf; |
| 307 |
pub use self::tgamma::tgamma; |
| 308 |
pub use self::tgammaf::tgammaf; |
| 309 |
pub use self::trunc::trunc; |
| 310 |
pub use self::truncf::truncf; |
| 311 |
|
| 312 |
// Private modules |
| 313 |
mod expo2; |
| 314 |
mod fenv; |
| 315 |
mod k_cos; |
| 316 |
mod k_cosf; |
| 317 |
mod k_expo2; |
| 318 |
mod k_expo2f; |
| 319 |
mod k_sin; |
| 320 |
mod k_sinf; |
| 321 |
mod k_tan; |
| 322 |
mod k_tanf; |
| 323 |
mod rem_pio2; |
| 324 |
mod rem_pio2_large; |
| 325 |
mod rem_pio2f; |
| 326 |
|
| 327 |
// Private re-imports |
| 328 |
use self::expo2::expo2; |
| 329 |
use self::k_cos::k_cos; |
| 330 |
use self::k_cosf::k_cosf; |
| 331 |
use self::k_expo2::k_expo2; |
| 332 |
use self::k_expo2f::k_expo2f; |
| 333 |
use self::k_sin::k_sin; |
| 334 |
use self::k_sinf::k_sinf; |
| 335 |
use self::k_tan::k_tan; |
| 336 |
use self::k_tanf::k_tanf; |
| 337 |
use self::rem_pio2::rem_pio2; |
| 338 |
use self::rem_pio2_large::rem_pio2_large; |
| 339 |
use self::rem_pio2f::rem_pio2f; |
| 340 |
|
| 341 |
#[inline] |
| 342 |
fn get_high_word(x: f64) -> u32 { |
| 343 |
(x.to_bits() >> 32) as u32 |
| 344 |
} |
| 345 |
|
| 346 |
#[inline] |
| 347 |
fn get_low_word(x: f64) -> u32 { |
| 348 |
x.to_bits() as u32 |
| 349 |
} |
| 350 |
|
| 351 |
#[inline] |
| 352 |
fn with_set_high_word(f: f64, hi: u32) -> f64 { |
| 353 |
let mut tmp = f.to_bits(); |
| 354 |
tmp &= 0x00000000_ffffffff; |
| 355 |
tmp |= (hi as u64) << 32; |
| 356 |
f64::from_bits(tmp) |
| 357 |
} |
| 358 |
|
| 359 |
#[inline] |
| 360 |
fn with_set_low_word(f: f64, lo: u32) -> f64 { |
| 361 |
let mut tmp = f.to_bits(); |
| 362 |
tmp &= 0xffffffff_00000000; |
| 363 |
tmp |= lo as u64; |
| 364 |
f64::from_bits(tmp) |
| 365 |
} |
| 366 |
|
| 367 |
#[inline] |
| 368 |
fn combine_words(hi: u32, lo: u32) -> f64 { |
| 369 |
f64::from_bits((hi as u64) << 32 | lo as u64) |
| 370 |
} |