diff options
author | Siva Chandra <sivachandra@google.com> | 2021-02-01 23:43:05 -0800 |
---|---|---|
committer | Siva Chandra <sivachandra@google.com> | 2021-02-02 15:36:19 -0800 |
commit | 2668714747c5a35fcdce45fb2d09d73fa4a46134 (patch) | |
tree | 06c7f9bb4893c07eaca42d27aaa318d696246f67 /libc | |
parent | [mlir] Fix scf.for single iteration canonicalization check (diff) | |
download | llvm-project-2668714747c5a35fcdce45fb2d09d73fa4a46134.tar.gz llvm-project-2668714747c5a35fcdce45fb2d09d73fa4a46134.tar.bz2 llvm-project-2668714747c5a35fcdce45fb2d09d73fa4a46134.zip |
[libc] Add hardware implementations of ceil and ceilf for aarch64.
This change also introduces a new source layout for adding machine
specific and generic implementations. To keep the scope of this change
small, this new pattern is only applied for ceil, ceilf and ceill.
Follow up changes will switch all math functions in to the new pattern.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D95850
Diffstat (limited to 'libc')
-rw-r--r-- | libc/src/math/CMakeLists.txt | 74 | ||||
-rw-r--r-- | libc/src/math/aarch64/CMakeLists.txt | 19 | ||||
-rw-r--r-- | libc/src/math/aarch64/ceil.cpp | 25 | ||||
-rw-r--r-- | libc/src/math/aarch64/ceilf.cpp | 25 | ||||
-rw-r--r-- | libc/src/math/generic/CMakeLists.txt | 35 | ||||
-rw-r--r-- | libc/src/math/generic/ceil.cpp (renamed from libc/src/math/ceil.cpp) | 0 | ||||
-rw-r--r-- | libc/src/math/generic/ceilf.cpp (renamed from libc/src/math/ceilf.cpp) | 0 | ||||
-rw-r--r-- | libc/src/math/generic/ceill.cpp (renamed from libc/src/math/ceill.cpp) | 0 | ||||
-rw-r--r-- | libc/test/src/math/CMakeLists.txt | 2 | ||||
-rw-r--r-- | libc/test/src/math/generic/CMakeLists.txt | 39 |
10 files changed, 183 insertions, 36 deletions
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 34b7dfcd4306..ac4ee312fb81 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -1,3 +1,41 @@ +add_subdirectory(generic) +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_MACHINE}) + add_subdirectory(${LIBC_TARGET_MACHINE}) +endif() + +function(add_math_entrypoint_object name) + # We prefer machine specific implementation if available. Hence we check + # that first and retrun early if we are able to add an alias target for the + # machine specific implementation. + get_fq_target_name("${LIBC_TARGET_MACHINE}.${name}" fq_machine_specific_target_name) + if(TARGET ${fq_machine_specific_target_name}) + add_entrypoint_object( + ${name} + ALIAS + DEPENDS + .${LIBC_TARGET_MACHINE}.${name} + ) + return() + endif() + + get_fq_target_name("generic.${name}" fq_generic_target_name) + if(TARGET ${fq_generic_target_name}) + add_entrypoint_object( + ${name} + ALIAS + DEPENDS + .generic.${name} + ) + return() + endif() + + message(FATAL_ERROR "No machine specific or generic implementation found for ${name}.") +endfunction() + +add_math_entrypoint_object(ceil) +add_math_entrypoint_object(ceilf) +add_math_entrypoint_object(ceill) + add_object_library( math_utils SRCS @@ -129,42 +167,6 @@ add_entrypoint_object( ) add_entrypoint_object( - ceil - SRCS - ceil.cpp - HDRS - ceil.h - DEPENDS - libc.utils.FPUtil.fputil - COMPILE_OPTIONS - -O2 -) - -add_entrypoint_object( - ceilf - SRCS - ceilf.cpp - HDRS - ceilf.h - DEPENDS - libc.utils.FPUtil.fputil - COMPILE_OPTIONS - -O2 -) - -add_entrypoint_object( - ceill - SRCS - ceill.cpp - HDRS - ceill.h - DEPENDS - libc.utils.FPUtil.fputil - COMPILE_OPTIONS - -O2 -) - -add_entrypoint_object( floor SRCS floor.cpp diff --git a/libc/src/math/aarch64/CMakeLists.txt b/libc/src/math/aarch64/CMakeLists.txt new file mode 100644 index 000000000000..716fbe3bf7c6 --- /dev/null +++ b/libc/src/math/aarch64/CMakeLists.txt @@ -0,0 +1,19 @@ +add_entrypoint_object( + ceil + SRCS + ceil.cpp + HDRS + ../ceil.h + COMPILE_OPTIONS + -O2 +) + +add_entrypoint_object( + ceilf + SRCS + ceilf.cpp + HDRS + ../ceilf.h + COMPILE_OPTIONS + -O2 +) diff --git a/libc/src/math/aarch64/ceil.cpp b/libc/src/math/aarch64/ceil.cpp new file mode 100644 index 000000000000..c39dbfc50993 --- /dev/null +++ b/libc/src/math/aarch64/ceil.cpp @@ -0,0 +1,25 @@ +//===-- Implementation of the ceil 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/ceil.h" +#include "src/__support/common.h" + +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"); + return y; +} + +} // namespace __llvm_libc diff --git a/libc/src/math/aarch64/ceilf.cpp b/libc/src/math/aarch64/ceilf.cpp new file mode 100644 index 000000000000..1d8047757835 --- /dev/null +++ b/libc/src/math/aarch64/ceilf.cpp @@ -0,0 +1,25 @@ +//===-- Implementation of the ceilf 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/ceilf.h" +#include "src/__support/common.h" + +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"); + return y; +} + +} // namespace __llvm_libc diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt new file mode 100644 index 000000000000..6c481b57b3d6 --- /dev/null +++ b/libc/src/math/generic/CMakeLists.txt @@ -0,0 +1,35 @@ +add_entrypoint_object( + ceil + SRCS + ceil.cpp + HDRS + ../ceil.h + DEPENDS + libc.utils.FPUtil.fputil + COMPILE_OPTIONS + -O2 +) + +add_entrypoint_object( + ceilf + SRCS + ceilf.cpp + HDRS + ../ceilf.h + DEPENDS + libc.utils.FPUtil.fputil + COMPILE_OPTIONS + -O2 +) + +add_entrypoint_object( + ceill + SRCS + ceill.cpp + HDRS + ../ceill.h + DEPENDS + libc.utils.FPUtil.fputil + COMPILE_OPTIONS + -O2 +) diff --git a/libc/src/math/ceil.cpp b/libc/src/math/generic/ceil.cpp index 7c59c938acff..7c59c938acff 100644 --- a/libc/src/math/ceil.cpp +++ b/libc/src/math/generic/ceil.cpp diff --git a/libc/src/math/ceilf.cpp b/libc/src/math/generic/ceilf.cpp index 9093ee196617..9093ee196617 100644 --- a/libc/src/math/ceilf.cpp +++ b/libc/src/math/generic/ceilf.cpp diff --git a/libc/src/math/ceill.cpp b/libc/src/math/generic/ceill.cpp index 23edb7a441c8..23edb7a441c8 100644 --- a/libc/src/math/ceill.cpp +++ b/libc/src/math/generic/ceill.cpp diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt index 8764d57a1413..841e4db5a22b 100644 --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -1070,3 +1070,5 @@ add_fp_unittest( libc.src.math.fmaf libc.utils.FPUtil.fputil ) + +add_subdirectory(generic) diff --git a/libc/test/src/math/generic/CMakeLists.txt b/libc/test/src/math/generic/CMakeLists.txt new file mode 100644 index 000000000000..d1bf53271f09 --- /dev/null +++ b/libc/test/src/math/generic/CMakeLists.txt @@ -0,0 +1,39 @@ +add_fp_unittest( + ceil_test + NEED_MPFR + SUITE + libc_math_unittests + SRCS + ../ceil_test.cpp + DEPENDS + libc.include.math + libc.src.math.generic.ceil + libc.utils.FPUtil.fputil +) + +add_fp_unittest( + ceilf_test + NEED_MPFR + SUITE + libc_math_unittests + SRCS + ../ceilf_test.cpp + DEPENDS + libc.include.math + libc.src.math.generic.ceilf + libc.utils.FPUtil.fputil +) + +add_fp_unittest( + ceill_test + NEED_MPFR + SUITE + libc_math_unittests + SRCS + ../ceill_test.cpp + DEPENDS + libc.include.math + libc.src.math.generic.ceill + libc.utils.FPUtil.fputil +) + |