Re: (x * x) % y

New Message Reply About this list Date view Thread view Subject view Author view

Wei Dai (weidai@eskimo.com)
Wed, 28 Apr 1999 01:29:10 -0700


On Tue, Apr 27, 1999 at 12:10:35PM +0200, mok-kong shen wrote:
> As far as I understand, the problem posed was not how to do
> multi-precision arithmetics with single precision operations but
> to write a piece of code in a high-level programming language
> such that the (hidden) hardware register is used and therefore one
> achieves the same good efficiency as if an assembler code were
> written. Since the standards of programming languages do not
> specify the semantics concerning such registers, there is no way
> of doing that (anyway if the program is to be standard conform). On
> the other hand, compilers often provide routines in addition to what
> is required by the language standards. It would be beneficial if
> there could be some quasi-standard way of making the full product
> of two 32 bit operands (and the reverse operation of division)
> available to the programmers of high-level languages. That would
> greatly facilitate the writing of packages for multi-precision
> arithmetics.

There is already a quasi-standard way of getting the 64-bit product,
namely (word64)a*b, where word64 is "unsigned long long" or "unsigned
__int64". This turns out to be fairly efficient on most compilers, except
there happens to be a bug in MSVC (not fixed as of version 6.0 SP2) that
causes it to emit really inefficient code when either one of the operands
is used elsewhere in a 32x32->64 bit multiplication (this is especially
obvious when you do (word64)a*a but also shows up when you do (word64)a*b
followed by (word64)a*c).


New Message Reply About this list Date view Thread view Subject view Author view

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

The following archive was created by hippie-mail 7.98617-22 on Thu May 27 1999 - 23:44:23