optimized reg_lesseq_w (word <= word)

This commit is contained in:
Irmen de Jong 2020-11-30 02:12:49 +01:00
parent 05d3a2450c
commit b8bda867b6
2 changed files with 240 additions and 15 deletions

View File

@ -554,28 +554,23 @@ lesseq_uw .proc
reg_lesseq_w .proc
; -- AY <= P8ZP_SCRATCH_W2?
sta P8ZP_SCRATCH_B1
tya
sec
sbc P8ZP_SCRATCH_W2+1
; TODO can we reverse this comparison and not use zeropage storage?
sta P8ZP_SCRATCH_W1
sty P8ZP_SCRATCH_W1+1
lda P8ZP_SCRATCH_W2
cmp P8ZP_SCRATCH_W1
lda P8ZP_SCRATCH_W2+1
sbc P8ZP_SCRATCH_W1+1
bvc +
eor #$80
+ bmi _true
bvc +
eor #$80
+ bne _false
lda P8ZP_SCRATCH_B1
sbc P8ZP_SCRATCH_W2
beq _true ; TODO is this correct word compare <= for all cases?
bcs _false
_true lda #1
+ bpl _true
lda #0
rts
_false lda #0
_true lda #1
rts
.pend
lesseq_w .proc
; TODO is this word compare <= correct? it is different from reg_lesseq_w
lda P8ESTACK_LO+1,x
cmp P8ESTACK_LO+2,x
lda P8ESTACK_HI+1,x
@ -657,6 +652,7 @@ greatereq_uw .proc
.pend
greatereq_w .proc
; TODO IS THIS CORRECT???
lda P8ESTACK_LO+2,x
cmp P8ESTACK_LO+1,x
lda P8ESTACK_HI+2,x

View File

@ -7,9 +7,184 @@ main {
sub start() {
; word_less()
word_lessequal()
}
sub word_lessequal() {
word lessvar
word comparevar
txt.print("word <=\n")
comparevar = 0
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in comparevar downto -32768 {
check_lesseq_w(lessvar, comparevar)
}
comparevar = -2
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in comparevar downto -32768 {
check_lesseq_w(lessvar, comparevar)
}
comparevar = -254
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in comparevar downto -32768 {
check_lesseq_w(lessvar, comparevar)
}
comparevar = -255
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in comparevar downto -32768 {
check_lesseq_w(lessvar, comparevar)
}
comparevar = -256
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in comparevar downto -32768 {
check_lesseq_w(lessvar, comparevar)
}
comparevar = -5000
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in comparevar downto -32768 {
check_lesseq_w(lessvar, comparevar)
}
comparevar = 1
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in comparevar downto -32768 {
check_lesseq_w(lessvar, comparevar)
}
comparevar = 255
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in comparevar downto -32768 {
check_lesseq_w(lessvar, comparevar)
}
comparevar = 256
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in comparevar downto -32768 {
check_lesseq_w(lessvar, comparevar)
}
comparevar = 257
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in comparevar downto -32768 {
check_lesseq_w(lessvar, comparevar)
}
comparevar = 32767
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in comparevar downto -32768 {
check_lesseq_w(lessvar, comparevar)
}
comparevar = -32768
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in 32766 downto comparevar+1 {
check_not_lesseq_w(lessvar, comparevar)
}
comparevar = -1
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in 32766 downto comparevar+1 {
check_not_lesseq_w(lessvar, comparevar)
}
comparevar = 0
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in 32766 downto comparevar+1 {
check_not_lesseq_w(lessvar, comparevar)
}
comparevar = 11111
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in 32766 downto comparevar+1 {
check_not_lesseq_w(lessvar, comparevar)
}
test_stack.test()
return
sub check_lesseq_w(word w1, word w2) {
word zero = 0
ubyte error=0
ubyte ub = w1<=w2
if not ub {
error++
txt.print("ub!")
}
if w1<=(w2+zero) {
zero = 0 ; dummy
} else {
error++
txt.print("c!")
}
if error {
txt.print(" ")
txt.print_w(w1)
txt.print(" <= ")
txt.print_w(w2)
txt.chrout('\n')
exit(1)
}
}
sub check_not_lesseq_w(word w1, word w2) {
word zero = 0
ubyte error=0
ubyte ub = w1<=w2
if ub {
error++
txt.print("ub!")
}
if w1<=(w2+zero) {
error++
txt.print("c!")
} else {
zero = 0 ; dummy
}
if error {
txt.print(" ")
txt.print_w(w1)
txt.print(" not <= ")
txt.print_w(w2)
txt.chrout('\n')
exit(1)
}
}
}
sub word_less() {
word lessvar
word comparevar
txt.print("word <\n")
comparevar = 0
txt.print_w(comparevar)
txt.chrout('\n')
@ -87,6 +262,33 @@ main {
check_less_w(lessvar, comparevar)
}
comparevar = -32768
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in 32766 downto -32768 {
check_not_less_w(lessvar, comparevar)
}
comparevar = -1
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in 32766 downto -1 {
check_not_less_w(lessvar, comparevar)
}
comparevar = 0
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in 32766 downto 0 {
check_not_less_w(lessvar, comparevar)
}
comparevar = 11111
txt.print_w(comparevar)
txt.chrout('\n')
for lessvar in 32766 downto 11111 {
check_not_less_w(lessvar, comparevar)
}
test_stack.test()
return
@ -117,6 +319,33 @@ main {
exit(1)
}
}
sub check_not_less_w(word w1, word w2) {
word zero = 0
ubyte error=0
ubyte ub = w1<w2
if ub {
error++
txt.print("ub!")
}
if w1<(w2+zero) {
error++
txt.print("c!")
} else {
zero = 0 ; dummy
}
if error {
txt.print(" ")
txt.print_w(w1)
txt.print(" not < ")
txt.print_w(w2)
txt.chrout('\n')
exit(1)
}
}
}
}