[email protected]
[Top] [All Lists]

[PATCH] fast Copysign for PPC, -flag_unsafe_math_optimizations only

Subject: [PATCH] fast Copysign for PPC, -flag_unsafe_math_optimizations only
From: Andrew Pinski
Date: Sun, 30 Jan 2005 19:12:40 -0500
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.

Attachment: fastcopysign.diff.txt
Description: Text document




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();
}
<Prev in Thread] Current Thread [Next in Thread>