mirror of
https://github.com/irmen/prog8.git
synced 2024-12-25 23:29:55 +00:00
optimized float var comparison without translateExpression()
This commit is contained in:
parent
49db10539a
commit
38d06a7e94
@ -447,6 +447,40 @@ notequal_f .proc
|
||||
rts
|
||||
.pend
|
||||
|
||||
vars_less_f .proc
|
||||
; -- is float in AY < float in P8ZP_SCRATCH_W2 ?
|
||||
jsr MOVFM
|
||||
lda P8ZP_SCRATCH_W2
|
||||
ldy P8ZP_SCRATCH_W2+1
|
||||
stx P8ZP_SCRATCH_REG
|
||||
jsr FCOMP
|
||||
ldx P8ZP_SCRATCH_REG
|
||||
cmp #255
|
||||
bne +
|
||||
lda #1
|
||||
rts
|
||||
+ lda #0
|
||||
rts
|
||||
.pend
|
||||
|
||||
vars_lesseq_f .proc
|
||||
; -- is float in AY <= float in P8ZP_SCRATCH_W2 ?
|
||||
jsr MOVFM
|
||||
lda P8ZP_SCRATCH_W2
|
||||
ldy P8ZP_SCRATCH_W2+1
|
||||
stx P8ZP_SCRATCH_REG
|
||||
jsr FCOMP
|
||||
ldx P8ZP_SCRATCH_REG
|
||||
cmp #255
|
||||
bne +
|
||||
- lda #1
|
||||
rts
|
||||
+ cmp #0
|
||||
beq -
|
||||
lda #0
|
||||
rts
|
||||
.pend
|
||||
|
||||
less_f .proc
|
||||
; -- is f1 < f2?
|
||||
jsr compare_floats
|
||||
|
@ -182,35 +182,91 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
}
|
||||
|
||||
private fun translateFloatLessJump(left: Expression, right: Expression, leftConstVal: NumericLiteralValue?, rightConstVal: NumericLiteralValue?, jumpIfFalseLabel: String) {
|
||||
if(asmgen.options.slowCodegenWarnings)
|
||||
println("warning: slow stack evaluation used (e1): '<' at ${left.position}") // TODO float via func args?
|
||||
translateExpression(left)
|
||||
translateExpression(right)
|
||||
asmgen.out(" jsr floats.less_f | inx | lda P8ESTACK_LO,x | beq $jumpIfFalseLabel")
|
||||
if(left is IdentifierReference && right is IdentifierReference) {
|
||||
val leftName = asmgen.asmVariableName(left)
|
||||
val rightName = asmgen.asmVariableName(right)
|
||||
asmgen.out("""
|
||||
lda #<$rightName
|
||||
ldy #>$rightName
|
||||
sta P8ZP_SCRATCH_W2
|
||||
sty P8ZP_SCRATCH_W2+1
|
||||
lda #<$leftName
|
||||
ldy #>$leftName
|
||||
jsr floats.vars_less_f
|
||||
beq $jumpIfFalseLabel""")
|
||||
} else {
|
||||
if (asmgen.options.slowCodegenWarnings)
|
||||
println("warning: slow stack evaluation used (e1): '<' at ${left.position}") // TODO float via func args?
|
||||
translateExpression(left)
|
||||
translateExpression(right)
|
||||
asmgen.out(" jsr floats.less_f | inx | lda P8ESTACK_LO,x | beq $jumpIfFalseLabel")
|
||||
}
|
||||
}
|
||||
|
||||
private fun translateFloatLessOrEqualJump(left: Expression, right: Expression, leftConstVal: NumericLiteralValue?, rightConstVal: NumericLiteralValue?, jumpIfFalseLabel: String) {
|
||||
if(asmgen.options.slowCodegenWarnings)
|
||||
println("warning: slow stack evaluation used (e1): '<=' at ${left.position}") // TODO float via func args?
|
||||
translateExpression(left)
|
||||
translateExpression(right)
|
||||
asmgen.out(" jsr floats.lesseq_f | inx | lda P8ESTACK_LO,x | beq $jumpIfFalseLabel")
|
||||
if(left is IdentifierReference && right is IdentifierReference) {
|
||||
val leftName = asmgen.asmVariableName(left)
|
||||
val rightName = asmgen.asmVariableName(right)
|
||||
asmgen.out("""
|
||||
lda #<$rightName
|
||||
ldy #>$rightName
|
||||
sta P8ZP_SCRATCH_W2
|
||||
sty P8ZP_SCRATCH_W2+1
|
||||
lda #<$leftName
|
||||
ldy #>$leftName
|
||||
jsr floats.vars_lesseq_f
|
||||
beq $jumpIfFalseLabel""")
|
||||
} else {
|
||||
if (asmgen.options.slowCodegenWarnings)
|
||||
println("warning: slow stack evaluation used (e1): '<=' at ${left.position}") // TODO float via func args?
|
||||
translateExpression(left)
|
||||
translateExpression(right)
|
||||
asmgen.out(" jsr floats.lesseq_f | inx | lda P8ESTACK_LO,x | beq $jumpIfFalseLabel")
|
||||
}
|
||||
}
|
||||
|
||||
private fun translateFloatGreaterJump(left: Expression, right: Expression, leftConstVal: NumericLiteralValue?, rightConstVal: NumericLiteralValue?, jumpIfFalseLabel: String) {
|
||||
if(asmgen.options.slowCodegenWarnings)
|
||||
println("warning: slow stack evaluation used (e1): '>' at ${left.position}") // TODO float via func args?
|
||||
translateExpression(left)
|
||||
translateExpression(right)
|
||||
asmgen.out(" jsr floats.greater_f | inx | lda P8ESTACK_LO,x | beq $jumpIfFalseLabel")
|
||||
if(left is IdentifierReference && right is IdentifierReference) {
|
||||
val leftName = asmgen.asmVariableName(left)
|
||||
val rightName = asmgen.asmVariableName(right)
|
||||
asmgen.out("""
|
||||
lda #<$leftName
|
||||
ldy #>$leftName
|
||||
sta P8ZP_SCRATCH_W2
|
||||
sty P8ZP_SCRATCH_W2+1
|
||||
lda #<$rightName
|
||||
ldy #>$rightName
|
||||
jsr floats.vars_less_f
|
||||
beq $jumpIfFalseLabel""")
|
||||
} else {
|
||||
if (asmgen.options.slowCodegenWarnings)
|
||||
println("warning: slow stack evaluation used (e1): '>' at ${left.position}") // TODO float via func args?
|
||||
translateExpression(left)
|
||||
translateExpression(right)
|
||||
asmgen.out(" jsr floats.greater_f | inx | lda P8ESTACK_LO,x | beq $jumpIfFalseLabel")
|
||||
}
|
||||
}
|
||||
|
||||
private fun translateFloatGreaterOrEqualJump(left: Expression, right: Expression, leftConstVal: NumericLiteralValue?, rightConstVal: NumericLiteralValue?, jumpIfFalseLabel: String) {
|
||||
if(asmgen.options.slowCodegenWarnings)
|
||||
println("warning: slow stack evaluation used (e1): '>=' at ${left.position}") // TODO float via func args
|
||||
translateExpression(left)
|
||||
translateExpression(right)
|
||||
asmgen.out(" jsr floats.greatereq_f | inx | lda P8ESTACK_LO,x | beq $jumpIfFalseLabel")
|
||||
if(left is IdentifierReference && right is IdentifierReference) {
|
||||
val leftName = asmgen.asmVariableName(left)
|
||||
val rightName = asmgen.asmVariableName(right)
|
||||
asmgen.out("""
|
||||
lda #<$leftName
|
||||
ldy #>$leftName
|
||||
sta P8ZP_SCRATCH_W2
|
||||
sty P8ZP_SCRATCH_W2+1
|
||||
lda #<$rightName
|
||||
ldy #>$rightName
|
||||
jsr floats.vars_lesseq_f
|
||||
beq $jumpIfFalseLabel""")
|
||||
} else {
|
||||
if (asmgen.options.slowCodegenWarnings)
|
||||
println("warning: slow stack evaluation used (e1): '>=' at ${left.position}") // TODO float via func args
|
||||
translateExpression(left)
|
||||
translateExpression(right)
|
||||
asmgen.out(" jsr floats.greatereq_f | inx | lda P8ESTACK_LO,x | beq $jumpIfFalseLabel")
|
||||
}
|
||||
}
|
||||
|
||||
private fun translateUbyteLessJump(left: Expression, right: Expression, leftConstVal: NumericLiteralValue?, rightConstVal: NumericLiteralValue?, jumpIfFalseLabel: String) {
|
||||
|
Loading…
Reference in New Issue
Block a user