float typecasts optimization

This commit is contained in:
Irmen de Jong 2020-11-26 01:52:48 +01:00
parent 2f4c6c8697
commit a74403c347
2 changed files with 24 additions and 12 deletions

View File

@ -89,17 +89,27 @@ cast_from_b .proc
cast_as_uw_into_ya .proc ; also used for float 2 ub cast_as_uw_into_ya .proc ; also used for float 2 ub
; -- cast float at A/Y to uword into Y/A ; -- cast float at A/Y to uword into Y/A
stx P8ZP_SCRATCH_REG
jsr MOVFM jsr MOVFM
jmp cast_FAC1_as_uw_into_ya
.pend
cast_as_w_into_ay .proc ; also used for float 2 b
; -- cast float at A/Y to word into A/Y
jsr MOVFM
jmp cast_FAC1_as_w_into_ay
.pend
cast_FAC1_as_uw_into_ya .proc ; also used for float 2 ub
; -- cast fac1 to uword into Y/A
stx P8ZP_SCRATCH_REG
jsr GETADR ; into Y/A jsr GETADR ; into Y/A
ldx P8ZP_SCRATCH_REG ldx P8ZP_SCRATCH_REG
rts rts
.pend .pend
cast_as_w_into_ay .proc ; also used for float 2 b cast_FAC1_as_w_into_ay .proc ; also used for float 2 b
; -- cast float at A/Y to word into A/Y ; -- cast fac1 to word into A/Y
stx P8ZP_SCRATCH_REG stx P8ZP_SCRATCH_REG
jsr MOVFM
jsr AYINT jsr AYINT
ldy $64 ldy $64
lda $65 lda $65

View File

@ -9,7 +9,6 @@ import prog8.compiler.target.CompilationTarget
import prog8.compiler.target.CpuType import prog8.compiler.target.CpuType
import prog8.compiler.target.c64.codegen.AsmGen import prog8.compiler.target.c64.codegen.AsmGen
import prog8.compiler.target.c64.codegen.ExpressionsAsmGen import prog8.compiler.target.c64.codegen.ExpressionsAsmGen
import prog8.compiler.target.subroutineFloatEvalResultVar
import prog8.compiler.toHex import prog8.compiler.toHex
import prog8.functions.BuiltinFunctions import prog8.functions.BuiltinFunctions
import prog8.functions.builtinFunctionReturnType import prog8.functions.builtinFunctionReturnType
@ -282,13 +281,8 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
return assignTypeCastedRegisters(target.asmVarname, targetDt, RegisterOrPair.AY, valueDt) return assignTypeCastedRegisters(target.asmVarname, targetDt, RegisterOrPair.AY, valueDt)
} }
DataType.FLOAT -> { DataType.FLOAT -> {
// TODO try with FAC1 directly assignExpressionToRegister(value, RegisterOrPair.FAC1)
// assignExpressionToRegister(value, RegisterOrPair.FAC1) return assignTypecastedFloatFAC1(target.asmVarname, targetDt)
// assignTypecastedFloatFAC1(target.asmVarname, targetDt)
val scope = value.definingSubroutine()!!
scope.asmGenInfo.usedFloatEvalResultVar = true
assignExpressionToVariable(value, subroutineFloatEvalResultVar, valueDt, scope)
return assignTypeCastedIdentifier(target.asmVarname, targetDt, subroutineFloatEvalResultVar, valueDt)
} }
in PassByReferenceDatatypes -> { in PassByReferenceDatatypes -> {
// str/array value cast (most likely to UWORD, take address-of) // str/array value cast (most likely to UWORD, take address-of)
@ -311,6 +305,14 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
if(targetDt==DataType.FLOAT) if(targetDt==DataType.FLOAT)
throw AssemblyError("typecast to identical type") throw AssemblyError("typecast to identical type")
when(targetDt) {
DataType.UBYTE -> asmgen.out(" jsr floats.cast_FAC1_as_uw_into_ya | sty $targetAsmVarName")
DataType.BYTE -> asmgen.out(" jsr floats.cast_FAC1_as_w_into_ay | sta $targetAsmVarName")
DataType.UWORD -> asmgen.out(" jsr floats.cast_FAC1_as_uw_into_ya | sty $targetAsmVarName | sta $targetAsmVarName+1")
DataType.WORD -> asmgen.out(" jsr floats.cast_FAC1_as_w_into_ay | sta $targetAsmVarName | sty $targetAsmVarName+1")
else -> throw AssemblyError("weird type")
}
} }