diff --git a/libc/src/math/aarch64/CMakeLists.txt b/libc/src/math/aarch64/CMakeLists.txt --- a/libc/src/math/aarch64/CMakeLists.txt +++ b/libc/src/math/aarch64/CMakeLists.txt @@ -17,3 +17,83 @@ 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/floor.cpp b/libc/src/math/aarch64/floor.cpp new file mode 100644 --- /dev/null +++ b/libc/src/math/aarch64/floor.cpp @@ -0,0 +1,25 @@ +//===-- 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__("ldr d0, %1\n" + "frintm d0, d0\n" + "str d0, %0\n" + : "=m"(y) + : "m"(x) + : "d0"); + 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 --- /dev/null +++ b/libc/src/math/aarch64/floorf.cpp @@ -0,0 +1,25 @@ +//===-- 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__("ldr s0, %1\n" + "frintm s0, s0\n" + "str s0, %0\n" + : "=m"(y) + : "m"(x) + : "s0"); + 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 --- /dev/null +++ b/libc/src/math/aarch64/round.cpp @@ -0,0 +1,25 @@ +//===-- 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__("ldr d0, %1\n" + "frinta d0, d0\n" + "str d0, %0\n" + : "=m"(y) + : "m"(x) + : "d0"); + 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 --- /dev/null +++ b/libc/src/math/aarch64/roundf.cpp @@ -0,0 +1,25 @@ +//===-- 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__("ldr s0, %1\n" + "frinta s0, s0\n" + "str s0, %0\n" + : "=m"(y) + : "m"(x) + : "s0"); + 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 --- /dev/null +++ b/libc/src/math/aarch64/sqrt.cpp @@ -0,0 +1,25 @@ +//===-- 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__("ldr d0, %1\n" + "fsqrt d0, d0\n" + "str d0, %0\n" + : "=m"(y) + : "m"(x) + : "d0"); + 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 --- /dev/null +++ b/libc/src/math/aarch64/sqrtf.cpp @@ -0,0 +1,25 @@ +//===-- 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__("ldr s0, %1\n" + "fsqrt s0, s0\n" + "str s0, %0\n" + : "=m"(y) + : "m"(x) + : "s0"); + 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 --- /dev/null +++ b/libc/src/math/aarch64/trunc.cpp @@ -0,0 +1,25 @@ +//===-- 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__("ldr d0, %1\n" + "frintz d0, d0\n" + "str d0, %0\n" + : "=m"(y) + : "m"(x) + : "d0"); + 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 --- /dev/null +++ b/libc/src/math/aarch64/truncf.cpp @@ -0,0 +1,25 @@ +//===-- 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__("ldr s0, %1\n" + "frintz s0, s0\n" + "str s0, %0\n" + : "=m"(y) + : "m"(x) + : "s0"); + return y; +} + +} // namespace __llvm_libc