[fpc-pascal] fast integer multiplication

Marcel Martin mm10 at ellipsa.net
Fri Jul 29 18:40:03 CEST 2005

Peter Vreman a écrit :
>>>>Since you ask the question, I suppose you cannot simply
>>>>suppress the "movl $0,%edx" line generation [*]. What about
>>>>using a compiler directive, something like {$EXTENDEDMUL ON/OFF}
>>>>for instance?
>>>I don't like this. This means we have to add directives for all kind of
>>>special cpu features to improve some special corner cases.
>>But it is a special case because FPC makes it special. As I wrote
>>yesterday, when you write Word := Byte * Byte, what you get is
>>the exact result (not the result mod 2^8), when you write
>>Longword := Word * Word, what you get is the exact result (not the
>>Result mod 2^16), but when you write QWord := Longword * Longword,
>>there, what you get is not (always) the exact result but the result
>>mod 2^32. This is FPC which makes special this case by setting the
>>product high part to 0 (what it doesn't do with other cases).
>>Being said that, I agree with you that adding compiler directives
>>is not a good thing [*]. Here, it would be sufficient to suppress
>>the generation of the line "movl $0,%edx". Since you do not do so,
>>I suppose there would be some side effects I don't see at the
>>moment, but it would be the simplest solution.
>>[*] If QWord := Longword * Longword gave the exact result, it would
>>allow me to suppress a lot of compiler directives :-)
> The rules are the same as with int64:=longint*longint. Below is a test.
> The result is -2 on both fpc and delphi.
> var
>   e : int64;
>   i,j : longint;
> begin
>   i:=$7fffffff;
>   j:=2;
>   e:=i*j;
>   writeln(e);
> end.

I was talking about the unsigned cases (but, yes, this is the
same with signed ones).

Now, concerning "both fpc and delphi". That Delphi code can be
compiled with FPC is rather good thing but FPC has not to follow
Delphi. The future of Pascal is not Delphi, it is FreePascal. And,
no, for once, I am not joking. :-)

I recently downloaded Lazarus. I wanted to see whether it could
be possible to adapt one of my softwares ("Primo", see at
http://www.ellipsa.net, written with Delphi 5). After having played
a few hours with Lazarus, I estimated that it was feasible and that
it could take me two weeks to do it. I was wrong. It took me less
than three days! Yes, in less than three days, a version of Primo
entirely written with FreePascal and Lazarus was working. Well,
there still are many "cosmetic" problems but it works.
I think that, in at most one year, it will be possible to write
very good programs with FreePascal and Lazarus (I am talking of
programs having clean GUI's).


BTW, since a few days, I have big problems with this list. Most of
my posts come back with messages like:

   Diagnostic-Code: X-Postfix; host lists.freepascal.org[]
   said: 550-32 x Worm.Lovgate.Z. Last seen 2005-07-29 11:01:07.905214
   (CET) 550 mail from rejected: administrative
   prohibition (host is blacklisted) (in reply to RCPT TO command)

No, there is no worm on my PC ;-)

More information about the fpc-pascal mailing list