top 32 bits of 64-bit product of two 32-bit integers
Author Message
top 32 bits of 64-bit product of two 32-bit integers

I would be interested if any of {C,C++,fortran90} can do the following:

AFAIK, most modern CPUs calculate the product of two unsigned 32-bit integers
as a 64-bit integer, and return the bottom 32-bits.  Is there a fast way to
access the top 32 bits of that product in {C,C++,Fortran90}, or is there a
quick way to access the assembly language routine that does so?  Or is the
only way to do this to use the "doubled-precision-multiply" technique:

top32(A*B) =    top16( top16( bot16(A)*bot16(B) )
+ bot16(A)*top16(B)
+ top16(A)*bot16(B) )
+ top16(A)*top16(B)

And would the resulting code be somewhat portable?  How about getting the top
64 bits of the 128-bit product of two 64-bit integers [I work on a DEC Alpha
AXP running OSF/1]?

I don't want to start flame wars, I'm just curious!  Given a task, I use
whatever tool works to get the task done, so I have no emotional involvement

E-mail replies appreciated.  I'll summarize if there is interest.
Thanks,
--
-- Ted
------------------------------------------------------------------------------
Dept. of Applied Math, FS-20    University of Washington    Seattle, WA  98195

------------------------------------------------------------------------------

Mon, 21 Apr 1997 02:45:22 GMT
top 32 bits of 64-bit product of two 32-bit integers

Quote:
> AFAIK, most modern CPUs calculate the product of two unsigned 32-bit integers
> as a 64-bit integer, and return the bottom 32-bits.  Is there a fast way to
> access the top 32 bits of that product in {C,C++,Fortran90}, or is there a
> quick way to access the assembly language routine that does so?  Or is the
> only way to do this to use the "doubled-precision-multiply" technique:

>         top32(A*B) =    top16( top16( bot16(A)*bot16(B) )
>                              + bot16(A)*top16(B)
>                              + top16(A)*bot16(B) )
>                       + top16(A)*top16(B)

> And would the resulting code be somewhat portable?  How about getting the top
> 64 bits of the 128-bit product of two 64-bit integers [I work on a DEC Alpha
> AXP running OSF/1]?

A general multiple precision integer solution: write your own package for it
or get one already written (g++/GNU C++ comes with an Integer class, which
seems to work fine for very very large integers).

For an AXP solution: On an AXP running VMS, then you can in C use the type
__int64, or in FORTRAN (FORTRAN77) use the type INTEGER*8, both will give
you a full 64 bit integer.

Arne

Arne Vajh?j                             local DECNET:  KO::ARNE
Computer Department                     PSI:           PSI%238310013040::ARNE

Tue, 22 Apr 1997 01:14:10 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages