Adjust rounding, loop exits
Still slight differences between positive and negative Y halves Not sure what's wrong
This commit is contained in:
parent
b6ddc0d50e
commit
76715a6151
1 changed files with 39 additions and 32 deletions
71
mandel.s
71
mandel.s
|
@ -359,48 +359,38 @@ positive_result:
|
|||
|
||||
.macro round16 arg
|
||||
; Round top 16 bits of 32-bit fixed-point number in-place
|
||||
.local zero
|
||||
.local one
|
||||
.local positive
|
||||
.local negative
|
||||
.local neg2
|
||||
.local increment
|
||||
.local next
|
||||
|
||||
; no round - 5 cycles
|
||||
; round pos, no carry - 17
|
||||
; round pos, carry - 22
|
||||
; round neg, no carry - 23
|
||||
; round neg, carry - 28
|
||||
; average = 5 / 2 + (17 + 22 + 23 + 28) / 8
|
||||
; = 5 / 2 + 90 / 8
|
||||
; = 2.5 + 11.25 = 13.75 cycles average on evenly distributed input
|
||||
; positive input:
|
||||
; 0 rounds down, no change - 10 cyc
|
||||
; 1 rounds up, add one - 17-22 cyc
|
||||
; negative input:
|
||||
; 0 rounds up, add one - 19-24 cyc
|
||||
; 1 rounds down, no change - 10 cyc
|
||||
|
||||
lda arg + 1 ; 3 cyc
|
||||
bpl zero ; 2 cyc
|
||||
|
||||
one:
|
||||
; check sign bit
|
||||
lda arg + 3 ; 3 cyc
|
||||
bpl positive ; 2 cyc
|
||||
|
||||
negative:
|
||||
lda arg + 2 ; 3 cyc
|
||||
beq neg2 ; 2 cyc
|
||||
|
||||
dec arg + 2 ; 5 cyc
|
||||
jmp next ; 3 cyc
|
||||
|
||||
neg2:
|
||||
dec arg + 2 ; 5 cyc
|
||||
dec arg + 3 ; 5 cyc
|
||||
jmp next ; 3 cyc
|
||||
; check 16th bit down
|
||||
lda arg + 1 ; 3 cyc
|
||||
bmi next ; 2 cyc
|
||||
bpl increment ; 2 cyc
|
||||
|
||||
positive:
|
||||
; check 16th bit down
|
||||
lda arg + 1 ; 3 cyc
|
||||
bpl next ; 2 cyc
|
||||
|
||||
increment:
|
||||
inc arg + 2 ; 5 cyc
|
||||
bne next ; 2 cyc
|
||||
inc arg + 3 ; 5 cyc
|
||||
|
||||
zero:
|
||||
next:
|
||||
|
||||
.endmacro
|
||||
|
@ -435,17 +425,34 @@ loop:
|
|||
keep_going:
|
||||
|
||||
.macro quick_exit arg, max
|
||||
.local keep_going
|
||||
.local keep_going2
|
||||
.local positive
|
||||
.local negative
|
||||
.local nope_out
|
||||
.local first_equal
|
||||
.local all_done
|
||||
|
||||
; check sign bit
|
||||
lda arg + 1
|
||||
bmi negative
|
||||
|
||||
positive:
|
||||
cmp #((max) << 4)
|
||||
bmi keep_going
|
||||
bmi all_done ; 'less than'
|
||||
rts
|
||||
keep_going:
|
||||
|
||||
negative:
|
||||
cmp #(256 - ((max) << 4))
|
||||
bpl keep_going2
|
||||
beq first_equal ; 'equal' on first byte
|
||||
bpl all_done ; 'greater than'
|
||||
|
||||
nope_out:
|
||||
rts
|
||||
keep_going2:
|
||||
|
||||
first_equal:
|
||||
lda arg
|
||||
beq nope_out ; 2nd byte 0 shows it's really 'equal'
|
||||
|
||||
all_done:
|
||||
.endmacro
|
||||
|
||||
; 4.12: (-8 .. +7.9)
|
||||
|
|
Loading…
Reference in a new issue