[ADT] Add bit_floor, bit_ceil, and bit_width to bit.h
This patch adds C++20-style bit_floor, bit_ceil, and bit_width. In a subsequent patch, I'm going to define PowerOf2Floor in MathExtras.h in terms of bit_floor. Unfortunately, PowerOf2Ceil isn't quite the same as bit_ceil because PowerOf2Ceil(0) == 0, whereas bit_ceil(0) == 1. MathExtras.h does not have a function directly corresponding to bit_width, but Log2_32(X) + 1, which occurs in a few places, can be replaced with bit_width(X). Differential Revision: https://reviews.llvm.org/D142179
Loading
Please sign in to comment