flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > [fasmg, CALM] any tips for macros optimization? |
Author |
|
Tomasz Grysztar 04 May 2021, 16:14
First of all, the expression evaluator in fasmg is really not well tuned at the moment - before I introduced CALM it was not a problem, as its poor performance was generally overshadowed by preprocessing-related overhead, but with CALM I have now exposed its problems and it's a bit of a shame. I may try to improve some of the most critical paths in the future, but I do not promise anything at the moment.
Also, ALM compiler is currently not doing any expression optimization, so even if your expression contains only numeric literals and no variable references, it is still not going to be reduced and COMPUTE is going to perform all the operations. Which means that if you use an expression to compute a constant, it is better to calculate it separately at definition time. For example: Code: calminstruction masked value compute result, value and (1 shl 24 - 1) end calminstruction Code: ; this is going to be slightly faster: include 'xcalm.inc' calminstruction masked value local mask init mask, 1 shl 24 - 1 compute result, value and mask end calminstruction On the other hand, when your expression contains multiple operations on variables, it may be slightly better to leave it as a single complex expression instead of splitting it into multiple COMPUTE commands - there is a small overhead related to assigning results to variables. But this overhead is still likely smaller than the time needed for any actual computations, so if you can calculate a sub-expression that is common to multiple COMPUTE/CHECK commands and store it into variable, it is most likely better to do so. All of the above could perhaps be summarized into a simple rule of thumb: first minimize the number of operations performed by your COMPUTE commands (including moving some of them to the definition-time if possible) and secondarily minimize the number of separate commands. |
|||
04 May 2021, 16:14 |
|
Tomasz Grysztar 04 May 2021, 17:05
One more thing: when a sub-expression is inside a symbolic variable, then its computation is going to be even slower, as it needs to be parsed before it can be evaluated. If you have an argument that you use multiple times in COMPUTE/CHECK commands, start by converting it into its evaluated numeric value:
Code: compute argument, argument Code: compute argument, +argument ; if argument is a string, evaluate as number |
|||
04 May 2021, 17:05 |
|
Tomasz Grysztar 05 May 2021, 11:55
A little off-topic, but I have just realized that there is a little trick that allows to easily create a mask spanning a given number of bytes. The same as:
Code: 1 shl 24 - 1 Code: (-1) bswap 3 |
|||
05 May 2021, 11:55 |
|
bitRAKE 06 May 2021, 01:30
Tomasz Grysztar wrote:
Yet, in another it seems more expository. (three bytes) _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
06 May 2021, 01:30 |
|
revolution 06 May 2021, 01:48
It feels weird to me that "((-1) bswap 3) bswap 3" doesn't return the original value of -1
|
|||
06 May 2021, 01:48 |
|
Tomasz Grysztar 06 May 2021, 06:26
The original -1 is arbitrary length, while with "bswap N" you introduce a fixed size. You get a -1 valid for that size, but obviously you cannot get anything longer (endianness switching does work well for "infinite" length numbers).
|
|||
06 May 2021, 06:26 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.