From 9a579d62e855bb013858d433ddd089a43245bce2 Mon Sep 17 00:00:00 2001 From: Siva Chandra Reddy Date: Wed, 19 Apr 2023 23:11:10 +0000 Subject: [PATCH] [libc][math] Remove the unused dp_trig target and tests. --- libc/src/math/generic/CMakeLists.txt | 15 ---- libc/src/math/generic/dp_trig.cpp | 105 --------------------------- libc/src/math/generic/dp_trig.h | 22 ------ libc/test/src/math/CMakeLists.txt | 12 --- libc/test/src/math/mod_k_pi_test.cpp | 56 -------------- 5 files changed, 210 deletions(-) delete mode 100644 libc/src/math/generic/dp_trig.cpp delete mode 100644 libc/src/math/generic/dp_trig.h delete mode 100644 libc/test/src/math/mod_k_pi_test.cpp diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index 9fe0fce1c8a67..ac48e9cef7a38 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -1205,21 +1205,6 @@ add_entrypoint_object( -O2 ) -add_object_library( - dp_trig - SRCS - dp_trig.cpp - HDRS - dp_trig.h - DEPENDS - libc.src.__support.FPUtil.fp_bits - libc.src.__support.FPUtil.manipulation_functions - libc.src.__support.FPUtil.xfloat - libc.src.__support.uint - COMPILE_OPTIONS - -O3 -) - add_entrypoint_object( fmod SRCS diff --git a/libc/src/math/generic/dp_trig.cpp b/libc/src/math/generic/dp_trig.cpp deleted file mode 100644 index 3fa9d4a0ca0fe..0000000000000 --- a/libc/src/math/generic/dp_trig.cpp +++ /dev/null @@ -1,105 +0,0 @@ -//===-- Utilities for double precision trigonometric functions ------------===// -// -// 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/FPUtil/FPBits.h" -#include "src/__support/FPUtil/ManipulationFunctions.h" -#include "src/__support/FPUtil/UInt.h" -#include "src/__support/FPUtil/XFloat.h" - -using FPBits = __llvm_libc::fputil::FPBits; - -namespace __llvm_libc { - -// Implementation is based on the Payne and Hanek range reduction algorithm. -// The caller should ensure that x is positive. -// Consider: -// x/y = x * 1/y = I + F -// I is the integral part and F the fractional part of the result of the -// division operation. Then M = mod(x, y) = F * y. In order to compute M, we -// first compute F. We do it by dropping bits from 1/y which would only -// contribute integral results in the operation x * 1/y. This helps us get -// accurate values of F even when x is a very large number. -// -// Internal operations are performed at 192 bits of precision. -static double mod_impl(double x, const uint64_t y_bits[3], - const uint64_t inv_y_bits[20], int y_exponent, - int inv_y_exponent) { - FPBits bits(x); - int exponent = bits.get_exponent(); - int bit_drop = (exponent - 52) + inv_y_exponent + 1; - bit_drop = bit_drop >= 0 ? bit_drop : 0; - int word_drop = bit_drop / 64; - bit_drop %= 64; - fputil::UInt<256> man4; - for (size_t i = 0; i < 4; ++i) { - man4[3 - i] = inv_y_bits[word_drop + i]; - } - man4.shift_left(bit_drop); - fputil::UInt<192> man_bits; - for (size_t i = 0; i < 3; ++i) - man_bits[i] = man4[i + 1]; - fputil::XFloat<192> result(inv_y_exponent - word_drop * 64 - bit_drop, - man_bits); - result.mul(x); - result.drop_int(); // |result| now holds fractional part of x/y. - - fputil::UInt<192> y_man; - for (size_t i = 0; i < 3; ++i) - y_man[i] = y_bits[2 - i]; - fputil::XFloat<192> y_192(y_exponent, y_man); - return result.mul(y_192); -} - -static constexpr int TwoPIExponent = 2; - -// The mantissa bits of 2 * PI. -// The most signification bits are in the first uint64_t word -// and the least signification bits are in the last word. The -// first word includes the implicit '1' bit. -static constexpr uint64_t TwoPI[] = {0xc90fdaa22168c234, 0xc4c6628b80dc1cd1, - 0x29024e088a67cc74}; - -static constexpr int InvTwoPIExponent = -3; - -// The mantissa bits of 1/(2 * PI). -// The most signification bits are in the first uint64_t word -// and the least signification bits are in the last word. The -// first word includes the implicit '1' bit. -static constexpr uint64_t InvTwoPI[] = { - 0xa2f9836e4e441529, 0xfc2757d1f534ddc0, 0xdb6295993c439041, - 0xfe5163abdebbc561, 0xb7246e3a424dd2e0, 0x6492eea09d1921c, - 0xfe1deb1cb129a73e, 0xe88235f52ebb4484, 0xe99c7026b45f7e41, - 0x3991d639835339f4, 0x9c845f8bbdf9283b, 0x1ff897ffde05980f, - 0xef2f118b5a0a6d1f, 0x6d367ecf27cb09b7, 0x4f463f669e5fea2d, - 0x7527bac7ebe5f17b, 0x3d0739f78a5292ea, 0x6bfb5fb11f8d5d08, - 0x56033046fc7b6bab, 0xf0cfbc209af4361e}; - -double mod_2pi(double x) { - static constexpr double _2pi = 6.283185307179586; - if (x < _2pi) - return x; - return mod_impl(x, TwoPI, InvTwoPI, TwoPIExponent, InvTwoPIExponent); -} - -// Returns mod(x, pi/2) -double mod_pi_over_2(double x) { - static constexpr double pi_over_2 = 1.5707963267948966; - if (x < pi_over_2) - return x; - return mod_impl(x, TwoPI, InvTwoPI, TwoPIExponent - 2, InvTwoPIExponent + 2); -} - -// Returns mod(x, pi/4) -double mod_pi_over_4(double x) { - static constexpr double pi_over_4 = 0.7853981633974483; - if (x < pi_over_4) - return x; - return mod_impl(x, TwoPI, InvTwoPI, TwoPIExponent - 3, InvTwoPIExponent + 3); -} - -} // namespace __llvm_libc diff --git a/libc/src/math/generic/dp_trig.h b/libc/src/math/generic/dp_trig.h deleted file mode 100644 index a724da04c1717..0000000000000 --- a/libc/src/math/generic/dp_trig.h +++ /dev/null @@ -1,22 +0,0 @@ -//===-- Utilities for double precision trigonometric functions --*- 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_GENERIC_DP_TRIG_H -#define LLVM_LIBC_SRC_MATH_GENERIC_DP_TRIG_H - -namespace __llvm_libc { - -double mod_2pi(double); - -double mod_pi_over_2(double); - -double mod_pi_over_4(double); - -} // namespace __llvm_libc - -#endif // LLVM_LIBC_SRC_MATH_GENERIC_DP_TRIG_H diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt index c4b883a2f988c..c8fa74da00440 100644 --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -1267,18 +1267,6 @@ add_fp_unittest( libc.src.__support.FPUtil.fp_bits ) -add_fp_unittest( - mod_k_pi_test - NEED_MPFR - SUITE - libc-long-running-tests - SRCS - mod_k_pi_test.cpp - DEPENDS - libc.src.math.generic.dp_trig - libc.src.__support.FPUtil.fp_bits -) - add_fp_unittest( logf_test NEED_MPFR diff --git a/libc/test/src/math/mod_k_pi_test.cpp b/libc/test/src/math/mod_k_pi_test.cpp deleted file mode 100644 index ef34027f83b80..0000000000000 --- a/libc/test/src/math/mod_k_pi_test.cpp +++ /dev/null @@ -1,56 +0,0 @@ -//===-- Unittests mod_2pi, mod_pi_over_4 and mod_pi_over_2 ----------------===// -// -// 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/generic/dp_trig.h" -#include "test/UnitTest/FPMatcher.h" -#include "test/UnitTest/Test.h" -#include "utils/MPFRWrapper/MPFRUtils.h" - -#include - -namespace mpfr = __llvm_libc::testing::mpfr; -using FPBits = __llvm_libc::fputil::FPBits; -using UIntType = FPBits::UIntType; - -TEST(LlvmLibcMod2PITest, Range) { - constexpr UIntType count = 1000000000; - constexpr UIntType step = UIntType(-1) / count; - for (UIntType i = 0, v = 0; i <= count; ++i, v += step) { - double x = double(FPBits(v)); - if (isnan(x) || isinf(x) || x <= 0.0) - continue; - - ASSERT_MPFR_MATCH(mpfr::Operation::Mod2PI, x, __llvm_libc::mod_2pi(x), 0); - } -} - -TEST(LlvmLibcModPIOver2Test, Range) { - constexpr UIntType count = 1000000000; - constexpr UIntType step = UIntType(-1) / count; - for (UIntType i = 0, v = 0; i <= count; ++i, v += step) { - double x = double(FPBits(v)); - if (isnan(x) || isinf(x) || x <= 0.0) - continue; - - ASSERT_MPFR_MATCH(mpfr::Operation::ModPIOver2, x, - __llvm_libc::mod_pi_over_2(x), 0); - } -} - -TEST(LlvmLibcModPIOver4Test, Range) { - constexpr UIntType count = 1000000000; - constexpr UIntType step = UIntType(-1) / count; - for (UIntType i = 0, v = 0; i <= count; ++i, v += step) { - double x = double(FPBits(v)); - if (isnan(x) || isinf(x) || x <= 0.0) - continue; - - ASSERT_MPFR_MATCH(mpfr::Operation::ModPIOver4, x, - __llvm_libc::mod_pi_over_4(x), 0); - } -}