]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
denc, os: s/ctz/std::countr_zero/
authorKefu Chai <tchaikov@gmail.com>
Sun, 21 Aug 2022 16:50:43 +0000 (00:50 +0800)
committerKefu Chai <tchaikov@gmail.com>
Wed, 24 Aug 2022 09:49:41 +0000 (17:49 +0800)
prefer the facilities provided by standard library over the homebrew
ones for better readability and maintainability.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/common/histogram.h
src/crimson/os/seastore/seastore_types.h
src/include/denc.h
src/os/bluestore/BlueStore.cc
src/os/bluestore/bluestore_types.h

index 828ed47c4e21efc84bb33300d9c2c066249e25f9..cdaca61c277645d78ccb0c5ac3a715a7cb8de02d 100644 (file)
@@ -14,8 +14,8 @@
 #define CEPH_HISTOGRAM_H
 
 #include <list>
-
 #include "include/encoding.h"
+#include "include/intarith.h"
 
 namespace ceph {
   class Formatter;
index 250c791a491412a9a1a2eac8252f6779716c742d..ae6aa64ecf8d1c865588534a79454127d9a6e471 100644 (file)
@@ -15,8 +15,9 @@
 #include "include/byteorder.h"
 #include "include/denc.h"
 #include "include/buffer.h"
-#include "include/uuid.h"
+#include "include/intarith.h"
 #include "include/interval_set.h"
+#include "include/uuid.h"
 
 namespace crimson::os::seastore {
 
index 621da9e70bcc29b081f0880353ec967fbe317595..0f080abc678a06a3c505517c9d8f3594d763890c 100644 (file)
@@ -25,6 +25,7 @@
 #define _ENC_DEC_H
 
 #include <array>
+#include <bit>
 #include <cstring>
 #include <concepts>
 #include <map>
@@ -41,7 +42,6 @@
 #include <boost/optional.hpp>
 
 #include "include/compat.h"
-#include "include/intarith.h"
 #include "include/int_types.h"
 #include "include/scope_guard.h"
 
@@ -477,7 +477,7 @@ inline void denc_varint_lowz(uint64_t v, size_t& p) {
 }
 inline void denc_varint_lowz(uint64_t v,
                             ceph::buffer::list::contiguous_appender& p) {
-  int lowznib = v ? (ctz(v) / 4) : 0;
+  int lowznib = v ? (std::countr_zero(v) / 4) : 0;
   if (lowznib > 3)
     lowznib = 3;
   v >>= lowznib * 4;
@@ -514,7 +514,7 @@ inline void denc_signed_varint_lowz(int64_t v, It& p) {
     v = -v;
     negative = true;
   }
-  unsigned lowznib = v ? (ctz(v) / 4) : 0u;
+  unsigned lowznib = v ? (std::countr_zero(std::bit_cast<uint64_t>(v)) / 4) : 0u;
   if (lowznib > 3)
     lowznib = 3;
   v >>= lowznib * 4;
@@ -559,7 +559,7 @@ inline void denc_lba(uint64_t v, size_t& p) {
 template<class It>
 requires (!is_const_iterator<It>)
 inline void denc_lba(uint64_t v, It& p) {
-  int low_zero_nibbles = v ? (int)(ctz(v) / 4) : 0;
+  int low_zero_nibbles = v ? std::countr_zero(v) / 4 : 0;
   int pos;
   uint32_t word;
   int t = low_zero_nibbles - 3;
index e96ccbc5b4389f756b303c99dc78e80ec838995c..89748853babbda464b299fbac48d0dc3c503b9f4 100644 (file)
@@ -4601,7 +4601,7 @@ BlueStore::BlueStore(CephContext *cct,
     zoned_cleaner_thread(this),
 #endif
     min_alloc_size(_min_alloc_size),
-    min_alloc_size_order(ctz(_min_alloc_size)),
+    min_alloc_size_order(std::countr_zero(_min_alloc_size)),
     mempool_thread(this)
 {
   _init_logger();
@@ -5531,7 +5531,7 @@ int BlueStore::_open_bdev(bool create)
   // initialize global block parameters
   block_size = bdev->get_block_size();
   block_mask = ~(block_size - 1);
-  block_size_order = ctz(block_size);
+  block_size_order = std::countr_zero(block_size);
   ceph_assert(block_size == 1u << block_size_order);
   _set_max_defer_interval();
   // and set cache_size based on device type
@@ -12301,7 +12301,7 @@ int BlueStore::_open_super_meta()
       uint64_t val;
       decode(val, p);
       min_alloc_size = val;
-      min_alloc_size_order = ctz(val);
+      min_alloc_size_order = std::countr_zero(val);
       min_alloc_size_mask  = min_alloc_size - 1;
 
       ceph_assert(min_alloc_size == 1u << min_alloc_size_order);
@@ -15587,7 +15587,7 @@ int BlueStore::_do_alloc_write(
     if (wi.compressed) {
       final_length = wi.compressed_bl.length();
       csum_length = final_length;
-      unsigned csum_order = ctz(csum_length);
+      unsigned csum_order = std::countr_zero(csum_length);
       l = &wi.compressed_bl;
       dblob.set_compressed(wi.blob_length, wi.compressed_len);
       if (csum != Checksummer::CSUM_NONE) {
@@ -15611,7 +15611,7 @@ int BlueStore::_do_alloc_write(
                 << block_size_order << dendl;
        csum_order = block_size_order;
       } else {
-        csum_order = std::min(wctx->csum_order, ctz(l->length()));
+        csum_order = std::min<unsigned>(wctx->csum_order, std::countr_zero(l->length()));
       }
       // try to align blob with max_blob_size to improve
       // its reuse ratio, e.g. in case of reverse write
@@ -15944,7 +15944,7 @@ void BlueStore::_choose_write_options(
 
     if (o->onode.expected_write_size) {
       wctx->csum_order = std::max(min_alloc_size_order,
-                                 (uint8_t)ctz(o->onode.expected_write_size));
+                                 (uint8_t)std::countr_zero(o->onode.expected_write_size));
     } else {
       wctx->csum_order = min_alloc_size_order;
     }
@@ -19007,7 +19007,7 @@ int BlueStore::reconstruct_allocations(SimpleBitmap *sbmap, read_alloc_stats_t &
 //-----------------------------------------------------------------------------------
 static void copy_simple_bitmap_to_allocator(SimpleBitmap* sbmap, Allocator* dest_alloc, uint64_t alloc_size)
 {
-  int alloc_size_shift = ctz(alloc_size);
+  int alloc_size_shift = std::countr_zero(alloc_size);
   uint64_t offset = 0;
   extent_t ext    = sbmap->get_next_clr_extent(offset);
   while (ext.length != 0) {
index 84461daf2ae7345d38b9d37ce3485534c562bb0f..9c4fc5bfdc3d441776a9eac177ecad70b6239408 100644 (file)
@@ -1222,7 +1222,7 @@ public:
     : ref_counter_2hash_tracker_t(mem_cap) {
     ceph_assert(alloc_unit);
     ceph_assert(std::has_single_bit(alloc_unit));
-    au_void_bits = ctz(alloc_unit);
+    au_void_bits = std::countr_zero(alloc_unit);
   }
   void inc(uint64_t sbid, uint64_t offset, int n);
   void inc_range(uint64_t sbid, uint64_t offset, uint32_t len, int n);