libm: more 32-bit armv8 optimization.
There's no good reason to have the floor() trick not apply to ceil(),
rint(), and trunc() (and their float variants).
Rather than duplicate the existing trick three more times, switch to a less verbose alternative that conditionally builds the msun files from the .bp file rather than via #include from builtins.cpp.
It's unlikely we'll be rid of armv7 before we stop supporting LP32
completely, so this is probably as tidy as it gets for now.
Test: treehugger
Change-Id: I746491e494d7d0cc3015cde0ec5829d7b654fdd7
diff --git a/libm/Android.bp b/libm/Android.bp
index c6e44fc..4291c6a 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -161,8 +161,6 @@
"upstream-freebsd/lib/msun/src/s_nextafterf.c",
"upstream-freebsd/lib/msun/src/s_remquo.c",
"upstream-freebsd/lib/msun/src/s_remquof.c",
- "upstream-freebsd/lib/msun/src/s_rint.c",
- "upstream-freebsd/lib/msun/src/s_rintf.c",
"upstream-freebsd/lib/msun/src/s_round.c",
"upstream-freebsd/lib/msun/src/s_roundf.c",
"upstream-freebsd/lib/msun/src/s_scalbln.c",
@@ -179,8 +177,6 @@
"upstream-freebsd/lib/msun/src/s_tanh.c",
"upstream-freebsd/lib/msun/src/s_tanhf.c",
"upstream-freebsd/lib/msun/src/s_tgammaf.c",
- "upstream-freebsd/lib/msun/src/s_trunc.c",
- "upstream-freebsd/lib/msun/src/s_truncf.c",
"upstream-freebsd/lib/msun/src/w_cabs.c",
"upstream-freebsd/lib/msun/src/w_cabsf.c",
"upstream-freebsd/lib/msun/src/w_cabsl.c",
@@ -276,9 +272,22 @@
arm: {
srcs: [
"arm/fenv.c",
- "upstream-freebsd/lib/msun/src/s_ceil.c",
- "upstream-freebsd/lib/msun/src/s_ceilf.c",
],
+ armv7_a_neon: {
+ // armv7 arm32 has no instructions to implement these as
+ // builtins, so we build the portable implementations for armv7,
+ // because the NDK still supports armv7.
+ srcs: [
+ "upstream-freebsd/lib/msun/src/s_ceil.c",
+ "upstream-freebsd/lib/msun/src/s_ceilf.c",
+ "upstream-freebsd/lib/msun/src/s_floor.c",
+ "upstream-freebsd/lib/msun/src/s_floorf.c",
+ "upstream-freebsd/lib/msun/src/s_rint.c",
+ "upstream-freebsd/lib/msun/src/s_rintf.c",
+ "upstream-freebsd/lib/msun/src/s_trunc.c",
+ "upstream-freebsd/lib/msun/src/s_truncf.c",
+ ],
+ },
instruction_set: "arm",
version_script: ":libm.arm.map",
no_libcrt: true,
@@ -309,12 +318,8 @@
"upstream-freebsd/lib/msun/src/s_lrintf.c",
"upstream-freebsd/lib/msun/src/s_lround.c",
"upstream-freebsd/lib/msun/src/s_lroundf.c",
- "upstream-freebsd/lib/msun/src/s_rint.c",
- "upstream-freebsd/lib/msun/src/s_rintf.c",
"upstream-freebsd/lib/msun/src/s_round.c",
"upstream-freebsd/lib/msun/src/s_roundf.c",
- "upstream-freebsd/lib/msun/src/s_trunc.c",
- "upstream-freebsd/lib/msun/src/s_truncf.c",
],
version_script: ":libm.arm64.map",
},
@@ -339,12 +344,8 @@
"upstream-freebsd/lib/msun/src/s_lrintf.c",
"upstream-freebsd/lib/msun/src/s_lround.c",
"upstream-freebsd/lib/msun/src/s_lroundf.c",
- "upstream-freebsd/lib/msun/src/s_rint.c",
- "upstream-freebsd/lib/msun/src/s_rintf.c",
"upstream-freebsd/lib/msun/src/s_round.c",
"upstream-freebsd/lib/msun/src/s_roundf.c",
- "upstream-freebsd/lib/msun/src/s_trunc.c",
- "upstream-freebsd/lib/msun/src/s_truncf.c",
],
version_script: ":libm.riscv64.map",
},
@@ -358,10 +359,6 @@
exclude_srcs: [
"upstream-freebsd/lib/msun/src/s_lrint.c",
"upstream-freebsd/lib/msun/src/s_lrintf.c",
- "upstream-freebsd/lib/msun/src/s_rint.c",
- "upstream-freebsd/lib/msun/src/s_rintf.c",
- "upstream-freebsd/lib/msun/src/s_trunc.c",
- "upstream-freebsd/lib/msun/src/s_truncf.c",
],
local_include_dirs: ["i387"],
// The x86 ABI doesn't include this, which is needed for the
@@ -381,10 +378,6 @@
"upstream-freebsd/lib/msun/src/s_llrintf.c",
"upstream-freebsd/lib/msun/src/s_lrint.c",
"upstream-freebsd/lib/msun/src/s_lrintf.c",
- "upstream-freebsd/lib/msun/src/s_rint.c",
- "upstream-freebsd/lib/msun/src/s_rintf.c",
- "upstream-freebsd/lib/msun/src/s_trunc.c",
- "upstream-freebsd/lib/msun/src/s_truncf.c",
],
version_script: ":libm.x86_64.map",
},
diff --git a/libm/builtins.cpp b/libm/builtins.cpp
index 41e145b..22a0191 100644
--- a/libm/builtins.cpp
+++ b/libm/builtins.cpp
@@ -18,13 +18,12 @@
#include "fpmath.h"
-double fabs(double x) { return __builtin_fabs(x); }
-float fabsf(float x) { return __builtin_fabsf(x); }
-long double fabsl(long double x) { return __builtin_fabsl(x); }
-
-#if defined(__aarch64__) || defined(__riscv) || defined(__i386__) || defined(__x86_64__)
-float ceilf(float x) { return __builtin_ceilf(x); }
+#if defined(__arm__) && (__ARM_ARCH <= 7)
+// armv7 arm32 has no instructions to implement these builtins,
+// so we include the msun source in the .bp file instead.
+#else
double ceil(double x) { return __builtin_ceil(x); }
+float ceilf(float x) { return __builtin_ceilf(x); }
#if defined(__ILP32__)
__weak_reference(ceil, ceill);
#endif
@@ -34,21 +33,16 @@
float copysignf(float x, float y) { return __builtin_copysignf(x, y); }
long double copysignl(long double x, long double y) { return __builtin_copysignl(x, y); }
-#if defined(__arm__) && (__ARM_ARCH < 8)
-// armv8 arm32 has a single-instruction implementation for these, but
-// armv7 arm32 doesn't, so __builtin_ doesn't work for arm32.
-#include "math_private.h"
-namespace s_floor {
-#include "upstream-freebsd/lib/msun/src/s_floor.c"
-}
-namespace s_floorf {
-#include "upstream-freebsd/lib/msun/src/s_floorf.c"
-}
-float floorf(float x) { return s_floorf::floorf(x); }
-double floor(double x) { return s_floor::floor(x); }
+double fabs(double x) { return __builtin_fabs(x); }
+float fabsf(float x) { return __builtin_fabsf(x); }
+long double fabsl(long double x) { return __builtin_fabsl(x); }
+
+#if defined(__arm__) && (__ARM_ARCH <= 7)
+// armv7 arm32 has no instructions to implement these builtins,
+// so we include the msun source in the .bp file instead.
#else
-float floorf(float x) { return __builtin_floorf(x); }
double floor(double x) { return __builtin_floor(x); }
+float floorf(float x) { return __builtin_floorf(x); }
#if defined(__ILP32__)
__weak_reference(floor, floorl);
#endif
@@ -79,28 +73,34 @@
long long llroundf(float x) { return __builtin_llroundf(x); }
#endif
-#if defined(__aarch64__) || defined(__riscv) || defined(__i386__) || defined(__x86_64__)
-float rintf(float x) { return __builtin_rintf(x); }
+#if defined(__arm__) && (__ARM_ARCH <= 7)
+// armv7 arm32 has no instructions to implement these builtins,
+// so we include the msun source in the .bp file instead.
+#else
double rint(double x) { return __builtin_rint(x); }
+float rintf(float x) { return __builtin_rintf(x); }
#if defined(__ILP32__)
__weak_reference(rint, rintl);
#endif
#endif
#if defined(__aarch64__) || defined(__riscv)
-float roundf(float x) { return __builtin_roundf(x); }
double round(double x) { return __builtin_round(x); }
+float roundf(float x) { return __builtin_roundf(x); }
#endif
-float sqrtf(float x) { return __builtin_sqrtf(x); }
double sqrt(double x) { return __builtin_sqrt(x); }
+float sqrtf(float x) { return __builtin_sqrtf(x); }
#if defined(__ILP32__)
__weak_reference(sqrt, sqrtl);
#endif
-#if defined(__aarch64__) || defined(__riscv) || defined(__i386__) || defined(__x86_64__)
-float truncf(float x) { return __builtin_truncf(x); }
+#if defined(__arm__) && (__ARM_ARCH <= 7)
+// armv7 arm32 has no instructions to implement these builtins,
+// so we include the msun source in the .bp file instead.
+#else
double trunc(double x) { return __builtin_trunc(x); }
+float truncf(float x) { return __builtin_truncf(x); }
#if defined(__ILP32__)
__weak_reference(trunc, truncl);
#endif