Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Unified Diff: runtime/vm/bit_set.h

Issue 538213003: Speed up freelist by using intrinsics to find last set bit. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/platform/utils_win.h ('k') | runtime/vm/bit_set_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/bit_set.h
===================================================================
--- runtime/vm/bit_set.h (revision 39895)
+++ runtime/vm/bit_set.h (working copy)
@@ -58,13 +58,33 @@
for (int w = kLengthInWords - 1; w >= 0; --w) {
uword d = data_[w];
if (d != 0) {
- // TODO(koda): Define HighestBit(uword) or use uint64_t[] for data_.
- return (w << kBitsPerWordLog2) + Utils::HighestBit(d);
+ return ((w + 1) << kBitsPerWordLog2) - Utils::CountLeadingZeros(d) - 1;
}
}
return -1;
}
+ intptr_t ClearLastAndFindPrevious(intptr_t current_last) {
+ ASSERT(Test(current_last));
+ ASSERT(Last() == current_last);
+ intptr_t w = current_last >> kBitsPerWordLog2;
+ uword bits = data_[w];
+ // Clear the current last.
+ bits ^= (static_cast<uword>(1) << (current_last & (kBitsPerWord - 1)));
+ data_[w] = bits;
+ // Search backwards for a non-zero word.
+ while (bits == 0 && w > 0) {
+ bits = data_[--w];
+ }
+ if (bits == 0) {
+ // None found.
+ return -1;
+ } else {
+ // Bitlength incl. w, minus leading zeroes of w, minus 1 to 0-based index.
+ return ((w + 1) << kBitsPerWordLog2) - Utils::CountLeadingZeros(bits) - 1;
+ }
+ }
+
void Reset() {
memset(data_, 0, sizeof(data_));
}
« no previous file with comments | « runtime/platform/utils_win.h ('k') | runtime/vm/bit_set_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698