diff --git a/compiler/res/prog8lib/cx16/verafx.p8 b/compiler/res/prog8lib/cx16/verafx.p8 index 3d083861e..0bf78d974 100644 --- a/compiler/res/prog8lib/cx16/verafx.p8 +++ b/compiler/res/prog8lib/cx16/verafx.p8 @@ -42,25 +42,19 @@ verafx { cx16.VERA_FX_MULT = 0 cx16.VERA_FX_CTRL = %01000000 ; cache write enable - if (num_longwords & %1111110000000011) == 0 { - repeat lsb(num_longwords >> 2) - unroll 4 cx16.VERA_DATA0=0 ; write 4*4 bytes at a time, unrolled + cx16.r0 = num_longwords>>3 + if cx16.r0H==0 { + repeat cx16.r0L { + unroll 8 cx16.VERA_DATA0=0 ; write 8*4 bytes at a time, unrolled + } + } else { + repeat cx16.r0 { + unroll 8 cx16.VERA_DATA0=0 ; write 8*4 bytes at a time, unrolled + } } - else if (num_longwords & %1111111000000001) == 0 { - repeat lsb(num_longwords >> 1) - unroll 2 cx16.VERA_DATA0=0 ; write 2*4 bytes at a time, unrolled - } - else if (lsb(num_longwords) & 3) == 0 { - repeat num_longwords >> 2 - unroll 4 cx16.VERA_DATA0=0 ; write 4*4 bytes at a time, unrolled - } - else if (lsb(num_longwords) & 1) == 0 { - repeat num_longwords >> 1 - unroll 2 cx16.VERA_DATA0=0 ; write 2*4 bytes at a time, unrolled - } - else { - repeat num_longwords - cx16.VERA_DATA0=0 ; write 4 bytes at a time + + repeat lsb(num_longwords) & 7 { + cx16.VERA_DATA0=0 ; write 4 bytes at a time (remaining longs) } cx16.VERA_FX_CTRL = 0 ; cache write disable @@ -81,35 +75,41 @@ verafx { cx16.VERA_CTRL = 2<<1 ; dcsel = 2 cx16.VERA_FX_MULT = 0 cx16.VERA_FX_CTRL = %01100000 ; cache write enable + cache fill enable - cx16.r0 = num_longwords - if (cx16.r0L & 1) == 0 { - repeat cx16.r0>>1 { - %asm {{ - lda cx16.VERA_DATA1 ; fill cache with 4 source bytes... + cx16.r0 = num_longwords>>1 + + if cx16.r0H==0 { + repeat cx16.r0L { + unroll 2 %asm {{ lda cx16.VERA_DATA1 lda cx16.VERA_DATA1 lda cx16.VERA_DATA1 - stz cx16.VERA_DATA0 ; write 4 bytes at once. - lda cx16.VERA_DATA1 ; fill cache with 4 source bytes... lda cx16.VERA_DATA1 - lda cx16.VERA_DATA1 - lda cx16.VERA_DATA1 - stz cx16.VERA_DATA0 ; write 4 bytes at once. + stz cx16.VERA_DATA0 }} } } else { repeat cx16.r0 { - %asm {{ - lda cx16.VERA_DATA1 ; fill cache with 4 source bytes... + unroll 2 %asm {{ lda cx16.VERA_DATA1 lda cx16.VERA_DATA1 lda cx16.VERA_DATA1 - stz cx16.VERA_DATA0 ; write 4 bytes at once. + lda cx16.VERA_DATA1 + stz cx16.VERA_DATA0 }} } } + if lsb(num_longwords) & 1 == 1 { + %asm {{ + lda cx16.VERA_DATA1 + lda cx16.VERA_DATA1 + lda cx16.VERA_DATA1 + lda cx16.VERA_DATA1 + stz cx16.VERA_DATA0 + }} + } + cx16.VERA_FX_CTRL = 0 ; cache write disable cx16.VERA_CTRL = 0 } diff --git a/compiler/test/TestCompilerOnExamples.kt b/compiler/test/TestCompilerOnExamples.kt index f2ecc4e9a..7ca9472fd 100644 --- a/compiler/test/TestCompilerOnExamples.kt +++ b/compiler/test/TestCompilerOnExamples.kt @@ -221,7 +221,7 @@ class TestCompilerOnExamplesCx16: FunSpec({ ExampleSizes("charfade", cx16SizeOptimized=1054, cx16SizeUnoptimized=1371), ExampleSizes("charsets", cx16SizeOptimized=1125, cx16SizeUnoptimized=1417), ExampleSizes("circles", cx16SizeOptimized=2409, cx16SizeUnoptimized=5209), - ExampleSizes("cobramk3-gfx", cx16SizeOptimized=7842, cx16SizeUnoptimized=11048), + ExampleSizes("cobramk3-gfx", cx16SizeOptimized=7722, cx16SizeUnoptimized=10930), ExampleSizes("colorbars", cx16SizeOptimized=1606, cx16SizeUnoptimized=1904), ExampleSizes("cxlogo", cx16SizeOptimized=599, cx16SizeUnoptimized=895), ExampleSizes("diskspeed", cx16SizeOptimized=6298, cx16SizeUnoptimized=8376), diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 0536f7eb2..56f0a92a8 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -81,7 +81,6 @@ Libraries Optimizations ------------- -- repeat 256 {...} doesn't use STZ on the 65C02 (maybe other repeat values too?) - inliner: extend multi-value return inlining to support parameterized subroutines. Currently only works for parameterless subroutines. (Void calls with parameters already work if the parameters are unused in the body.) - bind types in the Ast much sooner than the simplifiedAst creation, so that we maybe could get rid of InferredType ? - Port more benchmarks from https://thred.github.io/c-bench-64/ to prog8 and see how it stacks up. (see benchmark-c/ directory) diff --git a/examples/test.p8 b/examples/test.p8 index 6edd37abd..184d5fcef 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,26 +1,14 @@ -%import textio - -plane { - struct Point { - ubyte x - ubyte y - } -} - -txt { - %option merge - sub print_pt(^^plane.Point p) { - txt.chrout('(') - txt.print_ub(p.x) - txt.chrout(',') - txt.print_ub(p.y) - txt.chrout(')') - } -} +%import monogfx +%import verafx main { sub start() { - ^^plane.Point origin = ^^plane.Point:[0,0] - txt.print_pt(origin) + monogfx.lores() + monogfx.circle(160, 60, 59, true) + + verafx.clear(0, 0, 255, 320*10/8/4) + verafx.copy(0,0, 0, 320*120/8, 320*120/8/4) + + repeat {} } }