Assembler instructions for most CPUs
permit forming the 64-bit product of
two 32-bit integers, then access to
the top and bottom parts.
Such operations provide the essentials
for a class of random number generators,
called
multiply-with-carry (MWC) RNGs,
in which, given a 32-bit multiplier 'a',
and a current 32-bit pair x,c, one gets
a new pair by forming t=a*x+c in 64 bits,
then the new c is the top 32 bits of t,
and the new x is the bottom 32 bits of t.
This is easy to do in C---for example,
this C code produces 1000 integers from
a certain MWC RNG with period>2^60 and
excellent performance in tests of randomness:
unsigned long x=1234567,c=0;
unsigned long long t; int i;
for(i=0;i<1000;i++)
{t=695696193*x+c; c=t>>32; x=t; printf("%U",x); }
If Fortran allowed unsigned integers, that same
set of 1000 integers might be produced by a code
segment such as this:
unsigned integer*4 x=1234567,c=0
unsigned integer*8 t
do 2 i=1,1000
t=695696193*x+c
c=ishft(t,-32)
x=t
2 print*,x
Are there now any Fortran compilers
for which that code, or modifications,
could be implemented, permitting
formation of a*x+c in 64 bits,
then easy access to the top-32
and bottom-32 parts?
I switched from Fortran to C a number of
years ago, partly because the Fortran compiler
I used, Microsoft Fortran, would not run
on Windows XP, but also because Fortran
provided no easy way to get a 64-bit
version of a*x+c and extract the top and
bottom parts.
Are there any current Fortrans that do?
George Marsaglia