[compiler-rt][builtins]Adjust complex division for aarch64 (#106664)

Adjust __divsc3 to ensure consistent behavior across x86_64 and AArch64 when the divisor should be treated as infinity if one of its components is a NaN (including signaling NaNs).

Test plan: ninja check-all
This commit is contained in:
Alexander Shaposhnikov
2024-09-06 12:21:06 -07:00
committed by GitHub
parent 7f77db4ffc
commit d60ca0c913
3 changed files with 149 additions and 164 deletions

View File

@@ -20,7 +20,7 @@
COMPILER_RT_ABI Fcomplex __divsc3(float __a, float __b, float __c, float __d) {
int __ilogbw = 0;
float __logbw =
__compiler_rt_logbf(__compiler_rt_fmaxf(crt_fabsf(__c), crt_fabsf(__d)));
__compiler_rt_logbf(__compiler_rt_fmaxX(crt_fabsf(__c), crt_fabsf(__d)));
if (crt_isfinite(__logbw)) {
__ilogbw = (int)__logbw;
__c = __compiler_rt_scalbnf(__c, -__ilogbw);

View File

@@ -346,15 +346,6 @@ static __inline fp_t __compiler_rt_logbf(fp_t x) {
static __inline fp_t __compiler_rt_scalbnf(fp_t x, int y) {
return __compiler_rt_scalbnX(x, y);
}
static __inline fp_t __compiler_rt_fmaxf(fp_t x, fp_t y) {
#if defined(__aarch64__)
// Use __builtin_fmaxf which turns into an fmaxnm instruction on AArch64.
return __builtin_fmaxf(x, y);
#else
// __builtin_fmaxf frequently turns into a libm call, so inline the function.
return __compiler_rt_fmaxX(x, y);
#endif
}
#elif defined(DOUBLE_PRECISION)

View File

@@ -3,11 +3,11 @@
// REQUIRES: c99-complex
#include "int_lib.h"
#include "fp_test.h"
#include <math.h>
#include <complex.h>
#include <stdio.h>
// Returns: the quotient of (a + ib) / (c + id)
COMPILER_RT_ABI float _Complex
@@ -190,174 +190,168 @@ int test__divsc3(float a, float b, float c, float d)
return 0;
}
float x[][2] =
{
{ 1.e-6, 1.e-6},
{-1.e-6, 1.e-6},
{-1.e-6, -1.e-6},
{ 1.e-6, -1.e-6},
int main() {
float x[][2] = {{1.e-6, 1.e-6},
{-1.e-6, 1.e-6},
{-1.e-6, -1.e-6},
{1.e-6, -1.e-6},
{ 1.e+6, 1.e-6},
{-1.e+6, 1.e-6},
{-1.e+6, -1.e-6},
{ 1.e+6, -1.e-6},
{1.e+6, 1.e-6},
{-1.e+6, 1.e-6},
{-1.e+6, -1.e-6},
{1.e+6, -1.e-6},
{ 1.e-6, 1.e+6},
{-1.e-6, 1.e+6},
{-1.e-6, -1.e+6},
{ 1.e-6, -1.e+6},
{1.e-6, 1.e+6},
{-1.e-6, 1.e+6},
{-1.e-6, -1.e+6},
{1.e-6, -1.e+6},
{ 1.e+6, 1.e+6},
{-1.e+6, 1.e+6},
{-1.e+6, -1.e+6},
{ 1.e+6, -1.e+6},
{1.e+6, 1.e+6},
{-1.e+6, 1.e+6},
{-1.e+6, -1.e+6},
{1.e+6, -1.e+6},
{NAN, NAN},
{-INFINITY, NAN},
{-2, NAN},
{-1, NAN},
{-0.5, NAN},
{-0., NAN},
{+0., NAN},
{0.5, NAN},
{1, NAN},
{2, NAN},
{INFINITY, NAN},
{NAN, NAN},
{-INFINITY, NAN},
{-2, NAN},
{-1, NAN},
{-0.5, NAN},
{-0., NAN},
{+0., NAN},
{0.5, NAN},
{1, NAN},
{2, NAN},
{INFINITY, NAN},
{NAN, -INFINITY},
{-INFINITY, -INFINITY},
{-2, -INFINITY},
{-1, -INFINITY},
{-0.5, -INFINITY},
{-0., -INFINITY},
{+0., -INFINITY},
{0.5, -INFINITY},
{1, -INFINITY},
{2, -INFINITY},
{INFINITY, -INFINITY},
{NAN, -INFINITY},
{-INFINITY, -INFINITY},
{-2, -INFINITY},
{-1, -INFINITY},
{-0.5, -INFINITY},
{-0., -INFINITY},
{+0., -INFINITY},
{0.5, -INFINITY},
{1, -INFINITY},
{2, -INFINITY},
{INFINITY, -INFINITY},
{NAN, -2},
{-INFINITY, -2},
{-2, -2},
{-1, -2},
{-0.5, -2},
{-0., -2},
{+0., -2},
{0.5, -2},
{1, -2},
{2, -2},
{INFINITY, -2},
{NAN, -2},
{-INFINITY, -2},
{-2, -2},
{-1, -2},
{-0.5, -2},
{-0., -2},
{+0., -2},
{0.5, -2},
{1, -2},
{2, -2},
{INFINITY, -2},
{NAN, -1},
{-INFINITY, -1},
{-2, -1},
{-1, -1},
{-0.5, -1},
{-0., -1},
{+0., -1},
{0.5, -1},
{1, -1},
{2, -1},
{INFINITY, -1},
{NAN, -1},
{-INFINITY, -1},
{-2, -1},
{-1, -1},
{-0.5, -1},
{-0., -1},
{+0., -1},
{0.5, -1},
{1, -1},
{2, -1},
{INFINITY, -1},
{NAN, -0.5},
{-INFINITY, -0.5},
{-2, -0.5},
{-1, -0.5},
{-0.5, -0.5},
{-0., -0.5},
{+0., -0.5},
{0.5, -0.5},
{1, -0.5},
{2, -0.5},
{INFINITY, -0.5},
{NAN, -0.5},
{-INFINITY, -0.5},
{-2, -0.5},
{-1, -0.5},
{-0.5, -0.5},
{-0., -0.5},
{+0., -0.5},
{0.5, -0.5},
{1, -0.5},
{2, -0.5},
{INFINITY, -0.5},
{NAN, -0.},
{-INFINITY, -0.},
{-2, -0.},
{-1, -0.},
{-0.5, -0.},
{-0., -0.},
{+0., -0.},
{0.5, -0.},
{1, -0.},
{2, -0.},
{INFINITY, -0.},
{NAN, -0.},
{-INFINITY, -0.},
{-2, -0.},
{-1, -0.},
{-0.5, -0.},
{-0., -0.},
{+0., -0.},
{0.5, -0.},
{1, -0.},
{2, -0.},
{INFINITY, -0.},
{NAN, 0.},
{-INFINITY, 0.},
{-2, 0.},
{-1, 0.},
{-0.5, 0.},
{-0., 0.},
{+0., 0.},
{0.5, 0.},
{1, 0.},
{2, 0.},
{INFINITY, 0.},
{NAN, 0.},
{-INFINITY, 0.},
{-2, 0.},
{-1, 0.},
{-0.5, 0.},
{-0., 0.},
{+0., 0.},
{0.5, 0.},
{1, 0.},
{2, 0.},
{INFINITY, 0.},
{NAN, 0.5},
{-INFINITY, 0.5},
{-2, 0.5},
{-1, 0.5},
{-0.5, 0.5},
{-0., 0.5},
{+0., 0.5},
{0.5, 0.5},
{1, 0.5},
{2, 0.5},
{INFINITY, 0.5},
{NAN, 0.5},
{-INFINITY, 0.5},
{-2, 0.5},
{-1, 0.5},
{-0.5, 0.5},
{-0., 0.5},
{+0., 0.5},
{0.5, 0.5},
{1, 0.5},
{2, 0.5},
{INFINITY, 0.5},
{NAN, 1},
{-INFINITY, 1},
{-2, 1},
{-1, 1},
{-0.5, 1},
{-0., 1},
{+0., 1},
{0.5, 1},
{1, 1},
{2, 1},
{INFINITY, 1},
{NAN, 1},
{-INFINITY, 1},
{-2, 1},
{-1, 1},
{-0.5, 1},
{-0., 1},
{+0., 1},
{0.5, 1},
{1, 1},
{2, 1},
{INFINITY, 1},
{NAN, 2},
{-INFINITY, 2},
{-2, 2},
{-1, 2},
{-0.5, 2},
{-0., 2},
{+0., 2},
{0.5, 2},
{1, 2},
{2, 2},
{INFINITY, 2},
{NAN, 2},
{-INFINITY, 2},
{-2, 2},
{-1, 2},
{-0.5, 2},
{-0., 2},
{+0., 2},
{0.5, 2},
{1, 2},
{2, 2},
{INFINITY, 2},
{NAN, INFINITY},
{-INFINITY, INFINITY},
{-2, INFINITY},
{-1, INFINITY},
{-0.5, INFINITY},
{-0., INFINITY},
{+0., INFINITY},
{0.5, INFINITY},
{1, INFINITY},
{2, INFINITY},
{INFINITY, INFINITY}
{NAN, INFINITY},
{-INFINITY, INFINITY},
{-2, INFINITY},
{-1, INFINITY},
{-0.5, INFINITY},
{-0., INFINITY},
{+0., INFINITY},
{0.5, INFINITY},
{1, INFINITY},
{2, INFINITY},
{INFINITY, INFINITY},
{INFINITY, fromRep32(0x7f800001) /* SNaN */}};
};
int main()
{
const unsigned N = sizeof(x) / sizeof(x[0]);
unsigned i, j;
for (i = 0; i < N; ++i)
{
for (j = 0; j < N; ++j)
{
if (test__divsc3(x[i][0], x[i][1], x[j][0], x[j][1]))
return 1;
}
const unsigned N = sizeof(x) / sizeof(x[0]);
unsigned i, j;
for (i = 0; i < N; ++i) {
for (j = 0; j < N; ++j) {
if (test__divsc3(x[i][0], x[i][1], x[j][0], x[j][1]))
return 1;
}
}
return 0;
return 0;
}