mirror of
https://github.com/irmen/prog8.git
synced 2025-11-01 06:16:15 +00:00
optimized codegen for word*128 (word << 7): no longer do 7 shifts
This commit is contained in:
@@ -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 -> {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user