From: pmontgom@cwi.nl (Peter L. Montgomery)
Subject: Re: Final kick at the "Merced Guessing Game"
Date: 1997/10/20 [thread overview]
Message-ID: <EICC0n.AC0@cwi.nl> (raw)
In-Reply-To: 62eqtu$2ua$1@goanna.cs.rmit.edu.au
In article <62eqtu$2ua$1@goanna.cs.rmit.edu.au>
ok@goanna.cs.rmit.edu.au (Richard A. O'Keefe) writes:
>pmontgom@cwi.nl (Peter L. Montgomery) writes:
>>Craig Burley <burley@tweedledumb.cygnus.com> writes:
>
>>>I don't see any rebuttal there. Care to explain what *low-level*
>>>constructs C is offering that Fortran doesn't offer, aside from
>>>pointers?
>
>> Nobody has been mentioning unsigned arithmetic.
>
>The machine I used as an undergraduate didn't _have_ unsigned arithmetic
>in any form, and nobody ever missed it. I mean this quite literally:
>the machine had _no_ instructions that could be used to do any kind of
>unsigned arithmetic directly. Bitwise operations, yes.
>
>I wonder how many people would "need" unsigned arithmetic if C
>didn't have it?
The machine _I_ used as an undergraduate was the CDC 6400.
Later, I used the CDC 7600 for 10 years as a professional.
The CDC was ones' complement with 60-bit registers in the CPU.
It lacked two's complement 60-bit addition/subtraction,
but one could compute A + B mod 2^59 (say) by doing a ones' complement
add and masking off the upper bit. It also lacked
the shifts with zero-fill with Fortran and C now require
(instead having circular shifts to the left and arithmetic shifts
to the right). Just because one architecture lacks
right and left shifts with zero fill is no reason for
Fortran and C to omit such operations from the language.
Lack of unsigned arithmetic made it hard to distinguish
+0 from -0, such as when distinguishing whether
60 successive items are all TRUE from when they are all FALSE,
in a bit array (I would test whether XOR(n, 1) .eq. 1
if I wanted to test n for +0). Code had kludges like this
where unsigned arithmetic would improve the design.
The CDC architecture also lacked double precision floating point
arithmetic (except for addition/subtraction/multiplication
of two single-precision operands), but its Fortran
compiler generated inline code for many double precision operations.
Today the Alpha architecture lacks integer division,
even though the Fortran and C languages specified
that operation long before the Alpha was designed.
> >> C has conditional compilation, which Fortran does not.
> >
>This claim is a little extreme. It's not as if C conditional compilation
> >were in any way integrated with the language, like SAIL or PL/I or Burroughs
> >Algol or Lisp.
>
>Remember: #if sizeof (int) == 4
>is not legal C.
Yes, there are severe limitations in C's
conditional compilation. In the old CDC days, I used
conditional compilation directives within UPDATE
(a card-oriented text editor), but that had limitations too,
like not allowing nested *IF - *ENDIF pairs.
>
> >> Fortran leads C in its large intrinsic function library.
> >>C9X will finally let one write a MAX function which evaluates its
> >>arguments once only and use the INLINE keyword to get good code,
> >
> >My understanding is that C9X is likely to contain
> > f{min,max}{f,,l}
> >functions anyway.
That will be a step forward.
> >> Neither language has constructs for the following operations
> >>(although some implementations make them available):
> >
> >> . Trailing zero count of nonzero binary number
> >> (equal to highest power of 2 dividing the number)
> >
> >This may be a low-level construct, but a lot of machines have no
> >direct support for it. It may be programmed as easily in Fortran
> >as in C.
> >
> >> . Truncated base-2 logarithm of nonnegative integer,
> >> with LOG2(0) = -1. [Or return the number of bits required
> >> to hold the value, which is one more than its logarithm.]
> >
> >This may be a low-level construct, but a lot of machines have no
> >direct support for it. It may be programmed as easily in Fortran
> >as in C.
> >
> >> . Population count of nonnegative integer.
> >
> >This may be a low-level construct, but a lot of machines have no
> >direct support for it. It may be programmed as easily in Fortran
> >as in C.
Many of my number-theoretic codes need these functions.
And they are frequently discussed on comp.arch, so others need them too.
For example, when using the left-to-right method of binary exponentiation,
I need to locate the leftmost nonzero bit in the exponent.
Or I may need to loop through all the one-bits in word,
where I anticipate only a few will be set (say 3 bits out of 32).
The inner loop of the binary GCD algorithm needs to repeatedly divide
a positive integer by 2 until the quotient is odd; that is,
it needs to shift right by the trailing zero count of the operand.
The population count arises when, for example, I
need to take an inner product of two vectors over the
field GF(2): this means taking the bitwise AND of the two vectors,
getting the population count of this AND, and
testing whether this count is odd or even.
Yes, they can be programmed in both languages,
but the straightforward methods have many branches
(or require you to hard-wire the number of bits in the datum,
such as if you try to take a population count by
splitting a 32-bit integer into four eight-bit bytes, and using
table look-ups). Branches are slow on modern processors,
and we want to avoid them.
Going back to the CDC 6400, which had population count, the others
might be implemented as:
Trailing zero count(N), where N <> 0:
return population_count((N-1) & ~N)
Base 2 logarithm(N)
temp = (N >> 12) & 0xFFFFFFFFFFFF; (arithmetic shift)
(constant is ~MASK(12))
if (temp == 0) then (N was less than 2**12)
return 47 - normalize_count(N);
else
return 59 - normalize_count(temp);
end if
(normalize_count is the B-register output of a
normalize instruction, used primarily to
align the mantissa of a floating point operand).
Putting these into a compiler may add a few hundred
bytes to the compiler's executable, but will not penalize
users who do not need the functions, except possibly to add
reserved names to the language.
Users whose codes benefit from the functions can use the functions
(and buy machines from the manufacturers who best support them).
Five years after the functions are in the standard,
they will start appearing in benchmarks, and other architectures may start
providing better support if doing so would improve benchmark speed.
> > >
> > >> . Upper half of (signed or unsigned) integer product.
> > >
> > >This may be a low-level construct, but some machines (sigh) have
> > >no direct support for it. Ultra-SPARC is one of them. Perhaps if
> >C _had_ had this, Ultra-SPARC would have, but then, it hasn't got
> >a mod instruction either.
> >
> >LIA-2 has MULLO and MULHI functions, and C9x is taking LIA seriously,
>so something of the sort may find its way into C. I wonder what they
>will do on an UltraSPARC? A Fortran binding for LIA-2 will also have
>to address this.
Yes, the Ultra-SPARC lacks these for 64-bit operands.
If I want high performance there, I'll need to use radix 2^32 in
my multiple-precision codes (the Ultra-SPARC can multiply two 32-bit
operands and get a 64-bit product). Meanwhile (using conditional compilation)
let me use 64-bit operands on the MIPS and Alpha architectures,
so I can take advantage of the 128-bit products available on those machines.
For (slow) compatibility, the Ultra-SPARC can have a library
routine which splits 64-bit operands into 32-bit operands
and computes the product the hard way.
Meanwhile the Ultra-SPARC can out-perform the MIPS machines and
the pre-21264 Alpha's on codes using population count heavily.
>
> >> . Greatest common divisor (GCD) of two integers.
>
> >This too is in LIA, so may be in C9x. A Fortran binding for LIA-2
> >will also have to address it.
That's good to hear. Few architectures support GCD directly,
so it will be a library routine almost everywhere.
Problems like writing a vectorizable GCD on the Cray will
be solved once (by the compiler writer,
if they consider GCD important), rather than separately
by every user needing the function.
>> . Floating point operations with explicit rounding,
>> such as ROUND_DOWN(a - ROUND_ZERO(b*c))
>> to round the product b*c towards zero and
>> round the difference a - b*c towards -infinity.
>
>Very nice, but there are pre-IEC559 machines that are still of
>practical importance that have good Fortran systems, even C systems,
>and cannot easily support these operations.
Yes, it presumes IEEE arithmetic. If the machine
does not support that, the application probably needs another algorithm.
>
>>All of these, except the GCD, have simple translations on the
>>latest DEC Alpha.
>
>A nice machine.
>
>>They have mathematical definitions
>>which do not refer to the target architecture,
>>except that we need the number of bits per datum to
>>define the upper half of an integer product.
>
> >Lisp has your truncated base-2 logarithm, population count, and
> >greatest common divisor. It doesn't need MULLO/MULHI.
>
Perhaps I should learn Lisp. We've been comparing Fortran and C
(in spite of the Subject: line of this article).
--
Peter L. Montgomery pmontgom@cwi.nl San Rafael, California
A mathematician whose age has doubled since he last drove an automobile.
next prev parent reply other threads:[~1997-10-20 4:00 UTC|newest]
Thread overview: 207+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-10-08 4:00 Final kick at the "Merced Guessing Game" Robert Harley
1997-10-08 4:00 ` brianh
1997-10-08 4:00 ` boo
1997-10-09 4:00 ` brianh
1997-10-09 4:00 ` Eric Hildum
1997-10-11 4:00 ` Jan Vorbrueggen
1997-10-12 4:00 ` boo
1997-10-13 4:00 ` Michael Williams
1997-10-13 4:00 ` Craig Burley
1997-10-13 4:00 ` boo
1997-10-15 4:00 ` Craig Burley
1997-10-16 4:00 ` Flexible Choice of Language (Nothing to do with: Final kick at the "Merced Guessing Game") Ian Dall
1997-10-16 4:00 ` Craig Burley
1997-10-17 4:00 ` Richard A. O'Keefe
1997-10-17 4:00 ` Keith Adams
1997-10-17 4:00 ` [Reposted due to Enlow UCE cancel]: " John Bayko
1997-10-20 4:00 ` Paul D. DeRocco
1997-10-17 4:00 ` John Bayko
1997-10-18 4:00 ` Kelly Hall
1997-10-20 4:00 ` [Reposted due to Enlow UCE cancel]: " Eric Hildum
[not found] ` <623ek6$ef5$1@news.iastate.edu>
1997-10-16 4:00 ` Final kick at the "Merced Guessing Game" Craig Burley
1997-10-16 4:00 ` SimGraphics
1997-10-17 4:00 ` Craig Burley
1997-10-17 4:00 ` David Chase
1997-10-18 4:00 ` Victor Yodaiken
1997-10-20 4:00 ` Eric Hildum
1997-10-17 4:00 ` William Clodius
1997-10-19 4:00 ` Craig Burley
1997-10-18 4:00 ` Peter L. Montgomery
1997-10-19 4:00 ` Craig Burley
[not found] ` <3456700e.14141203@news.demon.co.uk>
1997-10-28 5:00 ` Dirk van der Knijff
1997-10-20 4:00 ` Richard A. O'Keefe
1997-10-20 4:00 ` Peter L. Montgomery [this message]
1997-10-13 4:00 ` Paul Rubin
1997-10-13 4:00 ` William Clodius
1997-10-13 4:00 ` Craig Burley
1997-10-14 4:00 ` Richard A. O'Keefe
1997-10-14 4:00 ` Shankar Unni
1997-10-15 4:00 ` Richard A. O'Keefe
1997-10-15 4:00 ` Paul D. DeRocco
1997-10-15 4:00 ` William Clodius
1997-10-15 4:00 ` Joe Buck
1997-10-16 4:00 ` Richard A. O'Keefe
1997-10-16 4:00 ` Craig Burley
1997-10-17 4:00 ` Shankar Unni
1997-10-15 4:00 ` Achim Gratz
1997-10-14 4:00 ` Michael Williams
1997-10-14 4:00 ` Richard Black
1997-10-15 4:00 ` Craig Burley
1997-10-15 4:00 ` Michael Williams
1997-10-15 4:00 ` Dr. Richard Black
1997-10-16 4:00 ` Richard A. O'Keefe
1997-10-18 4:00 ` Bruce Hoult
1997-10-15 4:00 ` Paul Hsieh
1997-10-13 4:00 ` Carl Perkins
1997-10-09 4:00 ` Gregg E Economou
1997-10-10 4:00 ` Jan Vorbrueggen
1997-10-08 4:00 ` William Clodius
1997-10-08 4:00 ` David Chase
[not found] ` <61ho3v$3m0$1@goanna.cs.rmit.edu.au>
1997-10-09 4:00 ` boo
1997-10-09 4:00 ` William Clodius
1997-10-10 4:00 ` Tyson Richard DOWD
1997-10-12 4:00 ` boo
1997-10-13 4:00 ` Steve Tate
1997-10-13 4:00 ` boo
1997-10-13 4:00 ` Victor Yodaiken
1997-10-14 4:00 ` Jason.Ozolins
1997-10-15 4:00 ` boo
1997-10-14 4:00 ` Aaron Spink
1997-10-15 4:00 ` David Chase
1997-10-13 4:00 ` Bernd Paysan
1997-10-13 4:00 ` boo
1997-10-13 4:00 ` Aaron Spink
1997-10-14 4:00 ` boo
1997-10-18 4:00 ` tgg
1997-10-18 4:00 ` [Reposted due to Enlow UCE cancel]: " tgg
1997-10-13 4:00 ` Patricia Shanahan
1997-10-15 4:00 ` boo
1997-10-15 4:00 ` Patricia Shanahan
1997-10-10 4:00 ` boo
1997-10-11 4:00 ` Toon Moene
1997-10-11 4:00 ` Paul DeMone
1997-10-11 4:00 ` Patricia Shanahan
1997-10-13 4:00 ` Gregg E Economou
1997-10-13 4:00 ` Patricia Shanahan
1997-10-14 4:00 ` Richard A. O'Keefe
1997-10-15 4:00 ` boo
1997-10-16 4:00 ` Toon Moene
1997-10-16 4:00 ` Timothy A. Seufert
1997-10-16 4:00 ` boo
1997-10-17 4:00 ` Richard A. O'Keefe
1997-10-20 4:00 ` Jason.Ozolins
1997-10-20 4:00 ` [Reposted due to Enlow UCE cancel]: " tgg
1997-10-10 4:00 ` Richard A. O'Keefe
[not found] ` <EHrwv9.2w3@world.std.com>
1997-10-10 4:00 ` David Gould
1997-10-10 4:00 ` Maynard Handley
1997-10-11 4:00 ` new languages Preston Briggs
1997-10-10 4:00 ` Final kick at the "Merced Guessing Game" David Gould
1997-10-16 4:00 ` Patricia Shanahan
-- strict thread matches above, loose matches on Subject: below --
1997-10-09 4:00 Robert Harley
1997-10-08 4:00 Robert Harley
1997-10-08 4:00 ` Michael Meissner
1997-10-09 4:00 ` Richard A. O'Keefe
1997-10-08 4:00 Robert Harley
[not found] ` <343C0387.41C6@lanl.gov>
1997-10-08 4:00 ` boo
1997-10-09 4:00 ` Patrick Chase
1997-10-10 4:00 ` boo
1997-10-09 4:00 ` David Chase
1997-10-08 4:00 ` boo
1997-10-09 4:00 ` William Clodius
1997-10-09 4:00 ` David Chase
1997-10-07 4:00 Robert Harley
1997-10-07 4:00 ` Martin Rodgers
1997-10-07 4:00 ` Nick Maclaren
1997-10-07 4:00 ` Shankar Unni
1997-10-08 4:00 ` boo
1997-10-09 4:00 ` Patrick F. McGehearty
1997-10-10 4:00 ` Richard A. O'Keefe
1997-10-15 4:00 ` David Chase
1997-10-16 4:00 ` William Clodius
1997-10-03 4:00 Robert Harley
1997-10-06 4:00 ` Richard A. O'Keefe
1997-10-06 4:00 ` boo
1997-10-07 4:00 ` Richard A. O'Keefe
1997-10-06 4:00 ` Graham Hughes
1997-10-07 4:00 ` boo
1997-10-07 4:00 ` William Clodius
1997-10-07 4:00 ` William Clodius
[not found] ` <y4wwjon203.fsf@mailhost.neuroinformatik.ruhr-uni-bochum.de>
1997-10-08 4:00 ` William Clodius
1997-10-08 4:00 ` Stanley Chow
1997-10-08 4:00 ` Richard A. O'Keefe
1997-10-08 4:00 ` William Clodius
1997-10-08 4:00 ` William Clodius
1997-10-09 4:00 ` William Clodius
1997-10-10 4:00 ` Larry Kilgallen
1997-10-10 4:00 ` Zalman Stern
1997-10-11 4:00 ` Andrew Cruickshank
1997-10-12 4:00 ` Paul D. DeRocco
1997-10-13 4:00 ` Michael Williams
1997-10-08 4:00 ` Gregg E Economou
1997-10-08 4:00 ` David Chase
1997-10-08 4:00 ` Richard A. O'Keefe
1997-10-07 4:00 ` Serge Pachkovsky
1997-10-07 4:00 ` Martin Rodgers
1997-10-07 4:00 ` Greg Weeks
1997-10-07 4:00 ` Martin Rodgers
[not found] ` <343AAE5A.A3FCC9D@no.informatik.spam.tu-muenchen.thanks.de>
1997-10-09 4:00 ` Torben AEgidius Mogensen
[not found] ` <EHsr7B.Dt8@bit3.com>
1997-10-10 4:00 ` Torben AEgidius Mogensen
[not found] ` <61cv5e$qn$6@vixen.cso.uiuc.edu>
1997-10-08 4:00 ` William Clodius
1997-10-07 4:00 ` Carlie Coats
1997-10-07 4:00 ` Paul Hsieh
1997-10-07 4:00 ` boo
1997-10-08 4:00 ` Carlie Coats
1997-10-08 4:00 ` James C. Stutts
1997-10-02 4:00 Robert Harley
1997-10-02 4:00 ` Nick Maclaren
1997-10-03 4:00 ` Richard A. O'Keefe
1997-10-02 4:00 Robert Harley
1997-10-02 4:00 ` Nick Maclaren
1997-10-02 4:00 ` Stanley Chow
1997-09-30 4:00 Paul DeMone
1997-09-30 4:00 ` Guy Harris
1997-10-01 4:00 ` Tom Thornhill
1997-10-01 4:00 ` Tom Thornhill
1997-10-01 4:00 ` Paul DeMone
1997-10-01 4:00 ` Jim Hull
1997-10-01 4:00 ` Richard A. Schumacher
1997-10-01 4:00 ` Nick Maclaren
1997-10-01 4:00 ` J. Corbally
1997-10-01 4:00 ` Nick Maclaren
1997-10-01 4:00 ` Ketil Z Malde
1997-10-01 4:00 ` Michael D. Nahas
1997-10-01 4:00 ` brianh
1997-10-01 4:00 ` Stefan Monnier
1997-10-01 4:00 ` Nick Maclaren
1997-10-01 4:00 ` Allen Kim
1997-10-01 4:00 ` John Wilson
1997-10-01 4:00 ` P Murray
1997-10-01 4:00 ` Nick Maclaren
1997-10-02 4:00 ` Vesa Karvonen
1997-10-02 4:00 ` Joseph H Allen
1997-10-02 4:00 ` Wilco Dijkstra
1997-10-03 4:00 ` Jason.Ozolins
1997-10-03 4:00 ` Alex Colvin
1997-10-06 4:00 ` Richard A. O'Keefe
1997-10-08 4:00 ` Zalman Stern
1997-10-03 4:00 ` Stefan Monnier
1997-10-03 4:00 ` Stefan Monnier
1997-10-02 4:00 ` Andrew Glew
1997-10-02 4:00 ` Torben AEgidius Mogensen
1997-10-02 4:00 ` Patrick F. McGehearty
1997-10-02 4:00 ` brianh
1997-10-03 4:00 ` Michael Williams
1997-10-02 4:00 ` Jon Leech
1997-10-02 4:00 ` Stefan Monnier
1997-10-03 4:00 ` Richard A. O'Keefe
1997-10-03 4:00 ` Mike Smith
1997-10-03 4:00 ` Nick Maclaren
1997-10-03 4:00 ` Rob Barris
1997-10-03 4:00 ` Andrew Glew
1997-10-05 4:00 ` Gianni Mariani
1997-10-04 4:00 ` Nick Maclaren
1997-10-04 4:00 ` H. Eckert
1997-10-05 4:00 ` Andy "Krazy" Glew
1997-10-06 4:00 ` Nick Maclaren
1997-10-02 4:00 ` Eric Hildum
1997-10-01 4:00 ` Paul DeMone
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox