float init optimization in asm

This commit is contained in:
Irmen de Jong 2019-01-16 23:56:50 +01:00
parent 9424387803
commit 76aeb06c97
3 changed files with 128 additions and 31 deletions

View File

@ -654,13 +654,13 @@ private class StatementTranslator(private val prog: IntermediateProgram,
DataType.STR, DataType.STR_P, DataType.STR_S, DataType.STR_PS -> { DataType.STR, DataType.STR_P, DataType.STR_S, DataType.STR_PS -> {
if(lv.heapId==null) if(lv.heapId==null)
throw CompilerException("string should have been moved into heap ${lv.position}") throw CompilerException("string should have been moved into heap ${lv.position}")
prog.instr(Opcode.PUSH_ADDR_HEAPVAR, callLabel = "@todo-string-varname?") // XXX push address of string TODO("push address of string with PUSH_ADDR_HEAPVAR")
} }
DataType.ARRAY_UB, DataType.ARRAY_UW, DataType.ARRAY_F, DataType.ARRAY_UB, DataType.ARRAY_UW, DataType.ARRAY_F,
DataType.ARRAY_B, DataType.ARRAY_W -> { DataType.ARRAY_B, DataType.ARRAY_W -> {
if(lv.heapId==null) if(lv.heapId==null)
throw CompilerException("array should have been moved into heap ${lv.position}") throw CompilerException("array should have been moved into heap ${lv.position}")
prog.instr(Opcode.PUSH_WORD, Value(lv.type, lv.heapId)) // XXX push address of array TODO("push address of array with PUSH_WORD")
} }
} }
} }

View File

@ -37,6 +37,7 @@ fun optimizeSameAssignments(linesByFourteen: List<List<IndexedValue<String>>>):
// optimize sequential assignments of the same value to various targets (bytes, words, floats) // optimize sequential assignments of the same value to various targets (bytes, words, floats)
// the float one is the one that requires 2*7=14 lines of code to check... // the float one is the one that requires 2*7=14 lines of code to check...
// @todo a better place to do this is in the Compiler instead and work on opcodes, and never even create the inefficient asm...
val removeLines = mutableListOf<Int>() val removeLines = mutableListOf<Int>()
for (pair in linesByFourteen) { for (pair in linesByFourteen) {
@ -71,7 +72,28 @@ fun optimizeSameAssignments(linesByFourteen: List<List<IndexedValue<String>>>):
} }
} }
// @todo check float initializations. if(first.startsWith("lda") && second.startsWith("ldy") && third.startsWith("sta") && fourth.startsWith("sty") &&
fifth.startsWith("lda") && sixth.startsWith("ldy") && seventh.startsWith("jsr c64flt.copy_float")) {
val nineth = pair[8].value.trimStart()
val tenth = pair[9].value.trimStart()
val eleventh = pair[10].value.trimStart()
val twelveth = pair[11].value.trimStart()
val thirteenth = pair[12].value.trimStart()
val fourteenth = pair[13].value.trimStart()
if(eighth.startsWith("lda") && nineth.startsWith("ldy") && tenth.startsWith("sta") && eleventh.startsWith("sty") &&
twelveth.startsWith("lda") && thirteenth.startsWith("ldy") && fourteenth.startsWith("jsr c64flt.copy_float")) {
if(first.substring(4) == eighth.substring(4) && second.substring(4)==nineth.substring(4)) {
// identical float init
removeLines.add(pair[7].index)
removeLines.add(pair[8].index)
removeLines.add(pair[9].index)
removeLines.add(pair[10].index)
}
}
}
} }
return removeLines return removeLines
} }

View File

@ -5,37 +5,112 @@
sub start() { sub start() {
ubyte ub ubyte ub1
byte b ubyte ub2
word w ubyte ub3
uword uw ubyte ub4
byte b1
byte b2
byte b3
byte b4
word w1
word w2
word w3
word w4
uword uw1
uword uw2
uword uw3
uword uw4
float f1
float f2
float f3
float f4
memory ubyte mub1 = $c000
memory ubyte mub2 = $c000
memory ubyte mub3 = $c000
memory ubyte mub4 = $c000
memory byte mb1 = $c000
memory byte mb2 = $c000
memory byte mb3 = $c000
memory byte mb4 = $c000
memory word mw1 = $c000
memory word mw2 = $c000
memory word mw3 = $c000
memory word mw4 = $c000
memory uword muw1 = $c000
memory uword muw2 = $c000
memory uword muw3 = $c000
memory uword muw4 = $c000
memory float mf1 = $c010
memory float mf2 = $c020
memory float mf3 = $c030
memory float mf4 = $c040
ub1 = $11
ub2 = $11
ub3 = $11
mub1 = $11
mub2 = $11
mub3 = $11
ub4 = $44
mub4 = $44
ubyte[2] uba b1=$11
byte[2] ba b2=$11
word[2] wa b3=$11
uword[2] uwa mb1=$11
str s mb2=$11
str_p sp mb3=$11
str_s ss b4=$44
str_ps sps mb4=$44
s = ub as str w1=$1111
sp = ub as str_p w2=$1111
ss = ub as str_s w3=$1111
sps = ub as str_ps mw1=$1111
s = b as str mw2=$1111
sp = b as str_p mw3=$1111
ss = b as str_s w4=$4444
sps = b as str_ps mw4=$4444
s = w as str
sp = w as str_p uw1=$1111
ss = w as str_s uw2=$1111
sps = w as str_ps uw3=$1111
s = uw as str muw1=$1111
sp = uw as str_p muw2=$1111
ss = uw as str_s muw3=$1111
sps = uw as str_ps uw4=$4444
muw4=$4444
f1 = 12.11
f1 = 13.11
f1 = 14.11
f1 = 15.11
f1 = 11.11
f2 = 11.11
f3 = 11.11
mf1 = 11.11
mf2 = 11.11
mf3 = 11.11
f4 = 44.44
mf4 = 44.44
c64flt.print_f(f1)
c64.CHROUT('\n')
c64flt.print_f(f2)
c64.CHROUT('\n')
c64flt.print_f(f3)
c64.CHROUT('\n')
c64flt.print_f(f4)
c64.CHROUT('\n')
c64flt.print_f(mf1)
c64.CHROUT('\n')
c64flt.print_f(mf2)
c64.CHROUT('\n')
c64flt.print_f(mf3)
c64.CHROUT('\n')
c64flt.print_f(mf4)
c64.CHROUT('\n')
} }