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/ceil.cpp b/libc/src/math/aarch64/ceil.cpp --- a/libc/src/math/aarch64/ceil.cpp +++ b/libc/src/math/aarch64/ceil.cpp @@ -13,12 +13,7 @@ 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 --- a/libc/src/math/aarch64/ceilf.cpp +++ b/libc/src/math/aarch64/ceilf.cpp @@ -13,12 +13,7 @@ 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/ceil.cpp b/libc/src/math/aarch64/floor.cpp copy from libc/src/math/aarch64/ceil.cpp copy to libc/src/math/aarch64/floor.cpp --- a/libc/src/math/aarch64/ceil.cpp +++ b/libc/src/math/aarch64/floor.cpp @@ -1,4 +1,4 @@ -//===-- Implementation of the ceil function for aarch64 -------------------===// +//===-- 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. @@ -6,19 +6,14 @@ // //===----------------------------------------------------------------------===// -#include "src/math/ceil.h" +#include "src/math/floor.h" #include "src/__support/common.h" namespace __llvm_libc { -LLVM_LIBC_FUNCTION(double, ceil, (double x)) { +LLVM_LIBC_FUNCTION(double, floor, (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__("frintm %d0, %d1\n\t" : "=w"(y) : "w"(x)); return y; } diff --git a/libc/src/math/aarch64/ceilf.cpp b/libc/src/math/aarch64/floorf.cpp copy from libc/src/math/aarch64/ceilf.cpp copy to libc/src/math/aarch64/floorf.cpp --- a/libc/src/math/aarch64/ceilf.cpp +++ b/libc/src/math/aarch64/floorf.cpp @@ -1,4 +1,4 @@ -//===-- Implementation of the ceilf function for aarch64 ------------------===// +//===-- 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. @@ -6,19 +6,14 @@ // //===----------------------------------------------------------------------===// -#include "src/math/ceilf.h" +#include "src/math/floorf.h" #include "src/__support/common.h" namespace __llvm_libc { -LLVM_LIBC_FUNCTION(float, ceilf, (float x)) { +LLVM_LIBC_FUNCTION(float, floorf, (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__("frintm %s0, %s1\n\t" : "=w"(y) : "w"(x)); return y; } diff --git a/libc/src/math/aarch64/ceil.cpp b/libc/src/math/aarch64/round.cpp copy from libc/src/math/aarch64/ceil.cpp copy to libc/src/math/aarch64/round.cpp --- a/libc/src/math/aarch64/ceil.cpp +++ b/libc/src/math/aarch64/round.cpp @@ -1,4 +1,4 @@ -//===-- Implementation of the ceil function for aarch64 -------------------===// +//===-- 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. @@ -6,19 +6,14 @@ // //===----------------------------------------------------------------------===// -#include "src/math/ceil.h" +#include "src/math/round.h" #include "src/__support/common.h" namespace __llvm_libc { -LLVM_LIBC_FUNCTION(double, ceil, (double x)) { +LLVM_LIBC_FUNCTION(double, round, (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__("frinta %d0, %d1\n\t" : "=w"(y) : "w"(x)); return y; } diff --git a/libc/src/math/aarch64/ceilf.cpp b/libc/src/math/aarch64/roundf.cpp copy from libc/src/math/aarch64/ceilf.cpp copy to libc/src/math/aarch64/roundf.cpp --- a/libc/src/math/aarch64/ceilf.cpp +++ b/libc/src/math/aarch64/roundf.cpp @@ -1,4 +1,4 @@ -//===-- Implementation of the ceilf function for aarch64 ------------------===// +//===-- 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. @@ -6,19 +6,14 @@ // //===----------------------------------------------------------------------===// -#include "src/math/ceilf.h" +#include "src/math/roundf.h" #include "src/__support/common.h" namespace __llvm_libc { -LLVM_LIBC_FUNCTION(float, ceilf, (float x)) { +LLVM_LIBC_FUNCTION(float, roundf, (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__("frinta %s0, %s1\n\t" : "=w"(y) : "w"(x)); return y; } diff --git a/libc/src/math/aarch64/ceil.cpp b/libc/src/math/aarch64/sqrt.cpp copy from libc/src/math/aarch64/ceil.cpp copy to libc/src/math/aarch64/sqrt.cpp --- a/libc/src/math/aarch64/ceil.cpp +++ b/libc/src/math/aarch64/sqrt.cpp @@ -1,4 +1,4 @@ -//===-- Implementation of the ceil function for aarch64 -------------------===// +//===-- 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. @@ -6,19 +6,14 @@ // //===----------------------------------------------------------------------===// -#include "src/math/ceil.h" +#include "src/math/sqrt.h" #include "src/__support/common.h" namespace __llvm_libc { -LLVM_LIBC_FUNCTION(double, ceil, (double x)) { +LLVM_LIBC_FUNCTION(double, sqrt, (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__("fsqrt %d0, %d1\n\t" : "=w"(y) : "w"(x)); return y; } diff --git a/libc/src/math/aarch64/ceilf.cpp b/libc/src/math/aarch64/sqrtf.cpp copy from libc/src/math/aarch64/ceilf.cpp copy to libc/src/math/aarch64/sqrtf.cpp --- a/libc/src/math/aarch64/ceilf.cpp +++ b/libc/src/math/aarch64/sqrtf.cpp @@ -1,4 +1,4 @@ -//===-- Implementation of the ceilf function for aarch64 ------------------===// +//===-- 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. @@ -6,19 +6,14 @@ // //===----------------------------------------------------------------------===// -#include "src/math/ceilf.h" +#include "src/math/sqrtf.h" #include "src/__support/common.h" namespace __llvm_libc { -LLVM_LIBC_FUNCTION(float, ceilf, (float x)) { +LLVM_LIBC_FUNCTION(float, sqrtf, (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__("fsqrt %s0, %s1\n\t" : "=w"(y) : "w"(x)); return y; } diff --git a/libc/src/math/aarch64/ceil.cpp b/libc/src/math/aarch64/trunc.cpp copy from libc/src/math/aarch64/ceil.cpp copy to libc/src/math/aarch64/trunc.cpp --- a/libc/src/math/aarch64/ceil.cpp +++ b/libc/src/math/aarch64/trunc.cpp @@ -1,4 +1,4 @@ -//===-- Implementation of the ceil function for aarch64 -------------------===// +//===-- 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. @@ -6,19 +6,14 @@ // //===----------------------------------------------------------------------===// -#include "src/math/ceil.h" +#include "src/math/trunc.h" #include "src/__support/common.h" namespace __llvm_libc { -LLVM_LIBC_FUNCTION(double, ceil, (double x)) { +LLVM_LIBC_FUNCTION(double, trunc, (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__("frintz %d0, %d1\n" : "=w"(y) : "w"(x)); return y; } diff --git a/libc/src/math/aarch64/ceilf.cpp b/libc/src/math/aarch64/truncf.cpp copy from libc/src/math/aarch64/ceilf.cpp copy to libc/src/math/aarch64/truncf.cpp --- a/libc/src/math/aarch64/ceilf.cpp +++ b/libc/src/math/aarch64/truncf.cpp @@ -1,4 +1,4 @@ -//===-- Implementation of the ceilf function for aarch64 ------------------===// +//===-- 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. @@ -6,19 +6,14 @@ // //===----------------------------------------------------------------------===// -#include "src/math/ceilf.h" +#include "src/math/truncf.h" #include "src/__support/common.h" namespace __llvm_libc { -LLVM_LIBC_FUNCTION(float, ceilf, (float x)) { +LLVM_LIBC_FUNCTION(float, truncf, (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__("frintz %s0, %s1\n\t" : "=w"(y) : "w"(x)); return y; }