From 6afae69a318d70d14279b9f85164765479158e24 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Thu, 27 Feb 2020 18:48:34 +0100 Subject: [PATCH] speed optimization of multiplication routine --- STATUS.md | 2 +- c64/basic/math/mul_FAC2_FAC1_8x8.s | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/STATUS.md b/STATUS.md index d5ed350b..aeaabc42 100644 --- a/STATUS.md +++ b/STATUS.md @@ -199,7 +199,7 @@ Floating point mathematical routines - not official, but well known and broadly | `$B947` | `inv_FAC1_mantissa` | NOT DONE | | | `$B9EA` | `log_FAC1` | NOT DONE | | | `$BA28` | `mul_MEM_FAC1` | DONE | | -| `$BA2B` | `mul_FAC2_FAC1` | PARTIAL | very imprecise; not yet clear, why | +| `$BA2B` | `mul_FAC2_FAC1` | PARTIAL | sometime imprecise - like PI*PI | | `$BA8C` | `mov_MEM_FAC2` | DONE | | | `$BA90` | `get_FAC2_via_INDEX` | NOT DONE | | | `$BAE2` | `mul10_FAC1` | DONE | | diff --git a/c64/basic/math/mul_FAC2_FAC1_8x8.s b/c64/basic/math/mul_FAC2_FAC1_8x8.s index d247b0bd..fa0ebfec 100644 --- a/c64/basic/math/mul_FAC2_FAC1_8x8.s +++ b/c64/basic/math/mul_FAC2_FAC1_8x8.s @@ -7,13 +7,20 @@ // - https://codebase64.org/doku.php?id=base:8bit_multiplication_16bit_product_fast_no_tables // // input: .A, INDEX+3 -// output: .X (high byte), .A and INDEX+2 (low byte), carry always clear +// output: .X (high byte), .A (low byte), carry always clear // mul_FAC2_FAC1_8x8: sta INDEX+2 + // Special case (optimization) - handle 0 + + lda INDEX+2 + beq mul_FAC2_FAC1_8x8_zero + lda INDEX+3 + beq mul_FAC2_FAC1_8x8_zero + lda #$00 dec INDEX+3 // decrement because we will be adding with carry set for speed (an extra one) @@ -62,6 +69,14 @@ mul_FAC2_FAC1_8x8: tax lda INDEX+2 - clc + clc + rts + +mul_FAC2_FAC1_8x8_zero: + + lda #$00 + tax + + clc rts