Author: Siva Chandra Reddy Date: 2021-01-05T21:51:10-08:00 New Revision: 993d8ac5cb935b78fb136c25a7e4bae18852f429
URL: https://github.com/llvm/llvm-project/commit/993d8ac5cb935b78fb136c25a7e4bae18852f429 DIFF: https://github.com/llvm/llvm-project/commit/993d8ac5cb935b78fb136c25a7e4bae18852f429.diff LOG: [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 Added: libc/src/math/nearbyint.cpp libc/src/math/nearbyint.h libc/src/math/nearbyintf.cpp libc/src/math/nearbyintf.h libc/src/math/nearbyintl.cpp libc/src/math/nearbyintl.h Modified: libc/config/linux/x86_64/entrypoints.txt libc/spec/stdc.td libc/src/math/CMakeLists.txt Removed: ################################################################################ diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 8e430afbcfc8..45571ee85d49 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 0eea8e55701f..355321c4025d 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 ff9d79131a60..aa4b4a5d4a79 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 000000000000..0938952752dd --- /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 000000000000..957a06b97921 --- /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 000000000000..cc19da6f3814 --- /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 000000000000..3793f6bc1b88 --- /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 000000000000..561883223948 --- /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 000000000000..7029e86a5211 --- /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 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits