optimized codegen for word*128 (word << 7): no longer do 7 shifts

This commit is contained in:
Irmen de Jong
2025-01-04 23:05:22 +01:00
parent 407773bda2
commit a56ae7539a
4 changed files with 67 additions and 13 deletions

View File

@@ -1161,6 +1161,23 @@ internal class AssignmentAsmGen(
}
}
} else if(dt.isWord) {
if(shifts==7 && expr.operator == "<<") {
// optimized shift left 7 (*128) by first swapping the lsb/msb and then doing just one final shift
assignExpressionToRegister(expr.left, RegisterOrPair.AY, signed)
asmgen.out("""
; shift left 7
sty P8ZP_SCRATCH_REG ; msb
lsr P8ZP_SCRATCH_REG
php ; save carry
sta P8ZP_SCRATCH_REG
lda #0
plp ; restore carry
ror P8ZP_SCRATCH_REG
ror a
ldy P8ZP_SCRATCH_REG""")
return true
}
assignExpressionToRegister(expr.left, RegisterOrPair.AY, signed)
when (shifts) {
in 0..7 -> {

View File

@@ -1901,6 +1901,20 @@ $shortcutLabel:""")
else
asmgen.out(" lda #0 | sta $lsb")
}
value==7 -> {
// optimized shift left 7 (*128) by first swapping the lsb/msb and then doing just one final shift
asmgen.out("""
; shift left 7
lsr $msb
php ; save carry
lda $lsb
sta $msb
lda #0
sta $lsb
plp ; restore carry
ror $msb
ror $lsb""")
}
value>3 -> asmgen.out("""
ldy #$value
- asl $lsb