mirror of
https://github.com/irmen/prog8.git
synced 2024-11-22 15:33:02 +00:00
optimize x % p where p=power-of-2, into just x & (p-1)
This commit is contained in:
parent
c853afe769
commit
91e421d961
@ -490,9 +490,9 @@ internal class ExpressionSimplifier(private val program: Program) : AstWalker()
|
||||
if(!idt.isKnown)
|
||||
throw FatalAstException("unknown dt")
|
||||
return NumericLiteralValue(idt.typeOrElse(DataType.STRUCT), 0, expr.position)
|
||||
} else if (cv == 2.0) {
|
||||
} else if (cv in powersOfTwo) {
|
||||
expr.operator = "&"
|
||||
expr.right = NumericLiteralValue.optimalInteger(1, expr.position)
|
||||
expr.right = NumericLiteralValue.optimalInteger(cv!!.toInt()-1, expr.position)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
- optimize %32 to & 31
|
||||
|
||||
- optimize several inner loops in gfx2
|
||||
- hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine)
|
||||
- optimize swap of two memread values with index, using the same pointer expression/variable, like swap(@(ptr+1), @(ptr+2))
|
||||
|
@ -1,10 +1,17 @@
|
||||
%import textio
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
uword width
|
||||
uword width2 = 12345
|
||||
ubyte ub1
|
||||
ubyte ub2 = 123
|
||||
|
||||
; TODO fix compiler crash with noopt:
|
||||
uword x1 = (width-1 as uword) + 2
|
||||
ub1 = ub2 % 32
|
||||
txt.print_ub(ub1)
|
||||
txt.nl()
|
||||
width = width2 % 32
|
||||
txt.print_uw(width)
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user