Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
julic20s committed Nov 27, 2023
1 parent 982ee77 commit 289d25b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/common/bitfield_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static uint64_t WrappedSignedBitfieldPlus(uint64_t value, int64_t incr, uint8_t
return res;
}

// See also https://github.com/redis/redis/blob/7f4bae817614988c43c3024402d16edcbf3b3277/src/bitops.c#L325
StatusOr<bool> SignedBitfieldPlus(uint64_t value, int64_t incr, uint8_t bits, BitfieldOverflowBehavior overflow,
uint64_t *dst) {
Status bits_status(BitfieldEncoding::CheckSupportedBitLengths(BitfieldEncoding::Type::kSigned, bits));
Expand Down Expand Up @@ -84,7 +85,7 @@ static uint64_t WrappedUnsignedBitfieldPlus(uint64_t value, int64_t incr, uint8_
return res;
}

// return true if overflow.
// See also https://github.com/redis/redis/blob/7f4bae817614988c43c3024402d16edcbf3b3277/src/bitops.c#L288
StatusOr<bool> UnsignedBitfieldPlus(uint64_t value, int64_t incr, uint8_t bits, BitfieldOverflowBehavior overflow,
uint64_t *dst) {
Status bits_status(BitfieldEncoding::CheckSupportedBitLengths(BitfieldEncoding::Type::kUnsigned, bits));
Expand Down
2 changes: 1 addition & 1 deletion src/common/bitfield_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class ArrayBitfieldBitmap {

// for a bits of k signed number, 1 << (bits - 1) is the MSB (most-significant bit).
// the number is a negative when the MSB is "1".
auto msb = static_cast<uint64_t>(1) << (bits - 1);
auto msb = static_cast<uint64_t>(1) << (bits - 1); // NOLINT
if ((value & msb) != 0) {
// The way of enlarge width of a signed integer is sign-extended.
// The values of higher bits should all "1", when the number is negative.
Expand Down

0 comments on commit 289d25b

Please sign in to comment.