rethought the rounding function

realized the top bits are not enough, that was a brainfart
doing comparisons now
This commit is contained in:
Brooke Vibber 2023-01-28 16:31:55 -08:00
parent b55015ff87
commit ca5db83e8f

View file

@ -359,35 +359,33 @@ positive_result:
.macro round16 arg .macro round16 arg
; Round top 16 bits of 32-bit fixed-point number in-place ; Round top 16 bits of 32-bit fixed-point number in-place
.local positive .local increment
.local negative .local high_half
.local no_carry .local check_sign
.local next .local next
; positive input: ; low word > $8000: round up
; 0 rounds down, no change - 5 cyc ; = $8000: round up if positive
; 1 rounds up, add one - 15-20 cyc ; round down if negative
; negative input: ; < $8000: round down
; 0 rounds up, no change - 5 cyc
; 1 rounds down, sub one - 23-28 cyc
; check 16th bit down lda arg + 1
lda arg + 1 ; 3 cyc cmp #$80
bpl next ; 2 cyc beq high_half
bpl increment
bmi next
; check sign bit high_half:
lda arg + 3 ; 3 cyc lda arg
bpl positive ; 2 cyc beq check_sign
bpl increment
bmi next
negative: ; 13-18 cyc check_sign:
lda arg + 2 ; 3 cyc lda arg + 3
bne no_carry ; 2 cyc bmi next
dec arg + 3 ; 5 cyc
no_carry:
dec arg + 2 ; 5 cyc
jmp next ; 3 cyc
positive: ; 5-10 cyc increment: ; 5-10 cyc
inc arg + 2 ; 5 cyc inc arg + 2 ; 5 cyc
bne next ; 2 cyc bne next ; 2 cyc
inc arg + 3 ; 5 cyc inc arg + 3 ; 5 cyc