Skip to content

[libc][complex] Testing infra for MPC #121261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 67 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
d37cba9
header file for mpc
Sh0g0-1758 Dec 27, 2024
46b6d8e
mpc testing infra init
Sh0g0-1758 Dec 27, 2024
b6157ef
add separate rounding mode for real and imaginary
Sh0g0-1758 Dec 27, 2024
7dedaa6
fmt
Sh0g0-1758 Dec 27, 2024
a22292b
added MPCNumber
Sh0g0-1758 Dec 27, 2024
f06817f
fmt
Sh0g0-1758 Dec 27, 2024
09c6880
more fmt
Sh0g0-1758 Dec 27, 2024
fd7ccfc
cmake for MPCWrapper
Sh0g0-1758 Dec 28, 2024
c8956f6
init
Sh0g0-1758 Dec 28, 2024
5a1594c
Merge branch 'carg' into mpc_testing_infra
Sh0g0-1758 Dec 28, 2024
9ce03e9
fixed a couple bugs
Sh0g0-1758 Dec 28, 2024
d939e5c
fmt
Sh0g0-1758 Dec 28, 2024
da739e4
Implement a basic MPC test
Sh0g0-1758 Dec 28, 2024
5d8bc06
fmt
Sh0g0-1758 Dec 28, 2024
7a2df72
nit
Sh0g0-1758 Dec 28, 2024
8b6d3c5
Merge branch 'main' into mpc_testing_infra
Sh0g0-1758 Dec 28, 2024
b711cf5
bug fix
Sh0g0-1758 Dec 28, 2024
6089ad6
give useful error message
Sh0g0-1758 Dec 30, 2024
9e65cd0
fmt
Sh0g0-1758 Dec 30, 2024
659abcd
fix: only one rounding mode
Sh0g0-1758 Jan 8, 2025
5cd8c63
fmt
Sh0g0-1758 Jan 8, 2025
3284f80
remove mpfr functions and add cmake module for mpc
Sh0g0-1758 Jan 8, 2025
66500f3
MPC fmt
Sh0g0-1758 Jan 8, 2025
9dac333
add custom cmake function to skip mpc tests when in full build mode
Sh0g0-1758 Jan 8, 2025
a497f18
remove cargf and add cproj for verification
Sh0g0-1758 Jan 8, 2025
e65fe59
free mpc
Sh0g0-1758 Jan 8, 2025
17663c6
MPC fmt
Sh0g0-1758 Jan 8, 2025
f80dff3
fix: only check for mpc if mpfr is present
Sh0g0-1758 Jan 8, 2025
e56a349
Expose a single rounding mode
Sh0g0-1758 Jan 8, 2025
3de816a
MPC fmt
Sh0g0-1758 Jan 8, 2025
a04923e
move project and conjugate to complex_basic_ops
Sh0g0-1758 Jan 8, 2025
14bb02e
use complex_type in MPCWrapper
Sh0g0-1758 Jan 8, 2025
2d7b90b
fmt
Sh0g0-1758 Jan 8, 2025
cf88bba
nit
Sh0g0-1758 Jan 10, 2025
2ab8f32
nit
Sh0g0-1758 Jan 10, 2025
5ef5975
nit
Sh0g0-1758 Jan 10, 2025
eb44508
nit
Sh0g0-1758 Jan 10, 2025
ab3c5bf
nit
Sh0g0-1758 Jan 10, 2025
16a615c
nit
Sh0g0-1758 Jan 10, 2025
81226da
generalize add_fp_unittest
Sh0g0-1758 Jan 10, 2025
363e238
nit
Sh0g0-1758 Jan 10, 2025
b482b4b
nit
Sh0g0-1758 Jan 10, 2025
a9a12a3
fmt
Sh0g0-1758 Jan 10, 2025
6c5620a
nit
Sh0g0-1758 Jan 11, 2025
37e5681
fmt
Sh0g0-1758 Jan 11, 2025
6565b14
bug fix
Sh0g0-1758 Jan 11, 2025
af06fd9
separate the definitions and declarations needed for mpc
Sh0g0-1758 Jan 12, 2025
d593619
fmt
Sh0g0-1758 Jan 12, 2025
2ed5fc3
move extra precision to header
Sh0g0-1758 Jan 12, 2025
ea7203c
fmt
Sh0g0-1758 Jan 12, 2025
78c7f28
nit
Sh0g0-1758 Jan 12, 2025
5ea22aa
2 linker errors resolved
Sh0g0-1758 Jan 12, 2025
7f72499
fmt
Sh0g0-1758 Jan 12, 2025
7c95bb0
moved extraprecision
Sh0g0-1758 Jan 12, 2025
cfaea9d
Revert "moved extraprecision"
Sh0g0-1758 Jan 12, 2025
0e58f6e
solved all linker error
Sh0g0-1758 Jan 12, 2025
590379e
clean up
Sh0g0-1758 Jan 12, 2025
a7d540d
simplify target libraries
Sh0g0-1758 Jan 12, 2025
e51e8b8
fix full build
Sh0g0-1758 Jan 12, 2025
7f6c9d3
clang-fmt
Sh0g0-1758 Jan 12, 2025
ee25c97
simplify deps
Sh0g0-1758 Jan 12, 2025
f3c3898
fix overlay build
Sh0g0-1758 Jan 12, 2025
d1d9e70
simplify dependencies
Sh0g0-1758 Jan 12, 2025
48a44f1
fmt
Sh0g0-1758 Jan 12, 2025
e82fe51
nit
Sh0g0-1758 Jan 13, 2025
420d3bc
a couple fixes
Sh0g0-1758 Jan 23, 2025
fbae743
fmt
Sh0g0-1758 Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ if(LIBC_TARGET_OS_IS_GPU)
endif()

include(LLVMLibCCheckMPFR)
include(LLVMLibCCheckMPC)

if(LLVM_LIBC_CLANG_TIDY)
set(LLVM_LIBC_ENABLE_LINTING ON)
Expand Down
22 changes: 22 additions & 0 deletions libc/cmake/modules/LLVMLibCCheckMPC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
if(LIBC_TESTS_CAN_USE_MPFR)
set(LLVM_LIBC_MPC_INSTALL_PATH "" CACHE PATH "Path to where MPC is installed (e.g. C:/src/install or ~/src/install)")

if(LLVM_LIBC_MPC_INSTALL_PATH)
set(LIBC_TESTS_CAN_USE_MPC TRUE)
elseif(LIBC_TARGET_OS_IS_GPU OR LLVM_LIBC_FULL_BUILD)
# In full build mode, the MPC library should be built using our own facilities,
# which is currently not possible.
set(LIBC_TESTS_CAN_USE_MPC FALSE)
else()
try_compile(
LIBC_TESTS_CAN_USE_MPC
${CMAKE_CURRENT_BINARY_DIR}
SOURCES
${LIBC_SOURCE_DIR}/utils/MPCWrapper/check_mpc.cpp
COMPILE_DEFINITIONS
${LIBC_COMPILE_OPTIONS_DEFAULT}
LINK_LIBRARIES
-lmpc -lmpfr -lgmp -latomic
)
endif()
endif()
12 changes: 10 additions & 2 deletions libc/src/__support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,20 @@ add_header_library(
HDRS
complex_type.h
DEPENDS
libc.src.__support.CPP.bit
libc.src.__support.FPUtil.fp_bits
libc.src.__support.macros.properties.types
libc.src.__support.macros.properties.complex_types
)

add_header_library(
complex_basic_ops
HDRS
complex_basic_ops.h
DEPENDS
.complex_type
libc.src.__support.CPP.bit
libc.src.__support.FPUtil.fp_bits
)

add_header_library(
integer_operations
HDRS
Expand Down
1 change: 1 addition & 0 deletions libc/src/__support/CPP/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "src/__support/CPP/type_traits/is_array.h"
#include "src/__support/CPP/type_traits/is_base_of.h"
#include "src/__support/CPP/type_traits/is_class.h"
#include "src/__support/CPP/type_traits/is_complex.h"
#include "src/__support/CPP/type_traits/is_const.h"
#include "src/__support/CPP/type_traits/is_constant_evaluated.h"
#include "src/__support/CPP/type_traits/is_convertible.h"
Expand Down
36 changes: 36 additions & 0 deletions libc/src/__support/complex_basic_ops.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===-- complex basic operations --------------------------------*- 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___SUPPORT_COMPLEX_BASIC_OPERATIONS_H
#define LLVM_LIBC_SRC___SUPPORT_COMPLEX_BASIC_OPERATIONS_H

#include "complex_type.h"
#include "src/__support/CPP/bit.h"
#include "src/__support/FPUtil/FPBits.h"

namespace LIBC_NAMESPACE_DECL {

template <typename T> LIBC_INLINE constexpr T conjugate(T c) {
Complex<make_real_t<T>> c_c = cpp::bit_cast<Complex<make_real_t<T>>>(c);
c_c.imag = -c_c.imag;
return cpp::bit_cast<T>(c_c);
}

template <typename T> LIBC_INLINE constexpr T project(T c) {
using real_t = make_real_t<T>;
Complex<real_t> c_c = cpp::bit_cast<Complex<real_t>>(c);
if (fputil::FPBits<real_t>(c_c.real).is_inf() ||
fputil::FPBits<real_t>(c_c.imag).is_inf())
return cpp::bit_cast<T>(
Complex<real_t>{(fputil::FPBits<real_t>::inf(Sign::POS).get_val()),
static_cast<real_t>(c_c.imag > 0 ? 0.0 : -0.0)});
return c;
}

} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_COMPLEX_BASIC_OPERATIONS_H
21 changes: 0 additions & 21 deletions libc/src/__support/complex_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_COMPLEX_TYPE_H
#define LLVM_LIBC_SRC___SUPPORT_COMPLEX_TYPE_H

#include "src/__support/CPP/bit.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/complex_types.h"
#include "src/__support/macros/properties/types.h"
Expand Down Expand Up @@ -71,24 +69,5 @@ template <> struct make_real<cfloat128> {

template <typename T> using make_real_t = typename make_real<T>::type;

template <typename T> LIBC_INLINE constexpr T conjugate(T c) {
Complex<make_real_t<T>> c_c = cpp::bit_cast<Complex<make_real_t<T>>>(c);
c_c.imag = -c_c.imag;
return cpp::bit_cast<T>(c_c);
}

template <typename T> LIBC_INLINE constexpr T project(T c) {
using real_t = make_real_t<T>;
Complex<real_t> c_c = cpp::bit_cast<Complex<real_t>>(c);
if (fputil::FPBits<real_t>(c_c.real).is_inf() ||
fputil::FPBits<real_t>(c_c.imag).is_inf()) {
return cpp::bit_cast<T>(
Complex<real_t>{(fputil::FPBits<real_t>::inf(Sign::POS).get_val()),
static_cast<real_t>(c_c.imag > 0 ? 0.0 : -0.0)});
} else {
return c;
}
}

} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_COMPLEX_TYPE_H
20 changes: 10 additions & 10 deletions libc/src/complex/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_entrypoint_object(
COMPILE_OPTIONS
${libc_opt_high_flag}
DEPENDS
libc.src.__support.complex_type
libc.src.__support.complex_basic_ops
)

add_entrypoint_object(
Expand All @@ -19,7 +19,7 @@ add_entrypoint_object(
COMPILE_OPTIONS
${libc_opt_high_flag}
DEPENDS
libc.src.__support.complex_type
libc.src.__support.complex_basic_ops
)

add_entrypoint_object(
Expand All @@ -31,7 +31,7 @@ add_entrypoint_object(
COMPILE_OPTIONS
${libc_opt_high_flag}
DEPENDS
libc.src.__support.complex_type
libc.src.__support.complex_basic_ops
)

add_entrypoint_object(
Expand All @@ -43,7 +43,7 @@ add_entrypoint_object(
COMPILE_OPTIONS
${libc_opt_high_flag}
DEPENDS
libc.src.__support.complex_type
libc.src.__support.complex_basic_ops
libc.src.__support.macros.properties.types
libc.src.__support.macros.properties.complex_types
)
Expand All @@ -57,7 +57,7 @@ add_entrypoint_object(
COMPILE_OPTIONS
${libc_opt_high_flag}
DEPENDS
libc.src.__support.complex_type
libc.src.__support.complex_basic_ops
libc.src.__support.macros.properties.types
libc.src.__support.macros.properties.complex_types
)
Expand All @@ -71,7 +71,7 @@ add_entrypoint_object(
COMPILE_OPTIONS
${libc_opt_high_flag}
DEPENDS
libc.src.__support.complex_type
libc.src.__support.complex_basic_ops
)

add_entrypoint_object(
Expand All @@ -83,7 +83,7 @@ add_entrypoint_object(
COMPILE_OPTIONS
${libc_opt_high_flag}
DEPENDS
libc.src.__support.complex_type
libc.src.__support.complex_basic_ops
)

add_entrypoint_object(
Expand All @@ -95,7 +95,7 @@ add_entrypoint_object(
COMPILE_OPTIONS
${libc_opt_high_flag}
DEPENDS
libc.src.__support.complex_type
libc.src.__support.complex_basic_ops
)

add_entrypoint_object(
Expand All @@ -107,7 +107,7 @@ add_entrypoint_object(
COMPILE_OPTIONS
${libc_opt_high_flag}
DEPENDS
libc.src.__support.complex_type
libc.src.__support.complex_basic_ops
libc.src.__support.macros.properties.types
libc.src.__support.macros.properties.complex_types
)
Expand All @@ -121,7 +121,7 @@ add_entrypoint_object(
COMPILE_OPTIONS
${libc_opt_high_flag}
DEPENDS
libc.src.__support.complex_type
libc.src.__support.complex_basic_ops
libc.src.__support.macros.properties.types
libc.src.__support.macros.properties.complex_types
)
Expand Down
2 changes: 1 addition & 1 deletion libc/src/complex/generic/conj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "src/complex/conj.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"
#include "src/__support/complex_basic_ops.h"

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/complex/generic/conjf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "src/complex/conjf.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"
#include "src/__support/complex_basic_ops.h"

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/complex/generic/conjf128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "src/complex/conjf128.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"
#include "src/__support/complex_basic_ops.h"

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/complex/generic/conjf16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "src/complex/conjf16.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"
#include "src/__support/complex_basic_ops.h"

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/complex/generic/conjl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "src/complex/conjl.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"
#include "src/__support/complex_basic_ops.h"

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/complex/generic/cproj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "src/complex/cproj.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"
#include "src/__support/complex_basic_ops.h"

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/complex/generic/cprojf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "src/complex/cprojf.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"
#include "src/__support/complex_basic_ops.h"

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/complex/generic/cprojf128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "src/complex/cprojf128.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"
#include "src/__support/complex_basic_ops.h"

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/complex/generic/cprojf16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "src/complex/cprojf16.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"
#include "src/__support/complex_basic_ops.h"

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/complex/generic/cprojl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "src/complex/cprojl.h"
#include "src/__support/common.h"
#include "src/__support/complex_type.h"
#include "src/__support/complex_basic_ops.h"

namespace LIBC_NAMESPACE_DECL {

Expand Down
1 change: 0 additions & 1 deletion libc/test/UnitTest/FPMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "src/__support/CPP/array.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/CPP/type_traits/is_complex.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/fpbits_str.h"
Expand Down
11 changes: 10 additions & 1 deletion libc/test/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
function(add_fp_unittest name)
cmake_parse_arguments(
"MATH_UNITTEST"
"NEED_MPFR;UNIT_TEST_ONLY;HERMETIC_TEST_ONLY" # Optional arguments
"NEED_MPFR;NEED_MPC;UNIT_TEST_ONLY;HERMETIC_TEST_ONLY" # Optional arguments
"" # Single value arguments
"LINK_LIBRARIES;DEPENDS" # Multi-value arguments
${ARGN}
)

if(MATH_UNITTEST_NEED_MPC)
set(MATH_UNITTEST_NEED_MPFR TRUE)
if(NOT LIBC_TESTS_CAN_USE_MPC)
message(VERBOSE "Complex test ${name} will be skipped as MPC library is not available.")
return()
endif()
list(APPEND MATH_UNITTEST_LINK_LIBRARIES libcMPCWrapper)
endif()

if(MATH_UNITTEST_NEED_MPFR)
if(NOT LIBC_TESTS_CAN_USE_MPFR)
message(VERBOSE "Math test ${name} will be skipped as MPFR library is not available.")
Expand Down
Loading
Loading