[all-commits] [llvm/llvm-project] eaabc1: [ADT] Add bit_floor, bit_ceil, and bit_width to bit.h

kazutakahirata via All-commits all-commits at lists.llvm.org
Fri Jan 20 19:34:57 PST 2023

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: eaabc1bbeaa057bac3fe699bebda1472dc2ae03b
  Author: Kazu Hirata <kazu at google.com>
  Date:   2023-01-20 (Fri, 20 Jan 2023)

  Changed paths:
    M llvm/include/llvm/ADT/bit.h
    M llvm/unittests/ADT/BitTest.cpp

  Log Message:
  [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

More information about the All-commits mailing list