arm64: Use builtin for nearbyintf/nearbyint

This allows compiler optimize both calls to a single frinti.

Test: Builds, ran unit tests on arm64.

Change-Id: Ie59ac11a419281836a8051ecda26a5c7b72f3dea
diff --git a/libm/Android.bp b/libm/Android.bp
index 3b88fa3..c0862c8 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -315,6 +315,8 @@
                 "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_nearbyintf.c",
+                "upstream-freebsd/lib/msun/src/s_nearbyint.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",
diff --git a/libm/builtins.cpp b/libm/builtins.cpp
index 2ea6305..515b68a 100644
--- a/libm/builtins.cpp
+++ b/libm/builtins.cpp
@@ -57,4 +57,12 @@
 
 float roundf(float x) { return __builtin_roundf(x); }
 double round(double x) { return __builtin_round(x); }
+
+float nearbyintf(float x) { return __builtin_nearbyintf(x); }
+double nearbyint(double x) { return __builtin_nearbyint(x); }
+// msun s_nearbyint.c defines all floating-point version, so we need to
+// redefine the long double one here. For aarch64, clang/compiler-rt
+// soft-float routines does not use single/double floating-point operation,
+// so it should be safe to call rintl directly.
+long double nearbyintl(long double x) { return rintl(x); }
 #endif