2016-10-01 06:15:44 +08:00
|
|
|
macro_rules! pow {
|
2016-10-07 23:17:44 +08:00
|
|
|
($intrinsic:ident: $fty:ty, $ity:ident) => {
|
2016-10-01 06:15:44 +08:00
|
|
|
/// Returns `a` raised to the power `b`
|
|
|
|
#[cfg_attr(not(test), no_mangle)]
|
|
|
|
pub extern "C" fn $intrinsic(a: $fty, b: $ity) -> $fty {
|
|
|
|
let (mut a, mut b) = (a, b);
|
|
|
|
let recip = b < 0;
|
|
|
|
let mut r: $fty = 1.0;
|
|
|
|
loop {
|
|
|
|
if (b & 1) != 0 {
|
|
|
|
r *= a;
|
|
|
|
}
|
2016-10-07 23:17:44 +08:00
|
|
|
b = sdiv!($ity, b, 2);
|
2016-10-01 06:15:44 +08:00
|
|
|
if b == 0 {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
a *= a;
|
|
|
|
}
|
|
|
|
|
|
|
|
if recip {
|
|
|
|
1.0 / r
|
|
|
|
} else {
|
|
|
|
r
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pow!(__powisf2: f32, i32);
|
|
|
|
pow!(__powidf2: f64, i32);
|