Compare commits

..
4 Commits
Author SHA1 Message Date
Irmen de Jong 2d7e95e1b6 release 9.2.1 2023-07-30 17:39:18 +02:00
Irmen de Jong 0816a57032 never add rts to inline asmsubs and always inline them regardless of optimization setting
otherwise they can't specify a sequence of assembly instructions that should be inserted in-place, such as those that manipulate the cpu stack.
for instance cx16.irqsafe_set_irqd() / cx16.irqsafe_clear_irqd()
2023-07-30 14:52:37 +02:00
Irmen de Jong b89ad4b328 don't optimize empty where choice away! It would call the else clause incorrectly. 2023-07-29 18:25:52 +02:00
Irmen de Jong c112b327ab tiny optimization 2023-07-29 17:04:41 +02:00
9 changed files with 30 additions and 44 deletions

No files matched your search

@@ -63,8 +63,8 @@ internal class FunctionCallAsmGen(private val program: PtProgram, private val as
if(sub is PtAsmSub) {
argumentsViaRegisters(sub, call)
if (sub.inline && asmgen.options.optimize) {
// inline the subroutine.
if (sub.inline) {
// inline the subroutine. (regardless of optimization settings!)
// we do this by copying the subroutine's statements at the call site.
// NOTE: *if* there is a return statement, it will be the only one, and the very last statement of the subroutine
// (this condition has been enforced by an ast check earlier)
@@ -271,9 +271,7 @@ internal class ProgramAndVarsGen(
internal fun translateAsmSubroutine(sub: PtAsmSub) {
if(sub.inline) {
if(options.optimize) {
return
}
return // subroutine gets inlined at call site.
}
asmgen.out("")
@@ -413,10 +413,17 @@ class IRCodeGen(
result += translateNode(choice.statements)
addInstr(result, IRInstruction(Opcode.JUMP, labelSymbol = endLabel), null)
} else {
val choiceLabel = createLabelName()
choices.add(choiceLabel to choice)
choice.values.children.map { it as PtNumber }.sortedBy { it.number }.forEach { value ->
addInstr(result, IRInstruction(Opcode.BEQ, valueDt, reg1=valueTr.resultReg, immediate = value.number.toInt(), labelSymbol = choiceLabel), null)
if(choice.statements.children.isEmpty()) {
// no statements for this choice value, jump to the end immediately
choice.values.children.map { it as PtNumber }.sortedBy { it.number }.forEach { value ->
addInstr(result, IRInstruction(Opcode.BEQ, valueDt, reg1=valueTr.resultReg, immediate = value.number.toInt(), labelSymbol = endLabel), null)
}
} else {
val choiceLabel = createLabelName()
choices.add(choiceLabel to choice)
choice.values.children.map { it as PtNumber }.sortedBy { it.number }.forEach { value ->
addInstr(result, IRInstruction(Opcode.BEQ, valueDt, reg1=valueTr.resultReg, immediate = value.number.toInt(), labelSymbol = choiceLabel), null)
}
}
}
}
+2
View File
@@ -290,6 +290,7 @@ close_end:
sub f_read(uword bufferpointer, uword num_bytes) -> uword {
; -- read from the currently open file, up to the given number of bytes.
; returns the actual number of bytes read. (checks for End-of-file and error conditions)
; NOTE: cannot be used to load into VRAM. Use vload() or call cx16.macptr() yourself with the vera data register as address.
if not iteration_in_progress or not num_bytes
return 0
@@ -347,6 +348,7 @@ m_in_buffer sta $ffff
; optimized for Commander X16 to use MACPTR block read kernal call
sub f_read_all(uword bufferpointer) -> uword {
; -- read the full contents of the file, returns number of bytes read.
; NOTE: cannot be used to load into VRAM. Use vload() or call cx16.macptr() yourself with the vera data register as address.
if not iteration_in_progress
return 0
+4 -4
View File
@@ -427,17 +427,17 @@ _done
}
word @zp d = 0
cx16.r13 = true ; 'positive_ix'
cx16.r1L = true ; 'positive_ix'
if dx < 0 {
dx = -dx
cx16.r13 = false
cx16.r1L = false
}
word @zp dx2 = dx*2
word @zp dy2 = dy*2
cx16.r14 = x1 ; internal plot X
if dx >= dy {
if cx16.r13 {
if cx16.r1L {
repeat {
plot(cx16.r14, y1, color)
if cx16.r14==x2
@@ -464,7 +464,7 @@ _done
}
}
else {
if cx16.r13 {
if cx16.r1L {
repeat {
plot(cx16.r14, y1, color)
if y1 == y2
@@ -150,7 +150,7 @@ internal class BeforeAsmAstChanger(val program: Program,
}
}
if (!subroutine.inline || !options.optimize) {
if (!subroutine.inline) {
if (subroutine.isAsmSubroutine && subroutine.asmAddress==null && !subroutine.hasRtsInAsm()) {
// make sure the NOT INLINED asm subroutine actually has a rts at the end
// (non-asm routines get a Return statement as needed, above)
@@ -262,15 +262,5 @@ internal class VariousCleanups(val program: Program, val errors: IErrorReporter,
}
return noModifications
}
override fun after(whenStmt: When, parent: Node): Iterable<IAstModification> {
val removals = mutableListOf<Int>()
whenStmt.choices.withIndex().forEach { (index, choice) ->
if(choice.statements.isEmpty())
removals.add(index)
}
removals.reversed().forEach { whenStmt.choices.removeAt(it) }
return noModifications
}
}
+8 -19
View File
@@ -1,27 +1,16 @@
%import gfx2
%import textio
%zeropage basicsafe
main {
sub start() {
gfx2.screen_mode(6) ; 1 and 5 are lo-res and hi-res monochrome
ubyte var = 0
uword xx
gfx2.rect(10, 10, 180, 140, 3)
gfx2.rect(12, 12, 180, 140, 3)
cbm.SETTIM(0,0,0)
for xx in 5 to 100 {
gfx2.text(xx, xx, 1, sc:"hello world! should be pixel-aligned.")
gfx2.text(xx, xx, 2, sc:"hello world! should be pixel-aligned.")
gfx2.text(xx, xx, 3, sc:"hello world! should be pixel-aligned.")
gfx2.text(xx, xx, 0, sc:"hello world! should be pixel-aligned.")
when var {
1 -> txt.print("one")
2 -> txt.print("two")
0 -> {
}
else -> txt.print("other")
}
gfx2.screen_mode(0)
txt.print_uw(cbm.RDTIM16())
txt.print(" jiffies")
repeat { }
}
}
+1 -1
View File
@@ -5,4 +5,4 @@ org.gradle.daemon=true
kotlin.code.style=official
javaVersion=11
kotlinVersion=1.9.0
version=9.2
version=9.2.1