OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_BIT_SET_H_ | 5 #ifndef VM_BIT_SET_H_ |
6 #define VM_BIT_SET_H_ | 6 #define VM_BIT_SET_H_ |
7 | 7 |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 return (w << kBitsPerWordLog2) + Utils::CountTrailingZeros(data_[w]); | 51 return (w << kBitsPerWordLog2) + Utils::CountTrailingZeros(data_[w]); |
52 } | 52 } |
53 } | 53 } |
54 return -1; | 54 return -1; |
55 } | 55 } |
56 | 56 |
57 intptr_t Last() const { | 57 intptr_t Last() const { |
58 for (int w = kLengthInWords - 1; w >= 0; --w) { | 58 for (int w = kLengthInWords - 1; w >= 0; --w) { |
59 uword d = data_[w]; | 59 uword d = data_[w]; |
60 if (d != 0) { | 60 if (d != 0) { |
61 // TODO(koda): Define HighestBit(uword) or use uint64_t[] for data_. | 61 return ((w + 1) << kBitsPerWordLog2) - Utils::CountLeadingZeros(d) - 1; |
62 return (w << kBitsPerWordLog2) + Utils::HighestBit(d); | |
63 } | 62 } |
64 } | 63 } |
65 return -1; | 64 return -1; |
66 } | 65 } |
67 | 66 |
67 intptr_t ClearLastAndFindPrevious(intptr_t current_last) { | |
68 ASSERT(Test(current_last)); | |
69 ASSERT(Last() == current_last); | |
70 intptr_t w = current_last >> kBitsPerWordLog2; | |
71 uword mask = (static_cast<uword>(1) << (current_last & (kBitsPerWord - 1))); | |
72 data_[w] ^= mask; | |
73 do { | |
74 uword d = data_[w]; | |
75 if (d != 0) { | |
76 return ((w + 1) << kBitsPerWordLog2) - Utils::CountLeadingZeros(d) - 1; | |
77 } | |
78 } while (--w >= 0); | |
Ivan Posva
2014/09/08 06:58:08
I find this loop hard to read. In addition it visu
koda
2014/09/09 20:51:41
I aimed for consistency with existing code.
Uploa
| |
79 return -1; | |
80 } | |
81 | |
68 void Reset() { | 82 void Reset() { |
69 memset(data_, 0, sizeof(data_)); | 83 memset(data_, 0, sizeof(data_)); |
70 } | 84 } |
71 | 85 |
72 intptr_t Size() const { | 86 intptr_t Size() const { |
73 return N; | 87 return N; |
74 } | 88 } |
75 | 89 |
76 private: | 90 private: |
77 static const int kLengthInWords = 1 + ((N - 1) / kBitsPerWord); | 91 static const int kLengthInWords = 1 + ((N - 1) / kBitsPerWord); |
78 uword data_[kLengthInWords]; | 92 uword data_[kLengthInWords]; |
79 }; | 93 }; |
80 | 94 |
81 } // namespace dart | 95 } // namespace dart |
82 | 96 |
83 #endif // VM_BIT_SET_H_ | 97 #endif // VM_BIT_SET_H_ |
OLD | NEW |