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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/platform/utils_win.h ('k') | runtime/vm/bit_set_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 bits = data_[w];
72 // Clear the current last.
73 bits ^= (static_cast<uword>(1) << (current_last & (kBitsPerWord - 1)));
74 data_[w] = bits;
75 // Search backwards for a non-zero word.
76 while (bits == 0 && w > 0) {
77 bits = data_[--w];
78 }
79 if (bits == 0) {
80 // None found.
81 return -1;
82 } else {
83 // Bitlength incl. w, minus leading zeroes of w, minus 1 to 0-based index.
84 return ((w + 1) << kBitsPerWordLog2) - Utils::CountLeadingZeros(bits) - 1;
85 }
86 }
87
68 void Reset() { 88 void Reset() {
69 memset(data_, 0, sizeof(data_)); 89 memset(data_, 0, sizeof(data_));
70 } 90 }
71 91
72 intptr_t Size() const { 92 intptr_t Size() const {
73 return N; 93 return N;
74 } 94 }
75 95
76 private: 96 private:
77 static const int kLengthInWords = 1 + ((N - 1) / kBitsPerWord); 97 static const int kLengthInWords = 1 + ((N - 1) / kBitsPerWord);
78 uword data_[kLengthInWords]; 98 uword data_[kLengthInWords];
79 }; 99 };
80 100
81 } // namespace dart 101 } // namespace dart
82 102
83 #endif // VM_BIT_SET_H_ 103 #endif // VM_BIT_SET_H_
OLDNEW
« 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