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

Side by Side Diff: src/utils.h

Issue 679073002: A type vector with multiple IC types needs metadata. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments. Created 6 years, 1 month 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 | « src/type-feedback-vector-inl.h ('k') | test/cctest/test-feedback-vector.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_UTILS_H_ 5 #ifndef V8_UTILS_H_
6 #define V8_UTILS_H_ 6 #define V8_UTILS_H_
7 7
8 #include <limits.h> 8 #include <limits.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 232
233 template<class T, int shift, int size> 233 template<class T, int shift, int size>
234 class BitField : public BitFieldBase<T, shift, size, uint32_t> { }; 234 class BitField : public BitFieldBase<T, shift, size, uint32_t> { };
235 235
236 236
237 template<class T, int shift, int size> 237 template<class T, int shift, int size>
238 class BitField64 : public BitFieldBase<T, shift, size, uint64_t> { }; 238 class BitField64 : public BitFieldBase<T, shift, size, uint64_t> { };
239 239
240 240
241 // ---------------------------------------------------------------------------- 241 // ----------------------------------------------------------------------------
242 // BitSetComputer is a help template for encoding and decoding information for
243 // a variable number of items in an array.
244 //
245 // To encode boolean data in a smi array you would use:
246 // typedef BitSetComputer<bool, 1, kSmiValueSize, uint32_t> BoolComputer;
247 //
248 template <class T, int kBitsPerItem, int kBitsPerWord, class U>
249 class BitSetComputer {
250 public:
251 static const int kItemsPerWord = kBitsPerWord / kBitsPerItem;
252 static const int kMask = (1 << kBitsPerItem) - 1;
253
254 // The number of array elements required to embed T information for each item.
255 static int word_count(int items) {
256 if (items == 0) return 0;
257 return (items - 1) / kItemsPerWord + 1;
258 }
259
260 // The array index to look at for item.
261 static int index(int base_index, int item) {
262 return base_index + item / kItemsPerWord;
263 }
264
265 // Extract T data for a given item from data.
266 static T decode(U data, int item) {
267 return static_cast<T>((data >> shift(item)) & kMask);
268 }
269
270 // Return the encoding for a store of value for item in previous.
271 static U encode(U previous, int item, T value) {
272 int shift_value = shift(item);
273 int set_bits = (static_cast<int>(value) << shift_value);
274 return (previous & ~(kMask << shift_value)) | set_bits;
275 }
276
277 static int shift(int item) { return (item % kItemsPerWord) * kBitsPerItem; }
278 };
279
280
281 // ----------------------------------------------------------------------------
242 // Hash function. 282 // Hash function.
243 283
244 static const uint32_t kZeroHashSeed = 0; 284 static const uint32_t kZeroHashSeed = 0;
245 285
246 // Thomas Wang, Integer Hash Functions. 286 // Thomas Wang, Integer Hash Functions.
247 // http://www.concentric.net/~Ttwang/tech/inthash.htm 287 // http://www.concentric.net/~Ttwang/tech/inthash.htm
248 inline uint32_t ComputeIntegerHash(uint32_t key, uint32_t seed) { 288 inline uint32_t ComputeIntegerHash(uint32_t key, uint32_t seed) {
249 uint32_t hash = key; 289 uint32_t hash = key;
250 hash = hash ^ seed; 290 hash = hash ^ seed;
251 hash = ~hash + (hash << 15); // hash = (hash << 15) - hash - 1; 291 hash = ~hash + (hash << 15); // hash = (hash << 15) - hash - 1;
(...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 // Takes the address of the limit variable in order to find out where 1529 // Takes the address of the limit variable in order to find out where
1490 // the top of stack is right now. 1530 // the top of stack is right now.
1491 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit); 1531 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit);
1492 return limit; 1532 return limit;
1493 } 1533 }
1494 1534
1495 } // namespace internal 1535 } // namespace internal
1496 } // namespace v8 1536 } // namespace v8
1497 1537
1498 #endif // V8_UTILS_H_ 1538 #endif // V8_UTILS_H_
OLDNEW
« no previous file with comments | « src/type-feedback-vector-inl.h ('k') | test/cctest/test-feedback-vector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698