Skip to content

[libc][bazel] Add targets for stdbit functions #128934

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 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
58 changes: 58 additions & 0 deletions utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3356,6 +3356,64 @@ libc_function(
],
)

############################### stdbit targets ###############################

bit_suffix_list = [
"uc",
"us",
"ui",
"ul",
"ull",
]

bit_prefix_list = [
"stdc_leading_zeros_",
"stdc_leading_ones_",
"stdc_trailing_zeros_",
"stdc_trailing_ones_",
"stdc_count_ones_",
"stdc_has_single_bit_",
"stdc_bit_width_",
"stdc_bit_floor_",
"stdc_bit_ceil_",
]

bit_prefix_needs_math_list = [
"stdc_first_leading_zero_",
"stdc_first_leading_one_",
"stdc_first_trailing_zero_",
"stdc_first_trailing_one_",
"stdc_count_zeros_",
]

[
libc_function(
name = bit_prefix + bit_suffix,
srcs = ["src/stdbit/" + bit_prefix + bit_suffix + ".cpp"],
hdrs = ["src/stdbit/" + bit_prefix + bit_suffix + ".h"],
deps = [
":__support_common",
":__support_cpp_bit",
],
)
for bit_prefix in bit_prefix_list
for bit_suffix in bit_suffix_list
]

[
libc_function(
name = bit_prefix + bit_suffix,
srcs = ["src/stdbit/" + bit_prefix + bit_suffix + ".cpp"],
hdrs = ["src/stdbit/" + bit_prefix + bit_suffix + ".h"],
deps = [
":__support_common",
":__support_math_extras",
],
)
for bit_prefix in bit_prefix_needs_math_list
for bit_suffix in bit_suffix_list
]

############################### stdlib targets ###############################

libc_function(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def libc_math_function(

Args:
name: The name of the function.
additional_deps: Other deps like helper cc_library targes used by the
additional_deps: Other deps like helper cc_library targets used by the
math function.
"""
additional_deps = additional_deps or []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This file is licensed 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

# Tests for LLVM libc stdbit.h functions.

load("//libc/test:libc_test_rules.bzl", "libc_test")

package(default_visibility = ["//visibility:public"])

licenses(["notice"])

bit_suffix_list = [
"uc",
"us",
"ui",
"ul",
"ull",
]

bit_prefix_list = [
"stdc_leading_zeros_",
"stdc_leading_ones_",
"stdc_trailing_zeros_",
"stdc_trailing_ones_",
"stdc_count_ones_",
"stdc_has_single_bit_",
"stdc_bit_width_",
"stdc_bit_floor_",
"stdc_bit_ceil_",
"stdc_first_leading_zero_",
"stdc_first_leading_one_",
"stdc_first_trailing_zero_",
"stdc_first_trailing_one_",
"stdc_count_zeros_",
]

[
libc_test(
name = bit_prefix + bit_suffix + "_test",
srcs = [bit_prefix + bit_suffix + "_test.cpp"],
libc_function_deps = ["//libc:" + bit_prefix + bit_suffix],
deps = ["//libc:__support_cpp_limits"],
)
for bit_prefix in bit_prefix_list
for bit_suffix in bit_suffix_list
]