base:fastest_multiplication
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
base:fastest_multiplication [2017-04-17 13:55] – repose | base:fastest_multiplication [2017-04-19 09:59] – repose | ||
---|---|---|---|
Line 7: | Line 7: | ||
Jack Asser' | Jack Asser' | ||
Chris Jam's: 204.5 ref: http:// | Chris Jam's: 204.5 ref: http:// | ||
- | Mine: 201 zp variation: | + | Mine: 196 zp variation: |
Times above need to add 12 for jsr/rts \\ | Times above need to add 12 for jsr/rts \\ | ||
Line 15: | Line 15: | ||
;and being less elegant and harder to follow. | ;and being less elegant and harder to follow. | ||
;by Repose 2017 | ;by Repose 2017 | ||
+ | ;table generator by Graham | ||
+ | ;addition improvement suggested by JackAsser | ||
+ | |||
+ | ;data: 2044 bytes | ||
+ | ;zero page ram required: minimum 8 bytes, ideally 14 | ||
+ | ;do_add: 30 bytes in zp, if used | ||
+ | ;time: 196 cycles, option for 192 if you use 30 more zp bytes for do_add | ||
+ | ; | ||
+ | |||
+ | ;How to use: | ||
+ | ;put numbers in x/y and result is Y reg, X reg, z1, z0 | ||
;tables of squares | ;tables of squares | ||
Line 35: | Line 46: | ||
y0=$fd; | y0=$fd; | ||
y1=$fe | y1=$fe | ||
- | z0=$80; | + | z0=$80; |
z1=$81 | z1=$81 | ||
- | z2=$82 | + | ;z2=$82 |
- | z3=$83 | + | ;z3=$83 |
;Example showing use | ;Example showing use | ||
Line 153: | Line 164: | ||
lda (p_sqr_hi), | lda (p_sqr_hi), | ||
sbc (p_invsqr_hi), | sbc (p_invsqr_hi), | ||
- | sta z3;x1*y1h;31 | + | tay;x1*y1h;Y=z3, 30 cycles |
+ | ; | ||
- | ;4*31+2*17 so far=158 | + | ;jmp do_adds; |
- | ;add partials | + | |
- | ;-add first two numbers in column 1 | + | |
- | ;jmp do_adds;put in zp to save 3 cycles :) | + | |
do_adds: | do_adds: | ||
- | clc | + | ;-add the first two numbers of column 1 |
- | c1a lda #0 | + | clc |
- | c1b adc #0 | + | c1a: lda #0 |
- | sta z1;9 | + | c1b: adc #0 |
- | ;-continue to first two numbers | + | sta z1;9 |
- | c2a lda #0 | + | |
- | c2b adc #0 | + | ;-continue to first two numbers |
- | sta z2;7 | + | c2a: lda #0 |
- | bcc c1c;3 taken/9 not taken, avg 6 | + | c2b: adc #0 |
- | inc z3 | + | tax;X=z2, 6 cycles |
- | clc | + | bcc c1c; |
- | ;-add last number of column 1 (row c) | + | iny;z3++ |
- | c1c lda #0 | + | clc |
- | adc z1 | + | |
- | sta z1;8 | + | ;-add last number of column 1 |
+ | c1c: lda #0 | ||
+ | adc z1 | ||
+ | sta z1;8 | ||
;-add last number of column 2 | ;-add last number of column 2 | ||
- | c2c lda #0 | + | txa;A=z2 |
- | adc z2 | + | c2c: adc #0 |
- | sta z2;8 | + | tax;X=z2, 6 |
- | bcc fin;3/7 avg 5 | + | bcc fin;3/4 avg 3.5 |
- | inc z3 | + | iny;z3++ |
- | ;9+7+6+8+8+5=43 | + | |
- | fin rts | + | ;Y=z3, X=z2 |
+ | ;9+6+4.5+8+6+3.5=37 | ||
+ | fin: rts | ||
Diagram of the additions | Diagram of the additions |
base/fastest_multiplication.txt · Last modified: 2024-02-13 08:24 by repose