mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
optimize cmp word equal/notequal
This commit is contained in:
parent
eee805183c
commit
10760a53a8
@ -2456,11 +2456,9 @@ $repeatLabel lda $counterVar
|
|||||||
assignExpressionToRegister(right, RegisterOrPair.AY)
|
assignExpressionToRegister(right, RegisterOrPair.AY)
|
||||||
} else {
|
} else {
|
||||||
pushCpuStack(DataType.UWORD, left)
|
pushCpuStack(DataType.UWORD, left)
|
||||||
assignExpressionToRegister(right, RegisterOrPair.AY)
|
assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||||
out(" sta P8ZP_SCRATCH_REG")
|
restoreRegisterStack(CpuRegister.Y, false)
|
||||||
popCpuStack(DataType.UWORD, "P8ZP_SCRATCH_W2")
|
restoreRegisterStack(CpuRegister.A, false)
|
||||||
out(" lda P8ZP_SCRATCH_REG")
|
|
||||||
// TODO optimize this path..... CMP_OPT
|
|
||||||
}
|
}
|
||||||
out("""
|
out("""
|
||||||
cmp P8ZP_SCRATCH_W2
|
cmp P8ZP_SCRATCH_W2
|
||||||
@ -2544,11 +2542,9 @@ $repeatLabel lda $counterVar
|
|||||||
assignExpressionToRegister(right, RegisterOrPair.AY)
|
assignExpressionToRegister(right, RegisterOrPair.AY)
|
||||||
} else {
|
} else {
|
||||||
pushCpuStack(DataType.UWORD, left)
|
pushCpuStack(DataType.UWORD, left)
|
||||||
assignExpressionToRegister(right, RegisterOrPair.AY)
|
assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||||
out(" sta P8ZP_SCRATCH_REG")
|
restoreRegisterStack(CpuRegister.Y, false)
|
||||||
popCpuStack(DataType.UWORD, "P8ZP_SCRATCH_W2")
|
restoreRegisterStack(CpuRegister.A, false)
|
||||||
out(" lda P8ZP_SCRATCH_REG")
|
|
||||||
// TODO optimize this path..... CMP_OPT
|
|
||||||
}
|
}
|
||||||
out("""
|
out("""
|
||||||
cmp P8ZP_SCRATCH_W2
|
cmp P8ZP_SCRATCH_W2
|
||||||
|
@ -3,8 +3,6 @@ TODO
|
|||||||
|
|
||||||
For next release
|
For next release
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^
|
||||||
- optimize cmp's that can use the variable directly out(" cmp $.....
|
|
||||||
- optimize cmp word equal/notequal search for CMP_OPT
|
|
||||||
- 6502 codegen: make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as ``p8v_``? Or not worth it (most 3 letter opcodes as variables are nonsensical anyway)
|
- 6502 codegen: make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as ``p8v_``? Or not worth it (most 3 letter opcodes as variables are nonsensical anyway)
|
||||||
then we can get rid of the instruction lists in the machinedefinitions as well. This is already no problem at all in the IR codegen.
|
then we can get rid of the instruction lists in the machinedefinitions as well. This is already no problem at all in the IR codegen.
|
||||||
- create BSS section in output program and put StStaticVariables in there with bss=true. Don't forget to add init code to zero out everything that was put in bss. If array in bss->only zero ONCE! So requires self-modifying code
|
- create BSS section in output program and put StStaticVariables in there with bss=true. Don't forget to add init code to zero out everything that was put in bss. If array in bss->only zero ONCE! So requires self-modifying code
|
||||||
|
133
examples/test.p8
133
examples/test.p8
@ -1,11 +1,17 @@
|
|||||||
%import textio
|
%import textio
|
||||||
%zeropage dontuse
|
%zeropage dontuse
|
||||||
|
|
||||||
|
|
||||||
|
; base level code size: $279
|
||||||
|
|
||||||
|
|
||||||
main {
|
main {
|
||||||
bool[1] expected = [ true ]
|
bool[1] expected = [ true ]
|
||||||
uword[1] expectedw = [4242 ]
|
uword[1] expectedw = [4242 ]
|
||||||
|
|
||||||
sub get() -> bool {
|
sub get() -> bool {
|
||||||
|
ubyte xx
|
||||||
|
xx = 1
|
||||||
%asm {{
|
%asm {{
|
||||||
stz P8ZP_SCRATCH_W1
|
stz P8ZP_SCRATCH_W1
|
||||||
stz P8ZP_SCRATCH_W1+1
|
stz P8ZP_SCRATCH_W1+1
|
||||||
@ -14,9 +20,11 @@ main {
|
|||||||
stz P8ZP_SCRATCH_REG
|
stz P8ZP_SCRATCH_REG
|
||||||
stz P8ZP_SCRATCH_B1
|
stz P8ZP_SCRATCH_B1
|
||||||
}}
|
}}
|
||||||
return true
|
return xx
|
||||||
}
|
}
|
||||||
sub same() -> bool {
|
sub same() -> bool {
|
||||||
|
ubyte xx
|
||||||
|
xx = 1
|
||||||
%asm {{
|
%asm {{
|
||||||
stz P8ZP_SCRATCH_W1
|
stz P8ZP_SCRATCH_W1
|
||||||
stz P8ZP_SCRATCH_W1+1
|
stz P8ZP_SCRATCH_W1+1
|
||||||
@ -25,10 +33,11 @@ main {
|
|||||||
stz P8ZP_SCRATCH_REG
|
stz P8ZP_SCRATCH_REG
|
||||||
stz P8ZP_SCRATCH_B1
|
stz P8ZP_SCRATCH_B1
|
||||||
}}
|
}}
|
||||||
return true
|
return xx
|
||||||
}
|
}
|
||||||
|
|
||||||
sub getw() -> uword {
|
sub getw() -> uword {
|
||||||
|
uword xx=4242
|
||||||
%asm {{
|
%asm {{
|
||||||
stz P8ZP_SCRATCH_W1
|
stz P8ZP_SCRATCH_W1
|
||||||
stz P8ZP_SCRATCH_W1+1
|
stz P8ZP_SCRATCH_W1+1
|
||||||
@ -37,9 +46,10 @@ main {
|
|||||||
stz P8ZP_SCRATCH_REG
|
stz P8ZP_SCRATCH_REG
|
||||||
stz P8ZP_SCRATCH_B1
|
stz P8ZP_SCRATCH_B1
|
||||||
}}
|
}}
|
||||||
return 4242
|
return xx
|
||||||
}
|
}
|
||||||
sub samew() -> uword {
|
sub samew() -> uword {
|
||||||
|
uword xx=4242
|
||||||
%asm {{
|
%asm {{
|
||||||
stz P8ZP_SCRATCH_W1
|
stz P8ZP_SCRATCH_W1
|
||||||
stz P8ZP_SCRATCH_W1+1
|
stz P8ZP_SCRATCH_W1+1
|
||||||
@ -48,9 +58,22 @@ main {
|
|||||||
stz P8ZP_SCRATCH_REG
|
stz P8ZP_SCRATCH_REG
|
||||||
stz P8ZP_SCRATCH_B1
|
stz P8ZP_SCRATCH_B1
|
||||||
}}
|
}}
|
||||||
return 4242
|
return xx
|
||||||
|
}
|
||||||
|
sub differentw() -> uword {
|
||||||
|
uword xx=9999
|
||||||
|
%asm {{
|
||||||
|
stz P8ZP_SCRATCH_W1
|
||||||
|
stz P8ZP_SCRATCH_W1+1
|
||||||
|
stz P8ZP_SCRATCH_W2
|
||||||
|
stz P8ZP_SCRATCH_W2+1
|
||||||
|
stz P8ZP_SCRATCH_REG
|
||||||
|
stz P8ZP_SCRATCH_B1
|
||||||
|
}}
|
||||||
|
return xx
|
||||||
}
|
}
|
||||||
sub one() -> ubyte {
|
sub one() -> ubyte {
|
||||||
|
ubyte xx=1
|
||||||
%asm {{
|
%asm {{
|
||||||
stz P8ZP_SCRATCH_W1
|
stz P8ZP_SCRATCH_W1
|
||||||
stz P8ZP_SCRATCH_W1+1
|
stz P8ZP_SCRATCH_W1+1
|
||||||
@ -59,110 +82,50 @@ main {
|
|||||||
stz P8ZP_SCRATCH_REG
|
stz P8ZP_SCRATCH_REG
|
||||||
stz P8ZP_SCRATCH_B1
|
stz P8ZP_SCRATCH_B1
|
||||||
}}
|
}}
|
||||||
return 1
|
return xx
|
||||||
}
|
}
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
if get() == expected[0]
|
|
||||||
txt.print("ok\n")
|
|
||||||
else
|
|
||||||
txt.print("fail\n")
|
|
||||||
|
|
||||||
; this is working fine:
|
|
||||||
if expected[0] == get()
|
|
||||||
txt.print("ok\n")
|
|
||||||
else
|
|
||||||
txt.print("fail\n")
|
|
||||||
|
|
||||||
if getw() == expectedw[0]
|
|
||||||
txt.print("ok\n")
|
|
||||||
else
|
|
||||||
txt.print("fail\n")
|
|
||||||
|
|
||||||
; this is working fine:
|
|
||||||
if expectedw[0] == getw()
|
|
||||||
txt.print("ok\n")
|
|
||||||
else
|
|
||||||
txt.print("fail\n")
|
|
||||||
|
|
||||||
; unquals
|
|
||||||
|
|
||||||
if get() != expected[0]
|
|
||||||
txt.print("fail\n")
|
|
||||||
else
|
|
||||||
txt.print("ok\n")
|
|
||||||
|
|
||||||
; this is working fine:
|
|
||||||
if expected[0] != get()
|
|
||||||
txt.print("fail\n")
|
|
||||||
else
|
|
||||||
txt.print("ok\n")
|
|
||||||
|
|
||||||
if getw() != expectedw[0]
|
|
||||||
txt.print("fail\n")
|
|
||||||
else
|
|
||||||
txt.print("ok\n")
|
|
||||||
|
|
||||||
; this is working fine:
|
|
||||||
if expectedw[0] != getw()
|
|
||||||
txt.print("fail\n")
|
|
||||||
else
|
|
||||||
txt.print("ok\n")
|
|
||||||
|
|
||||||
; now with 2 non-simple operands:
|
|
||||||
if get() == same()
|
|
||||||
txt.print("ok\n")
|
|
||||||
else
|
|
||||||
txt.print("fail\n")
|
|
||||||
|
|
||||||
; this is working fine:
|
|
||||||
if same() == get()
|
|
||||||
txt.print("ok\n")
|
|
||||||
else
|
|
||||||
txt.print("fail\n")
|
|
||||||
|
|
||||||
if getw() == samew()
|
if getw() == samew()
|
||||||
txt.print("ok\n")
|
txt.print("ok\n")
|
||||||
else
|
else
|
||||||
txt.print("fail\n")
|
txt.print("fail\n")
|
||||||
|
|
||||||
; this is working fine:
|
|
||||||
if samew() == getw()
|
if samew() == getw()
|
||||||
txt.print("ok\n")
|
txt.print("ok\n")
|
||||||
else
|
else
|
||||||
txt.print("fail\n")
|
txt.print("fail\n")
|
||||||
|
|
||||||
; unquals
|
|
||||||
|
|
||||||
if get() != same()
|
|
||||||
txt.print("fail\n")
|
|
||||||
else
|
|
||||||
txt.print("ok\n")
|
|
||||||
|
|
||||||
; this is working fine:
|
|
||||||
if same() != get()
|
|
||||||
txt.print("fail\n")
|
|
||||||
else
|
|
||||||
txt.print("ok\n")
|
|
||||||
|
|
||||||
if getw() != samew()
|
if getw() != samew()
|
||||||
txt.print("fail\n")
|
txt.print("fail\n")
|
||||||
else
|
else
|
||||||
txt.print("ok\n")
|
txt.print("ok\n")
|
||||||
|
|
||||||
; this is working fine:
|
|
||||||
if samew() != getw()
|
if samew() != getw()
|
||||||
txt.print("fail\n")
|
txt.print("fail\n")
|
||||||
else
|
else
|
||||||
txt.print("ok\n")
|
txt.print("ok\n")
|
||||||
|
|
||||||
|
|
||||||
; pointer stuff
|
if getw() == differentw()
|
||||||
uword ptr = $4000
|
txt.print("fail\n")
|
||||||
@(ptr+one()) = 42
|
else
|
||||||
if @(ptr+one()) == 42
|
txt.print("ok\n")
|
||||||
txt.print("ok\n")
|
|
||||||
else
|
if differentw() == getw()
|
||||||
txt.print("fail\n")
|
txt.print("fail\n")
|
||||||
|
else
|
||||||
|
txt.print("ok\n")
|
||||||
|
|
||||||
|
if getw() != differentw()
|
||||||
|
txt.print("ok\n")
|
||||||
|
else
|
||||||
|
txt.print("fail\n")
|
||||||
|
|
||||||
|
if differentw() != getw()
|
||||||
|
txt.print("ok\n")
|
||||||
|
else
|
||||||
|
txt.print("fail\n")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user