diff --git a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AssignmentAsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AssignmentAsmGen.kt index a171ced1c..10fdd8b03 100644 --- a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AssignmentAsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AssignmentAsmGen.kt @@ -442,9 +442,35 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen } } - // No more special optmized cases yet. Do the rest via more complex evaluation - // note: cannot use assignTypeCastedValue because that is ourselves :P - asmgen.assignExpressionTo(origTypeCastExpression, target) + if(targetDt==DataType.FLOAT && (target.register==RegisterOrPair.FAC1 || target.register==RegisterOrPair.FAC2)) { + when(valueDt) { + DataType.UBYTE -> { + assignExpressionToRegister(value, RegisterOrPair.Y, false) + asmgen.out(" jsr floats.FREADUY") + } + DataType.BYTE -> { + assignExpressionToRegister(value, RegisterOrPair.A, true) + asmgen.out(" jsr floats.FREADSA") + } + DataType.UWORD -> { + assignExpressionToRegister(value, RegisterOrPair.AY, false) + asmgen.out(" jsr floats.GIVUAYFAY") + } + DataType.WORD -> { + assignExpressionToRegister(value, RegisterOrPair.AY, true) + asmgen.out(" jsr floats.GIVAYFAY") + } + else -> throw AssemblyError("invalid dt") + } + if(target.register==RegisterOrPair.FAC2) { + asmgen.out(" jsr floats.MOVEF") + } + } else { + // No more special optmized cases yet. Do the rest via more complex evaluation + // note: cannot use assignTypeCastedValue because that is ourselves :P + // NOTE: THIS MAY TURN INTO A STACK OVERFLOW ERROR IF IT CAN'T SIMPLIFY THE TYPECAST..... :-/ + asmgen.assignExpressionTo(origTypeCastExpression, target) + } } private fun assignCastViaLsbFunc(value: Expression, target: AsmAssignTarget) { diff --git a/compiler/test/TestOptimization.kt b/compiler/test/TestOptimization.kt index 65cb63b9e..59ff37b25 100644 --- a/compiler/test/TestOptimization.kt +++ b/compiler/test/TestOptimization.kt @@ -204,7 +204,6 @@ class TestOptimization: FunSpec({ """ val result1 = compileText(C64Target, optimize=false, src, writeAssembly = false).assertSuccess() - // yy = (dy*(pixely as float) ) val assignYY = result1.program.entrypoint.statements.last() as Assignment assignYY.isAugmentable shouldBe true assignYY.target.identifier!!.nameInSource shouldBe listOf("ff") diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 46fce9234..05f253804 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,8 +3,6 @@ TODO For next compiler release (7.3) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- fix float crash in mandelbrot-gfx-colors.p8 (unittest is being written) - - add cosr8, sinr8, cosr16 and sinr16 that take a degree 0..179 (= 0..359 in 2 degree steps) to more easily scale halves/quarters etc of a circle than possible with the ones that take 0..255 'degrees'. diff --git a/examples/test.p8 b/examples/test.p8 index a27510e6b..2d10fd38c 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,17 +1,42 @@ %import textio -; %import floats +%import floats %zeropage basicsafe main { sub start() { - ubyte unused ; TODO FIX : why is this not removed as an unused variable? - ubyte @shared unused2 + ubyte ub=99 + byte bb=-99 + uword uw=9999 + word ww=-9999 + float ff + ff = 1.234 + ff += (ub as float) ; operator doesn't matter + floats.print_f(ff) + txt.nl() - ubyte bb - uword ww - ww = not bb or not ww ; TODO WHY DOES THIS USE STACK EVAL + ff = 1.234 + ff += (bb as float) ; operator doesn't matter + floats.print_f(ff) + txt.nl() + + ff = 1.234 + ff += (uw as float) ; operator doesn't matter + floats.print_f(ff) + txt.nl() + + ff = 1.234 + ff += (ww as float) ; operator doesn't matter + floats.print_f(ff) + txt.nl() + +; ubyte unused ; TODO FIX : why is this not removed as an unused variable? +; ubyte @shared unused2 +; +; ubyte bb +; uword ww +; ww = not bb or not ww ; TODO WHY DOES THIS USE STACK EVAL ; if not iteration_in_progress or not num_bytes ; return @@ -36,14 +61,14 @@ main { ; txt.print("xx is zero\n") ; } - ubyte yy=$30 +; ubyte yy=$30 ; ubyte zz=9 ; sys.memset(xx+200, yy*2, ~yy) ; - - if yy & %10000 { - yy++ - } +; +; if yy & %10000 { +; yy++ +; } ; ; @($c030) = 10 ; @(~xx) *= 2