aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorPeng Liu <winner245@hotmail.com>2025-05-21 12:16:40 -0400
committerGitHub <noreply@github.com>2025-05-21 12:16:40 -0400
commit81b81354f8c117fab07823fef24b97b3a1f47834 (patch)
tree774c2d4b5b7fcb44ed0cd6f54b35d6b3f2a17943 /clang/lib/CodeGen/CodeGenFunction.cpp
parentfc9898c4c09fa4e5b83f99d36e847769bf60da60 (diff)
downloadllvm-81b81354f8c117fab07823fef24b97b3a1f47834.zip
llvm-81b81354f8c117fab07823fef24b97b3a1f47834.tar.gz
llvm-81b81354f8c117fab07823fef24b97b3a1f47834.tar.bz2
[libc++] Optimize bitset::to_string (#128832)
This patch optimizes `bitset::to_string` by replacing the existing bit-by-bit processing with a more efficient bit traversal strategy. Instead of checking each bit sequentially, we leverage `std::__countr_zero` to efficiently locate the next set bit, skipping over consecutive zero bits. This greatly accelerates the conversion process, especially for sparse `bitset`s where zero bits dominate. To ensure similar improvements for dense `bitset`s, we exploit symmetry by inverting the bit pattern, allowing us to apply the same optimized traversal technique. Even for uniformly distributed `bitset`s, the proposed approach offers measurable performance gains over the existing implementation. Benchmarks demonstrate substantial improvements, achieving up to 13.5x speedup for sparse `bitset`s with `Pr(true bit) = 0.1`, 16.1x for dense `bitset`s with `Pr(true bit) = 0.9`, and 8.3x for uniformly distributed `bitset`s with `Pr(true bit) = 0.5)`.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
0 files changed, 0 insertions, 0 deletions