1616#define XLS_DATA_STRUCTURES_INLINE_BITMAP_H_
1717
1818#include < algorithm>
19+ #include < bit>
1920#include < compare>
2021#include < cstdint>
2122#include < cstring>
3031#include " absl/log/check.h"
3132#include " absl/types/span.h"
3233#include " xls/common/bits_util.h"
33- #include " xls/common/endian.h"
3434#include " xls/common/math_util.h"
3535#include " xls/common/test_macros.h"
3636
@@ -40,6 +40,9 @@ class BitmapView;
4040
4141// A bitmap that has 64-bits of inline storage by default.
4242class InlineBitmap {
43+ static_assert (std::endian::native == std::endian::little,
44+ " InlineBitmap requires little-endianness." );
45+
4346 public:
4447 // Constructs an InlineBitmap of width `bit_count` using the bits in
4548 // `word`. If `bit_count` is greater than 64, then all high bits are set to
@@ -263,7 +266,7 @@ class InlineBitmap {
263266 // is mapped to the least significant bits of word 1, and so on.
264267 void SetByte (int64_t byteno, uint8_t value) {
265268 DCHECK_LT (byteno, byte_count ());
266- CHECK ( kEndianness == Endianness:: kLittleEndian );
269+ DCHECK (std::endian::native == std::endian::little );
267270 absl::bit_cast<uint8_t *>(data_.data ())[byteno] = value;
268271 // Ensure the data is appropriately masked in case this byte writes to that
269272 // region of bits.
@@ -273,14 +276,14 @@ class InlineBitmap {
273276 // Returns the byte at the given offset. Byte order is little-endian.
274277 uint8_t GetByte (int64_t byteno) const {
275278 DCHECK_LT (byteno, byte_count ());
276- CHECK ( kEndianness == Endianness:: kLittleEndian );
279+ DCHECK (std::endian::native == std::endian::little );
277280 return absl::bit_cast<uint8_t *>(data_.data ())[byteno];
278281 }
279282
280283 // Writes the underlying bytes of the inline bit map to the given buffer. Byte
281284 // order is little-endian. Writes out Ceil(bit_count_ / 8) number of bytes.
282285 void WriteBytesToBuffer (absl::Span<uint8_t > bytes) const {
283- CHECK ( kEndianness == Endianness:: kLittleEndian );
286+ DCHECK (std::endian::native == std::endian::little );
284287 // memcpy() requires valid pointers even when the number of bytes copied is
285288 // zero, and an empty absl::Span's data() pointer may not be valid. Guard
286289 // the memcpy with a check that the span is not empty.
0 commit comments