[PATCH] D28817: Add SparseBitVector::find_last()

Daniel Berlin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 17 13:08:55 PST 2017

dberlin accepted this revision.
dberlin added inline comments.
This revision is now accepted and ready to land.

Comment at: llvm/include/llvm/ADT/SparseBitVector.h:141
+        return Idx * BITWORD_SIZE + BITWORD_SIZE -
+               countLeadingZeros(Bits[Idx]) - 1;
+    }
zturner wrote:
> dberlin wrote:
> > Don't you really just want counttrailingzeros, and the index is bitword_size - count trailing zeros?
> > 
> I made the same mistake at first.  Because the LSB is the bit with the lowest "index", we have to use `countLeadingZeros`.  i.e. 0b00000000000000000000000000000110  has bits 1 and 2 set.  The value we want returned from the function is 2.
This assumes we store these little endian.
If we store them big endian, ...

Anyway, i think you are correct, and if not, the test will fail, so :)



More information about the llvm-commits mailing list