From 0a5b30e21c17d4b0aa12b35697a1c1af9b7891fa Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 30 Apr 2021 22:30:21 +0200 Subject: [PATCH] added fast code for x*640 --- compiler/res/prog8lib/math.asm | 14 +++++++++++ .../compiler/target/cpu6502/codegen/AsmGen.kt | 2 +- examples/test.p8 | 23 +++++++++++++++---- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/compiler/res/prog8lib/math.asm b/compiler/res/prog8lib/math.asm index a06c8d0c3..665c3e19b 100644 --- a/compiler/res/prog8lib/math.asm +++ b/compiler/res/prog8lib/math.asm @@ -774,6 +774,13 @@ stack_mul_word_320 .proc rts .pend +stack_mul_word_640 .proc + ; stackW = (stackLo * 2 * 320) (stackHi doesn't matter) + asl P8ESTACK_LO+1,x + jmp stack_mul_word_320 + .pend + + ; ----------- optimized multiplications (in-place A (byte) and ?? (word)) : --------- mul_byte_3 .proc ; A = A + A*2 @@ -1264,6 +1271,13 @@ mul_word_320 .proc rts .pend +mul_word_640 .proc + ; AY = (A * 2 * 320) (msb in Y doesn't matter) + asl a + jmp mul_word_320 + .pend + + ; ----------- end optimized multiplications ----------- diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt index 9871ca5fa..11ee8feaf 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt @@ -30,7 +30,7 @@ internal class AsmGen(private val program: Program, // for expressions and augmented assignments: val optimizedByteMultiplications = setOf(3,5,6,7,9,10,11,12,13,14,15,20,25,40,50,80,100) - val optimizedWordMultiplications = setOf(3,5,6,7,9,10,12,15,20,25,40,50,80,100,320) + val optimizedWordMultiplications = setOf(3,5,6,7,9,10,12,15,20,25,40,50,80,100,320,640) private val callGraph = CallGraph(program) private val assemblyLines = mutableListOf() diff --git a/examples/test.p8 b/examples/test.p8 index b86bfda6a..9972ba874 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,14 +1,27 @@ +%import textio +%zeropage basicsafe main { sub start() { - uword enemyRef = $2000 - ubyte cur + uword x=22 + x*=320 + txt.print_uw(x) + txt.nl() + + x=22 + x*=640 + txt.print_uw(x) + txt.nl() + + ubyte a=1 + ubyte b=22 + + x = (a*b)*640*a + txt.print_uw(x) + txt.nl() - cur = enemyRef[1] - + enemyRef[2] - + enemyRef[3] } }