flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > [fasmg, CALM] any tips for macros optimization? 
Author 

Tomasz Grysztar
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 preprocessingrelated 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 subexpression 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 definitiontime if possible) and secondarily minimize the number of separate commands. 

04 May 2021, 16:14 

Tomasz Grysztar
One more thing: when a subexpression 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
A little offtopic, 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
Tomasz Grysztar wrote:
Yet, in another it seems more expository. (three bytes) 

06 May 2021, 01:30 

revolution
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
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 © 19992020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.