IR: using EXT more

This commit is contained in:
Irmen de Jong 2023-10-29 02:57:21 +01:00
parent 7ec4ba40ad
commit 513611c5a6
2 changed files with 16 additions and 10 deletions

View File

@ -348,15 +348,19 @@ internal class BuiltinFuncGen(private val codeGen: IRCodeGen, private val exprGe
}
private fun funcMkword(call: PtBuiltinFunctionCall): ExpressionCodeResult {
// TODO use ext instruction if msb is 0
val result = mutableListOf<IRCodeChunkBase>()
val resultReg = codeGen.registers.nextFree()
if((call.args[0] as? PtNumber)?.number == 0.0) {
// msb is 0, use EXT
val lsbTr = exprGen.translateExpression(call.args[1])
addToResult(result, lsbTr, lsbTr.resultReg, -1)
addInstr(result, IRInstruction(Opcode.EXT, IRDataType.BYTE, reg1=resultReg, reg2 = lsbTr.resultReg), null)
} else {
val msbTr = exprGen.translateExpression(call.args[0])
addToResult(result, msbTr, msbTr.resultReg, -1)
val lsbTr = exprGen.translateExpression(call.args[1])
addToResult(result, lsbTr, lsbTr.resultReg, -1)
val resultReg = codeGen.registers.nextFree()
result += IRCodeChunk(null, null).also {
it += IRInstruction(Opcode.CONCAT, IRDataType.BYTE, reg1=resultReg, reg2 = msbTr.resultReg, reg3 = lsbTr.resultReg)
addInstr(result, IRInstruction(Opcode.CONCAT, IRDataType.BYTE, reg1=resultReg, reg2 = msbTr.resultReg, reg3 = lsbTr.resultReg), null)
}
return ExpressionCodeResult(result, IRDataType.WORD, resultReg, -1)
}

View File

@ -5,8 +5,10 @@
main {
sub start() {
uword sprite_reg
cx16.r0 = sprite_reg+1
cx16.vpoke(1, sprite_reg+1, 42)
ubyte lower = 123
ubyte upper = 0
uword ww = mkword(upper, lower)
txt.print_uwhex(ww, true)
}
}