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 return noModifications
} }

View File

@ -4,8 +4,6 @@ TODO
For next release For next release
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
- crc ^= mkword(@(data), 0) produces faulty asm, as opposed to crc ^= mkword(variable, 0) - 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 { main {
sub start() { sub start() {
uword ww = $ff34 ubyte left = $12
ww = ww ^ ww<<8 ubyte right = $34
uword ww
ww = mkword(left, right)
txt.print_uwhex(ww, true) txt.print_uwhex(ww, true)
ww = $ff34 ww = mkword(left, 0)
ww = ww ^ mkword(lsb(ww), 0)
txt.print_uwhex(ww, true) txt.print_uwhex(ww, true)
ww = $ff34 ww = mkword(0, right)
ww = ww ^ ww >> 8
txt.print_uwhex(ww, true) txt.print_uwhex(ww, true)
ww = $ff34 ww = right as uword
ww = ww ^ msb(ww)
txt.print_uwhex(ww, true) txt.print_uwhex(ww, true)
} }