[fpc-devel] x86-64 compilation of while loops

Florian Klämpfl florian at freepascal.org
Tue May 29 22:27:05 CEST 2018


Am 28.05.2018 um 01:55 schrieb J. Gareth Moreton:
> 
> In this case, the ".balign" hint adds 2 bytes to pad the loop.  However, my question is this... why
> does it immediately jump to the end of the loop to check the condition (which is very likely to be
> true on the first iteration), only to jump to the beginning again? 

Several reasons:
- it is not that easy to find a heuristics when the condition should be checked twice
- two conditional jumps waste an extra branch prediction table entry
- bigger code, higher cache usage

Weigthing these reasons against the little overhead of an extra unconditional jump, we decided to
use the currently used code generation strategy.



More information about the fpc-devel mailing list