[PATCH] D23384: Use a byte array as an internal buffer of BitVector.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 10 17:42:23 PDT 2016


zturner added inline comments.

================
Comment at: include/llvm/ADT/BitVector.h:45
@@ +44,3 @@
+  // Words are in the little endian order on all platforms.
+  MutableArrayRef<Word> Words;
+
----------------
ruiu wrote:
> zturner wrote:
> > Since words are always little endian, why not make the type of Word be `support::ulittle32_t`
> But in many cases you don't actually care about endianness. For example, for count(), only the number of 1s matters. You don't need to swap bytes. So I think using ulittle32_t is inefficient.
But if you don't care about endianness, then it doesn't matter what you pass to popcnt either, so long as it contains the same number of 1s.  So you could write it like this:

```
  size_type count() const {
    unsigned NumBits = 0;
    for (unsigned i = 0; i < Bytes.size(); i += WORD_SIZE)
      NumBits += countPopulation(*reinterpret_cast<uint32_t*>(&Bytes[i]));
    return NumBits;
  }
```

Maybe it's better to delete the `Words` array entirely and just do word-sized operations by casting the underlying byte vector.


https://reviews.llvm.org/D23384





More information about the llvm-commits mailing list