fix element size calc when copying array

This commit is contained in:
Irmen de Jong 2024-02-10 22:58:44 +01:00
parent 8b8caa1c2e
commit 8201408f16
3 changed files with 10 additions and 32 deletions

View File

@ -153,7 +153,7 @@ internal class BuiltinFunctionsAsmGen(private val program: PtProgram,
}
else {
// normal array to array copy, various element types
val eltsize = asmgen.options.compTarget.memorySize(source.type)
val eltsize = asmgen.options.compTarget.memorySize(ArrayToElementTypes.getValue(source.type))
val numBytes = numElements * eltsize
asmgen.out("""
lda #<${sourceAsm}

View File

@ -1,10 +1,7 @@
package prog8.codegen.intermediate
import prog8.code.ast.*
import prog8.code.core.AssemblyError
import prog8.code.core.DataType
import prog8.code.core.SignedDatatypes
import prog8.code.core.SplitWordArrayTypes
import prog8.code.core.*
import prog8.intermediate.*
@ -102,7 +99,7 @@ internal class BuiltinFuncGen(private val codeGen: IRCodeGen, private val exprGe
}
else {
// normal array to array copy (various element types)
val eltsize = codeGen.options.compTarget.memorySize(source.type)
val eltsize = codeGen.options.compTarget.memorySize(ArrayToElementTypes.getValue(source.type))
result += IRCodeChunk(null, null).also {
it += IRInstruction(Opcode.LOAD, IRDataType.WORD, reg1=fromReg, labelSymbol = source.name)
it += IRInstruction(Opcode.LOAD, IRDataType.WORD, reg1=toReg, labelSymbol = target.name)

View File

@ -5,36 +5,17 @@
main {
sub start() {
uword[7] rolls
ubyte[5] cave_times
ubyte[5] diamonds_needed
txt.print("wait...\n")
repeat 30 {
repeat 1000 {
unroll 10 rolls[math.rnd() % len(rolls)]++
}
}
cave_times = [1,2,3,4,5]
diamonds_needed = [1,2,3,4,5]
for cx16.r0L in 0 to len(rolls)-1 {
txt.print_ub(cx16.r0L)
for cx16.r0L in 0 to len(cave_times)-1 {
txt.print_ub(cave_times[cx16.r0L])
txt.spc()
txt.print_uw(rolls[cx16.r0L])
txt.nl()
}
txt.print("wait...\n")
rolls = [0,0,0,0,0,0,0]
repeat 30 {
repeat 1000 {
unroll 10 rolls[math.randrange(len(rolls))]++
}
}
for cx16.r0L in 0 to len(rolls)-1 {
txt.print_ub(cx16.r0L)
txt.spc()
txt.print_uw(rolls[cx16.r0L])
txt.nl()
}
txt.nl()
}
}