step 1: sqr16_impl and imul16_impl take argument addresses

first step to removing function call overhead
This commit is contained in:
Brooke Vibber 2026-08-23 15:18:25 -07:00
commit d93dd2e6a6

View file

@ -799,15 +799,15 @@ inner_loop:
.endproc .endproc
; min base mem: 81 * 4 + 22 * 2 + 10 + 6 = 384 cyc ; min base mem: 81 * 4 + 22 * 2 + 10 = 378 cyc
; max base mem: 92 * 4 + 27 * 2 + 50 + 6 = 478 cyc ; max base mem: 92 * 4 + 27 * 2 + 50 = 472 cyc
; min ext-mem: 50 * 4 + 22 * 2 + 10 + 6 = 260 cyc ; min ext-mem: 50 * 4 + 22 * 2 + 10 = 254 cyc
; max ext-mem: 55 * 4 + 27 * 2 + 50 + 6 = 330 cyc ; max ext-mem: 55 * 4 + 27 * 2 + 50 = 324 cyc
.macro imul16_impl xe .macro imul16_impl result, arg1, arg2, xe
.scope .scope
arg1 = FR0 ; 16-bit arg ;arg1 ; 16-bit arg
arg2 = FR1 ; 16-bit arg ;arg2 ; 16-bit arg
result = FR2 ; 32-bit result (output) ;result ; 32-bit result (output)
inter = temp2 ; 16-bit temporary (clobbered) inter = temp2 ; 16-bit temporary (clobbered)
; h1l1 * h2l2 ; h1l1 * h2l2
@ -843,8 +843,6 @@ inner_loop:
bpl arg2_pos ; 2 cyc bpl arg2_pos ; 2 cyc
sub16 result + 2, result + 2, arg1 ; 20 cyc sub16 result + 2, result + 2, arg1 ; 20 cyc
arg2_pos: arg2_pos:
rts ; 6 cyc
.endscope .endscope
.endmacro .endmacro
@ -877,15 +875,15 @@ inner_loop:
.endmacro .endmacro
; min base ram: 5 + 163 + 6 = 174 ; min base ram: 5 + 163 + 3 = 171
; max base ram: 7 + 184 + 18 + 6 = 215 ; max base ram: 7 + 184 + 18 = 209
; min ext ram: 5 + 132 + 6 = 143 ; min ext ram: 5 + 132 + 3 = 140
; max ext ram: 7 + 147 + 18 + 6 = 178 ; max ext ram: 7 + 147 + 18 = 172
.macro sqr16_impl xe .macro sqr16_impl result, arg, xe
.scope .scope
arg = FR0 ; 16-bit arg ; arg ; 16-bit arg
negated = FR1 negated = FR1
result = FR2 ; 32-bit result ; result ; 32-bit result
; 5-7 cycles ; 5-7 cycles
lda arg + 1 ; 3 cyc lda arg + 1 ; 3 cyc
@ -894,29 +892,34 @@ inner_loop:
arg_pos: arg_pos:
sqr16_impl_inner result, arg, xe ; 163-184 / 132-147 cyc sqr16_impl_inner result, arg, xe ; 163-184 / 132-147 cyc
rts ; 6 cyc jmp done ; 3 cyc
arg_neg: arg_neg:
copy_neg16 negated, arg ; 18 cyc copy_neg16 negated, arg ; 18 cyc
sqr16_impl_inner result, negated, xe ; 163-184 / 132-147 cyc sqr16_impl_inner result, negated, xe ; 163-184 / 132-147 cyc
rts ; 6 cyc
done:
.endscope .endscope
.endmacro .endmacro
.proc imul16_func .proc imul16_func
imul16_impl 0 imul16_impl FR2, FR0, FR1, 0
rts
.endproc .endproc
.proc imul16xe_func .proc imul16xe_func
imul16_impl 1 imul16_impl FR2, FR0, FR1, 1
rts
.endproc .endproc
.proc sqr16_func .proc sqr16_func
sqr16_impl 0 sqr16_impl FR2, FR0, 0
rts
.endproc .endproc
.proc sqr16xe_func .proc sqr16xe_func
sqr16_impl 1 sqr16_impl FR2, FR0, 1
rts
.endproc .endproc
; 11-27 cycles ; 11-27 cycles