changeset 110:00c8df0b61f5

Fix some logic errors in floating point multiplication Floating point muliplication now yields correct results for a range of tests which is promising. Among the errors were not handling the overflow situation when an extra digit is needed and at least one inverted branch condition.
author William Astle <lost@l-w.ca>
date Mon, 25 Dec 2023 22:37:55 -0700
parents 1a5da3594a9e
children b10f6c8979a5
files src/fps.s
diffstat 1 files changed, 20 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/fps.s	Sun Dec 24 23:08:20 2023 -0700
+++ b/src/fps.s	Mon Dec 25 22:37:55 2023 -0700
@@ -486,7 +486,7 @@
                 std fpaextra+4
                 sta fpaextra+6
                 ldb fpa1+fpa.sig+4              ;* do each byte of multiplier significand in sequence
-                bsr fps_mul4
+                bsr fps_mul5                    ;* don't shift for first digit
                 ldb fpa1+fpa.sig+3
                 bsr fps_mul4
                 ldb fpa1+fpa.sig+2
@@ -495,7 +495,12 @@
                 bsr fps_mul4
                 ldb fpa1+fpa.sig
                 bsr fps_mul4
-                ldd fpaextra+1                  ; copy result into fpa0 significand (overflow byte will be zero)
+                ldb fpaextra                    ; did we have an overflow on the last digit?
+                beq fps_mul3a                   ; brif not
+                bsr fps_mul9                    ; shift digits right one digit to move extra digit in
+                inc fpa0+fpa.exp                ; bump exponent for result
+                bmi OVERROR                     ; brif we went out of range (went > 127)
+fps_mul3a       ldd fpaextra+1                  ; copy result into fpa0 significand (overflow byte will be zero)
                 std fpa0+fpa.sig
                 ldd fpaextra+3
                 std fpa0+fpa.sig+2
@@ -506,29 +511,19 @@
                 ldd fpaextra+9
                 std fpa0+fpa.sig+8
                 jmp fps_normalize               ; go normalize the result
-fps_mul4        bne fps_mul6                    ; brif at least one digit is nonzero
-                ldd fpaextra+8                  ; shift right by 8 bits
-                std fpaextra+9
-                ldd fpaextra+6
-                std fpaextra+7
-                ldd fpaextra+4
-                std fpaextra+5
-                ldd fpaextra+2
-                sta fpaextra+3
-                ldd fpaextra
-                std fpaextra+1
-                clr fpaextra
-                rts
-fps_mul5        bsr fps_mul11                   ; add multiplicand to accumulator
-                decb                            ; account for iteration
-fps_mul6        bitb #0x0f                      ; done everything for this digit?
-                bne fps_mul7
-                bsr fps_mul9                    ; shift accumulator
-                bra fps_mul8
-fps_mul7        bsr fps_mul11                   ; add multiplicand to accumulator
-                subb #0x10                      ; account for iteration
-fps_mul8        bitb #0xf0                      ; done all iterations?
-                bne fps_mul7                    ; brif not
+fps_mul4        bsr fps_mul9                    ; shift result right
+fps_mul5        bitb #0x0f                      ; are we finished this digit?
+                beq fps_mul6                    ; brif so
+                bsr fps_mul11                   ; add multiplicand to accumulator
+                decb                            ; adjust digit
+                bra fps_mul5                    ; see if we're done yet
+fps_mul6        bsr fps_mul9                    ; shift the result right
+fps_mul7        bitb #0xf0                      ; done this digit?
+                bne fps_mul8                    ; brif not
+                rts                             ; we're done now so return
+fps_mul8        bsr fps_mul11                   ; add multiplicand to accumulator
+                subb #0x010                     ; adjust digit
+                bra fps_mul7                    ; see if we're done yet
 fps_mul9        lsr fpaextra                    ; shift result
                 ror fpaextra+1
                 ror fpaextra+2