File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed
tensorflow_compression/cc/lib Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -35,8 +35,9 @@ BitWriter::BitWriter(size_t maximum_bit_size)
35
35
36
36
void BitWriter::WriteBits (uint32_t count, uint64_t bits) {
37
37
assert (count <= kMaxBitsPerCall );
38
- // This implementation relies on the unused MSBs in `bits` to be zero.
39
- assert (!(bits & (std::numeric_limits<uint64_t >::max () << count)));
38
+ // This implementation assumes unwritten MSBs in the buffer are zero.
39
+ // Clear the unused MSBs in bits first, then "or" it into the buffer.
40
+ bits &= (uint64_t {1 } << count) - 1 ;
40
41
buffer_ |= bits << bits_in_buffer_;
41
42
bits_in_buffer_ += count;
42
43
absl::little_endian::Store64 (next_byte_, buffer_);
@@ -54,7 +55,7 @@ void BitWriter::WriteGamma(int32_t value) {
54
55
WriteBits (n - 1 , 0 );
55
56
// Must write most significant bit first.
56
57
WriteBits (1 , 1 );
57
- WriteBits (n - 1 , value - ( 1 << (n - 1 )) );
58
+ WriteBits (n - 1 , value);
58
59
}
59
60
60
61
absl::string_view BitWriter::GetData () {
You can’t perform that action at this time.
0 commit comments