MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / FindFirstSet

Function FindFirstSet

tensorflow/core/lib/core/bitmap.cc:36–72  ·  view source on GitHub ↗

Return 1+index of the first set bit in w; return 0 if w == 0.

Source from the content-addressed store, hash-verified

34
35// Return 1+index of the first set bit in w; return 0 if w == 0.
36static size_t FindFirstSet(uint32 w) {
37 // TODO(jeff,sanjay): If this becomes a performance issue, we could
38 // use the __builtin_ffs(w) routine on GCC, or the ffs(w) routine on
39 // some other platforms.
40
41 // clang-format off
42 static uint8 kLowestBitSet[256] = {
43 /* 0*/ 0, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1,
44 /* 16*/ 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1,
45 /* 32*/ 6, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1,
46 /* 48*/ 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1,
47 /* 64*/ 7, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1,
48 /* 80*/ 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1,
49 /* 96*/ 6, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1,
50 /*112*/ 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1,
51 /*128*/ 8, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1,
52 /*144*/ 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1,
53 /*160*/ 6, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1,
54 /*176*/ 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1,
55 /*192*/ 7, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1,
56 /*208*/ 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1,
57 /*224*/ 6, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1,
58 /*240*/ 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1,
59 };
60 // clang-format on
61 if (w & 0xff) {
62 return kLowestBitSet[w & 0xff];
63 } else if ((w >> 8) & 0xff) {
64 return kLowestBitSet[(w >> 8) & 0xff] + 8;
65 } else if ((w >> 16) & 0xff) {
66 return kLowestBitSet[(w >> 16) & 0xff] + 16;
67 } else if ((w >> 24) & 0xff) {
68 return kLowestBitSet[(w >> 24) & 0xff] + 24;
69 } else {
70 return 0;
71 }
72}
73
74size_t Bitmap::FirstUnset(size_t start) const {
75 if (start >= nbits_) {

Callers 1

FirstUnsetMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected