Compare commits

...
1 Commits
Author SHA1 Message Date
Irmen de Jong ee09d35fdc fix byte 'downto 0' for-loop hanging on the virtual target
BSTPOS after DECM read stale status flags on the VM because DECM leaves
flags untouched there. Only use the BSTPOS fast path on 6502 hardware or
targets honoring the multi-byte status-bits contract; otherwise emit the
explicit LOADM+CMPI+BSTNE check. Backported from master (22a2f8cbc).
2026-09-12 01:36:51 +02:00
4 changed files with 18 additions and 12 deletions

No files matched your search

@@ -44,6 +44,11 @@ enum class CpuType(val statusBitsOnMultiByteOps: Boolean) {
* behavior consistent across all current targets.
*/
VIRTUAL(false)
;
/** True for the 6502-family targets (plain 6502 and 65C02). */
val is6502: Boolean
get() = this == CPU6502 || this == CPU65C02
}
interface ICompilationTarget: IStringEncoding, IMemSizer {
@@ -888,7 +888,10 @@ class IRCodeGen(
val chunk2 = addConstMem(loopvarDtIr, null, loopvarSymbol, iterable.step)
if(loopvarDtIr==IRDataType.BYTE && iterable.step==-1 && iterable.last==0) {
// downto 0 optimization (byte)
if(loopvarDt.isSignedByte || iterable.first<=127) {
// Only rely on DECM setting status bits on targets where it actually does (6502 hardware,
// or targets that honor the strict multi-byte status-bits contract). On the VM DECM
// leaves flags untouched, so BSTPOS would read stale state and loop forever.
if((loopvarDt.isSignedByte || iterable.first<=127) && (options.compTarget.cpu.is6502 || options.compTarget.cpu.statusBitsOnMultiByteOps)) {
chunk2 += IRInstruction(Opcode.BSTPOS, labelSymbol = loopLabel)
} else {
chunk2 += IRInstruction(Opcode.LOADM, loopvarDtIr, reg1 = indexReg, labelSymbol = loopvarSymbol)
+8 -10
View File
@@ -1,14 +1,12 @@
main {
const uword STACK_SIZE = 10
struct Stack {
uword[STACK_SIZE] stack1
uword[20] stack2
uword top
}
%import textio
%zeropage basicsafe
main {
sub start() {
^^Stack st = []
st.stack1[5] = 9999
st.stack2[5] = 8888
for cx16.r0L in 5 downto 0 {
txt.print_ub(cx16.r0L)
txt.spc()
}
}
}
+1 -1
View File
@@ -4,4 +4,4 @@ org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.configuration-cache=false
kotlin.code.style=official
version=12.3.4-SNAPSHOT
version=12.3.4