Skip to content

Commit

Permalink
[libc][bazel] Add BUILD targets for complex functions and tests. (#12…
Browse files Browse the repository at this point in the history
…9618)

This involved a little bit of yak shaving because one of the new tests
depends on MPC, and we didn't have targets for it yet, so I ended up
needing to add a similar setup to what we have for MPFR.
  • Loading branch information
slackito authored Mar 4, 2025
1 parent 6f25614 commit f9a6ea4
Show file tree
Hide file tree
Showing 8 changed files with 506 additions and 2 deletions.
1 change: 1 addition & 0 deletions libc/utils/MPCWrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ if(LIBC_TESTS_CAN_USE_MPC)
add_library(libcMPCWrapper STATIC
MPCUtils.cpp
MPCUtils.h
mpc_inc.h
)
_get_common_test_compile_options(compile_options "" "")
list(REMOVE_ITEM compile_options "-ffreestanding")
Expand Down
3 changes: 1 addition & 2 deletions libc/utils/MPCWrapper/MPCUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@

#include "src/__support/CPP/array.h"
#include "src/__support/CPP/stringstream.h"
#include "utils/MPCWrapper/mpc_inc.h"
#include "utils/MPFRWrapper/MPCommon.h"

#include <stdint.h>

#include "mpc.h"

template <typename T> using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>;

namespace LIBC_NAMESPACE_DECL {
Expand Down
23 changes: 23 additions & 0 deletions libc/utils/MPCWrapper/mpc_inc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- MPCUtils.h ----------------------------------------------*- 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_UTILS_MPCWRAPPER_MPC_INC_H
#define LLVM_LIBC_UTILS_MPCWRAPPER_MPC_INC_H

#ifdef CUSTOM_MPC_INCLUDER
// Some downstream repos are monoliths carrying MPC sources in their third
// party directory. In such repos, including the MPC header as
// `#include <mpc.h>` is either disallowed or not possible. If that is the
// case, a file named `CustomMPCIncluder.h` should be added through which the
// MPC header can be included in manner allowed in that repo.
#include "CustomMPCIncluder.h"
#else
#include <mpc.h>
#endif

#endif // LLVM_LIBC_UTILS_MPCWRAPPER_MPC_INC_H
9 changes: 9 additions & 0 deletions utils/bazel/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ maybe(
urls = ["https://www.mpfr.org/mpfr-4.1.1/mpfr-4.1.1.tar.gz"],
)

maybe(
http_archive,
name = "mpc",
build_file = "@llvm-raw//utils/bazel/third_party_build:mpc.BUILD",
sha256 = "ab642492f5cf882b74aa0cb730cd410a81edcdbec895183ce930e706c1c759b8",
strip_prefix = "mpc-1.3.1",
urls = ["https://ftp.gnu.org/gnu/mpc/mpc-1.3.1.tar.gz"],
)

maybe(
http_archive,
name = "pfm",
Expand Down
291 changes: 291 additions & 0 deletions utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,34 @@ config_setting(
flag_values = {":mpfr": "system"},
)

# A flag to pick which `mpc` to use for math tests.
# Usage: `--@llvm-project//libc:mpc=<disable|external|system>`.
# Flag documentation: https://bazel.build/extending/config
string_flag(
name = "mpc",
build_setting_default = "external",
values = [
"disable", # Skip tests that need mpc
"external", # Build mpc from source
"system", # Use system mpc (non hermetic)
],
)

config_setting(
name = "mpc_disable",
flag_values = {":mpc": "disable"},
)

config_setting(
name = "mpc_external",
flag_values = {":mpc": "external"},
)

config_setting(
name = "mpc_system",
flag_values = {":mpc": "system"},
)

########################### Header Generation ##################################

py_binary(
Expand Down Expand Up @@ -865,6 +893,26 @@ libc_support_library(
],
)

libc_support_library(
name = "__support_complex_type",
hdrs = ["src/__support/complex_type.h"],
deps = [
":__support_macros_config",
":__support_macros_properties_complex_types",
":__support_macros_properties_types",
],
)

libc_support_library(
name = "__support_complex_basic_ops",
hdrs = ["src/__support/complex_basic_ops.h"],
deps = [
":__support_complex_type",
":__support_cpp_bit",
":__support_fputil_fp_bits",
],
)

libc_support_library(
name = "__support_fputil_basic_operations",
hdrs = [
Expand Down Expand Up @@ -1890,6 +1938,249 @@ libc_support_library(
],
)

############################### complex targets ################################

libc_function(
name = "cimag",
srcs = ["src/complex/generic/cimag.cpp"],
hdrs = ["src/complex/cimag.h"],
deps = [
":__support_common",
":__support_complex_type",
":__support_cpp_bit",
":__support_macros_config",
],
)

libc_function(
name = "cimagf",
srcs = ["src/complex/generic/cimagf.cpp"],
hdrs = ["src/complex/cimagf.h"],
deps = [
":__support_common",
":__support_complex_type",
":__support_cpp_bit",
":__support_macros_config",
],
)

libc_function(
name = "cimagf128",
srcs = ["src/complex/generic/cimagf128.cpp"],
hdrs = ["src/complex/cimagf128.h"],
deps = [
":__support_common",
":__support_complex_type",
":__support_cpp_bit",
":__support_macros_config",
":__support_macros_properties_complex_types",
":__support_macros_properties_types",
],
)

libc_function(
name = "cimagf16",
srcs = ["src/complex/generic/cimagf16.cpp"],
hdrs = ["src/complex/cimagf16.h"],
deps = [
":__support_common",
":__support_complex_type",
":__support_cpp_bit",
":__support_macros_config",
":__support_macros_properties_complex_types",
":__support_macros_properties_types",
],
)

libc_function(
name = "cimagl",
srcs = ["src/complex/generic/cimagl.cpp"],
hdrs = ["src/complex/cimagl.h"],
deps = [
":__support_common",
":__support_complex_type",
":__support_cpp_bit",
":__support_macros_config",
],
)

libc_function(
name = "conj",
srcs = ["src/complex/generic/conj.cpp"],
hdrs = ["src/complex/conj.h"],
deps = [
":__support_common",
":__support_complex_basic_ops",
":__support_macros_config",
],
)

libc_function(
name = "conjf",
srcs = ["src/complex/generic/conjf.cpp"],
hdrs = ["src/complex/conjf.h"],
deps = [
":__support_common",
":__support_complex_basic_ops",
":__support_macros_config",
],
)

libc_function(
name = "conjf128",
srcs = ["src/complex/generic/conjf128.cpp"],
hdrs = ["src/complex/conjf128.h"],
deps = [
":__support_common",
":__support_complex_basic_ops",
":__support_macros_config",
":__support_macros_properties_complex_types",
],
)

libc_function(
name = "conjf16",
srcs = ["src/complex/generic/conjf16.cpp"],
hdrs = ["src/complex/conjf16.h"],
deps = [
":__support_common",
":__support_complex_basic_ops",
":__support_cpp_bit",
":__support_macros_config",
":__support_macros_properties_complex_types",
],
)

libc_function(
name = "conjl",
srcs = ["src/complex/generic/conjl.cpp"],
hdrs = ["src/complex/conjl.h"],
deps = [
":__support_common",
":__support_complex_basic_ops",
":__support_macros_config",
],
)

libc_function(
name = "cproj",
srcs = ["src/complex/generic/cproj.cpp"],
hdrs = ["src/complex/cproj.h"],
deps = [
":__support_common",
":__support_complex_basic_ops",
":__support_macros_config",
],
)

libc_function(
name = "cprojf",
srcs = ["src/complex/generic/cprojf.cpp"],
hdrs = ["src/complex/cprojf.h"],
deps = [
":__support_common",
":__support_complex_basic_ops",
":__support_macros_config",
],
)

libc_function(
name = "cprojf128",
srcs = ["src/complex/generic/cprojf128.cpp"],
hdrs = ["src/complex/cprojf128.h"],
deps = [
":__support_common",
":__support_complex_basic_ops",
":__support_macros_config",
":__support_macros_properties_complex_types",
],
)

libc_function(
name = "cprojf16",
srcs = ["src/complex/generic/cprojf16.cpp"],
hdrs = ["src/complex/cprojf16.h"],
deps = [
":__support_common",
":__support_complex_basic_ops",
":__support_macros_config",
":__support_macros_properties_complex_types",
],
)

libc_function(
name = "cprojl",
srcs = ["src/complex/generic/cprojl.cpp"],
hdrs = ["src/complex/cprojl.h"],
deps = [
":__support_common",
":__support_complex_basic_ops",
":__support_macros_config",
],
)

libc_function(
name = "creal",
srcs = ["src/complex/generic/creal.cpp"],
hdrs = ["src/complex/creal.h"],
deps = [
":__support_common",
":__support_complex_type",
":__support_cpp_bit",
":__support_macros_config",
],
)

libc_function(
name = "crealf",
srcs = ["src/complex/generic/crealf.cpp"],
hdrs = ["src/complex/crealf.h"],
deps = [
":__support_common",
":__support_complex_type",
":__support_cpp_bit",
":__support_macros_config",
],
)

libc_function(
name = "crealf128",
srcs = ["src/complex/generic/crealf128.cpp"],
hdrs = ["src/complex/crealf128.h"],
deps = [
":__support_common",
":__support_complex_type",
":__support_cpp_bit",
":__support_macros_config",
":__support_macros_properties_complex_types",
],
)

libc_function(
name = "crealf16",
srcs = ["src/complex/generic/crealf16.cpp"],
hdrs = ["src/complex/crealf16.h"],
deps = [
":__support_common",
":__support_complex_type",
":__support_cpp_bit",
":__support_macros_config",
":__support_macros_properties_complex_types",
],
)

libc_function(
name = "creall",
srcs = ["src/complex/generic/creall.cpp"],
hdrs = ["src/complex/creall.h"],
deps = [
":__support_common",
":__support_complex_type",
":__support_cpp_bit",
":__support_macros_config",
],
)

################################ math targets ##################################

libc_math_function(
Expand Down
Loading

0 comments on commit f9a6ea4

Please sign in to comment.