[llvm] Move bit counting functions to bit.h (NFC)
authorKazu Hirata <kazu@google.com>
Fri, 20 Jan 2023 05:15:39 +0000 (21:15 -0800)
committerKazu Hirata <kazu@google.com>
Fri, 20 Jan 2023 05:15:39 +0000 (21:15 -0800)
commitf37614b25ccaa9c0710cc8a4fc2ba2fb0fcb9159
treea32e580e62f942a17098ba1fee39bbbfaee911a2
parent71283fdbe013c762508d4726a9b616ff4b6aec25
[llvm] Move bit counting functions to bit.h (NFC)

This patch provides C++20-style countl_zero, countr_zero, countl_one,
and countr_one in bit.h.  Existing functions like countLeadingZeros
become wrappers around the new functions.

Note that I cannot quite declare countLeadingZeros as:

  template <class T> using countLeadingZeros = countl_zero<T>;

because countl_zero returns int, whereas countLeadingZeros returns
unsigned.

Differential Revision: https://reviews.llvm.org/D142078
llvm/include/llvm/ADT/bit.h
llvm/include/llvm/Support/MathExtras.h
llvm/unittests/ADT/BitTest.cpp