Changed mul_low algorithm to radix-4 multiplication

This commit is contained in:
Michał Isalski
2026-09-04 00:11:33 +02:00
parent c83269fcf7
commit a00c7f2a84
+20 -11
View File
@@ -6,20 +6,29 @@
; r1 - The lower 32 bits of the result
; Clobbers: r2, r3, r4, r5
pub mul_low:
mov r3, 0 ; result
mov r4, 31 ; loop counter
add r3, r2, r2 ; r3 = r2 * 2
mov r4, 0 ; r4 has the result
mul_low_loop:
asr r5, r2, 31
and r5, r5, r1
lsl r5, r5, r4
add r3, r3, r5
lsl r2, r2, 1
sub r4, r4, 1
cmp r4, 0
jge mul_low_loop
mov r1, r3
and r5, r1, 1 ; a0
neg r5, r5 ; mask
and r5, r2, r5 ; a0 ? r2 : 0
add r4, r4, r5
and r5, r1, 2 ; a1 is now 0 or 2
lsr r5, r5, 1 ; normalize to 0/1
neg r5, r5 ; mask
and r5, r3, r5 ; a1 ? r2 * 2 : 0
add r4, r4, r5
lsl r2, r2, 2
lsl r3, r3, 2
lsr r1, r1, 2
cmp r1, zr
jne mul_low_loop
mov r1, r4
jmp r13
; Calculates the absolute value of the value provided in the r1 register