Use own implementation of pow_int_ instead of llvm

Remove LLVM intrinsics code related to `Num.powInt`.
This commit is contained in:
Dimitar Apostolov 2020-09-17 12:07:33 +02:00
parent 2404882c1a
commit e89af31015
4 changed files with 45 additions and 8 deletions

View file

@ -10,3 +10,25 @@
pub fn i64_to_f64_(num: i64) -> f64 {
num as f64
}
#[no_mangle]
pub fn pow_int_(mut base: i64, mut exp: i64) -> i64 {
let mut acc = 1;
while exp > 1 {
if (exp & 1) == 1 {
acc *= base;
}
exp /= 2;
base *= base;
}
// Deal with the final bit of the exponent separately, since
// squaring the base afterwards is not necessary and may cause a
// needless overflow.
if exp == 1 {
acc *= base;
}
acc
}