mirror of
https://github.com/irmen/prog8.git
synced 2025-02-08 16:30:28 +00:00
vm: implemented in-place array multiplication better
This commit is contained in:
parent
de3d0b40dc
commit
04df3c9f7f
@ -711,7 +711,24 @@ internal class AssignmentGen(private val codeGen: IRCodeGen, private val express
|
||||
|
||||
private fun operatorMultiplyInplace(symbol: String?, array: PtArrayIndexer?, constAddress: Int?, memory: PtMemoryByte?, vmDt: IRDataType, operand: PtExpression): IRCodeChunks? {
|
||||
if(array!=null) {
|
||||
TODO("* in array")
|
||||
val eltSize = codeGen.program.memsizer.memorySize(array.type)
|
||||
val result = mutableListOf<IRCodeChunkBase>()
|
||||
if(array.splitWords)
|
||||
return operatorMultiplyInplaceSplitArray(array, operand)
|
||||
val eltDt = irType(array.type)
|
||||
val constIndex = array.index.asConstInteger()
|
||||
val constValue = operand.asConstInteger()
|
||||
if(constIndex!=null && constValue!=null) {
|
||||
if(constValue!=1) {
|
||||
val valueReg=codeGen.registers.nextFree()
|
||||
result += IRCodeChunk(null, null).also {
|
||||
it += IRInstruction(Opcode.LOAD, eltDt, reg1=valueReg, immediate = constValue)
|
||||
it += IRInstruction(Opcode.MULM, eltDt, reg1=valueReg, labelSymbol = array.variable.name, symbolOffset = constIndex*eltSize)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
return null // TODO("inplace array * non-const")
|
||||
}
|
||||
if(constAddress==null && memory!=null)
|
||||
return null // TODO("optimized memory in-place *"")
|
||||
@ -813,6 +830,10 @@ internal class AssignmentGen(private val codeGen: IRCodeGen, private val express
|
||||
return result
|
||||
}
|
||||
|
||||
private fun operatorMultiplyInplaceSplitArray(array: PtArrayIndexer, operand: PtExpression): IRCodeChunks? {
|
||||
return null // TODO("inplace split word array *")
|
||||
}
|
||||
|
||||
private fun operatorMinusInplaceSplitArray(array: PtArrayIndexer, operand: PtExpression): IRCodeChunks? {
|
||||
val result = mutableListOf<IRCodeChunkBase>()
|
||||
val constIndex = array.index.asConstInteger()
|
||||
|
@ -208,7 +208,7 @@ class TestCompilerOnExamplesVirtual: FunSpec({
|
||||
val (displayName, filepath) = prepareTestFiles(it, false, target)
|
||||
test(displayName) {
|
||||
val src = filepath.readText()
|
||||
compileText(target, true, src, writeAssembly = true) shouldNotBe null
|
||||
compileText(target, false, src, writeAssembly = true) shouldNotBe null
|
||||
compileText(target, true, src, writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
}
|
||||
|
@ -3,16 +3,20 @@
|
||||
%option no_sysinit
|
||||
|
||||
main {
|
||||
ubyte tw = other.width()
|
||||
sub start() {
|
||||
tw++
|
||||
txt.print_uw(tw)
|
||||
}
|
||||
}
|
||||
ubyte[] ubarray = [11,22,33]
|
||||
uword[] uwarray = [1111,2222,3333]
|
||||
uword[] @split suwarray = [1111,2222,3333]
|
||||
|
||||
other {
|
||||
sub width() -> ubyte {
|
||||
cx16.r0++
|
||||
return 80
|
||||
ubarray[1] *= 10
|
||||
uwarray[1] *= 10
|
||||
suwarray[1] *= 10
|
||||
|
||||
txt.print_ub(ubarray[1])
|
||||
txt.nl()
|
||||
txt.print_uw(uwarray[1])
|
||||
txt.nl()
|
||||
txt.print_uw(suwarray[1])
|
||||
txt.nl()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user