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
|
.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 zero
|
|
||||||
.local one
|
|
||||||
.local positive
|
.local positive
|
||||||
.local negative
|
.local negative
|
||||||
.local neg2
|
.local increment
|
||||||
.local next
|
.local next
|
||||||
|
|
||||||
; no round - 5 cycles
|
; positive input:
|
||||||
; round pos, no carry - 17
|
; 0 rounds down, no change - 10 cyc
|
||||||
; round pos, carry - 22
|
; 1 rounds up, add one - 17-22 cyc
|
||||||
; round neg, no carry - 23
|
; negative input:
|
||||||
; round neg, carry - 28
|
; 0 rounds up, add one - 19-24 cyc
|
||||||
; average = 5 / 2 + (17 + 22 + 23 + 28) / 8
|
; 1 rounds down, no change - 10 cyc
|
||||||
; = 5 / 2 + 90 / 8
|
|
||||||
; = 2.5 + 11.25 = 13.75 cycles average on evenly distributed input
|
|
||||||
|
|
||||||
lda arg + 1 ; 3 cyc
|
|
||||||
bpl zero ; 2 cyc
|
|
||||||
|
|
||||||
one:
|
|
||||||
; check sign bit
|
; check sign bit
|
||||||
lda arg + 3 ; 3 cyc
|
lda arg + 3 ; 3 cyc
|
||||||
bpl positive ; 2 cyc
|
bpl positive ; 2 cyc
|
||||||
|
|
||||||
negative:
|
negative:
|
||||||
lda arg + 2 ; 3 cyc
|
; check 16th bit down
|
||||||
beq neg2 ; 2 cyc
|
lda arg + 1 ; 3 cyc
|
||||||
|
bmi next ; 2 cyc
|
||||||
dec arg + 2 ; 5 cyc
|
bpl increment ; 2 cyc
|
||||||
jmp next ; 3 cyc
|
|
||||||
|
|
||||||
neg2:
|
|
||||||
dec arg + 2 ; 5 cyc
|
|
||||||
dec arg + 3 ; 5 cyc
|
|
||||||
jmp next ; 3 cyc
|
|
||||||
|
|
||||||
positive:
|
positive:
|
||||||
|
; check 16th bit down
|
||||||
|
lda arg + 1 ; 3 cyc
|
||||||
|
bpl next ; 2 cyc
|
||||||
|
|
||||||
|
increment:
|
||||||
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
|
||||||
|
|
||||||
zero:
|
|
||||||
next:
|
next:
|
||||||
|
|
||||||
.endmacro
|
.endmacro
|
||||||
|
@ -435,17 +425,34 @@ loop:
|
||||||
keep_going:
|
keep_going:
|
||||||
|
|
||||||
.macro quick_exit arg, max
|
.macro quick_exit arg, max
|
||||||
.local keep_going
|
.local positive
|
||||||
.local keep_going2
|
.local negative
|
||||||
|
.local nope_out
|
||||||
|
.local first_equal
|
||||||
|
.local all_done
|
||||||
|
|
||||||
|
; check sign bit
|
||||||
lda arg + 1
|
lda arg + 1
|
||||||
|
bmi negative
|
||||||
|
|
||||||
|
positive:
|
||||||
cmp #((max) << 4)
|
cmp #((max) << 4)
|
||||||
bmi keep_going
|
bmi all_done ; 'less than'
|
||||||
rts
|
rts
|
||||||
keep_going:
|
|
||||||
|
negative:
|
||||||
cmp #(256 - ((max) << 4))
|
cmp #(256 - ((max) << 4))
|
||||||
bpl keep_going2
|
beq first_equal ; 'equal' on first byte
|
||||||
|
bpl all_done ; 'greater than'
|
||||||
|
|
||||||
|
nope_out:
|
||||||
rts
|
rts
|
||||||
keep_going2:
|
|
||||||
|
first_equal:
|
||||||
|
lda arg
|
||||||
|
beq nope_out ; 2nd byte 0 shows it's really 'equal'
|
||||||
|
|
||||||
|
all_done:
|
||||||
.endmacro
|
.endmacro
|
||||||
|
|
||||||
; 4.12: (-8 .. +7.9)
|
; 4.12: (-8 .. +7.9)
|
||||||
|
|
Loading…
Reference in a new issue