mirror of
https://github.com/irmen/prog8.git
synced 2025-02-09 07:31:34 +00:00
optimized uword <<8 and >>8
This commit is contained in:
parent
2d34fdd28f
commit
4d2b21816d
@ -564,7 +564,14 @@ class ExpressionSimplifier(private val program: Program) : AstWalker() {
|
|||||||
DataType.UWORD, DataType.WORD -> {
|
DataType.UWORD, DataType.WORD -> {
|
||||||
if (amount >= 16) {
|
if (amount >= 16) {
|
||||||
return NumericLiteral(targetDt, 0.0, expr.position)
|
return NumericLiteral(targetDt, 0.0, expr.position)
|
||||||
} else if (amount > 8) {
|
}
|
||||||
|
else if(amount==8) {
|
||||||
|
// shift left by 8 bits is just a byte operation: mkword(lsb(X), 0)
|
||||||
|
val lsb = FunctionCallExpression(IdentifierReference(listOf("lsb"), expr.position), mutableListOf(expr.left), expr.position)
|
||||||
|
return FunctionCallExpression(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(lsb, NumericLiteral(DataType.UBYTE, 0.0, expr.position)), expr.position)
|
||||||
|
}
|
||||||
|
else if (amount > 8) {
|
||||||
|
// same as above but with residual shifts.
|
||||||
val lsb = FunctionCallExpression(IdentifierReference(listOf("lsb"), expr.position), mutableListOf(expr.left), expr.position)
|
val lsb = FunctionCallExpression(IdentifierReference(listOf("lsb"), expr.position), mutableListOf(expr.left), expr.position)
|
||||||
val shifted = BinaryExpression(lsb, "<<", NumericLiteral.optimalInteger(amount - 8, expr.position), expr.position)
|
val shifted = BinaryExpression(lsb, "<<", NumericLiteral.optimalInteger(amount - 8, expr.position), expr.position)
|
||||||
return FunctionCallExpression(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(shifted, NumericLiteral.optimalInteger(0, expr.position)), expr.position)
|
return FunctionCallExpression(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(shifted, NumericLiteral.optimalInteger(0, expr.position)), expr.position)
|
||||||
@ -603,12 +610,19 @@ class ExpressionSimplifier(private val program: Program) : AstWalker() {
|
|||||||
if (amount >= 16) {
|
if (amount >= 16) {
|
||||||
return NumericLiteral.optimalInteger(0, expr.position)
|
return NumericLiteral.optimalInteger(0, expr.position)
|
||||||
}
|
}
|
||||||
|
else if(amount==8) {
|
||||||
|
// shift right by 8 bits is just a byte operation: msb(X) as uword
|
||||||
|
val msb = FunctionCallExpression(IdentifierReference(listOf("msb"), expr.position), mutableListOf(expr.left), expr.position)
|
||||||
|
return TypecastExpression(msb, DataType.UWORD, true, expr.position)
|
||||||
|
}
|
||||||
else if (amount > 8) {
|
else if (amount > 8) {
|
||||||
|
// same as above but with residual shifts.
|
||||||
val msb = FunctionCallExpression(IdentifierReference(listOf("msb"), expr.position), mutableListOf(expr.left), expr.position)
|
val msb = FunctionCallExpression(IdentifierReference(listOf("msb"), expr.position), mutableListOf(expr.left), expr.position)
|
||||||
return TypecastExpression(BinaryExpression(msb, ">>", NumericLiteral.optimalInteger(amount - 8, expr.position), expr.position), DataType.UWORD, true, expr.position)
|
return TypecastExpression(BinaryExpression(msb, ">>", NumericLiteral.optimalInteger(amount - 8, expr.position), expr.position), DataType.UWORD, true, expr.position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DataType.WORD -> {
|
DataType.WORD -> {
|
||||||
|
// bit-shifting a signed value shouldn't be allowed by the compiler but here we go...
|
||||||
if (amount > 16) {
|
if (amount > 16) {
|
||||||
expr.right = NumericLiteral.optimalInteger(16, expr.right.position)
|
expr.right = NumericLiteral.optimalInteger(16, expr.right.position)
|
||||||
return null
|
return null
|
||||||
|
@ -3,6 +3,10 @@ TODO
|
|||||||
|
|
||||||
For next release
|
For next release
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^
|
||||||
|
- crc ^= mkword(@(data), 0) produces faulty asm, as opposed to crc ^= mkword(variable, 0)
|
||||||
|
- optimize asm generated for mkword(0, X) and mkword(X, 0)
|
||||||
|
- check signed value >> and << .... do we calculate the right thing?
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,18 @@
|
|||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
txt.print("yo")
|
uword ww = $ff34
|
||||||
|
ww = ww ^ ww<<8
|
||||||
|
txt.print_uwhex(ww, true)
|
||||||
|
ww = $ff34
|
||||||
|
ww = ww ^ mkword(lsb(ww), 0)
|
||||||
|
txt.print_uwhex(ww, true)
|
||||||
|
ww = $ff34
|
||||||
|
ww = ww ^ ww >> 8
|
||||||
|
txt.print_uwhex(ww, true)
|
||||||
|
ww = $ff34
|
||||||
|
ww = ww ^ msb(ww)
|
||||||
|
txt.print_uwhex(ww, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
; sub start2() {
|
; sub start2() {
|
||||||
@ -19,22 +30,3 @@ main {
|
|||||||
; txt.print_ub(arr[3])
|
; txt.print_ub(arr[3])
|
||||||
; }
|
; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
optional {
|
|
||||||
%option force_output
|
|
||||||
|
|
||||||
ubyte value
|
|
||||||
|
|
||||||
sub sub1() {
|
|
||||||
value++
|
|
||||||
}
|
|
||||||
|
|
||||||
sub sub2() {
|
|
||||||
value++
|
|
||||||
}
|
|
||||||
|
|
||||||
sub sub3() {
|
|
||||||
value++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user