libc.src.math.ceil
libc.src.math.ceilf
libc.src.math.ceill
+ libc.src.math.cos
libc.src.math.cosf
libc.src.math.expf
libc.src.math.exp2f
libc.src.math.round
libc.src.math.roundf
libc.src.math.roundl
+ libc.src.math.sin
libc.src.math.sincosf
libc.src.math.sinf
libc.src.math.sqrt
libc.src.math.sqrtf
libc.src.math.sqrtl
+ libc.src.math.tan
libc.src.math.trunc
libc.src.math.truncf
libc.src.math.truncl
FunctionSpec<"modff", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatPtr>]>,
FunctionSpec<"modfl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoublePtr>]>,
+ FunctionSpec<"cos", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"cosf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
+ FunctionSpec<"sin", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"sinf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
+ FunctionSpec<"tan", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"expf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
FunctionSpec<"exp2f", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
add_math_entrypoint_object(copysignf)
add_math_entrypoint_object(copysignl)
+add_math_entrypoint_object(cos)
add_math_entrypoint_object(cosf)
add_math_entrypoint_object(expf)
add_math_entrypoint_object(sincosf)
+add_math_entrypoint_object(sin)
add_math_entrypoint_object(sinf)
add_math_entrypoint_object(sqrt)
add_math_entrypoint_object(sqrtf)
add_math_entrypoint_object(sqrtl)
+add_math_entrypoint_object(tan)
+
add_math_entrypoint_object(trunc)
add_math_entrypoint_object(truncf)
add_math_entrypoint_object(truncl)
--- /dev/null
+//===-- Implementation header for cos ---------------------------*- 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_COS_H
+#define LLVM_LIBC_SRC_MATH_COS_H
+
+namespace __llvm_libc {
+
+double cos(double x);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_MATH_COS_H
--- /dev/null
+//===-- Implementation header for sin ---------------------------*- 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_SIN_H
+#define LLVM_LIBC_SRC_MATH_SIN_H
+
+namespace __llvm_libc {
+
+double sin(double x);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_MATH_SIN_H
--- /dev/null
+//===-- Implementation header for tan ---------------------------*- 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_TAN_H
+#define LLVM_LIBC_SRC_MATH_TAN_H
+
+namespace __llvm_libc {
+
+double tan(double x);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_MATH_TAN_H
--- /dev/null
+add_entrypoint_object(
+ cos
+ SRCS
+ cos.cpp
+ HDRS
+ ../cos.h
+ COMPILE_OPTIONS
+ -O2
+)
+
+add_entrypoint_object(
+ sin
+ SRCS
+ sin.cpp
+ HDRS
+ ../sin.h
+ COMPILE_OPTIONS
+ -O2
+)
+
+add_entrypoint_object(
+ tan
+ SRCS
+ tan.cpp
+ HDRS
+ ../tan.h
+ COMPILE_OPTIONS
+ -O2
+)
--- /dev/null
+//===-- Implementation of the cos function for x86_64 ---------------------===//
+//
+// 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/cos.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(double, cos, (double x)) {
+ double result;
+ __asm__ __volatile__("fcos" : "=t"(result) : "f"(x));
+ return result;
+}
+
+} // namespace __llvm_libc
--- /dev/null
+//===-- Implementation of the sin function for x86_64 ---------------------===//
+//
+// 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/sin.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(double, sin, (double x)) {
+ double result;
+ __asm__ __volatile__("fsin" : "=t"(result) : "f"(x));
+ return result;
+}
+
+} // namespace __llvm_libc
--- /dev/null
+//===-- Implementation of the tan function for x86_64 ---------------------===//
+//
+// 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/tan.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(double, tan, (double x)) {
+ double result;
+ double one;
+ // The fptan instruction pushes the number 1 on to the FP stack after
+ // computing tan. So, we read out the one before popping the actual result.
+ __asm__ __volatile__("fptan" : "=t"(one) : "f"(x));
+ __asm__ __volatile__("fstpl %0" : "=m"(result));
+ return result;
+}
+
+} // namespace __llvm_libc
)
add_fp_unittest(
+ cos_test
+ NEED_MPFR
+ SUITE
+ libc_math_unittests
+ SRCS
+ cos_test.cpp
+ DEPENDS
+ libc.src.math.cos
+ libc.utils.FPUtil.fputil
+)
+
+add_fp_unittest(
sinf_test
NEED_MPFR
SUITE
)
add_fp_unittest(
+ sin_test
+ NEED_MPFR
+ SUITE
+ libc_math_unittests
+ SRCS
+ sin_test.cpp
+ DEPENDS
+ libc.src.math.sin
+ libc.utils.FPUtil.fputil
+)
+
+add_fp_unittest(
sincosf_test
NEED_MPFR
SUITE
libc.utils.FPUtil.fputil
)
+add_fp_unittest(
+ tan_test
+ NEED_MPFR
+ SUITE
+ libc_math_unittests
+ SRCS
+ tan_test.cpp
+ DEPENDS
+ libc.src.math.tan
+ libc.utils.FPUtil.fputil
+)
+
add_subdirectory(generic)
add_subdirectory(exhaustive)
add_subdirectory(differential_testing)
--- /dev/null
+//===-- Unittests for cos -------------------------------------------------===//
+//
+// 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/cos.h"
+#include "utils/FPUtil/TestHelpers.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+#include "utils/UnitTest/Test.h"
+
+#include <math.h>
+
+namespace mpfr = __llvm_libc::testing::mpfr;
+
+DECLARE_SPECIAL_CONSTANTS(double)
+
+TEST(LlvmLibccosTest, Range) {
+ static constexpr double _2pi = 6.283185307179586;
+ constexpr UIntType count = 10000000;
+ constexpr UIntType step = UIntType(-1) / count;
+ for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
+ double x = double(FPBits(v));
+ // TODO: Expand the range of testing after range reduction is implemented.
+ if (isnan(x) || isinf(x) || x > _2pi || x < -_2pi)
+ continue;
+
+ ASSERT_MPFR_MATCH(mpfr::Operation::Cos, x, __llvm_libc::cos(x), 1.0);
+ }
+}
--- /dev/null
+//===-- Unittests for sin -------------------------------------------------===//
+//
+// 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/sin.h"
+#include "utils/FPUtil/TestHelpers.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+#include "utils/UnitTest/Test.h"
+
+#include <math.h>
+
+namespace mpfr = __llvm_libc::testing::mpfr;
+
+DECLARE_SPECIAL_CONSTANTS(double)
+
+TEST(LlvmLibcSinTest, Range) {
+ static constexpr double _2pi = 6.283185307179586;
+ constexpr UIntType count = 10000000;
+ constexpr UIntType step = UIntType(-1) / count;
+ for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
+ double x = double(FPBits(v));
+ // TODO: Expand the range of testing after range reduction is implemented.
+ if (isnan(x) || isinf(x) || x > _2pi || x < -_2pi)
+ continue;
+
+ ASSERT_MPFR_MATCH(mpfr::Operation::Sin, x, __llvm_libc::sin(x), 1.0);
+ }
+}
--- /dev/null
+//===-- Unittests for tan -------------------------------------------------===//
+//
+// 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/tan.h"
+#include "utils/FPUtil/TestHelpers.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+#include "utils/UnitTest/Test.h"
+
+#include <math.h>
+
+namespace mpfr = __llvm_libc::testing::mpfr;
+
+DECLARE_SPECIAL_CONSTANTS(double)
+
+TEST(LlvmLibctanTest, Range) {
+ static constexpr double _2pi = 6.283185307179586;
+ constexpr UIntType count = 10000000;
+ constexpr UIntType step = UIntType(-1) / count;
+ for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
+ double x = double(FPBits(v));
+ // TODO: Expand the range of testing after range reduction is implemented.
+ if (isnan(x) || isinf(x) || x > _2pi || x < -_2pi)
+ continue;
+
+ ASSERT_MPFR_MATCH(mpfr::Operation::Tan, x, __llvm_libc::tan(x), 1.0);
+ }
+}
return result;
}
+ MPFRNumber tan() const {
+ MPFRNumber result;
+ mpfr_tan(result.value, value, MPFR_RNDN);
+ return result;
+ }
+
MPFRNumber trunc() const {
MPFRNumber result;
mpfr_trunc(result.value, value);
return mpfrInput.sin();
case Operation::Sqrt:
return mpfrInput.sqrt();
+ case Operation::Tan:
+ return mpfrInput.tan();
case Operation::Trunc:
return mpfrInput.trunc();
default:
Round,
Sin,
Sqrt,
+ Tan,
Trunc,
EndUnaryOperationsSingleOutput,