diff --git a/libc/src/math/aarch64/CMakeLists.txt b/libc/src/math/aarch64/CMakeLists.txt index 716fbe3bf7c6d..6ce89441857ca 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 c39dbfc50993a..73c3cc02839d0 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 1d80477578357..2268989d131aa 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 0000000000000..8de1f67bd93c8 --- /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 0000000000000..6bb99ebeff28b --- /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 0000000000000..6659060fbd700 --- /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 0000000000000..6044c8b75136b --- /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 0000000000000..99ab7e3c15e7a --- /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 0000000000000..a747520a4f9bf --- /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 0000000000000..280d919bda9fb --- /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 0000000000000..a325ce3687f4a --- /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