This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH RFC] allow inline intrinsics for __ieee754_sqrt/f


On Jun 22 11:49, Jon Beniston wrote:
> Hi,
> 
> Most functions in libm call __ieee754_sqrt when needing to perform a square
> root. For most targets, this results in the s/w implementation in
> math/e_sqrt.c being using, even if the target has a h/w sqrt instruction.
> There are some targets that have machine specific implementations in
> machine/*/, but even if a single instruction, that code typically doesn't
> get inlined.
> 
> The following patch is one possible way to allow a sqrt instruction to be
> used and for the calls to be inlined. I've just done this for x86/arm for
> now. I've put this in include/machine/ieeefp.h, rather than fdlibm.h, as
> that's where most of the other target specific code seems to be.
> 
> Not sure if using the __IEEE754_INLINE_SQRT* macros is the best way to
> prevent redefinition errors. Perhaps someone has a better idea?
> 
> Cheers,
> Jon
> 
> diff --git a/newlib/libc/include/machine/ieeefp.h
> [...]
>  #ifdef __i386__
>  #define __IEEE_LITTLE_ENDIAN
> +
> +#define __IEEE754_INLINE_SQRT
> +static inline double
> +__ieee754_sqrt (double x)
> +{
> +  double result;
> +  __asm__ ("fsqrt" : "=t" (result) : "0" (x));
> +  return result;
> +}
> +
> +#define __IEEE754_INLINE_SQRTF
> +static inline float
> +__ieee754_sqrtf (float x)
> +{
> +  float result;
> +  __asm__ ("fsqrt" : "=t" (result) : "0" (x));
> +  return result;
> +}
> +
>  #endif

Can we really imply that an i386 always comes with a FPU?


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

Attachment: signature.asc
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]