ir: fix float instruction value in formatspec

This commit is contained in:
Irmen de Jong 2022-11-03 19:08:13 +01:00
parent 06b032af91
commit 144c1ba3a6
4 changed files with 15 additions and 4 deletions

View File

@ -294,7 +294,7 @@ class StatementOptimizer(private val program: Program,
if(bexpr!=null) {
val rightCv = bexpr.right.constValue(program)?.number
if(bexpr.operator=="-" && rightCv==null) {
if(bexpr.right isSameAs assignment.target) {
if(bexpr.right.isSimple && bexpr.right isSameAs assignment.target) {
// X = value - X --> X = -X ; X += value (to avoid need of stack-evaluation)
val negation = PrefixExpression("-", bexpr.right.copy(), bexpr.position)
val addValue = Assignment(assignment.target.copy(), BinaryExpression(bexpr.right, "+", bexpr.left, bexpr.position), AssignmentOrigin.OPTIMIZER, assignment.position)

View File

@ -3,6 +3,7 @@ TODO
For next release
^^^^^^^^^^^^^^^^
- check StatementOptimizer "optimize binary expressions a bit": flt[1] = 3.0-flt[1] beneficial or not? what about integer array?
- ir: get rid of '_' label prefix?
- fix expericodegen (ir code gen for regular cx16 target)

View File

@ -1,7 +1,13 @@
%import floats
%import textio
%zeropage basicsafe
main {
float[10] flt
sub start() {
flt[1] = 42.42
flt[1] = 3-flt[1]
floats.print_f(flt[1])
}
}

View File

@ -493,8 +493,12 @@ data class InstructionFormat(val datatype: IRDataType?,
">fr1" -> { fpreg1=OperandDirection.OUTPUT }
"<>fr1" -> { fpreg1=OperandDirection.INOUT }
"<fr2" -> fpreg2 = OperandDirection.INPUT
"<v" -> valueIn = true
"<fv" -> fpvalueIn = true
"<v" -> {
if('F' in typespec)
fpvalueIn = true
else
valueIn = true
}
else -> throw IllegalArgumentException(spec)
}
}
@ -521,7 +525,7 @@ data class InstructionFormat(val datatype: IRDataType?,
@Suppress("BooleanLiteralArgument")
val instructionFormats = mutableMapOf(
Opcode.NOP to InstructionFormat.from("N"),
Opcode.LOAD to InstructionFormat.from("BW,>r1,<v | F,>fr1,<fv"),
Opcode.LOAD to InstructionFormat.from("BW,>r1,<v | F,>fr1,<v"),
Opcode.LOADM to InstructionFormat.from("BW,>r1,<v | F,>fr1,<v"),
Opcode.LOADI to InstructionFormat.from("BW,>r1,<r2 | F,>fr1,<r1"),
Opcode.LOADX to InstructionFormat.from("BW,>r1,<r2,<v | F,>fr1,<r1,<v"),