fix faulty comparison optimization

This commit is contained in:
Irmen de Jong 2020-09-27 01:40:12 +02:00
parent 629222f103
commit 84c0685a60
6 changed files with 0 additions and 611 deletions

View File

@ -175,28 +175,6 @@ internal class ExpressionSimplifier(private val program: Program) : AstWalker()
// unsigned >= 0 --> true
return listOf(IAstModification.ReplaceNode(expr, NumericLiteralValue.fromBoolean(true, expr.position), parent))
}
when(leftDt) {
DataType.BYTE -> {
// signed >=0 --> signed ^ $80
return listOf(IAstModification.ReplaceNode(
expr,
BinaryExpression(expr.left, "^", NumericLiteralValue.optimalInteger(0x80, expr.position), expr.position),
parent
))
}
DataType.WORD -> {
// signedw >=0 --> msb(signedw) ^ $80
return listOf(IAstModification.ReplaceNode(
expr,
BinaryExpression(FunctionCall(IdentifierReference(listOf("msb"), expr.position),
mutableListOf(expr.left),
expr.position
), "^", NumericLiteralValue.optimalInteger(0x80, expr.position), expr.position),
parent
))
}
else -> {}
}
}
if(expr.operator == "<" && rightVal?.number == 0) {

View File

@ -1,95 +0,0 @@
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
sub start() {
byte v1
byte v2
ubyte cr
txt.print("signed byte ")
cr=v1==v2
cr=v1==v2
cr=v1==v2
cr=v1!=v2
cr=v1!=v2
cr=v1!=v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
; comparisons:
v1=-20
v2=125
txt.print("v1=-20, v2=125\n")
compare()
v1=80
v2=80
txt.print("v1 = v2 = 80\n")
compare()
v1=20
v2=-111
txt.print("v1=20, v2=-111\n")
compare()
return
sub compare() {
txt.print(" == != < > <= >=\n")
if v1==v2
txt.print(" Q ")
else
txt.print(" . ")
if v1!=v2
txt.print(" Q ")
else
txt.print(" . ")
if v1<v2
txt.print(" Q ")
else
txt.print(" . ")
if v1>v2
txt.print(" Q ")
else
txt.print(" . ")
if v1<=v2
txt.print(" Q ")
else
txt.print(" . ")
if v1>=v2
txt.print(" Q ")
else
txt.print(" . ")
c64.CHROUT('\n')
}
}
}

View File

@ -1,112 +0,0 @@
%import textio
%import floats
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
sub start() {
float v1
float v2
ubyte cr
txt.print("floating point ")
cr=v1==v2
cr=v1==v2
cr=v1==v2
cr=v1!=v2
cr=v1!=v2
cr=v1!=v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
; comparisons:
v1=20
v2=666.66
txt.print("v1=20, v2=666.66\n")
compare()
v1=-20
v2=666.66
txt.print("v1=-20, v2=666.66\n")
compare()
v1=666.66
v2=555.55
txt.print("v1=666.66, v2=555.55\n")
compare()
v1=3.1415
v2=-3.1415
txt.print("v1 = 3.1415, v2 = -3.1415\n")
compare()
v1=3.1415
v2=3.1415
txt.print("v1 = v2 = 3.1415\n")
compare()
v1=0
v2=0
txt.print("v1 = v2 = 0\n")
compare()
return
sub compare() {
txt.print(" == != < > <= >=\n")
if v1==v2
txt.print(" Q ")
else
txt.print(" . ")
if v1!=v2
txt.print(" Q ")
else
txt.print(" . ")
if v1<v2
txt.print(" Q ")
else
txt.print(" . ")
if v1>v2
txt.print(" Q ")
else
txt.print(" . ")
if v1<=v2
txt.print(" Q ")
else
txt.print(" . ")
if v1>=v2
txt.print(" Q ")
else
txt.print(" . ")
c64.CHROUT('\n')
}
}
}

View File

@ -1,96 +0,0 @@
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
sub start() {
ubyte v1
ubyte v2
ubyte cr
txt.print("unsigned byte ")
cr=v1==v2
cr=v1==v2
cr=v1==v2
cr=v1!=v2
cr=v1!=v2
cr=v1!=v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
; comparisons:
v1=20
v2=199
txt.print("v1=20, v2=199\n")
compare()
v1=80
v2=80
txt.print("v1 = v2 = 80\n")
compare()
v1=220
v2=10
txt.print("v1=220, v2=10\n")
compare()
return
sub compare() {
txt.print(" == != < > <= >=\n")
if v1==v2
txt.print(" Q ")
else
txt.print(" . ")
if v1!=v2
txt.print(" Q ")
else
txt.print(" . ")
if v1<v2
txt.print(" Q ")
else
txt.print(" . ")
if v1>v2
txt.print(" Q ")
else
txt.print(" . ")
if v1<=v2
txt.print(" Q ")
else
txt.print(" . ")
if v1>=v2
txt.print(" Q ")
else
txt.print(" . ")
c64.CHROUT('\n')
}
}
}

View File

@ -1,125 +0,0 @@
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
sub start() {
uword v1
uword v2
ubyte cr
txt.print("unsigned word ")
cr=v1==v2
cr=v1==v2
cr=v1==v2
cr=v1!=v2
cr=v1!=v2
cr=v1!=v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
; comparisons:
v1=20
v2=$00aa
txt.print("v1=20, v2=$00aa\n")
compare()
v1=20
v2=$ea00
txt.print("v1=20, v2=$ea00\n")
compare()
v1=$c400
v2=$22
txt.print("v1=$c400, v2=$22\n")
compare()
v1=$c400
v2=$2a00
txt.print("v1=$c400, v2=$2a00\n")
compare()
v1=$c433
v2=$2a00
txt.print("v1=$c433, v2=$2a00\n")
compare()
v1=$c433
v2=$2aff
txt.print("v1=$c433, v2=$2aff\n")
compare()
v1=$aabb
v2=$aabb
txt.print("v1 = v2 = aabb\n")
compare()
v1=$aa00
v2=$aa00
txt.print("v1 = v2 = aa00\n")
compare()
v1=$aa
v2=$aa
txt.print("v1 = v2 = aa\n")
compare()
return
sub compare() {
txt.print(" == != < > <= >=\n")
if v1==v2
txt.print(" Q ")
else
txt.print(" . ")
if v1!=v2
txt.print(" Q ")
else
txt.print(" . ")
if v1<v2
txt.print(" Q ")
else
txt.print(" . ")
if v1>v2
txt.print(" Q ")
else
txt.print(" . ")
if v1<=v2
txt.print(" Q ")
else
txt.print(" . ")
if v1>=v2
txt.print(" Q ")
else
txt.print(" . ")
c64.CHROUT('\n')
}
}
}

View File

@ -1,161 +0,0 @@
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
sub start() {
word v1
word v2
ubyte cr
txt.print("signed word ")
cr=v1==v2
cr=v1==v2
cr=v1==v2
cr=v1!=v2
cr=v1!=v2
cr=v1!=v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
; comparisons:
v1=20
v2=$00aa
txt.print("v1=20, v2=$00aa\n")
compare()
v1=20
v2=$7a00
txt.print("v1=20, v2=$7a00\n")
compare()
v1=$7400
v2=$22
txt.print("v1=$7400, v2=$22\n")
compare()
v1=$7400
v2=$2a00
txt.print("v1=$7400, v2=$2a00\n")
compare()
v1=$7433
v2=$2a00
txt.print("v1=$7433, v2=$2a00\n")
compare()
v1=$7433
v2=$2aff
txt.print("v1=$7433, v2=$2aff\n")
compare()
; with negative numbers:
v1=-512
v2=$00aa
txt.print("v1=-512, v2=$00aa\n")
compare()
v1=-512
v2=$7a00
txt.print("v1=-512, v2=$7a00\n")
compare()
v1=$7400
v2=-512
txt.print("v1=$7400, v2=-512\n")
compare()
v1=-20000
v2=-1000
txt.print("v1=-20000, v2=-1000\n")
compare()
v1=-1000
v2=-20000
txt.print("v1=-1000, v2=-20000\n")
compare()
v1=-1
v2=32767
txt.print("v1=-1, v2=32767\n")
compare()
v1=32767
v2=-1
txt.print("v1=32767, v2=-1\n")
compare()
v1=$7abb
v2=$7abb
txt.print("v1 = v2 = 7abb\n")
compare()
v1=$7a00
v2=$7a00
txt.print("v1 = v2 = 7a00\n")
compare()
v1=$aa
v2=$aa
txt.print("v1 = v2 = aa\n")
compare()
return
sub compare() {
txt.print(" == != < > <= >=\n")
if v1==v2
txt.print(" Q ")
else
txt.print(" . ")
if v1!=v2
txt.print(" Q ")
else
txt.print(" . ")
if v1<v2
txt.print(" Q ")
else
txt.print(" . ")
if v1>v2
txt.print(" Q ")
else
txt.print(" . ")
if v1<=v2
txt.print(" Q ")
else
txt.print(" . ")
if v1>=v2
txt.print(" Q ")
else
txt.print(" . ")
c64.CHROUT('\n')
}
}
}