Introduce pot_log2, which checks that its argument is a power of two then returns its log2.
Allows to convey in code that values are power of two, so the log2 is exact.

PiperOrigin-RevId: 270107047
diff --git a/block_map.cc b/block_map.cc
index 68a805a..756b6e9 100644
--- a/block_map.cc
+++ b/block_map.cc
@@ -140,7 +140,7 @@
   const int size = std::min(rows, cols);
   const int size_floor_log2 = floor_log2(size);
   const int depth_ceil_log2 = ceil_log2(depth);
-  const int kernel_width_log2 = ceil_log2(std::max(kernel_cols, kernel_rows));
+  const int kernel_width_log2 = pot_log2(std::max(kernel_cols, kernel_rows));
 
   // l1_size_log2 was originally, coarsely speaking the number of rows of LHS,
   // or the number of columns of RHS in a matrix multiplication that we expect,
@@ -162,7 +162,7 @@
   // by such clear principles linking this logic to cache sizes.
   l1_size_log2 = std::min(
       l1_size_log2, 15 - depth_ceil_log2 -
-                        ceil_log2(std::max(lhs_scalar_size, rhs_scalar_size)));
+                        pot_log2(std::max(lhs_scalar_size, rhs_scalar_size)));
   l1_size_log2 = std::max(l1_size_log2, kernel_width_log2);
   l1_size_log2 = std::min(l1_size_log2, size_floor_log2);
 
@@ -180,10 +180,10 @@
       round_down_pot(cols >> num_blocks_of_cols_log2, kernel_cols);
   const int missr =
       round_up_pot(rows - (smallr << num_blocks_of_rows_log2), kernel_rows) >>
-      floor_log2(kernel_rows);
+      pot_log2(kernel_rows);
   const int missc =
       round_up_pot(cols - (smallc << num_blocks_of_cols_log2), kernel_cols) >>
-      floor_log2(kernel_cols);
+      pot_log2(kernel_cols);
 
   block_map->dims[Side::kLhs] = rows;
   block_map->dims[Side::kRhs] = cols;
diff --git a/size_util.h b/size_util.h
index c087d31..bdffaa0 100644
--- a/size_util.h
+++ b/size_util.h
@@ -62,6 +62,12 @@
 }
 
 template <typename Integer>
+Integer pot_log2(Integer n) {
+  RUY_DCHECK(is_pot(n));
+  return floor_log2(n);
+}
+
+template <typename Integer>
 Integer round_down_pot(Integer value) {
   return static_cast<Integer>(1) << floor_log2(value);
 }
diff --git a/size_util_test.cc b/size_util_test.cc
index 6f09612..393f21e 100644
--- a/size_util_test.cc
+++ b/size_util_test.cc
@@ -36,6 +36,7 @@
 
   if (is_pot(value)) {
     EXPECT_EQ(floor_log2(value), ceil_log2(value));
+    EXPECT_EQ(floor_log2(value), pot_log2(value));
   } else {
     EXPECT_EQ(floor_log2(value) + 1, ceil_log2(value));
   }