diff options
author | Siva Chandra Reddy <sivachandra@google.com> | 2021-01-01 21:19:31 -0800 |
---|---|---|
committer | Siva Chandra Reddy <sivachandra@google.com> | 2021-01-05 21:51:10 -0800 |
commit | 993d8ac5cb935b78fb136c25a7e4bae18852f429 (patch) | |
tree | 690eae4acc98330228e64b9a6e753604db6822a2 | |
parent | cd088ba7e61a6132659d066918a1175861c9afe7 (diff) | |
download | llvm-993d8ac5cb935b78fb136c25a7e4bae18852f429.zip llvm-993d8ac5cb935b78fb136c25a7e4bae18852f429.tar.gz llvm-993d8ac5cb935b78fb136c25a7e4bae18852f429.tar.bz2 |
[libc] Add implementations of nearbyint[f|l].
The implementation is exactly the same as rint* as even rint does not
raise any floating point exceptions currently. [Note that the standards
do not specify that floating point exceptions must be raised - they
leave it up to the implementation to choose to raise FE_INEXACT when
rounding non-integral values.]
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D94112
-rw-r--r-- | libc/config/linux/x86_64/entrypoints.txt | 3 | ||||
-rw-r--r-- | libc/spec/stdc.td | 4 | ||||
-rw-r--r-- | libc/src/math/CMakeLists.txt | 36 | ||||
-rw-r--r-- | libc/src/math/nearbyint.cpp | 18 | ||||
-rw-r--r-- | libc/src/math/nearbyint.h | 18 | ||||
-rw-r--r-- | libc/src/math/nearbyintf.cpp | 18 | ||||
-rw-r--r-- | libc/src/math/nearbyintf.h | 18 | ||||
-rw-r--r-- | libc/src/math/nearbyintl.cpp | 18 | ||||
-rw-r--r-- | libc/src/math/nearbyintl.h | 18 |
9 files changed, 151 insertions, 0 deletions
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 8e430af..45571ee 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -141,6 +141,9 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.modf libc.src.math.modff libc.src.math.modfl + libc.src.math.nearbyint + libc.src.math.nearbyintf + libc.src.math.nearbyintl libc.src.math.remainderf libc.src.math.remainder libc.src.math.remainderl diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 0eea8e5..355321c 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -390,6 +390,10 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"trunc", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>, FunctionSpec<"truncf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>, FunctionSpec<"truncl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>, + + FunctionSpec<"nearbyint", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>, + FunctionSpec<"nearbyintf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>, + FunctionSpec<"nearbyintl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>, ] >; diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index ff9d791..aa4b4a5 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -416,6 +416,42 @@ add_entrypoint_object( -O2 ) +add_entrypoint_object( + nearbyint + SRCS + nearbyint.cpp + HDRS + nearbyint.h + DEPENDS + libc.utils.FPUtil.fputil + COMPILE_OPTIONS + -O2 +) + +add_entrypoint_object( + nearbyintf + SRCS + nearbyintf.cpp + HDRS + nearbyintf.h + DEPENDS + libc.utils.FPUtil.fputil + COMPILE_OPTIONS + -O2 +) + +add_entrypoint_object( + nearbyintl + SRCS + nearbyintl.cpp + HDRS + nearbyintl.h + DEPENDS + libc.utils.FPUtil.fputil + COMPILE_OPTIONS + -O2 +) + add_object_library( exp_utils HDRS diff --git a/libc/src/math/nearbyint.cpp b/libc/src/math/nearbyint.cpp new file mode 100644 index 0000000..0938952 --- /dev/null +++ b/libc/src/math/nearbyint.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of nearbyint function ------------------------------===// +// +// 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/__support/common.h" +#include "utils/FPUtil/NearestIntegerOperations.h" + +namespace __llvm_libc { + +double LLVM_LIBC_ENTRYPOINT(nearbyint)(double x) { + return fputil::roundUsingCurrentRoundingMode(x); +} + +} // namespace __llvm_libc diff --git a/libc/src/math/nearbyint.h b/libc/src/math/nearbyint.h new file mode 100644 index 0000000..957a06b --- /dev/null +++ b/libc/src/math/nearbyint.h @@ -0,0 +1,18 @@ +//===-- Implementation header for nearbyint ---------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_MATH_NEARBYINT_H +#define LLVM_LIBC_SRC_MATH_NEARBYINT_H + +namespace __llvm_libc { + +double nearbyint(double x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_NEARBYINT_H diff --git a/libc/src/math/nearbyintf.cpp b/libc/src/math/nearbyintf.cpp new file mode 100644 index 0000000..cc19da6 --- /dev/null +++ b/libc/src/math/nearbyintf.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of nearbyintf function -----------------------------===// +// +// 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/__support/common.h" +#include "utils/FPUtil/NearestIntegerOperations.h" + +namespace __llvm_libc { + +float LLVM_LIBC_ENTRYPOINT(nearbyintf)(float x) { + return fputil::roundUsingCurrentRoundingMode(x); +} + +} // namespace __llvm_libc diff --git a/libc/src/math/nearbyintf.h b/libc/src/math/nearbyintf.h new file mode 100644 index 0000000..3793f6b --- /dev/null +++ b/libc/src/math/nearbyintf.h @@ -0,0 +1,18 @@ +//===-- Implementation header for nearbyintf --------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_MATH_NEARBYINTF_H +#define LLVM_LIBC_SRC_MATH_NEARBYINTF_H + +namespace __llvm_libc { + +float nearbyintf(float x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_NEARBYINTF_H diff --git a/libc/src/math/nearbyintl.cpp b/libc/src/math/nearbyintl.cpp new file mode 100644 index 0000000..5618832 --- /dev/null +++ b/libc/src/math/nearbyintl.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of nearbyintl function -----------------------------===// +// +// 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/__support/common.h" +#include "utils/FPUtil/NearestIntegerOperations.h" + +namespace __llvm_libc { + +long double LLVM_LIBC_ENTRYPOINT(nearbyintl)(long double x) { + return fputil::roundUsingCurrentRoundingMode(x); +} + +} // namespace __llvm_libc diff --git a/libc/src/math/nearbyintl.h b/libc/src/math/nearbyintl.h new file mode 100644 index 0000000..7029e86a --- /dev/null +++ b/libc/src/math/nearbyintl.h @@ -0,0 +1,18 @@ +//===-- Implementation header for nearbyintl --------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_MATH_NEARBYINTL_H +#define LLVM_LIBC_SRC_MATH_NEARBYINTL_H + +namespace __llvm_libc { + +long double nearbyintl(long double x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_NEARBYINTL_H |