[PATCH 01/17] S390: Use load-fp-integer instruction for nearbyint functions.
Adhemerval Zanella
adhemerval.zanella@linaro.org
Mon Dec 2 15:20:00 GMT 2019
On 02/12/2019 11:56, Stefan Liebler wrote:
> 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
>
Thanks, I will review these set.
More information about the Libc-alpha
mailing list