[fpc-devel] The
J. Gareth Moreton
gareth at moreton-family.com
Tue Aug 24 21:46:21 CEST 2021
Some divisors, like 7, do not have a reciprocal that can be contained within 32 bits. Expanding to
64 bits, however, is a clever approach that I overlooked, since you can permit some loss of
precision (the reason why the bit shift is required) due to the limited range. This might be worth
exploring.
Gareth aka. Kit
On Tue 24/08/21 20:14 , "Marģers . via" fpc-develfpc-devel at lists.freepascal.org sent:
> I came up with even shorter variant of div
> example
> function teDWordDivBy7_v4( divided : dword):dword; assembler;
> nostackframe;
> asm
> mov ecx,divided
> mov rax,2635249153693862181
> mul rcx
> mov eax,edx
> end;
>
> current version for comparison
>
> function teDWordDivBy7_v0( divided : dword):dword; assembler;
> nostackframe;
> asm
> mov ecx,divided
> mov eax,613566757
> mul ecx
> add edx,ecx
> rcr edx,1
> shr edx,2
> mov eax,edx
> end;
>
>
>
>
>
>
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel [1]
>
>
>
> Links:
> ------
> [1]
> http://secureweb.fast.net.uk/parse.php?redirect=https://lists.freepascal.or
> g/cgi-bin/mailman/listinfo/fpc-devel
>
More information about the fpc-devel
mailing list