| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #include "src/compiler/node-cache.h" | 5 #include "src/compiler/node-cache.h" |
| 6 | 6 |
| 7 #include "src/zone.h" | |
| 8 | |
| 9 namespace v8 { | 7 namespace v8 { |
| 10 namespace internal { | 8 namespace internal { |
| 11 namespace compiler { | 9 namespace compiler { |
| 12 | 10 |
| 13 #define INITIAL_SIZE 16 | 11 #define INITIAL_SIZE 16 |
| 14 #define LINEAR_PROBE 5 | 12 #define LINEAR_PROBE 5 |
| 15 | 13 |
| 16 template <typename Key> | 14 template <typename Key> |
| 17 inline int NodeCacheHash(Key key); | 15 int32_t NodeCacheHash(Key key) { |
| 18 | 16 UNIMPLEMENTED(); |
| 17 return 0; |
| 18 } |
| 19 | 19 |
| 20 template <> | 20 template <> |
| 21 inline int NodeCacheHash(int32_t key) { | 21 inline int32_t NodeCacheHash(int32_t key) { |
| 22 return ComputeIntegerHash(key, 0); | 22 return ComputeIntegerHash(key, 0); |
| 23 } | 23 } |
| 24 | 24 |
| 25 | 25 |
| 26 template <> | 26 template <> |
| 27 inline int NodeCacheHash(int64_t key) { | 27 inline int32_t NodeCacheHash(int64_t key) { |
| 28 return ComputeLongHash(key); | 28 return ComputeLongHash(key); |
| 29 } | 29 } |
| 30 | 30 |
| 31 | 31 |
| 32 template <> |
| 33 inline int32_t NodeCacheHash(double key) { |
| 34 return ComputeLongHash(BitCast<int64_t>(key)); |
| 35 } |
| 36 |
| 37 |
| 38 template <> |
| 39 inline int32_t NodeCacheHash(void* key) { |
| 40 return ComputePointerHash(key); |
| 41 } |
| 42 |
| 43 |
| 32 template <typename Key> | 44 template <typename Key> |
| 33 bool NodeCache<Key>::Resize(Zone* zone) { | 45 bool NodeCache<Key>::Resize(Zone* zone) { |
| 34 if (size_ >= max_) return false; // Don't grow past the maximum size. | 46 if (size_ >= max_) return false; // Don't grow past the maximum size. |
| 35 | 47 |
| 36 // Allocate a new block of entries 4x the size. | 48 // Allocate a new block of entries 4x the size. |
| 37 Entry* old_entries = entries_; | 49 Entry* old_entries = entries_; |
| 38 int old_size = size_ + LINEAR_PROBE; | 50 int old_size = size_ + LINEAR_PROBE; |
| 39 size_ = size_ * 4; | 51 size_ = size_ * 4; |
| 40 int num_entries = size_ + LINEAR_PROBE; | 52 int num_entries = size_ + LINEAR_PROBE; |
| 41 entries_ = zone->NewArray<Entry>(num_entries); | 53 entries_ = zone->NewArray<Entry>(num_entries); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 57 } | 69 } |
| 58 } | 70 } |
| 59 } | 71 } |
| 60 } | 72 } |
| 61 return true; | 73 return true; |
| 62 } | 74 } |
| 63 | 75 |
| 64 | 76 |
| 65 template <typename Key> | 77 template <typename Key> |
| 66 Node** NodeCache<Key>::Find(Zone* zone, Key key) { | 78 Node** NodeCache<Key>::Find(Zone* zone, Key key) { |
| 67 int hash = NodeCacheHash(key); | 79 int32_t hash = NodeCacheHash(key); |
| 68 if (entries_ == NULL) { | 80 if (entries_ == NULL) { |
| 69 // Allocate the initial entries and insert the first entry. | 81 // Allocate the initial entries and insert the first entry. |
| 70 int num_entries = INITIAL_SIZE + LINEAR_PROBE; | 82 int num_entries = INITIAL_SIZE + LINEAR_PROBE; |
| 71 entries_ = zone->NewArray<Entry>(num_entries); | 83 entries_ = zone->NewArray<Entry>(num_entries); |
| 72 size_ = INITIAL_SIZE; | 84 size_ = INITIAL_SIZE; |
| 73 memset(entries_, 0, sizeof(Entry) * num_entries); | 85 memset(entries_, 0, sizeof(Entry) * num_entries); |
| 74 Entry* entry = &entries_[hash & (INITIAL_SIZE - 1)]; | 86 Entry* entry = &entries_[hash & (INITIAL_SIZE - 1)]; |
| 75 entry->key_ = key; | 87 entry->key_ = key; |
| 76 return &entry->value_; | 88 return &entry->value_; |
| 77 } | 89 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 93 } | 105 } |
| 94 | 106 |
| 95 // If resized to maximum and still didn't find space, overwrite an entry. | 107 // If resized to maximum and still didn't find space, overwrite an entry. |
| 96 Entry* entry = &entries_[hash & (size_ - 1)]; | 108 Entry* entry = &entries_[hash & (size_ - 1)]; |
| 97 entry->key_ = key; | 109 entry->key_ = key; |
| 98 entry->value_ = NULL; | 110 entry->value_ = NULL; |
| 99 return &entry->value_; | 111 return &entry->value_; |
| 100 } | 112 } |
| 101 | 113 |
| 102 | 114 |
| 115 template class NodeCache<int64_t>; |
| 103 template class NodeCache<int32_t>; | 116 template class NodeCache<int32_t>; |
| 104 template class NodeCache<int64_t>; | 117 template class NodeCache<void*>; |
| 105 | 118 } |
| 106 } // namespace compiler | 119 } |
| 107 } // namespace internal | 120 } // namespace v8::internal::compiler |
| 108 } // namespace v8 | |
| OLD | NEW |