[fpc-pascal] Basic routines

Marcel Martin mm10 at ellipsa.net
Sun Apr 10 00:16:32 CEST 2005


Hello,

While writing the "pure Pascal" version of a big integer library
(for FPC 2.0), I notice that the use of a very small assembler
function lowers the average running time of the computations by
about 30-35%. This is far from insignificant.

Currently I use a macro to enable the x86 (32 bits) procedure,
letting to the user the task to re-write it for other processors.
But that's not a good idea ;-) So, it would be nice if such a
routine were part of FPC.

Here it is

function UInt32x32To64(A,B: Longword): QWord; assembler;
asm
   mull %edx
end;

Its use is 3 times as fast than "t := QWord(A)*B;".
(Notice that this routine exists in the Windows SDK)

I also have one concerning the division but, there, the "right"
interface is less obvious and, contrary to the previous function,
it might raise an exception.
In fact, it would be sufficient that FPC uses ONLY one division
for the following code:
   r := a mod b;
   q := a div b;
to divide by two (almost) the running times of divisions of big
integers by small ones.

Would it be difficult to add the mul function to FPC?
Thanks.

mm





More information about the fpc-pascal mailing list