fix arm64

This commit is contained in:
kbkpbot 2025-08-08 14:04:22 +08:00
parent de303701f5
commit a5114893a7

View file

@ -10,22 +10,18 @@ module bits
// This function's execution time does not depend on the inputs. // This function's execution time does not depend on the inputs.
@[inline] @[inline]
pub fn mul_64(x u64, y u64) (u64, u64) { pub fn mul_64(x u64, y u64) (u64, u64) {
$if android { mut hi := u64(0)
return mul_64_default(x, y) mut lo := u64(0)
} $else { asm arm64 {
mut hi := u64(0) mul lo, x, y
mut lo := u64(0) umulh hi, x, y
asm arm64 { ; +r (hi)
mul lo, x, y +r (lo)
umulh hi, x, y ; r (x)
; =r (hi) r (y)
=r (lo) ; cc
; r (x)
r (y)
; cc
}
return hi, lo
} }
return hi, lo
} }
// mul_add_64 returns the 128-bit result of x * y + z: (hi, lo) = x * y + z // mul_add_64 returns the 128-bit result of x * y + z: (hi, lo) = x * y + z
@ -33,23 +29,19 @@ pub fn mul_64(x u64, y u64) (u64, u64) {
// half returned in lo. // half returned in lo.
@[inline] @[inline]
pub fn mul_add_64(x u64, y u64, z u64) (u64, u64) { pub fn mul_add_64(x u64, y u64, z u64) (u64, u64) {
$if android { mut hi := u64(0)
return mul_add_64_default(x, y, z) mut lo := u64(0)
} $else { asm arm64 {
mut hi := u64(0) mul lo, x, y
mut lo := u64(0) umulh hi, x, y
asm arm64 { adds lo, lo, z
mul lo, x, y adc hi, hi, xzr
umulh hi, x, y ; +r (hi)
adds lo, lo, z +r (lo)
adc hi, hi, xzr ; r (x)
; =r (hi) r (y)
=r (lo) r (z)
; r (x) ; cc
r (y)
r (z)
; cc
}
return hi, lo
} }
return hi, lo
} }