OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libc/] [machine/] [i386/] [f_powf.c] - Diff between revs 207 and 345

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
/*
/*
 * ====================================================
 * ====================================================
 * Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved.
 * Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved.
 *
 *
 * Permission to use, copy, modify, and distribute this
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * software is freely granted, provided that this notice
 * is preserved.
 * is preserved.
 * ====================================================
 * ====================================================
 */
 */
 
 
#if !defined(_SOFT_FLOAT)
#if !defined(_SOFT_FLOAT)
 
 
/*
/*
Fast version of pow using Intel float instructions.
Fast version of pow using Intel float instructions.
 
 
   float _f_powf (float x, float y);
   float _f_powf (float x, float y);
 
 
Function calculates x to power of y.
Function calculates x to power of y.
The function optimizes the case where x is >0.0 and y is finite.
The function optimizes the case where x is >0.0 and y is finite.
In such a case, there is no error checking or setting of errno.
In such a case, there is no error checking or setting of errno.
All other cases defer to normal powf() function which will
All other cases defer to normal powf() function which will
set errno as normal.
set errno as normal.
*/
*/
 
 
#include <math.h>
#include <math.h>
#include <ieeefp.h>
#include <ieeefp.h>
#include "f_math.h"
#include "f_math.h"
 
 
float _f_powf (float x, float y)
float _f_powf (float x, float y)
{
{
  /* following sequence handles the majority of cases for pow() */
  /* following sequence handles the majority of cases for pow() */
  if (x > 0.0 && check_finitef(y))
  if (x > 0.0 && check_finitef(y))
    {
    {
      float result;
      float result;
      /* calculate x ** y as 2 ** (y log2(x)).  On Intel, can only
      /* calculate x ** y as 2 ** (y log2(x)).  On Intel, can only
         raise 2 to an integer or a small fraction, thus, we have
         raise 2 to an integer or a small fraction, thus, we have
         to perform two steps 2**integer portion * 2**fraction. */
         to perform two steps 2**integer portion * 2**fraction. */
      asm ("flds 8(%%ebp); fyl2x; fld %%st; frndint; fsub %%st,%%st(1);" \
      asm ("flds 8(%%ebp); fyl2x; fld %%st; frndint; fsub %%st,%%st(1);" \
           "fxch; fchs; f2xm1; fld1; faddp; fxch; fld1; fscale; fstp %%st(1);"\
           "fxch; fchs; f2xm1; fld1; faddp; fxch; fld1; fscale; fstp %%st(1);"\
           "fmulp" : "=t" (result) : "0" (y));
           "fmulp" : "=t" (result) : "0" (y));
      return result;
      return result;
    }
    }
  else /* all other strange cases, defer to normal pow() */
  else /* all other strange cases, defer to normal pow() */
    return powf (x,y);
    return powf (x,y);
}
}
 
 
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.