Long long usage question
Claus Fischer
claus.fischer@clausfischer.com
Sat Mar 16 17:44:00 GMT 2002
I need to write a function that takes four signed 32 bit values,
builds two products, and compares the size, thusly:
int prodcomp(long a, long b, long c, long d)
{
long long p1 = (long long) a * (long long) b;
long long p2 = (long long) c * (long long) d;
return p1 < p2;
}
I'm assuming that most 32 bit CPU's have an instruction for
multiplying two 32 bit values.
Questions:
1. Does the compiler know that the cast results have their highest
32 bits zeroed? Does it pick a fast instruction for that case?
2. If the answer is 'no', does it help to use
long long p1 = (long long) a * b;
3. Is there a way of telling the compiler what I really want:
long long p1 = a * b;
but the multiplication performed in the long long realm?
4. Is there documentation covering how to best do such arithmetic
in GNU C on glibc? I'm speaking of 32 bit arithmetics with
occasional products and divisions leading in the 64 bit domain.
Thanks in advance for your kind answers
Claus
--
Claus Fischer <claus.fischer@clausfischer.com>
http://www.clausfischer.com/
More information about the Gcc
mailing list