[fpc-devel] The "magic div" algorithm

J. Gareth Moreton gareth at moreton-family.com
Fri Aug 20 15:21:37 CEST 2021


Hi everyone,

I know I was told what the algorithm was already, but I can't find it in my email history, so I'm 
forced to ask again... is there a reference to the algorithm that's used to calculate the 
reciprocal constants used in the integer division optimisations for x86 and AArch64? It's more to 
gain a personal understanding of the algorithm so I can possibly learn to write assembly language 
routines that both do it faster and produce the same results (my original implementation, such 
required double-width registers, produced magic constants that were bit-shifted to 
calc_magic_div_unsigned but which nonetheless produced correct results when the actual divisions 
were applied).

Gareth aka. Kit


More information about the fpc-devel mailing list