prog8/compiler/test/comparisons/optimized_compares.p8

340 lines
6.4 KiB
Plaintext
Raw Normal View History

2023-08-12 11:42:24 +00:00
%import textio
%zeropage basicsafe
main {
sub start() {
greater()
greater_signed()
less()
less_signed()
greatereq()
greatereq_signed()
lesseq()
lesseq_signed()
}
sub value(ubyte arg) -> ubyte {
cx16.r0++
return arg
}
sub svalue(byte arg) -> byte {
cx16.r0++
return arg
}
sub greater () {
2024-02-21 16:04:39 +00:00
ubyte @shared b1 = 10
ubyte @shared b2 = 20
ubyte @shared b3 = 10
2023-08-12 11:42:24 +00:00
txt.print(">(u): 101010: ")
2024-02-21 16:04:39 +00:00
bool xx
2023-08-12 11:42:24 +00:00
xx = b2>10
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>20
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>b1
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b3>b1
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>value(10)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b3>value(20)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
txt.nl()
}
sub greater_signed () {
2024-02-21 16:04:39 +00:00
byte @shared b1 = -20
byte @shared b2 = -10
byte @shared b3 = -20
2023-08-12 11:42:24 +00:00
txt.print(">(s): 101010: ")
2024-02-21 16:04:39 +00:00
bool xx
2023-08-12 11:42:24 +00:00
xx = b2 > -20
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2 > -10
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>b1
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b3>b1
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>svalue(-20)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b3>svalue(-10)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
txt.nl()
}
sub less () {
2024-02-21 16:04:39 +00:00
ubyte @shared b1 = 20
ubyte @shared b2 = 10
ubyte @shared b3 = 20
2023-08-12 11:42:24 +00:00
txt.print("<(u): 101010: ")
2024-02-21 16:04:39 +00:00
bool xx
2023-08-12 11:42:24 +00:00
xx = b2<20
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<10
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<b1
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b3<b1
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<value(20)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<value(10)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
txt.nl()
}
sub less_signed () {
2024-02-21 16:04:39 +00:00
byte @shared b1 = -10
byte @shared b2 = -20
byte @shared b3 = -10
2023-08-12 11:42:24 +00:00
txt.print("<(s): 101010: ")
2024-02-21 16:04:39 +00:00
bool xx
2023-08-12 11:42:24 +00:00
xx = b2 < -10
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2 < -20
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<b1
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b3<b1
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<svalue(-10)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b3<svalue(-20)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
txt.nl()
}
sub greatereq () {
2024-02-21 16:04:39 +00:00
ubyte @shared b1 = 19
ubyte @shared b2 = 20
ubyte @shared b3 = 21
ubyte @shared b4 = 20
2023-08-12 11:42:24 +00:00
txt.print(">=(u): 110110110: ")
2024-02-21 16:04:39 +00:00
bool xx
2023-08-12 11:42:24 +00:00
xx = b2>=19
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>=20
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>=21
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>=b1
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>=b4
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>=b3
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>=value(19)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>=value(20)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>=value(21)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
txt.nl()
}
sub greatereq_signed () {
2024-02-21 16:04:39 +00:00
byte @shared b1 = -19
byte @shared b2 = -20
byte @shared b3 = -21
byte @shared b4 = -20
2023-08-12 11:42:24 +00:00
txt.print(">=(s): 011011011: ")
2024-02-21 16:04:39 +00:00
bool xx
2023-08-12 11:42:24 +00:00
xx = b2>= -19
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>= -20
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>= -21
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>=b1
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>=b4
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>=b3
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>=svalue(-19)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>=svalue(-20)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2>=svalue(-21)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
txt.nl()
}
sub lesseq () {
2024-02-21 16:04:39 +00:00
ubyte @shared b1 = 19
ubyte @shared b2 = 20
ubyte @shared b3 = 21
ubyte @shared b4 = 20
2023-08-12 11:42:24 +00:00
txt.print("<=(u): 011011011: ")
2024-02-21 16:04:39 +00:00
bool xx
2023-08-12 11:42:24 +00:00
xx = b2<=19
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<=20
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<=21
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<=b1
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<=b4
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<=b3
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<=value(19)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<=value(20)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<=value(21)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
txt.nl()
}
sub lesseq_signed () {
2024-02-21 16:04:39 +00:00
byte @shared b1 = -19
byte @shared b2 = -20
byte @shared b3 = -21
byte @shared b4 = -20
2023-08-12 11:42:24 +00:00
txt.print("<=(s): 110110110: ")
2024-02-21 16:04:39 +00:00
bool xx
2023-08-12 11:42:24 +00:00
xx = b2<= -19
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<= -20
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<= -21
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<=b1
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<=b4
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<=b3
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<=svalue(-19)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<=svalue(-20)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
xx = b2<=svalue(-21)
2024-02-21 16:04:39 +00:00
txt.print_ub(xx as ubyte)
2023-08-12 11:42:24 +00:00
txt.spc()
txt.nl()
}
}