optimize word&=$ff00 and word&=$00ff

This commit is contained in:
Irmen de Jong 2022-01-28 13:40:28 +01:00
parent 990c8e1f18
commit 06128b5d07
4 changed files with 37 additions and 19 deletions

View File

@ -798,7 +798,8 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
"<=" -> asmgen.out(if(dt==DataType.UWORD) " jsr prog8_lib.lesseq_uw" else " jsr prog8_lib.lesseq_w")
">=" -> asmgen.out(if(dt==DataType.UWORD) " jsr prog8_lib.greatereq_uw" else " jsr prog8_lib.greatereq_w")
"==" -> asmgen.out(" jsr prog8_lib.equal_w")
"!=" -> asmgen.out(" jsr prog8_lib.notequal_w") "&" -> asmgen.out(" jsr prog8_lib.bitand_w")
"!=" -> asmgen.out(" jsr prog8_lib.notequal_w")
"&" -> asmgen.out(" jsr prog8_lib.bitand_w")
"^" -> asmgen.out(" jsr prog8_lib.bitxor_w")
"|" -> asmgen.out(" jsr prog8_lib.bitor_w")
"and" -> asmgen.out(" jsr prog8_lib.and_w")

View File

@ -1066,6 +1066,18 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
else
asmgen.out(" lda #0 | sta $name | sta $name+1")
}
value == 0x00ff -> {
if(asmgen.isTargetCpu(CpuType.CPU65c02))
asmgen.out(" stz $name+1")
else
asmgen.out(" lda #0 | sta $name+1")
}
value == 0xff00 -> {
if(asmgen.isTargetCpu(CpuType.CPU65c02))
asmgen.out(" stz $name")
else
asmgen.out(" lda #0 | sta $name")
}
value and 255 == 0 -> {
if(asmgen.isTargetCpu(CpuType.CPU65c02))
asmgen.out(" stz $name")

View File

@ -3,6 +3,10 @@ TODO
For next release
^^^^^^^^^^^^^^^^
- fix optimization of w >>= 8 , it generates bad code when opt=on, ok when opt=off
- fix w <<= 8 generates weird code with pha/pla in it when opt=on, ok when opt=off
- optimize w=msb(w) => w >>=8, w=lsb(w) ==> w &= $00ff
fix the value of ww being wrong (with optimizations enabled) in :
sub start() {
byte ub1 = -50
@ -17,7 +21,6 @@ fix the value of ww being wrong (with optimizations enabled) in :
return x1
}
- optimize w=msb(w), w=lsb(w)
...
@ -37,7 +40,7 @@ Blocked by an official Commander-x16 r39 release
Future Things and Ideas
^^^^^^^^^^^^^^^^^^^^^^^
- nameInAssemblyCode() should search smarter
- nameInAssemblyCode() should search smarter (only labels in column 0? only full words, not part of a larger word?)
- Fix: don't report as recursion if code assigns address of its own subroutine to something, rather than calling it
- allow "xxx" * constexpr (where constexpr is not a number literal, now gives expression error not same type)
- can we promise a left-to-right function call argument evaluation? without sacrificing performance

View File

@ -1,23 +1,25 @@
%import textio
%import string
%zeropage basicsafe
main {
sub start() {
uword xx=$ea31
xx = lsb(xx)
uword ww = plot(lsb(xx), msb(xx))
ww=msb(ww)
txt.print_uwhex(ww, true)
uword @shared xx=$ea31
xx &= $00ff
;xx = lsb(xx)
txt.print_uwhex(xx, true)
xx = $ea31
xx &= $ff00
; xx = msb(xx)
; %asm {{
; nop
; nop
; }}
; xx >>= 8
; %asm {{
; nop
; nop
; }}
; xx <<= 8
txt.print_uwhex(xx, true)
}
inline asmsub plot(uword plotx @R0, uword ploty @R1) -> uword @AY{
%asm {{
lda cx16.r0
ldy cx16.r1
rts
}}
}
}