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 {
return mul_64_default(x, y)
} $else {
mut hi := u64(0) mut hi := u64(0)
mut lo := u64(0) mut lo := u64(0)
asm arm64 { asm arm64 {
mul lo, x, y mul lo, x, y
umulh hi, x, y umulh hi, x, y
; =r (hi) ; +r (hi)
=r (lo) +r (lo)
; r (x) ; r (x)
r (y) r (y)
; cc ; 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,9 +29,6 @@ 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 {
return mul_add_64_default(x, y, z)
} $else {
mut hi := u64(0) mut hi := u64(0)
mut lo := u64(0) mut lo := u64(0)
asm arm64 { asm arm64 {
@ -43,13 +36,12 @@ pub fn mul_add_64(x u64, y u64, z u64) (u64, u64) {
umulh hi, x, y umulh hi, x, y
adds lo, lo, z adds lo, lo, z
adc hi, hi, xzr adc hi, hi, xzr
; =r (hi) ; +r (hi)
=r (lo) +r (lo)
; r (x) ; r (x)
r (y) r (y)
r (z) r (z)
; cc ; cc
} }
return hi, lo return hi, lo
}
} }