Skip to content

Commit 579ead1

Browse files
[libc][bazel] Add targets for stdbit functions (#128934)
Adds targets for the stdbit functions. Since the names follow a strict pattern, this is done via list comprehensions. I don't want to handwrite all 50.
1 parent 177ede2 commit 579ead1

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3356,6 +3356,64 @@ libc_function(
33563356
],
33573357
)
33583358

3359+
############################### stdbit targets ###############################
3360+
3361+
bit_suffix_list = [
3362+
"uc",
3363+
"us",
3364+
"ui",
3365+
"ul",
3366+
"ull",
3367+
]
3368+
3369+
bit_prefix_list = [
3370+
"stdc_leading_zeros_",
3371+
"stdc_leading_ones_",
3372+
"stdc_trailing_zeros_",
3373+
"stdc_trailing_ones_",
3374+
"stdc_count_ones_",
3375+
"stdc_has_single_bit_",
3376+
"stdc_bit_width_",
3377+
"stdc_bit_floor_",
3378+
"stdc_bit_ceil_",
3379+
]
3380+
3381+
bit_prefix_needs_math_list = [
3382+
"stdc_first_leading_zero_",
3383+
"stdc_first_leading_one_",
3384+
"stdc_first_trailing_zero_",
3385+
"stdc_first_trailing_one_",
3386+
"stdc_count_zeros_",
3387+
]
3388+
3389+
[
3390+
libc_function(
3391+
name = bit_prefix + bit_suffix,
3392+
srcs = ["src/stdbit/" + bit_prefix + bit_suffix + ".cpp"],
3393+
hdrs = ["src/stdbit/" + bit_prefix + bit_suffix + ".h"],
3394+
deps = [
3395+
":__support_common",
3396+
":__support_cpp_bit",
3397+
],
3398+
)
3399+
for bit_prefix in bit_prefix_list
3400+
for bit_suffix in bit_suffix_list
3401+
]
3402+
3403+
[
3404+
libc_function(
3405+
name = bit_prefix + bit_suffix,
3406+
srcs = ["src/stdbit/" + bit_prefix + bit_suffix + ".cpp"],
3407+
hdrs = ["src/stdbit/" + bit_prefix + bit_suffix + ".h"],
3408+
deps = [
3409+
":__support_common",
3410+
":__support_math_extras",
3411+
],
3412+
)
3413+
for bit_prefix in bit_prefix_needs_math_list
3414+
for bit_suffix in bit_suffix_list
3415+
]
3416+
33593417
############################### stdlib targets ###############################
33603418

33613419
libc_function(

utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def libc_math_function(
128128
129129
Args:
130130
name: The name of the function.
131-
additional_deps: Other deps like helper cc_library targes used by the
131+
additional_deps: Other deps like helper cc_library targets used by the
132132
math function.
133133
"""
134134
additional_deps = additional_deps or []
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
# Tests for LLVM libc stdbit.h functions.
6+
7+
load("//libc/test:libc_test_rules.bzl", "libc_test")
8+
9+
package(default_visibility = ["//visibility:public"])
10+
11+
licenses(["notice"])
12+
13+
bit_suffix_list = [
14+
"uc",
15+
"us",
16+
"ui",
17+
"ul",
18+
"ull",
19+
]
20+
21+
bit_prefix_list = [
22+
"stdc_leading_zeros_",
23+
"stdc_leading_ones_",
24+
"stdc_trailing_zeros_",
25+
"stdc_trailing_ones_",
26+
"stdc_count_ones_",
27+
"stdc_has_single_bit_",
28+
"stdc_bit_width_",
29+
"stdc_bit_floor_",
30+
"stdc_bit_ceil_",
31+
"stdc_first_leading_zero_",
32+
"stdc_first_leading_one_",
33+
"stdc_first_trailing_zero_",
34+
"stdc_first_trailing_one_",
35+
"stdc_count_zeros_",
36+
]
37+
38+
[
39+
libc_test(
40+
name = bit_prefix + bit_suffix + "_test",
41+
srcs = [bit_prefix + bit_suffix + "_test.cpp"],
42+
libc_function_deps = ["//libc:" + bit_prefix + bit_suffix],
43+
deps = ["//libc:__support_cpp_limits"],
44+
)
45+
for bit_prefix in bit_prefix_list
46+
for bit_suffix in bit_suffix_list
47+
]

0 commit comments

Comments
 (0)