optimized mkword(0, X)

This commit is contained in:
Irmen de Jong 2022-08-11 22:51:09 +02:00
parent 4d2b21816d
commit 4d840c7db8
3 changed files with 16 additions and 10 deletions

View File

@ -331,6 +331,14 @@ class ExpressionSimplifier(private val program: Program) : AstWalker() {
}
}
if(functionCallExpr.target.nameInSource == listOf("mkword")) {
if(functionCallExpr.args[0].constValue(program)?.number==0.0) {
// just cast the lsb to uword
val cast = TypecastExpression(functionCallExpr.args[1], DataType.UWORD, true, functionCallExpr.position)
return listOf(IAstModification.ReplaceNode(functionCallExpr, cast, parent))
}
}
return noModifications
}

View File

@ -4,8 +4,6 @@ TODO
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?
...

View File

@ -3,17 +3,17 @@
main {
sub start() {
uword ww = $ff34
ww = ww ^ ww<<8
ubyte left = $12
ubyte right = $34
uword ww
ww = mkword(left, right)
txt.print_uwhex(ww, true)
ww = $ff34
ww = ww ^ mkword(lsb(ww), 0)
ww = mkword(left, 0)
txt.print_uwhex(ww, true)
ww = $ff34
ww = ww ^ ww >> 8
ww = mkword(0, right)
txt.print_uwhex(ww, true)
ww = $ff34
ww = ww ^ msb(ww)
ww = right as uword
txt.print_uwhex(ww, true)
}