[PATCH] fast Copysign for PPC, -flag_unsafe_math_optimizations only
Andrew Pinski
pinskia@physics.uc.edu
Mon Jan 31 00:13:00 GMT 2005
This patch implements a fast copysign for PPC but only
for -flag_unsafe_math_optimizations as it does not handle
signed zeros correctly. This uses the optable which RTH
added a couple of days ago to do this expansion.
With this patch copysign is expanded to:
fabs f0,f1
fnabs f1,f1
fsel f1,f2,f0,f1
Which is faster and smaller than storing and doing
bitfield operations on the sign bit.
OK? Bootstrapped and tested on powerpc-darwin with no regressions.
Thanks,
Andrew Pinski
ChangeLog:
* config/rs6000/rs6000.md (copysignsf3): New expand.
(copysigndf3): Likewise.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fastcopysign.diff.txt
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20050131/c112263a/attachment.txt>
-------------- next part --------------
Testcase:
/* { dg-do run } */
/* { dg-options "-O2 -ffast-math" } */
float copysignf(float,float);
double copysign(double, double);
float fs(float a,float b)
{
return copysignf(a,b);
}
double f(double a,double b)
{
return copysign(a,b);
}
float a = __builtin_inf();
float b = 1.0;
void abort(void);
int main(void)
{
if (fs (a,a)!=__builtin_fabs(a))
abort();
if (fs (a,-a)!=-__builtin_fabs(a))
abort();
if (fs (-a,a)!=__builtin_fabs(a))
abort();
if (fs (-a,-a)!=-__builtin_fabs(a))
abort();
if (f (a,a)!=__builtin_fabs(a))
abort();
if (f (a,-a)!=-__builtin_fabs(a))
abort();
if (f (-a,a)!=__builtin_fabs(a))
abort();
if (f (-a,-a)!=-__builtin_fabs(a))
abort();
if (fs (b,b)!=__builtin_fabs(b))
abort();
if (fs (b,-b)!=-__builtin_fabs(b))
abort();
if (fs (-b,b)!=__builtin_fabs(b))
abort();
if (fs (-b,-b)!=-__builtin_fabs(b))
abort();
if (f (b,b)!=__builtin_fabs(b))
abort();
if (f (b,-b)!=-__builtin_fabs(b))
abort();
if (f (-b,b)!=__builtin_fabs(b))
abort();
if (f (-b,-b)!=-__builtin_fabs(b))
abort();
}
More information about the Gcc-patches
mailing list