aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/bitops.h
diff options
context:
space:
mode:
authordanlark <danlark@yandex-team.ru>2022-02-10 16:46:10 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:10 +0300
commitbaa58daefa91fde4b4769facdbd2903763b9c6a8 (patch)
tree1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util/generic/bitops.h
parent3426a9bc7f169ae9da54cef557ad2a33f6e8eee0 (diff)
downloadydb-baa58daefa91fde4b4769facdbd2903763b9c6a8.tar.gz
Restoring authorship annotation for <danlark@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/generic/bitops.h')
-rw-r--r--util/generic/bitops.h38
1 files changed, 19 insertions, 19 deletions
diff --git a/util/generic/bitops.h b/util/generic/bitops.h
index add0b75a17..2db15fc59b 100644
--- a/util/generic/bitops.h
+++ b/util/generic/bitops.h
@@ -424,31 +424,31 @@ constexpr T RotateBitsRightCT(T value, const ui8 shift) noexcept {
// do trick with mask to avoid undefined behaviour
return (value >> shift) | (value << ((-shift) & (sizeof(T) * 8 - 1)));
}
-
-/* Remain `size` bits to current `offset` of `value`
- size, offset are less than number of bits in size_type
- */
+
+/* Remain `size` bits to current `offset` of `value`
+ size, offset are less than number of bits in size_type
+ */
template <size_t Offset, size_t Size, class T>
-Y_FORCE_INLINE T SelectBits(T value) {
+Y_FORCE_INLINE T SelectBits(T value) {
static_assert(Size < sizeof(T) * 8, "violated: Size < sizeof(T) * 8");
static_assert(Offset < sizeof(T) * 8, "violated: Offset < sizeof(T) * 8");
- T id = 1;
- return (value >> Offset) & ((id << Size) - id);
-}
-
-/* Set `size` bits of `bits` to current offset of `value`. Requires that bits <= (1 << size) - 1
- size, offset are less than number of bits in size_type
- */
+ T id = 1;
+ return (value >> Offset) & ((id << Size) - id);
+}
+
+/* Set `size` bits of `bits` to current offset of `value`. Requires that bits <= (1 << size) - 1
+ size, offset are less than number of bits in size_type
+ */
template <size_t Offset, size_t Size, class T>
-void SetBits(T& value, T bits) {
+void SetBits(T& value, T bits) {
static_assert(Size < sizeof(T) * 8, "violated: Size < sizeof(T) * 8");
static_assert(Offset < sizeof(T) * 8, "violated: Offset < sizeof(T) * 8");
- T id = 1;
- T maxValue = ((id << Size) - id);
- Y_ASSERT(bits <= maxValue);
- value &= ~(maxValue << Offset);
- value |= bits << Offset;
-}
+ T id = 1;
+ T maxValue = ((id << Size) - id);
+ Y_ASSERT(bits <= maxValue);
+ value &= ~(maxValue << Offset);
+ value |= bits << Offset;
+}
inline constexpr ui64 NthBit64(int bit) {
return ui64(1) << bit;