From 452c29574d9a1d5450fe74c48bce3eddbdcf4265 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 7 Dec 2020 22:55:16 +0100 Subject: [PATCH] added optimized mul 320 routine --- compiler/res/prog8lib/math.asm | 51 ++++++++++++++++++ .../compiler/target/c64/codegen/AsmGen.kt | 2 +- examples/test.p8 | 53 +++++++++++++++++-- syntax-files/Sublimetext3/readme.txt | 5 +- 4 files changed, 106 insertions(+), 5 deletions(-) diff --git a/compiler/res/prog8lib/math.asm b/compiler/res/prog8lib/math.asm index a8d872169..2a2d17050 100644 --- a/compiler/res/prog8lib/math.asm +++ b/compiler/res/prog8lib/math.asm @@ -774,6 +774,31 @@ stack_mul_word_100 .proc rts .pend +stack_mul_word_320 .proc + ; stackW = stackLo * 256 + stackLo * 64 (stackHi doesn't matter) + ldy P8ESTACK_LO+1,x + lda #0 + sta P8ESTACK_HI+1,x + tya + asl a + rol P8ESTACK_HI+1,x + asl a + rol P8ESTACK_HI+1,x + asl a + rol P8ESTACK_HI+1,x + asl a + rol P8ESTACK_HI+1,x + asl a + rol P8ESTACK_HI+1,x + asl a + rol P8ESTACK_HI+1,x + sta P8ESTACK_LO+1,x + tya + clc + adc P8ESTACK_HI+1,x + sta P8ESTACK_HI+1,x + rts + .pend ; ----------- optimized multiplications (in-place A (byte) and ?? (word)) : --------- mul_byte_3 .proc @@ -1241,6 +1266,32 @@ mul_word_100 .proc rts .pend +mul_word_320 .proc + ; AY = A * 256 + A * 64 (msb doesn't matter) + sta P8ZP_SCRATCH_B1 + ldy #0 + sty P8ZP_SCRATCH_REG + asl a + rol P8ZP_SCRATCH_REG + asl a + rol P8ZP_SCRATCH_REG + asl a + rol P8ZP_SCRATCH_REG + asl a + rol P8ZP_SCRATCH_REG + asl a + rol P8ZP_SCRATCH_REG + asl a + rol P8ZP_SCRATCH_REG + pha + clc + lda P8ZP_SCRATCH_B1 + adc P8ZP_SCRATCH_REG + tay + pla + rts + .pend + ; ----------- end optimized multiplications ----------- diff --git a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt index af5487811..44a59b32f 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt @@ -36,7 +36,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) + val optimizedWordMultiplications = setOf(3,5,6,7,9,10,12,15,20,25,40,50,80,100,320) private val assemblyLines = mutableListOf() private val globalFloatConsts = mutableMapOf() // all float values in the entire program (value -> varname) diff --git a/examples/test.p8 b/examples/test.p8 index 416ad08de..329869cf9 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -5,12 +5,59 @@ main { sub start() { - const ubyte size = 100 + uword uw + ubyte ub - ubyte[size+10] bytes + ub = 10 + uw = ub * 320 + txt.print_uw(uw) + txt.chrout('\n') + + ub = 100 + uw = ub * 320 + txt.print_uw(uw) + txt.chrout('\n') + + ub = 200 + uw = ub * 320 + txt.print_uw(uw) + txt.chrout('\n') + + uw = 10 + uw *= 320 + txt.print_uw(uw) + txt.chrout('\n') + + uw = 100 + uw *= 320 + txt.print_uw(uw) + txt.chrout('\n') + + uw = 200 + uw *= 320 + txt.print_uw(uw) + txt.chrout('\n') + txt.chrout('\n') + + uw = 0 + ub = 10 + uw = uw + 320*ub + txt.print_uw(uw) + txt.chrout('\n') + + uw = 0 + ub = 100 + uw = uw + 320*ub + txt.print_uw(uw) + txt.chrout('\n') + + uw = 0 + ub = 200 + uw = uw + 320*ub + txt.print_uw(uw) + txt.chrout('\n') txt.print("hello\n") - ubyte dummy = bytes[0] } } diff --git a/syntax-files/Sublimetext3/readme.txt b/syntax-files/Sublimetext3/readme.txt index 1333ed77b..88360ab69 100644 --- a/syntax-files/Sublimetext3/readme.txt +++ b/syntax-files/Sublimetext3/readme.txt @@ -1 +1,4 @@ -TODO +A contributed syntax definition file for Sublime Text 3 can be obtained from: + +https://github.com/akubiczek/Prog8-TmLanguage-VsCode/tree/master/sublime3 +