This release includes a optimizes constant arguments to inlined words, including, when possible, constant arguments to inlined instructions in such words, such as +
, -
, AND
, OR
, XOR
, LSHIFT
, RSHIFT
, ARSHIFT
, B!
, H!
, and !
.
This release includes a optimizes constant arguments to inlined words, including, when possible, constant arguments to inlined instructions in such words, such as +
, -
, AND
, OR
, XOR
, LSHIFT
, RSHIFT
, ARSHIFT
, B!
, H!
, and !
.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
That's impressive! How does the compiler "know" that FOO is immutable?
Are you sure? yes | no
It analyzes the instructions in FOO and only if these instructions are identical to that of a CONSTANT with a given value does it treat the word as being able to be optimized away. At the present the word also needs to be marked as inlinable, even though I could potentially in the future add some degree of automatic inlining.
Are you sure? yes | no
The particular instructions it looks for are:
PUSH {LR}
SUBS R7, #$4
STR R6, [R7]
Either:
MOVS R6, #<lower 8 bits>
or:
MOVW R6, #<lower 16 bits>
or:
MOVW R6, #<lower 16 bits>
MOVT R6, #<upper 16 bits>
and then:
POP {PC}
Are you sure? yes | no
Nice :-)
How do you collapse phrases onto single instructions?
Are there limitations (e.g. "readADC 2 *" works but "2 readADC * " doesn't)?
Are you sure? yes | no
The main limitations are that it only collapses instruction sequences where the last argument is a constant, and that it never statically evaluates expressions. However such constants include ones defined with CONSTANT.
Are you sure? yes | no
Also note that any inlined word instruction-for-instruction equivalent to a word defined with CONSTANT is treated similarly by the optimizer. Take the following for instance:
: FOO 4 [INLINED] ; ok
SEE FOO
2000045C B500: FOO: PUSH {LR}
2000045E 3F04: SUBS R7, #$4
20000460 603E: STR R6, [R7]
20000462 2604: MOVS R6, #$4
20000464 BD00: POP {PC}
ok
4 CONSTANT BAR ok
SEE BAR
20000474 B500: BAR: PUSH {LR}
20000476 3F04: SUBS R7, #$4
20000478 603E: STR R6, [R7]
2000047A 2604: MOVS R6, #$4
2000047C BD00: POP {PC}
ok
: +FOO FOO + ; ok
SEE +FOO
2000048E B500: +FOO: PUSH {LR}
20000490 3604: ADDS R6, #$4
20000492 BD00: POP {PC}
ok
: +BAR BAR + ; ok
SEE +BAR
200004A6 B500: +BAR: PUSH {LR}
200004A8 3604: ADDS R6, #$4
200004AA BD00: POP {PC}
ok
Are you sure? yes | no