This is the mail archive of the mailing list for the glibc 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] Sparc exp(), expf() performance improvement

On 03/08/2017 13:50, Patrick McGehearty wrote:
> On 8/2/2017 6:19 PM, David Miller wrote:
>> From: Patrick McGehearty <>
>> Date: Wed, 2 Aug 2017 14:53:19 -0500
>>> I concur that it would be beneficial to use -mcpu=niagara4 for
>>> selected libm functions, but do not believe it should be default on
>>> without more extensive testing (and likely more compiler tuning).
>> This is precisely what has been suggested, have an niagara4 IFUNC
>> vector for math functions that benefit greatly from the fp<-->int
>> register move instructions.
> I'm new to linux glibc development and have been using existing examples to suggest
> how I should do things like use ifunc. If there is a different approach that is recommended,
> I'm willing to use it but will need some hints/instruction on what is.
> My current approach of using
> sparc_libm_ifunc (exp, hwcap & HWCAP_SPARC_CRYPTO ?
>                   __exp_niagara4 : __ieee754_exp);
> in sysdeps/sparc/sparc64/fpu/multiarch/e_exp-niagara4.c matches the approach used in
> sysdeps/sparc/sparc64/fpu/multiarch/s_ceil.c
> sysdeps/sparc/sparc64/fpu/multiarch/s_ceilf.c
> sysdeps/sparc/sparc64/fpu/multiarch/s_floor.c
> sysdeps/sparc/sparc64/fpu/multiarch/s_floorf.c
> sysdeps/sparc/sparc64/fpu/multiarch/s_fma.c
> sysdeps/sparc/sparc64/fpu/multiarch/s_fmaf.c
> sysdeps/sparc/sparc64/fpu/multiarch/s_trunc.c
> sysdeps/sparc/sparc64/fpu/multiarch/s_truncf.c
> I'll note that simply using -mcpu=niagara4 on the existing ieee754 exp() code only
> provides a 5% performance gain. Due to other assignments, I will not have time/resources
> to redo other libm functions at this time.
> - patrick

SPARC code is still using a old way to define ifunc code which replicates the
logic already present on include/libc-symbols.h.  I would suggest you to use
the newer ifunc macro definition for new code:

#include <math.h>
#include <init-arch.h>

extern double __ieee754_exp_niagara (double);
extern double __ieee754_exp (double);

libm_ifunc (__ieee754_exp,
            hwcap & HWCAP_SPARC_CRYPTO
	       ? __exp_niagara4 : __ieee754_exp
strong_alias (__ieee754_exp, __exp_finite)

You will need also to provide a init-arch.h file, as for other architectures
(x86, aarch64, powerpc) which I think should do basically:

#include <ldsodefs.h>

#define INIT_ARCH() \
  unsigned long int hwcap = __GLRO(dl_hwcap); 

I would also advise against to include the default implementation on current
ifunc definition file (such as sparc s_ceil.c for instance). I would recommend
create a default file, for instance sysdeps/sparc/sparc64/fpu/multiarch/e_exp-default.c,
and then include the default exp function.

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