[PATCH] D107240: Make multiple mathextras functions constexpr

Alf via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 1 11:35:02 PDT 2021


gAlfonso-bit created this revision.
gAlfonso-bit added a reviewer: LLVM.
gAlfonso-bit added a project: LLVM.
Herald added a subscriber: dexonsmith.
gAlfonso-bit requested review of this revision.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107240

Files:
  llvm/include/llvm/Support/MathExtras.h


Index: llvm/include/llvm/Support/MathExtras.h
===================================================================
--- llvm/include/llvm/Support/MathExtras.h
+++ llvm/include/llvm/Support/MathExtras.h
@@ -91,3 +91,3 @@
 template <typename T, std::size_t SizeOfT> struct TrailingZerosCounter {
-  static unsigned count(T Val, ZeroBehavior) {
+  static constexpr unsigned count(T Val, ZeroBehavior) {
     if (!Val)
@@ -115,3 +115,3 @@
 template <typename T> struct TrailingZerosCounter<T, 4> {
-  static unsigned count(T Val, ZeroBehavior ZB) {
+  static constexpr unsigned count(T Val, ZeroBehavior ZB) {
     if (ZB != ZB_Undefined && Val == 0)
@@ -131,3 +131,3 @@
 template <typename T> struct TrailingZerosCounter<T, 8> {
-  static unsigned count(T Val, ZeroBehavior ZB) {
+  static constexpr unsigned count(T Val, ZeroBehavior ZB) {
     if (ZB != ZB_Undefined && Val == 0)
@@ -156,3 +156,3 @@
 template <typename T>
-unsigned countTrailingZeros(T Val, ZeroBehavior ZB = ZB_Width) {
+constexpr unsigned countTrailingZeros(T Val, ZeroBehavior ZB = ZB_Width) {
   static_assert(std::numeric_limits<T>::is_integer &&
@@ -165,3 +165,3 @@
 template <typename T, std::size_t SizeOfT> struct LeadingZerosCounter {
-  static unsigned count(T Val, ZeroBehavior) {
+  static constexpr unsigned count(T Val, ZeroBehavior) {
     if (!Val)
@@ -184,3 +184,3 @@
 template <typename T> struct LeadingZerosCounter<T, 4> {
-  static unsigned count(T Val, ZeroBehavior ZB) {
+  static constexpr unsigned count(T Val, ZeroBehavior ZB) {
     if (ZB != ZB_Undefined && Val == 0)
@@ -200,3 +200,3 @@
 template <typename T> struct LeadingZerosCounter<T, 8> {
-  static unsigned count(T Val, ZeroBehavior ZB) {
+  static constexpr unsigned count(T Val, ZeroBehavior ZB) {
     if (ZB != ZB_Undefined && Val == 0)
@@ -225,3 +225,3 @@
 template <typename T>
-unsigned countLeadingZeros(T Val, ZeroBehavior ZB = ZB_Width) {
+constexpr unsigned countLeadingZeros(T Val, ZeroBehavior ZB = ZB_Width) {
   static_assert(std::numeric_limits<T>::is_integer &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107240.363344.patch
Type: text/x-patch
Size: 2031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210801/7387d99f/attachment.bin>


More information about the llvm-commits mailing list