[committed] Implement C23 acospi

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Thu Jan 2 12:40:56 GMT 2025



On 02/01/25 07:56, Florian Weimer wrote:
> * Joseph Myers:
> 
>> C23 adds various <math.h> function families originally defined in TS
>> 18661-4.  Add the acospi functions (acos(x)/pi).
>>
>> Tested for x86_64 and x86, and with build-many-glibcs.py.
> 
> I see these new failures on powerpc64le (POWER9), at
> commit 396048fa5a41be38d196e03175ccc4bd318f4fb6:
> 
> ==> math/test-double-acospi.out <==
> testing double (without inline functions)
> Failure: acospi (qNaN): Exception "Invalid operation" set
> Failure: acospi (-qNaN): Exception "Invalid operation" set
> Failure: acospi_downward (qNaN): Exception "Invalid operation" set
> Failure: acospi_downward (-qNaN): Exception "Invalid operation" set
> Failure: acospi_towardzero (qNaN): Exception "Invalid operation" set
> Failure: acospi_towardzero (-qNaN): Exception "Invalid operation" set
> Failure: acospi_upward (qNaN): Exception "Invalid operation" set
> Failure: acospi_upward (-qNaN): Exception "Invalid operation" set
> 
> Test suite completed:
>   4 max error test cases,
>   396 input tests,
>   - with 1592 tests for exception flags,
>   - with 388 tests for errno executed.
>   8 errors occurred.
> 
> ==> math/test-float-acospi.out <==
> testing float (without inline functions)
> Failure: acospi (qNaN): Exception "Invalid operation" set
> Failure: acospi (-qNaN): Exception "Invalid operation" set
> Failure: acospi_downward (qNaN): Exception "Invalid operation" set
> Failure: acospi_downward (-qNaN): Exception "Invalid operation" set
> Failure: acospi_towardzero (qNaN): Exception "Invalid operation" set
> Failure: acospi_towardzero (-qNaN): Exception "Invalid operation" set
> Failure: acospi_upward (qNaN): Exception "Invalid operation" set
> Failure: acospi_upward (-qNaN): Exception "Invalid operation" set
> 
> Test suite completed:
>   4 max error test cases,
>   300 input tests,
>   - with 1208 tests for exception flags,
>   - with 292 tests for errno executed.
>   8 errors occurred.
> 
> ==> math/test-float128-acospi.out <==
> testing _Float128 (without inline functions)
> 
> Test suite completed:
>   4 max error test cases,
>   496 input tests,
>   - with 1992 tests for exception flags,
>   - with 488 tests for errno executed.
>   All tests passed successfully.
> 
> ==> math/test-float32-acospi.out <==
> testing _Float32 (without inline functions)
> Failure: acospi (qNaN): Exception "Invalid operation" set
> Failure: acospi (-qNaN): Exception "Invalid operation" set
> Failure: acospi_downward (qNaN): Exception "Invalid operation" set
> Failure: acospi_downward (-qNaN): Exception "Invalid operation" set
> Failure: acospi_towardzero (qNaN): Exception "Invalid operation" set
> Failure: acospi_towardzero (-qNaN): Exception "Invalid operation" set
> Failure: acospi_upward (qNaN): Exception "Invalid operation" set
> Failure: acospi_upward (-qNaN): Exception "Invalid operation" set
> 
> Test suite completed:
>   4 max error test cases,
>   300 input tests,
>   - with 1208 tests for exception flags,
>   - with 292 tests for errno executed.
>   8 errors occurred.
> 
> ==> math/test-float32x-acospi.out <==
> testing _Float32x (without inline functions)
> Failure: acospi (qNaN): Exception "Invalid operation" set
> Failure: acospi (-qNaN): Exception "Invalid operation" set
> Failure: acospi_downward (qNaN): Exception "Invalid operation" set
> Failure: acospi_downward (-qNaN): Exception "Invalid operation" set
> Failure: acospi_towardzero (qNaN): Exception "Invalid operation" set
> Failure: acospi_towardzero (-qNaN): Exception "Invalid operation" set
> Failure: acospi_upward (qNaN): Exception "Invalid operation" set
> Failure: acospi_upward (-qNaN): Exception "Invalid operation" set
> 
> Test suite completed:
>   4 max error test cases,
>   396 input tests,
>   - with 1592 tests for exception flags,
>   - with 388 tests for errno executed.
>   8 errors occurred.
> 
> ==> math/test-float64-acospi.out <==
> testing _Float64 (without inline functions)
> Failure: acospi (qNaN): Exception "Invalid operation" set
> Failure: acospi (-qNaN): Exception "Invalid operation" set
> Failure: acospi_downward (qNaN): Exception "Invalid operation" set
> Failure: acospi_downward (-qNaN): Exception "Invalid operation" set
> Failure: acospi_towardzero (qNaN): Exception "Invalid operation" set
> Failure: acospi_towardzero (-qNaN): Exception "Invalid operation" set
> Failure: acospi_upward (qNaN): Exception "Invalid operation" set
> Failure: acospi_upward (-qNaN): Exception "Invalid operation" set
> 
> Test suite completed:
>   4 max error test cases,
>   396 input tests,
>   - with 1592 tests for exception flags,
>   - with 388 tests for errno executed.
>   8 errors occurred.
> 
> (This is in addition to some ulps errors that are expected.)
> 
> Thanks,
> Florian

I saw this when building for POWER10 and it seems a compiler issue to me,
where gcc generates:

   0x00007ffff7eb0280 <+64>:    fdiv    f0,f1,f0
   0x00007ffff7eb0284 <+68>:    mtlr    r0
=> 0x00007ffff7eb0288 <+72>:    xscmpgtdp vs1,vs0,vs31
   0x00007ffff7eb028c <+76>:    xxsel   vs1,vs0,vs31,vs1

For 

  FLOAT ret = M_SUF (__ieee754_acos) (x) / M_MLIT (M_PI);
  /* Ensure that rounding upward for both acos and the division cannot
     yield a return value from acospi greater than 1.  */
  return isgreater (ret, M_LIT (1.0)) ? M_LIT (1.0) : ret;

I don't think compiler is allowed to transform this expression to
xscmpgtdp for unordered operations.


More information about the Libc-alpha mailing list