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
in the answer.

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  
 
 [ 2 post ] 

 Relevant Pages 

1. REQUEST: 64-bit integer math on 32-bit processor

2. x86-64 performance: 32 bit vs 64 bit

3. Division 32-Bit/32-Bit with 16-Bit Register

4. g77: 32-bit to 64-bit

5. SP on a 64-bit CPU and DP on a 32-bit CPU

6. Solaris to Linux: (32 bit and 64 bit):

7. 32 bit to 64 bit:

8. Problem with zipfile between 32-bit and 64-bit

9. 64-bit vs 32-bit tclsh

10. Loading 32 bit packages under 64 bit Tclsh

11. 64-bit expr support at the Tcl level (even on 32-bit OSes)

12. Reading binary file generated from 32-bit machine using 64-bit machine

 

 
Powered by phpBB® Forum Software