[PATCH 01/17] S390: Use load-fp-integer instruction for nearbyint functions.

Stefan Liebler stli@linux.ibm.com
Mon Dec 2 14:56:00 GMT 2019


On 11/4/19 7:22 PM, Adhemerval Zanella wrote:
> 
> 
> On 04/11/2019 12:27, Stefan Liebler wrote:
>> If compiled with z196 zarch support, the load-fp-integer instruction
>> is used to implement nearbyint, nearbyintf, nearbyintl.
>> Otherwise the common-code implementation is used.
> 
>> +
>> +double
>> +__nearbyint (double x)
>> +{
>> +  double y;
>> +  /* The z196 zarch "load fp integer" (fidbra) instruction is rounding
>> +     x to the nearest integer according to current rounding mode (M3-field: 0)
>> +     where inexact exceptions are suppressed (M4-field: 4).  */
>> +  __asm__ ("fidbra %0,0,%1,4" : "=f" (y) : "f" (x));
>> +  return y;
>> +}
>> +libm_alias_double (__nearbyint, nearbyint)
> 
> At least with recent gcc __builtin_nearbyint generates the expected fidbra
> instruction for -march=z196.  I wonder if we could start to simplify some
> math symbols implementation where new architectures/extensions provide
> direct implementation by a direct mapping implemented by compiler builtins.
> 
> I would expect to:
> 
>    1. Move all sysdeps/ieee754/dbl-64/wordsize-64 to sysdeps/ieee754/dbl-64/
>       since I hardly doubt these micro-optimizations really pay off with
>       recent architectures and compiler version.
> 
>    2. Add internal macros __USE_<SYMBOL>_BUILTIN and use as:
> 
>       * sysdeps/ieee754/dbl-64/s_nearbyint.c
>       
>       [...]
>       double
>       __nearbyint (double x)
>       {
>       #if __USE_NEARBYINT_BUILTIN
>         return __builtin_nearbyint (x);
>       #else
>         /* Use generic implementation.  */
>       #endif
>       }
> 
>    3. Define the __USE_<SYMBOL>_BUILTIN for each architecture.
> 
> It would allow to simplify some architectures, aarch64 for instance.
> 
This patch is superseded by the patch-series which is always using 
wordsize-64 version and allows to use the GCC builtins in common-code 
implementation:
"[PATCH 00/13] Use GCC builtins for some math functions if desired."
https://www.sourceware.org/ml/libc-alpha/2019-12/msg00029.html

Bye,
Stefan



More information about the Libc-alpha mailing list