Skip to content

[libc][docs] use docgen to generate stdbit rst docs #88540

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 1 commit into from
Apr 12, 2024
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
350 changes: 219 additions & 131 deletions libc/docs/stdbit.rst
Original file line number Diff line number Diff line change
@@ -1,135 +1,223 @@
=========================
Bitwise Utility Functions
=========================

.. include:: check.rst

---------------
Source Location
---------------

- The main source for bitwise utility functions is located at:
``libc/src/stdbit``.

- The source for internal helpers used to implement these is located at:
``libc/src/__support/CPP/bit.h``.

- The tests are located at:
``libc/test/src/stdbit/``, ``libc/test/include/stdbit_test.cpp``, and
``src/__support/CPP/bit_test.cpp``.

---------------------
Implementation Status
---------------------

Functions
=========

..
Do not order these, they are as they appear in the standard.

============================ =========
Function Name Available
============================ =========
stdc_leading_zeros_uc |check|
stdc_leading_zeros_us |check|
stdc_leading_zeros_ui |check|
stdc_leading_zeros_ul |check|
stdc_leading_zeros_ull |check|
stdc_leading_ones_uc |check|
stdc_leading_ones_us |check|
stdc_leading_ones_ui |check|
stdc_leading_ones_ul |check|
stdc_leading_ones_ull |check|
stdc_trailing_zeros_uc |check|
stdc_trailing_zeros_us |check|
stdc_trailing_zeros_ui |check|
stdc_trailing_zeros_ul |check|
stdc_trailing_zeros_ull |check|
stdc_trailing_ones_uc |check|
stdc_trailing_ones_us |check|
stdc_trailing_ones_ui |check|
stdc_trailing_ones_ul |check|
stdc_trailing_ones_ull |check|
stdc_first_leading_zero_uc |check|
stdc_first_leading_zero_us |check|
stdc_first_leading_zero_ui |check|
stdc_first_leading_zero_ul |check|
stdc_first_leading_zero_ull |check|
stdc_first_leading_one_uc |check|
stdc_first_leading_one_us |check|
stdc_first_leading_one_ui |check|
stdc_first_leading_one_ul |check|
stdc_first_leading_one_ull |check|
stdc_first_trailing_zero_uc |check|
stdc_first_trailing_zero_us |check|
stdc_first_trailing_zero_ui |check|
stdc_first_trailing_zero_ul |check|
stdc_first_trailing_zero_ull |check|
stdc_first_trailing_one_uc |check|
stdc_first_trailing_one_us |check|
stdc_first_trailing_one_ui |check|
stdc_first_trailing_one_ul |check|
stdc_first_trailing_one_ull |check|
stdc_count_zeros_uc |check|
stdc_count_zeros_us |check|
stdc_count_zeros_ui |check|
stdc_count_zeros_ul |check|
stdc_count_zeros_ull |check|
stdc_count_ones_uc |check|
stdc_count_ones_us |check|
stdc_count_ones_ui |check|
stdc_count_ones_ul |check|
stdc_count_ones_ull |check|
stdc_has_single_bit_uc |check|
stdc_has_single_bit_us |check|
stdc_has_single_bit_ui |check|
stdc_has_single_bit_ul |check|
stdc_has_single_bit_ull |check|
stdc_bit_width_uc |check|
stdc_bit_width_us |check|
stdc_bit_width_ui |check|
stdc_bit_width_ul |check|
stdc_bit_width_ull |check|
stdc_bit_floor_uc |check|
stdc_bit_floor_us |check|
stdc_bit_floor_ui |check|
stdc_bit_floor_ul |check|
stdc_bit_floor_ull |check|
stdc_bit_ceil_uc |check|
stdc_bit_ceil_us |check|
stdc_bit_ceil_ui |check|
stdc_bit_ceil_ul |check|
stdc_bit_ceil_ull |check|
============================ =========


Macros
======
stdbit.h Functions
==================

========================= =========
Macro Name Available
========================= =========
__STDC_VERSION_STDBIT_H__ |check|
__STDC_ENDIAN_LITTLE__ |check|
__STDC_ENDIAN_BIG__ |check|
__STDC_ENDIAN_NATIVE__ |check|
stdc_leading_zeros |check|
stdc_leading_ones |check|
stdc_trailing_zeros |check|
stdc_trailing_ones |check|
stdc_first_leading_zero |check|
stdc_first_leading_one |check|
stdc_first_trailing_zero |check|
stdc_first_trailing_one |check|
stdc_count_zeros |check|
stdc_count_ones |check|
stdc_has_single_bit |check|
stdc_bit_width |check|
stdc_bit_floor |check|
stdc_bit_ceil |check|
========================= =========
.. list-table::
:widths: auto
:align: center
:header-rows: 1

Standards
=========
stdbit.h was specified as part of C23 in section 7.18 "Bit and byte utilities."
* - Function
- Implemented
- Standard
* - stdc_bit_ceil_uc
- |check|
- 7.18.16
* - stdc_bit_ceil_ui
- |check|
- 7.18.16
* - stdc_bit_ceil_ul
- |check|
- 7.18.16
* - stdc_bit_ceil_ull
- |check|
- 7.18.16
* - stdc_bit_ceil_us
- |check|
- 7.18.16
* - stdc_bit_floor_uc
- |check|
- 7.18.15
* - stdc_bit_floor_ui
- |check|
- 7.18.15
* - stdc_bit_floor_ul
- |check|
- 7.18.15
* - stdc_bit_floor_ull
- |check|
- 7.18.15
* - stdc_bit_floor_us
- |check|
- 7.18.15
* - stdc_bit_width_uc
- |check|
- 7.18.14
* - stdc_bit_width_ui
- |check|
- 7.18.14
* - stdc_bit_width_ul
- |check|
- 7.18.14
* - stdc_bit_width_ull
- |check|
- 7.18.14
* - stdc_bit_width_us
- |check|
- 7.18.14
* - stdc_count_ones_uc
- |check|
- 7.18.12
* - stdc_count_ones_ui
- |check|
- 7.18.12
* - stdc_count_ones_ul
- |check|
- 7.18.12
* - stdc_count_ones_ull
- |check|
- 7.18.12
* - stdc_count_ones_us
- |check|
- 7.18.12
* - stdc_count_zeros_uc
- |check|
- 7.18.11
* - stdc_count_zeros_ui
- |check|
- 7.18.11
* - stdc_count_zeros_ul
- |check|
- 7.18.11
* - stdc_count_zeros_ull
- |check|
- 7.18.11
* - stdc_count_zeros_us
- |check|
- 7.18.11
* - stdc_first_leading_one_uc
- |check|
- 7.18.8
* - stdc_first_leading_one_ui
- |check|
- 7.18.8
* - stdc_first_leading_one_ul
- |check|
- 7.18.8
* - stdc_first_leading_one_ull
- |check|
- 7.18.8
* - stdc_first_leading_one_us
- |check|
- 7.18.8
* - stdc_first_leading_zero_uc
- |check|
- 7.18.7
* - stdc_first_leading_zero_ui
- |check|
- 7.18.7
* - stdc_first_leading_zero_ul
- |check|
- 7.18.7
* - stdc_first_leading_zero_ull
- |check|
- 7.18.7
* - stdc_first_leading_zero_us
- |check|
- 7.18.7
* - stdc_first_trailing_one_uc
- |check|
- 7.18.10
* - stdc_first_trailing_one_ui
- |check|
- 7.18.10
* - stdc_first_trailing_one_ul
- |check|
- 7.18.10
* - stdc_first_trailing_one_ull
- |check|
- 7.18.10
* - stdc_first_trailing_one_us
- |check|
- 7.18.10
* - stdc_first_trailing_zero_uc
- |check|
- 7.18.9
* - stdc_first_trailing_zero_ui
- |check|
- 7.18.9
* - stdc_first_trailing_zero_ul
- |check|
- 7.18.9
* - stdc_first_trailing_zero_ull
- |check|
- 7.18.9
* - stdc_first_trailing_zero_us
- |check|
- 7.18.9
* - stdc_has_single_bit_uc
- |check|
- 7.18.13
* - stdc_has_single_bit_ui
- |check|
- 7.18.13
* - stdc_has_single_bit_ul
- |check|
- 7.18.13
* - stdc_has_single_bit_ull
- |check|
- 7.18.13
* - stdc_has_single_bit_us
- |check|
- 7.18.13
* - stdc_leading_ones_uc
- |check|
- 7.18.4
* - stdc_leading_ones_ui
- |check|
- 7.18.4
* - stdc_leading_ones_ul
- |check|
- 7.18.4
* - stdc_leading_ones_ull
- |check|
- 7.18.4
* - stdc_leading_ones_us
- |check|
- 7.18.4
* - stdc_leading_zeros_uc
- |check|
- 7.18.3
* - stdc_leading_zeros_ui
- |check|
- 7.18.3
* - stdc_leading_zeros_ul
- |check|
- 7.18.3
* - stdc_leading_zeros_ull
- |check|
- 7.18.3
* - stdc_leading_zeros_us
- |check|
- 7.18.3
* - stdc_trailing_ones_uc
- |check|
- 7.18.6
* - stdc_trailing_ones_ui
- |check|
- 7.18.6
* - stdc_trailing_ones_ul
- |check|
- 7.18.6
* - stdc_trailing_ones_ull
- |check|
- 7.18.6
* - stdc_trailing_ones_us
- |check|
- 7.18.6
* - stdc_trailing_zeros_uc
- |check|
- 7.18.5
* - stdc_trailing_zeros_ui
- |check|
- 7.18.5
* - stdc_trailing_zeros_ul
- |check|
- 7.18.5
* - stdc_trailing_zeros_ull
- |check|
- 7.18.5
* - stdc_trailing_zeros_us
- |check|
- 7.18.5
8 changes: 8 additions & 0 deletions libc/utils/docgen/docgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ def is_implemented(hname: str, fname: str) -> bool:
"src",
hname.rstrip(".h")
)

if not path.exists():
raise FileNotFoundError(f"implementation dir does not exist: {path}")

if not path.is_dir():
raise NotADirectoryError(f"implementation dir is not a dir: {path}")

# Recursively search for the target source file in the subdirectories under
# libc/src/{hname}.
for _ in path.glob("**/" + fname + ".cpp"):
Expand All @@ -53,6 +60,7 @@ def print_functions(header: str, functions: Dict):


def print_header(header: str, api: Dict):
print(".. include:: check.rst\n")
fns = f"{header} Functions"
print(fns)
print("=" * (len(fns)))
Expand Down
Loading