Merge pull request 'Changed mul_low algorithm to radix-16-1 algorithm with swap' (#17) from Micha_i/symphony_stdlib:fast-math into main

Reviewed-on: #17
This commit was merged in pull request #17.
This commit is contained in:
2026-09-04 23:20:14 +02:00
+40 -18
View File
@@ -4,29 +4,51 @@
; r2 - The second value ; r2 - The second value
; Result: ; Result:
; r1 - The lower 32 bits of the result ; r1 - The lower 32 bits of the result
; Clobbers: r2, r3, r4, r5 ; Clobbers: r2, r3, r4, r5, r6
pub mul_low: pub mul_low:
add r3, r2, r2 ; r3 = r2 * 2 cmp r1, r2
jbe mul_low_noswap
xor r1, r2, r1
xor r2, r1, r2
xor r1, r2, r1
; Passthrough
; Multiplies r1 and r2, returning the lower part of the result
; This method assumes r1 is smaller than r2, which results in faster execution
; Arguments:
; r1 - The first value
; r2 - The second value
; Result:
; r1 - The lower 32 bits of the result
; Clobbers: r2, r3, r4, r5, r6
pub mul_low_noswap:
mov r4, 0 ; r4 has the result mov r4, 0 ; r4 has the result
mov r6, mul_loop_end
add r3, r2, r2
mul_low_loop: mul_loop:
and r5, r1, 14 ; Taking the first four bits, discarding the odd
lsl r5, r5, 1 ; 0000 - 0, 0001 - 2, 0010 - 4, 0011 - 8, etc.
sub r5, r6, r5
jmp r5
and r5, r1, 1 ; a0 add r4, r4, r3
neg r5, r5 ; mask add r4, r4, r3
and r5, r2, r5 ; a0 ? r2 : 0 add r4, r4, r3
add r4, r4, r5 add r4, r4, r3
add r4, r4, r3
and r5, r1, 2 ; a1 is now 0 or 2 add r4, r4, r3
lsr r5, r5, 1 ; normalize to 0/1 add r4, r4, r3
neg r5, r5 ; mask mul_loop_end:
and r5, r3, r5 ; a1 ? r2 * 2 : 0 mov flags, r1
add r4, r4, r5 jne mul_skip_one
add r4, r4, r2
lsl r2, r2, 2 mul_skip_one:
lsl r3, r3, 2 lsl r2, r2, 4
lsr r1, r1, 2 lsl r3, r3, 4
lsr r1, r1, 4
cmp r1, zr cmp r1, zr
jne mul_low_loop jne mul_loop
mov r1, r4 mov r1, r4
jmp r13 jmp r13