[common] move bit-related macros to bit_utils.hpp (#11890)

This change moves the `kBitsPerByte` constant and the `BitSizeOf()`
and `BytesForBitSize()` macros from `numeric_limits.hpp` to the
more specialized `bit_utils.hpp` header.

This consolidation places common bit-utility definitions into a more
appropriate, dedicated header, improving code organization and
logical grouping. Headers that relied on these definitions are
updated accordingly.
This commit is contained in:
Abtin Keshavarzian
2025-09-03 22:28:18 -07:00
committed by GitHub
parent ca8b29859d
commit 6849b541e9
5 changed files with 23 additions and 24 deletions
+1 -1
View File
@@ -36,9 +36,9 @@
#include "openthread-core-config.h"
#include "common/bit_utils.hpp"
#include "common/clearable.hpp"
#include "common/equatable.hpp"
#include "common/numeric_limits.hpp"
namespace ot {
+20
View File
@@ -40,6 +40,26 @@
namespace ot {
static constexpr uint8_t kBitsPerByte = 8; ///< Number of bits in a byte.
/**
* Returns the bit-size (number of bits) of a given type or variable.
*
* @param[in] aItem The item (type or variable or expression) to get the bit-size of.
*
* @returns Number of bits of @p aItem.
*/
#define BitSizeOf(aItem) (sizeof(aItem) * kBitsPerByte)
/**
* Determines number of bytes to represent a given number of bits.
*
* @param[in] aBitSize The bit-size (number of bits).
*
* @returns Number of bytes to represent @p aBitSize.
*/
#define BytesForBitSize(aBitSize) static_cast<uint8_t>(((aBitSize) + (kBitsPerByte - 1)) / kBitsPerByte)
/**
* Counts the number of `1` bits in the binary representation of a given unsigned int bit-mask value.
*
-20
View File
@@ -38,26 +38,6 @@
namespace ot {
static constexpr uint8_t kBitsPerByte = 8; ///< Number of bits in a byte.
/**
* Returns the bit-size (number of bits) of a given type or variable.
*
* @param[in] aItem The item (type or variable or expression) to get the bit-size of.
*
* @returns Number of bits of @p aItem.
*/
#define BitSizeOf(aItem) (sizeof(aItem) * kBitsPerByte)
/**
* Determines number of byes to represent a given number of bits.
*
* @param[in] aBitSize The bit-size (number of bits).
*
* @returns Number of bytes to represent @p aBitSize.
*/
#define BytesForBitSize(aBitSize) static_cast<uint8_t>(((aBitSize) + (kBitsPerByte - 1)) / kBitsPerByte)
/**
* Provides a way to query properties of arithmetic types.
*
+1 -1
View File
@@ -36,9 +36,9 @@
#include "openthread-core-config.h"
#include "common/bit_utils.hpp"
#include "common/locator.hpp"
#include "common/non_copyable.hpp"
#include "common/numeric_limits.hpp"
#include "common/time.hpp"
#include "common/timer.hpp"
+1 -2
View File
@@ -39,11 +39,10 @@
#include <openthread/ip6.h>
#include "common/as_core_type.hpp"
#include "common/bit_utils.hpp"
#include "common/clearable.hpp"
#include "common/encoding.hpp"
#include "common/equatable.hpp"
#include "common/num_utils.hpp"
#include "common/numeric_limits.hpp"
#include "common/string.hpp"
#include "mac/mac_types.hpp"