diff --git a/compiler/res/prog8lib/prog8_lib.asm b/compiler/res/prog8lib/prog8_lib.asm index 96cd107e5..47b410a27 100644 --- a/compiler/res/prog8lib/prog8_lib.asm +++ b/compiler/res/prog8lib/prog8_lib.asm @@ -552,20 +552,16 @@ lesseq_uw .proc .pend reg_lesseq_w .proc - ; -- AY <= P8ZP_SCRATCH_W2? - ; 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 + ; -- P8ZP_SCRATCH_W2 <= AY ? (note: order different from other routines) + cmp P8ZP_SCRATCH_W2 + tya + sbc P8ZP_SCRATCH_W2+1 bvc + eor #$80 -+ bpl _true ++ bpl + lda #0 rts -_true lda #1 ++ lda #1 rts .pend diff --git a/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt index 664718ac3..9f528605c 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt @@ -789,8 +789,8 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge } } - asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null) - asmgen.assignExpressionToRegister(left, RegisterOrPair.AY) + asmgen.assignExpressionToVariable(left, "P8ZP_SCRATCH_W2", DataType.UWORD, null) + asmgen.assignExpressionToRegister(right, RegisterOrPair.AY) asmgen.out(" jsr prog8_lib.reg_lesseq_w | beq $jumpIfFalseLabel") } @@ -916,8 +916,8 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge } } - asmgen.assignExpressionToVariable(left, "P8ZP_SCRATCH_W2", DataType.UWORD, null) - asmgen.assignExpressionToRegister(right, RegisterOrPair.AY) + asmgen.assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null) + asmgen.assignExpressionToRegister(left, RegisterOrPair.AY) asmgen.out(" jsr prog8_lib.reg_lesseq_w | beq $jumpIfFalseLabel") } diff --git a/examples/cmp/word_comps.p8 b/examples/cmp/word_comps.p8 new file mode 100644 index 000000000..d3658d304 --- /dev/null +++ b/examples/cmp/word_comps.p8 @@ -0,0 +1,913 @@ +%import textio +%import floats +%zeropage basicsafe +%import test_stack + +main { + + sub start() { + word_less() + word_lessequal() + word_greaterequal() + word_greater() + uword_lessequal() + } + + sub uword_lessequal() { + uword lessvar + uword comparevar + + txt.print("uword <=\n") + + txt.print_uw(65535) + txt.chrout('\n') + check_lesseq_uw(0, 65535) + txt.print_uw(0) + txt.chrout('\n') + check_not_lesseq_uw(65535, 0) + + comparevar = 65535 + txt.print_uw(comparevar) + txt.chrout('\n') + for lessvar in comparevar downto 0 { + check_lesseq_uw(lessvar, comparevar) + } + + comparevar = 65535-2 + txt.print_uw(comparevar) + txt.chrout('\n') + for lessvar in comparevar downto 0 { + check_lesseq_uw(lessvar, comparevar) + } + + comparevar = 65535-254 + txt.print_uw(comparevar) + txt.chrout('\n') + for lessvar in comparevar downto 0 { + check_lesseq_uw(lessvar, comparevar) + } + + comparevar = 65535-255 + txt.print_uw(comparevar) + txt.chrout('\n') + for lessvar in comparevar downto 0 { + check_lesseq_uw(lessvar, comparevar) + } + + comparevar = 65535-256 + txt.print_uw(comparevar) + txt.chrout('\n') + for lessvar in comparevar downto 0 { + check_lesseq_uw(lessvar, comparevar) + } + + comparevar = 65535-5000 + txt.print_uw(comparevar) + txt.chrout('\n') + for lessvar in comparevar downto 0 { + check_lesseq_uw(lessvar, comparevar) + } + + comparevar = 32769 + txt.print_uw(comparevar) + txt.chrout('\n') + for lessvar in comparevar downto 0 { + check_lesseq_uw(lessvar, comparevar) + } + + + comparevar = 32768 + txt.print_uw(comparevar) + txt.chrout('\n') + for lessvar in 65535 downto comparevar+1 { + check_not_lesseq_uw(lessvar, comparevar) + } + + comparevar = 1 + txt.print_uw(comparevar) + txt.chrout('\n') + for lessvar in 65535 downto comparevar+1 { + check_not_lesseq_uw(lessvar, comparevar) + } + + comparevar = 0 + txt.print_uw(comparevar) + txt.chrout('\n') + for lessvar in 65535 downto comparevar+1 { + check_not_lesseq_uw(lessvar, comparevar) + } + + comparevar = 11111 + txt.print_uw(comparevar) + txt.chrout('\n') + for lessvar in 65535 downto comparevar+1 { + check_not_lesseq_uw(lessvar, comparevar) + } + + comparevar = 255 + txt.print_uw(comparevar) + txt.chrout('\n') + for lessvar in 65535 downto comparevar+1 { + check_not_lesseq_uw(lessvar, comparevar) + } + + comparevar = 256 + txt.print_uw(comparevar) + txt.chrout('\n') + for lessvar in 65535 downto comparevar+1 { + check_not_lesseq_uw(lessvar, comparevar) + } + + + test_stack.test() + return + + sub check_lesseq_uw(uword w1, uword w2) { + uword 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_uw(w1) + txt.print(" <= ") + txt.print_uw(w2) + txt.chrout('\n') + exit(1) + } + } + + sub check_not_lesseq_uw(uword w1, uword w2) { + uword 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_uw(w1) + txt.print(" not <= ") + txt.print_uw(w2) + txt.chrout('\n') + exit(1) + } + } + } + + sub word_greater() { + word biggervar + word comparevar + + txt.print("word >\n") + + txt.print_w(-32767) + txt.chrout('\n') + check_greater_w(32767, -32767) + txt.print_w(32766) + txt.chrout('\n') + check_not_greater_w(-32766, 32766) + + comparevar = 32765 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in comparevar downto -32768 { + check_not_greater_w(biggervar, comparevar) + } + + comparevar = -1 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in comparevar downto -32768 { + check_not_greater_w(biggervar, comparevar) + } + + comparevar = 0 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in comparevar downto -32768 { + check_not_greater_w(biggervar, comparevar) + } + + comparevar = 11111 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in comparevar downto -32768 { + check_not_greater_w(biggervar, comparevar) + } + + comparevar = 0 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar+1 { + check_greater_w(biggervar, comparevar) + } + + comparevar = -2 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar+1 { + check_greater_w(biggervar, comparevar) + } + + comparevar = -254 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar+1 { + check_greater_w(biggervar, comparevar) + } + + comparevar = -255 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar+1 { + check_greater_w(biggervar, comparevar) + } + + comparevar = -256 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar+1 { + check_greater_w(biggervar, comparevar) + } + + comparevar = -5000 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar+1 { + check_greater_w(biggervar, comparevar) + } + + comparevar = 1 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar+1 { + check_greater_w(biggervar, comparevar) + } + + comparevar = 255 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar+1 { + check_greater_w(biggervar, comparevar) + } + + comparevar = 256 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar+1 { + check_greater_w(biggervar, comparevar) + } + + comparevar = 257 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar+1 { + check_greater_w(biggervar, comparevar) + } + + comparevar = 32760 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar+1 { + check_greater_w(biggervar, comparevar) + } + + + test_stack.test() + return + + sub check_greater_w(word w1, word w2) { + word zero = 0 + ubyte error=0 + + ubyte ub = w1>(w2+zero) + if not ub { + error++ + txt.print("ubz!") + } + + 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_greater_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 w1>w2 { + error++ + txt.print("c2!") + } 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_greaterequal() { + word biggervar + word comparevar + + txt.print("word >=\n") + + txt.print_w(-32767) + txt.chrout('\n') + check_greatereq_w(32767, -32767) + txt.print_w(32766) + txt.chrout('\n') + check_not_greatereq_w(-32766, 32766) + + comparevar = 32765 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in comparevar-1 downto -32768 { + check_not_greatereq_w(biggervar, comparevar) + } + + comparevar = -1 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in comparevar-1 downto -32768 { + check_not_greatereq_w(biggervar, comparevar) + } + + comparevar = 0 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in comparevar-1 downto -32768 { + check_not_greatereq_w(biggervar, comparevar) + } + + comparevar = 11111 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in comparevar-1 downto -32768 { + check_not_greatereq_w(biggervar, comparevar) + } + + comparevar = 0 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar { + check_greatereq_w(biggervar, comparevar) + } + + comparevar = -2 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar { + check_greatereq_w(biggervar, comparevar) + } + + comparevar = -254 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar { + check_greatereq_w(biggervar, comparevar) + } + + comparevar = -255 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar { + check_greatereq_w(biggervar, comparevar) + } + + comparevar = -256 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar { + check_greatereq_w(biggervar, comparevar) + } + + comparevar = -5000 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar { + check_greatereq_w(biggervar, comparevar) + } + + comparevar = 1 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar { + check_greatereq_w(biggervar, comparevar) + } + + comparevar = 255 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar { + check_greatereq_w(biggervar, comparevar) + } + + comparevar = 256 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar { + check_greatereq_w(biggervar, comparevar) + } + + comparevar = 257 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar { + check_greatereq_w(biggervar, comparevar) + } + + comparevar = 32767 + txt.print_w(comparevar) + txt.chrout('\n') + for biggervar in 32767 downto comparevar { + check_greatereq_w(biggervar, comparevar) + } + + + test_stack.test() + return + + sub check_greatereq_w(word w1, word w2) { + word zero = 0 + ubyte error=0 + + ubyte ub = w1>=(w2+zero) + if not ub { + error++ + txt.print("ubz!") + } + + 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_greatereq_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 w1>=w2 { + error++ + txt.print("c2!") + } 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_lessequal() { + word lessvar + word comparevar + + txt.print("word <=\n") + + txt.print_w(32767) + txt.chrout('\n') + check_lesseq_w(-32767, 32767) + txt.print_w(-32767) + txt.chrout('\n') + check_not_lesseq_w(32767, -32767) + + 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") + + txt.print_w(32767) + txt.chrout('\n') + check_less_w(-32767, 32767) + txt.print_w(-32767) + txt.chrout('\n') + check_not_less_w(32767, -32767) + + comparevar = 0 + txt.print_w(comparevar) + txt.chrout('\n') + for lessvar in -1 downto -32768 { + check_less_w(lessvar, comparevar) + } + + comparevar = -2 + txt.print_w(comparevar) + txt.chrout('\n') + for lessvar in -3 downto -32768 { + check_less_w(lessvar, comparevar) + } + + comparevar = -254 + txt.print_w(comparevar) + txt.chrout('\n') + for lessvar in -255 downto -32768 { + check_less_w(lessvar, comparevar) + } + + comparevar = -255 + txt.print_w(comparevar) + txt.chrout('\n') + for lessvar in -256 downto -32768 { + check_less_w(lessvar, comparevar) + } + + comparevar = -256 + txt.print_w(comparevar) + txt.chrout('\n') + for lessvar in -257 downto -32768 { + check_less_w(lessvar, comparevar) + } + + comparevar = -5000 + txt.print_w(comparevar) + txt.chrout('\n') + for lessvar in -5001 downto -32768 { + check_less_w(lessvar, comparevar) + } + + comparevar = 1 + txt.print_w(comparevar) + txt.chrout('\n') + for lessvar in 0 downto -32768 { + check_less_w(lessvar, comparevar) + } + + comparevar = 255 + txt.print_w(comparevar) + txt.chrout('\n') + for lessvar in 254 downto -32768 { + check_less_w(lessvar, comparevar) + } + + comparevar = 256 + txt.print_w(comparevar) + txt.chrout('\n') + for lessvar in 255 downto -32768 { + check_less_w(lessvar, comparevar) + } + + comparevar = 257 + txt.print_w(comparevar) + txt.chrout('\n') + for lessvar in 256 downto -32768 { + check_less_w(lessvar, comparevar) + } + + comparevar = 32767 + txt.print_w(comparevar) + txt.chrout('\n') + for lessvar in 32766 downto -32768 { + 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 + + sub check_less_w(word w1, word w2) { + word zero = 0 + ubyte error=0 + + ubyte ub = w1\n") - - txt.print_w(-32767) - txt.chrout('\n') - check_greater_w(32767, -32767) - txt.print_w(32766) - txt.chrout('\n') - check_not_greater_w(-32766, 32766) - - comparevar = 32765 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in comparevar downto -32768 { - check_not_greater_w(biggervar, comparevar) - } - - comparevar = -1 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in comparevar downto -32768 { - check_not_greater_w(biggervar, comparevar) - } - - comparevar = 0 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in comparevar downto -32768 { - check_not_greater_w(biggervar, comparevar) - } - - comparevar = 11111 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in comparevar downto -32768 { - check_not_greater_w(biggervar, comparevar) - } - - comparevar = 0 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar+1 { - check_greater_w(biggervar, comparevar) - } - - comparevar = -2 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar+1 { - check_greater_w(biggervar, comparevar) - } - - comparevar = -254 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar+1 { - check_greater_w(biggervar, comparevar) - } - - comparevar = -255 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar+1 { - check_greater_w(biggervar, comparevar) - } - - comparevar = -256 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar+1 { - check_greater_w(biggervar, comparevar) - } - - comparevar = -5000 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar+1 { - check_greater_w(biggervar, comparevar) - } - - comparevar = 1 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar+1 { - check_greater_w(biggervar, comparevar) - } - - comparevar = 255 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar+1 { - check_greater_w(biggervar, comparevar) - } - - comparevar = 256 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar+1 { - check_greater_w(biggervar, comparevar) - } - - comparevar = 257 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar+1 { - check_greater_w(biggervar, comparevar) - } - - comparevar = 32760 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar+1 { - check_greater_w(biggervar, comparevar) - } - - - test_stack.test() - return - - sub check_greater_w(word w1, word w2) { - word zero = 0 - ubyte error=0 - - ubyte ub = w1>(w2+zero) - if not ub { - error++ - txt.print("ubz!") - } - - 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_greater_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 w1>w2 { - error++ - txt.print("c2!") - } 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_greaterequal() { - word biggervar - word comparevar - - txt.print("word >=\n") - - txt.print_w(-32767) - txt.chrout('\n') - check_greatereq_w(32767, -32767) - txt.print_w(32766) - txt.chrout('\n') - check_not_greatereq_w(-32766, 32766) - - comparevar = 32765 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in comparevar-1 downto -32768 { - check_not_greatereq_w(biggervar, comparevar) - } - - comparevar = -1 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in comparevar-1 downto -32768 { - check_not_greatereq_w(biggervar, comparevar) - } - - comparevar = 0 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in comparevar-1 downto -32768 { - check_not_greatereq_w(biggervar, comparevar) - } - - comparevar = 11111 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in comparevar-1 downto -32768 { - check_not_greatereq_w(biggervar, comparevar) - } - - comparevar = 0 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar { - check_greatereq_w(biggervar, comparevar) - } - - comparevar = -2 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar { - check_greatereq_w(biggervar, comparevar) - } - - comparevar = -254 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar { - check_greatereq_w(biggervar, comparevar) - } - - comparevar = -255 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar { - check_greatereq_w(biggervar, comparevar) - } - - comparevar = -256 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar { - check_greatereq_w(biggervar, comparevar) - } - - comparevar = -5000 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar { - check_greatereq_w(biggervar, comparevar) - } - - comparevar = 1 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar { - check_greatereq_w(biggervar, comparevar) - } - - comparevar = 255 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar { - check_greatereq_w(biggervar, comparevar) - } - - comparevar = 256 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar { - check_greatereq_w(biggervar, comparevar) - } - - comparevar = 257 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar { - check_greatereq_w(biggervar, comparevar) - } - - comparevar = 32767 - txt.print_w(comparevar) - txt.chrout('\n') - for biggervar in 32767 downto comparevar { - check_greatereq_w(biggervar, comparevar) - } - - - test_stack.test() - return - - sub check_greatereq_w(word w1, word w2) { - word zero = 0 - ubyte error=0 - - ubyte ub = w1>=(w2+zero) - if not ub { - error++ - txt.print("ubz!") - } - - 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_greatereq_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 w1>=w2 { - error++ - txt.print("c2!") - } 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_lessequal() { - word lessvar - word comparevar - - txt.print("word <=\n") - - txt.print_w(32767) - txt.chrout('\n') - check_lesseq_w(-32767, 32767) - txt.print_w(-32767) - txt.chrout('\n') - check_not_lesseq_w(32767, -32767) - - 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") - - txt.print_w(32767) - txt.chrout('\n') - check_less_w(-32767, 32767) - txt.print_w(-32767) - txt.chrout('\n') - check_not_less_w(32767, -32767) - - comparevar = 0 - txt.print_w(comparevar) - txt.chrout('\n') - for lessvar in -1 downto -32768 { - check_less_w(lessvar, comparevar) - } - - comparevar = -2 - txt.print_w(comparevar) - txt.chrout('\n') - for lessvar in -3 downto -32768 { - check_less_w(lessvar, comparevar) - } - - comparevar = -254 - txt.print_w(comparevar) - txt.chrout('\n') - for lessvar in -255 downto -32768 { - check_less_w(lessvar, comparevar) - } - - comparevar = -255 - txt.print_w(comparevar) - txt.chrout('\n') - for lessvar in -256 downto -32768 { - check_less_w(lessvar, comparevar) - } - - comparevar = -256 - txt.print_w(comparevar) - txt.chrout('\n') - for lessvar in -257 downto -32768 { - check_less_w(lessvar, comparevar) - } - - comparevar = -5000 - txt.print_w(comparevar) - txt.chrout('\n') - for lessvar in -5001 downto -32768 { - check_less_w(lessvar, comparevar) - } - - comparevar = 1 - txt.print_w(comparevar) - txt.chrout('\n') - for lessvar in 0 downto -32768 { - check_less_w(lessvar, comparevar) - } - - comparevar = 255 - txt.print_w(comparevar) - txt.chrout('\n') - for lessvar in 254 downto -32768 { - check_less_w(lessvar, comparevar) - } - - comparevar = 256 - txt.print_w(comparevar) - txt.chrout('\n') - for lessvar in 255 downto -32768 { - check_less_w(lessvar, comparevar) - } - - comparevar = 257 - txt.print_w(comparevar) - txt.chrout('\n') - for lessvar in 256 downto -32768 { - check_less_w(lessvar, comparevar) - } - - comparevar = 32767 - txt.print_w(comparevar) - txt.chrout('\n') - for lessvar in 32766 downto -32768 { - 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 - - sub check_less_w(word w1, word w2) { - word zero = 0 - ubyte error=0 - - ubyte ub = w1