[compiler-rt] d60ca0c - [compiler-rt][builtins]Adjust complex division for aarch64 (#106664)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 6 12:21:09 PDT 2024
Author: Alexander Shaposhnikov
Date: 2024-09-06T12:21:06-07:00
New Revision: d60ca0c913f7521ee05da08a8a0c9dda1c439c88
URL: https://github.com/llvm/llvm-project/commit/d60ca0c913f7521ee05da08a8a0c9dda1c439c88
DIFF: https://github.com/llvm/llvm-project/commit/d60ca0c913f7521ee05da08a8a0c9dda1c439c88.diff
LOG: [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
Added:
Modified:
compiler-rt/lib/builtins/divsc3.c
compiler-rt/lib/builtins/fp_lib.h
compiler-rt/test/builtins/Unit/divsc3_test.c
Removed:
################################################################################
diff --git a/compiler-rt/lib/builtins/divsc3.c b/compiler-rt/lib/builtins/divsc3.c
index aa4fd8e79e0cc6..6529651252c554 100644
--- a/compiler-rt/lib/builtins/divsc3.c
+++ b/compiler-rt/lib/builtins/divsc3.c
@@ -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);
diff --git a/compiler-rt/lib/builtins/fp_lib.h b/compiler-rt/lib/builtins/fp_lib.h
index b2a89506135be9..0289cfd10db660 100644
--- a/compiler-rt/lib/builtins/fp_lib.h
+++ b/compiler-rt/lib/builtins/fp_lib.h
@@ -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)
diff --git a/compiler-rt/test/builtins/Unit/divsc3_test.c b/compiler-rt/test/builtins/Unit/divsc3_test.c
index 870ab6e8453857..05a073b4375c72 100644
--- a/compiler-rt/test/builtins/Unit/divsc3_test.c
+++ b/compiler-rt/test/builtins/Unit/divsc3_test.c
@@ -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},
-
- { 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},
- {NAN, NAN},
- {-INFINITY, NAN},
- {-2, NAN},
- {-1, NAN},
- {-0.5, NAN},
- {-0., NAN},
- {+0., NAN},
- {0.5, NAN},
- {1, NAN},
- {2, NAN},
- {INFINITY, NAN},
+ {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, -INFINITY},
- {-INFINITY, -INFINITY},
- {-2, -INFINITY},
- {-1, -INFINITY},
- {-0.5, -INFINITY},
- {-0., -INFINITY},
- {+0., -INFINITY},
- {0.5, -INFINITY},
- {1, -INFINITY},
- {2, -INFINITY},
- {INFINITY, -INFINITY},
+ {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, -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, -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, -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, -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.},
- {-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.},
+ {-INFINITY, 0.},
+ {-2, 0.},
+ {-1, 0.},
+ {-0.5, 0.},
+ {-0., 0.},
+ {+0., 0.},
+ {0.5, 0.},
+ {1, 0.},
+ {2, 0.},
+ {INFINITY, 0.},
- {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, 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, 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, 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;
}
More information about the llvm-commits
mailing list