Skip to content

Commit 7381ad8

Browse files
grebecopybara-github
authored andcommitted
Remove custom endianness enum in favor of std::endian.
PiperOrigin-RevId: 866647761
1 parent 79ebdb2 commit 7381ad8

File tree

4 files changed

+7
-48
lines changed

4 files changed

+7
-48
lines changed

xls/common/BUILD

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -623,12 +623,6 @@ cc_library(
623623
],
624624
)
625625

626-
cc_library(
627-
name = "endian",
628-
hdrs = ["endian.h"],
629-
deps = ["@com_google_absl//absl/base:config"],
630-
)
631-
632626
cc_library(
633627
name = "stopwatch",
634628
srcs = ["stopwatch.cc"],

xls/common/endian.h

Lines changed: 0 additions & 37 deletions
This file was deleted.

xls/data_structures/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ cc_library(
133133
hdrs = ["inline_bitmap.h"],
134134
deps = [
135135
"//xls/common:bits_util",
136-
"//xls/common:endian",
137136
"//xls/common:math_util",
138137
"//xls/common:test_macros",
139138
"@com_google_absl//absl/base",

xls/data_structures/inline_bitmap.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define XLS_DATA_STRUCTURES_INLINE_BITMAP_H_
1717

1818
#include <algorithm>
19+
#include <bit>
1920
#include <compare>
2021
#include <cstdint>
2122
#include <cstring>
@@ -30,7 +31,6 @@
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.
4242
class 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

Comments
 (0)