Improving gcc for gmp
Patrick Pelissier
Patrick.Pelissier at loria.fr
Fri Mar 19 09:23:05 CET 2004
Extract from GCC 3.4:
- Built-in Function: int __builtin_clz (unsigned int x)
Returns the number of leading 0-bits in X, starting at the most
significant bit position. If X is 0, the result is undefined.
- Built-in Function: int __builtin_clzl (unsigned long)
Similar to `__builtin_clz', except the argument type is `unsigned
long'.
- Built-in Function: int __builtin_clzll (unsigned long long)
Similar to `__builtin_clz', except the argument type is `unsigned
long long'.
--> clz = count_leading_zeros.
For umul_ppmm, if you do this:
unsigned long long f(unsigned long x, unsigned long y)
{
return (unsigned long long) x*y;
}
GCC optimizes this in (For x86):
f:
movl 8(%esp), %eax
mull 4(%esp)
ret
It is easy to get HIGH_PROD and LOW_PROD from this.
Sincerely,
Patrick Pelissier
On Fri, Mar 19, 2004 at 02:26:17 +0100, Torbjorn Granlund wrote:
> Many machines have to GMP vital instructions, like what we do with
> umul_ppmm and count_leading_zeros, yet is there no language constructs
> to use these. Inline assembly has critical drawbacks in that it
> blindfolds the scheduler of the compiler.
>
> I'd like to see extensions of gcc to support __builtin_ constructs for
> at least umul_ppmm (or rather umul_high) and count_leading_zeros.
> Since the backends already have support for the former (and perhaps
> also the latter) and since there are actually ready mechansims for
> using that (see expand_mult_highpart in expmed.c) implementing this
> should be fairly straightforward.
>
> I don't have time to do this. Could somebody on this list please look
> into writing the code, and submitting it to the GCC folks?
>
> --
> Torbjörn
> _______________________________________________
> gmp-devel mailing list
> gmp-devel at swox.com
> https://gmplib.org/mailman/listinfo/gmp-devel
More information about the gmp-devel
mailing list