The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Form t=a*x+c in 64 bits, get top and bottom 32 bits of t.
 There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic. There was an error processing your request. Please try again. Standard view   View as tree
 1 message

From:
To:
Cc:
Followup To:
Subject:
 Validation: For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon.

More options Jun 14 2007, 11:04 am
Newsgroups: alt.comp.lang.fortran
From: "George Marsaglia" <g...@stat.fsu.edu>
Date: Thu, 14 Jun 2007 11:04:47 -0400
Local: Thurs, Jun 14 2007 11:04 am
Subject: Form t=a*x+c in 64 bits, get top and bottom 32 bits of t.
Assembler instructions for most CPUs
permit forming the 64-bit product of
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,
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