[libc-commits] [libc] c90c8d3 - [libc] Add aarch64 flavors of floor, round, sqrt and trunc.
Siva Chandra via libc-commits
libc-commits at lists.llvm.org
Fri Feb 5 10:41:45 PST 2021
Author: Siva Chandra
Date: 2021-02-05T10:41:32-08:00
New Revision: c90c8d38d38e00d9ed7f3bce192e99665a386ef3
URL: https://github.com/llvm/llvm-project/commit/c90c8d38d38e00d9ed7f3bce192e99665a386ef3
DIFF: https://github.com/llvm/llvm-project/commit/c90c8d38d38e00d9ed7f3bce192e99665a386ef3.diff
LOG: [libc] Add aarch64 flavors of floor, round, sqrt and trunc.
Only single and double precision flavors have been added.
Reviewed By: lntue, sdesmalen
Differential Revision: https://reviews.llvm.org/D95999
Added:
libc/src/math/aarch64/floor.cpp
libc/src/math/aarch64/floorf.cpp
libc/src/math/aarch64/round.cpp
libc/src/math/aarch64/roundf.cpp
libc/src/math/aarch64/sqrt.cpp
libc/src/math/aarch64/sqrtf.cpp
libc/src/math/aarch64/trunc.cpp
libc/src/math/aarch64/truncf.cpp
Modified:
libc/src/math/aarch64/CMakeLists.txt
libc/src/math/aarch64/ceil.cpp
libc/src/math/aarch64/ceilf.cpp
Removed:
################################################################################
diff --git a/libc/src/math/aarch64/CMakeLists.txt b/libc/src/math/aarch64/CMakeLists.txt
index 716fbe3bf7c6..6ce89441857c 100644
--- a/libc/src/math/aarch64/CMakeLists.txt
+++ b/libc/src/math/aarch64/CMakeLists.txt
@@ -17,3 +17,83 @@ add_entrypoint_object(
COMPILE_OPTIONS
-O2
)
+
+add_entrypoint_object(
+ floor
+ SRCS
+ floor.cpp
+ HDRS
+ ../floor.h
+ COMPILE_OPTIONS
+ -O2
+)
+
+add_entrypoint_object(
+ floorf
+ SRCS
+ floorf.cpp
+ HDRS
+ ../floorf.h
+ COMPILE_OPTIONS
+ -O2
+)
+
+add_entrypoint_object(
+ trunc
+ SRCS
+ trunc.cpp
+ HDRS
+ ../trunc.h
+ COMPILE_OPTIONS
+ -O2
+)
+
+add_entrypoint_object(
+ truncf
+ SRCS
+ truncf.cpp
+ HDRS
+ ../truncf.h
+ COMPILE_OPTIONS
+ -O2
+)
+
+add_entrypoint_object(
+ round
+ SRCS
+ round.cpp
+ HDRS
+ ../round.h
+ COMPILE_OPTIONS
+ -O2
+)
+
+add_entrypoint_object(
+ roundf
+ SRCS
+ roundf.cpp
+ HDRS
+ ../roundf.h
+ COMPILE_OPTIONS
+ -O2
+)
+
+add_entrypoint_object(
+ sqrt
+ SRCS
+ sqrt.cpp
+ HDRS
+ ../sqrt.h
+ COMPILE_OPTIONS
+ -O2
+)
+
+add_entrypoint_object(
+ sqrtf
+ SRCS
+ sqrtf.cpp
+ HDRS
+ ../sqrtf.h
+ COMPILE_OPTIONS
+ -O2
+)
diff --git a/libc/src/math/aarch64/ceil.cpp b/libc/src/math/aarch64/ceil.cpp
index c39dbfc50993..73c3cc02839d 100644
--- a/libc/src/math/aarch64/ceil.cpp
+++ b/libc/src/math/aarch64/ceil.cpp
@@ -13,12 +13,7 @@ namespace __llvm_libc {
LLVM_LIBC_FUNCTION(double, ceil, (double x)) {
double y;
- __asm__ __volatile__("ldr d0, %1\n"
- "frintp d0, d0\n"
- "str d0, %0\n"
- : "=m"(y)
- : "m"(x)
- : "d0");
+ __asm__ __volatile__("frintp %d0, %d1\n\t" : "=w"(y) : "w"(x));
return y;
}
diff --git a/libc/src/math/aarch64/ceilf.cpp b/libc/src/math/aarch64/ceilf.cpp
index 1d8047757835..2268989d131a 100644
--- a/libc/src/math/aarch64/ceilf.cpp
+++ b/libc/src/math/aarch64/ceilf.cpp
@@ -13,12 +13,7 @@ namespace __llvm_libc {
LLVM_LIBC_FUNCTION(float, ceilf, (float x)) {
float y;
- __asm__ __volatile__("ldr s0, %1\n"
- "frintp s0, s0\n"
- "str s0, %0\n"
- : "=m"(y)
- : "m"(x)
- : "s0");
+ __asm__ __volatile__("frintp %s0, %s1\n\t" : "=w"(y) : "w"(x));
return y;
}
diff --git a/libc/src/math/aarch64/floor.cpp b/libc/src/math/aarch64/floor.cpp
new file mode 100644
index 000000000000..8de1f67bd93c
--- /dev/null
+++ b/libc/src/math/aarch64/floor.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of the floor function for aarch64 ------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/floor.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(double, floor, (double x)) {
+ double y;
+ __asm__ __volatile__("frintm %d0, %d1\n\t" : "=w"(y) : "w"(x));
+ return y;
+}
+
+} // namespace __llvm_libc
diff --git a/libc/src/math/aarch64/floorf.cpp b/libc/src/math/aarch64/floorf.cpp
new file mode 100644
index 000000000000..6bb99ebeff28
--- /dev/null
+++ b/libc/src/math/aarch64/floorf.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of the floorf function for aarch64 -----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/floorf.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(float, floorf, (float x)) {
+ float y;
+ __asm__ __volatile__("frintm %s0, %s1\n\t" : "=w"(y) : "w"(x));
+ return y;
+}
+
+} // namespace __llvm_libc
diff --git a/libc/src/math/aarch64/round.cpp b/libc/src/math/aarch64/round.cpp
new file mode 100644
index 000000000000..6659060fbd70
--- /dev/null
+++ b/libc/src/math/aarch64/round.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of the round function for aarch64 ------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/round.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(double, round, (double x)) {
+ double y;
+ __asm__ __volatile__("frinta %d0, %d1\n\t" : "=w"(y) : "w"(x));
+ return y;
+}
+
+} // namespace __llvm_libc
diff --git a/libc/src/math/aarch64/roundf.cpp b/libc/src/math/aarch64/roundf.cpp
new file mode 100644
index 000000000000..6044c8b75136
--- /dev/null
+++ b/libc/src/math/aarch64/roundf.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of the roundf function for aarch64 -----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/roundf.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(float, roundf, (float x)) {
+ float y;
+ __asm__ __volatile__("frinta %s0, %s1\n\t" : "=w"(y) : "w"(x));
+ return y;
+}
+
+} // namespace __llvm_libc
diff --git a/libc/src/math/aarch64/sqrt.cpp b/libc/src/math/aarch64/sqrt.cpp
new file mode 100644
index 000000000000..99ab7e3c15e7
--- /dev/null
+++ b/libc/src/math/aarch64/sqrt.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of the sqrt function for aarch64 -------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/sqrt.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(double, sqrt, (double x)) {
+ double y;
+ __asm__ __volatile__("fsqrt %d0, %d1\n\t" : "=w"(y) : "w"(x));
+ return y;
+}
+
+} // namespace __llvm_libc
diff --git a/libc/src/math/aarch64/sqrtf.cpp b/libc/src/math/aarch64/sqrtf.cpp
new file mode 100644
index 000000000000..a747520a4f9b
--- /dev/null
+++ b/libc/src/math/aarch64/sqrtf.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of the sqrtf function for aarch64 ------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/sqrtf.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(float, sqrtf, (float x)) {
+ float y;
+ __asm__ __volatile__("fsqrt %s0, %s1\n\t" : "=w"(y) : "w"(x));
+ return y;
+}
+
+} // namespace __llvm_libc
diff --git a/libc/src/math/aarch64/trunc.cpp b/libc/src/math/aarch64/trunc.cpp
new file mode 100644
index 000000000000..280d919bda9f
--- /dev/null
+++ b/libc/src/math/aarch64/trunc.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of the trunc function for aarch64 ------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/trunc.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(double, trunc, (double x)) {
+ double y;
+ __asm__ __volatile__("frintz %d0, %d1\n" : "=w"(y) : "w"(x));
+ return y;
+}
+
+} // namespace __llvm_libc
diff --git a/libc/src/math/aarch64/truncf.cpp b/libc/src/math/aarch64/truncf.cpp
new file mode 100644
index 000000000000..a325ce3687f4
--- /dev/null
+++ b/libc/src/math/aarch64/truncf.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of the truncf function for aarch64 -----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/truncf.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(float, truncf, (float x)) {
+ float y;
+ __asm__ __volatile__("frintz %s0, %s1\n\t" : "=w"(y) : "w"(x));
+ return y;
+}
+
+} // namespace __llvm_libc
More information about the libc-commits
mailing list