mirror of
https://github.com/irmen/prog8.git
synced 2024-12-25 08:29:25 +00:00
slight tweak to word bitshift for large shift values
This commit is contained in:
parent
f7953e4ef3
commit
b985604e22
@ -1642,6 +1642,13 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
}
|
||||
}
|
||||
DataType.UWORD -> {
|
||||
if(amount>=16) {
|
||||
if(CompilationTarget.instance.machine.cpu==CpuType.CPU65c02)
|
||||
asmgen.out(" stz P8ESTACK_LO+1,x | stz P8ESTACK_HI+1,x")
|
||||
else
|
||||
asmgen.out(" lda #0 | sta P8ESTACK_LO+1,x | sta P8ESTACK_HI+1,x")
|
||||
return
|
||||
}
|
||||
var left = amount
|
||||
while (left >= 7) {
|
||||
asmgen.out(" jsr math.shift_right_uw_7")
|
||||
@ -1653,6 +1660,20 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
asmgen.out(" jsr math.shift_right_uw_$left")
|
||||
}
|
||||
DataType.WORD -> {
|
||||
if(amount>=16) {
|
||||
asmgen.out("""
|
||||
lda P8ESTACK_HI+1,x
|
||||
bmi +
|
||||
lda #0
|
||||
sta P8ESTACK_LO+1,x
|
||||
sta P8ESTACK_HI+1,x
|
||||
beq ++
|
||||
+ lda #255
|
||||
sta P8ESTACK_LO+1,x
|
||||
sta P8ESTACK_HI+1,x
|
||||
+""")
|
||||
return
|
||||
}
|
||||
var left = amount
|
||||
while (left >= 7) {
|
||||
asmgen.out(" jsr math.shift_right_w_7")
|
||||
|
148
examples/test.p8
148
examples/test.p8
@ -6,154 +6,6 @@
|
||||
main {
|
||||
|
||||
sub start() {
|
||||
uword uw
|
||||
uword xx
|
||||
word ww
|
||||
word yy
|
||||
|
||||
uw = shiftruw7()
|
||||
xx+=uw
|
||||
uw = shiftruw8()
|
||||
xx+=uw
|
||||
uw = shiftruw9()
|
||||
xx+=uw
|
||||
uw = shiftruw10()
|
||||
xx+=uw
|
||||
uw = shiftruw11()
|
||||
xx+=uw
|
||||
uw = shiftruw12()
|
||||
xx+=uw
|
||||
uw = shiftruw13()
|
||||
xx+=uw
|
||||
uw = shiftruw14()
|
||||
xx+=uw
|
||||
uw = shiftruw15()
|
||||
xx+=uw
|
||||
|
||||
ww = shiftrsw7()
|
||||
yy+=ww
|
||||
ww = shiftrsw8()
|
||||
yy+=ww
|
||||
ww = shiftrsw9()
|
||||
yy+=ww
|
||||
ww = shiftrsw10()
|
||||
yy+=ww
|
||||
ww = shiftrsw11()
|
||||
yy+=ww
|
||||
ww = shiftrsw12()
|
||||
yy+=ww
|
||||
ww = shiftrsw13()
|
||||
yy+=ww
|
||||
ww = shiftrsw14()
|
||||
yy+=ww
|
||||
ww = shiftrsw15()
|
||||
yy+=ww
|
||||
ww = shiftrsw16() ; TODO why sub not replaced by const?
|
||||
yy+=ww
|
||||
ww = shiftrsw17() ; TODO why sub not replaced by const?
|
||||
yy+=ww
|
||||
|
||||
}
|
||||
|
||||
|
||||
sub shiftruw7() -> uword {
|
||||
uword q = $a49f
|
||||
return q >> 7
|
||||
}
|
||||
|
||||
sub shiftruw8() -> uword {
|
||||
uword q = $a49f
|
||||
return (q >> 8) ; TODO fix slow? (and for all below)
|
||||
}
|
||||
|
||||
sub shiftruw9() -> uword {
|
||||
uword q = $a49f
|
||||
return (q >> 9)
|
||||
}
|
||||
|
||||
sub shiftruw10() -> uword {
|
||||
uword q = $a49f
|
||||
return (q >> 10)
|
||||
}
|
||||
|
||||
sub shiftruw11() -> uword {
|
||||
uword q = $a49f
|
||||
return (q >> 11)
|
||||
}
|
||||
|
||||
sub shiftruw12() -> uword {
|
||||
uword q = $a49f
|
||||
return (q >> 12)
|
||||
}
|
||||
|
||||
sub shiftruw13() -> uword {
|
||||
uword q = $a49f
|
||||
return (q >> 13)
|
||||
}
|
||||
|
||||
sub shiftruw14() -> uword {
|
||||
uword q = $a49f
|
||||
return (q >> 14)
|
||||
}
|
||||
|
||||
sub shiftruw15() -> uword {
|
||||
uword q = $a49f
|
||||
return (q >> 15)
|
||||
}
|
||||
|
||||
sub shiftrsw7() -> word {
|
||||
word q = -12345
|
||||
return q >> 7
|
||||
}
|
||||
|
||||
sub shiftrsw8() -> word {
|
||||
word q = -12345
|
||||
return (q >> 8) ; TODO why not marked slow? What code is generated? Also for all below.
|
||||
}
|
||||
|
||||
sub shiftrsw9() -> word {
|
||||
word q = -12345
|
||||
return (q >> 9)
|
||||
}
|
||||
|
||||
sub shiftrsw10() -> word {
|
||||
word q = -12345
|
||||
return (q >> 10)
|
||||
}
|
||||
|
||||
sub shiftrsw11() -> word {
|
||||
word q = -12345
|
||||
return (q >> 11)
|
||||
}
|
||||
|
||||
sub shiftrsw12() -> word {
|
||||
word q = -12345
|
||||
return (q >> 12)
|
||||
}
|
||||
|
||||
sub shiftrsw13() -> word {
|
||||
word q = -12345
|
||||
return (q >> 13)
|
||||
}
|
||||
|
||||
sub shiftrsw14() -> word {
|
||||
word q = -12345
|
||||
return (q >> 14)
|
||||
}
|
||||
|
||||
sub shiftrsw15() -> word {
|
||||
word q = -12345
|
||||
return (q >> 15)
|
||||
}
|
||||
|
||||
sub shiftrsw16() -> word {
|
||||
word q = -12345
|
||||
return (q >> 16)
|
||||
}
|
||||
|
||||
sub shiftrsw17() -> word {
|
||||
word q = -12345
|
||||
return (q >> 17)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user