base:fastest_multiplication
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
base:fastest_multiplication [2023-08-21 05:18] – repose | base:fastest_multiplication [2024-02-13 08:24] (current) – accurate timing if Jack Asser code repose | ||
---|---|---|---|
Line 5: | Line 5: | ||
Requires tables or a generator routine such as [[table_generator_routine_for_fast_8_bit_mul_table]] | Requires tables or a generator routine such as [[table_generator_routine_for_fast_8_bit_mul_table]] | ||
- | Jack Asser' | + | Jack Asser' |
Chris Jam's: 204.5* | Chris Jam's: 204.5* | ||
Mine: 198.6 zp variation: 194.6 \\ | Mine: 198.6 zp variation: 194.6 \\ | ||
Times above need to add 6 for rts \\ | Times above need to add 6 for rts \\ | ||
Note: updated 2023; corrected code, typos and timings \\ | Note: updated 2023; corrected code, typos and timings \\ | ||
- | *Timing approximate for external code | + | *Timing approximate for external code \\ |
+ | This is the winner out of 120 published algorithms as independently tested here: | ||
+ | https:// | ||
+ | Note: I have a new version which is 188.1 cycles, excepting the RTS. \\ | ||
< | < | ||
Line 27: | Line 30: | ||
;How to use: | ;How to use: | ||
- | ;put numbers in x/y and result is Y reg, A reg, z1, z0 | + | ;put numbers in x/y and result is Y reg (z3), A reg (z2), z1, z0 |
;tables of squares | ;tables of squares | ||
Line 50: | Line 53: | ||
z0=$80; | z0=$80; | ||
z1=$81 | z1=$81 | ||
- | z2=$82 ;returned in X reg | + | z2=$82 ;returned in A reg |
z3=$83 ;returned in Y reg | z3=$83 ;returned in Y reg | ||
Line 170: | Line 173: | ||
lda (p_sqr_hi), | lda (p_sqr_hi), | ||
sbc (p_invsqr_hi), | sbc (p_invsqr_hi), | ||
- | tay;x1*y1h;Y=z3, 30.992 cycles | + | tay;Y=x1*y1h, 30.992 cycles |
; | ; | ||
Line 184: | Line 187: | ||
c2a: lda #0 | c2a: lda #0 | ||
c2b: adc #0 | c2b: adc #0 | ||
- | tax;X=z2, 6 cycles | + | tax |
- | bcc c1c;3/6 avg 4.5 | + | bcc c1c;9 |
iny;z3++ | iny;z3++ | ||
- | clc | + | clc;(+3) taken 7% of the time, 3*.07=+.21 |
;-add last number of column 1 | ;-add last number of column 1 | ||
Line 195: | Line 198: | ||
;-add last number of column 2 | ;-add last number of column 2 | ||
- | txa;A=z2 | + | txa |
c2c: adc #0 | c2c: adc #0 | ||
- | ;A=z2, 6 | + | ;A=z2 |
- | bcc fin;3/4 avg 3.5 | + | bcc fin;7 |
- | iny;z3++ | + | iny;(+1) taken 42% of the time, 1*.42=.42 |
;Y=z3, A=z2 | ;Y=z3, A=z2 | ||
- | ;33.63 | + | ;add partials part total cycles=33.63 (minimum=33, |
- | fin: rts | + | ;total time=164.97+33.63=198.6 |
+ | fin: rts;add 6 to include this (204.6) | ||
Diagram of the additions | Diagram of the additions |
base/fastest_multiplication.1692587911.txt.gz · Last modified: 2023-08-21 05:18 by repose