comparison src/fps.s @ 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 df803556bfae
comparison
equal deleted inserted replaced
109:1a5da3594a9e 110:00c8df0b61f5
484 std fpaextra ;* one extra byte to make sure lowest extra digit is zero) 484 std fpaextra ;* one extra byte to make sure lowest extra digit is zero)
485 std fpaextra+2 485 std fpaextra+2
486 std fpaextra+4 486 std fpaextra+4
487 sta fpaextra+6 487 sta fpaextra+6
488 ldb fpa1+fpa.sig+4 ;* do each byte of multiplier significand in sequence 488 ldb fpa1+fpa.sig+4 ;* do each byte of multiplier significand in sequence
489 bsr fps_mul4 489 bsr fps_mul5 ;* don't shift for first digit
490 ldb fpa1+fpa.sig+3 490 ldb fpa1+fpa.sig+3
491 bsr fps_mul4 491 bsr fps_mul4
492 ldb fpa1+fpa.sig+2 492 ldb fpa1+fpa.sig+2
493 bsr fps_mul4 493 bsr fps_mul4
494 ldb fpa1+fpa.sig+1 494 ldb fpa1+fpa.sig+1
495 bsr fps_mul4 495 bsr fps_mul4
496 ldb fpa1+fpa.sig 496 ldb fpa1+fpa.sig
497 bsr fps_mul4 497 bsr fps_mul4
498 ldd fpaextra+1 ; copy result into fpa0 significand (overflow byte will be zero) 498 ldb fpaextra ; did we have an overflow on the last digit?
499 beq fps_mul3a ; brif not
500 bsr fps_mul9 ; shift digits right one digit to move extra digit in
501 inc fpa0+fpa.exp ; bump exponent for result
502 bmi OVERROR ; brif we went out of range (went > 127)
503 fps_mul3a ldd fpaextra+1 ; copy result into fpa0 significand (overflow byte will be zero)
499 std fpa0+fpa.sig 504 std fpa0+fpa.sig
500 ldd fpaextra+3 505 ldd fpaextra+3
501 std fpa0+fpa.sig+2 506 std fpa0+fpa.sig+2
502 ldd fpaextra+5 507 ldd fpaextra+5
503 sta fpa0+fpa.sig+4 508 sta fpa0+fpa.sig+4
504 ldd fpaextra+7 509 ldd fpaextra+7
505 std fpa0+fpa.sig+6 510 std fpa0+fpa.sig+6
506 ldd fpaextra+9 511 ldd fpaextra+9
507 std fpa0+fpa.sig+8 512 std fpa0+fpa.sig+8
508 jmp fps_normalize ; go normalize the result 513 jmp fps_normalize ; go normalize the result
509 fps_mul4 bne fps_mul6 ; brif at least one digit is nonzero 514 fps_mul4 bsr fps_mul9 ; shift result right
510 ldd fpaextra+8 ; shift right by 8 bits 515 fps_mul5 bitb #0x0f ; are we finished this digit?
511 std fpaextra+9 516 beq fps_mul6 ; brif so
512 ldd fpaextra+6 517 bsr fps_mul11 ; add multiplicand to accumulator
513 std fpaextra+7 518 decb ; adjust digit
514 ldd fpaextra+4 519 bra fps_mul5 ; see if we're done yet
515 std fpaextra+5 520 fps_mul6 bsr fps_mul9 ; shift the result right
516 ldd fpaextra+2 521 fps_mul7 bitb #0xf0 ; done this digit?
517 sta fpaextra+3 522 bne fps_mul8 ; brif not
518 ldd fpaextra 523 rts ; we're done now so return
519 std fpaextra+1 524 fps_mul8 bsr fps_mul11 ; add multiplicand to accumulator
520 clr fpaextra 525 subb #0x010 ; adjust digit
521 rts 526 bra fps_mul7 ; see if we're done yet
522 fps_mul5 bsr fps_mul11 ; add multiplicand to accumulator
523 decb ; account for iteration
524 fps_mul6 bitb #0x0f ; done everything for this digit?
525 bne fps_mul7
526 bsr fps_mul9 ; shift accumulator
527 bra fps_mul8
528 fps_mul7 bsr fps_mul11 ; add multiplicand to accumulator
529 subb #0x10 ; account for iteration
530 fps_mul8 bitb #0xf0 ; done all iterations?
531 bne fps_mul7 ; brif not
532 fps_mul9 lsr fpaextra ; shift result 527 fps_mul9 lsr fpaextra ; shift result
533 ror fpaextra+1 528 ror fpaextra+1
534 ror fpaextra+2 529 ror fpaextra+2
535 ror fpaextra+3 530 ror fpaextra+3
536 ror fpaextra+4 531 ror fpaextra+4