OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 inline Vector< Handle<Object> > HandleVector(v8::internal::Handle<T>* elms, | 118 inline Vector< Handle<Object> > HandleVector(v8::internal::Handle<T>* elms, |
119 int length) { | 119 int length) { |
120 return Vector< Handle<Object> >( | 120 return Vector< Handle<Object> >( |
121 reinterpret_cast<v8::internal::Handle<Object>*>(elms), length); | 121 reinterpret_cast<v8::internal::Handle<Object>*>(elms), length); |
122 } | 122 } |
123 | 123 |
124 | 124 |
125 // ---------------------------------------------------------------------------- | 125 // ---------------------------------------------------------------------------- |
126 // Memory | 126 // Memory |
127 | 127 |
128 // Copies data from |src| to |dst|. The data spans must not overlap. | 128 // Copies words from |src| to |dst|. The data spans must not overlap. |
129 template <typename T> | 129 template <typename T> |
130 inline void CopyWords(T* dst, T* src, int num_words) { | 130 inline void CopyWords(T* dst, const T* src, size_t num_words) { |
131 STATIC_ASSERT(sizeof(T) == kPointerSize); | 131 STATIC_ASSERT(sizeof(T) == kPointerSize); |
132 ASSERT(Min(dst, src) + num_words <= Max(dst, src)); | 132 ASSERT(Min(dst, const_cast<T*>(src)) + num_words <= |
133 Max(dst, const_cast<T*>(src))); | |
133 ASSERT(num_words > 0); | 134 ASSERT(num_words > 0); |
134 | 135 |
135 // Use block copying OS::MemCopy if the segment we're copying is | 136 // Use block copying OS::MemCopy if the segment we're copying is |
136 // enough to justify the extra call/setup overhead. | 137 // enough to justify the extra call/setup overhead. |
137 static const int kBlockCopyLimit = 16; | 138 static const size_t kBlockCopyLimit = 16; |
138 STATIC_ASSERT(kBlockCopyLimit * kPointerSize >= OS::kMinComplexMemCopy); | |
139 | 139 |
140 if (num_words >= kBlockCopyLimit) { | 140 if (num_words < kBlockCopyLimit) { |
141 do { | |
142 num_words--; | |
143 *dst++ = *src++; | |
144 } while (num_words > 0); | |
145 } else { | |
141 OS::MemCopy(dst, src, num_words * kPointerSize); | 146 OS::MemCopy(dst, src, num_words * kPointerSize); |
147 } | |
148 } | |
149 | |
150 | |
151 // Copies words from |src| to |dst|. No restrictions. | |
152 template <typename T> | |
153 inline void MoveWords(T* dst, const T* src, size_t num_words) { | |
154 STATIC_ASSERT(sizeof(T) == kPointerSize); | |
155 ASSERT(num_words > 0); | |
156 | |
157 // Use block copying OS::MemCopy if the segment we're copying is | |
158 // enough to justify the extra call/setup overhead. | |
159 static const size_t kBlockCopyLimit = 16; | |
160 | |
161 if (num_words < kBlockCopyLimit && | |
162 ((dst < src) || (dst >= (src + num_words * kPointerSize)))) { | |
163 T* end = dst + num_words; | |
164 do { | |
165 num_words--; | |
166 *dst++ = *src++; | |
167 } while (num_words > 0); | |
142 } else { | 168 } else { |
143 int remaining = num_words; | 169 OS::MemMove(dst, src, num_words * kPointerSize); |
144 do { | |
145 remaining--; | |
146 *dst++ = *src++; | |
147 } while (remaining > 0); | |
148 } | 170 } |
149 } | 171 } |
150 | 172 |
151 | 173 |
152 // Copies data from |src| to |dst|. The data spans must not overlap. | 174 // Copies data from |src| to |dst|. The data spans must not overlap. |
153 template <typename T> | 175 template <typename T> |
154 inline void CopyBytes(T* dst, T* src, size_t num_bytes) { | 176 inline void CopyBytes(T* dst, const T* src, size_t num_bytes) { |
155 STATIC_ASSERT(sizeof(T) == 1); | 177 STATIC_ASSERT(sizeof(T) == 1); |
156 ASSERT(Min(dst, src) + num_bytes <= Max(dst, src)); | 178 ASSERT(Min(dst, const_cast<T*>(src)) + num_bytes <= |
179 Max(dst, const_cast<T*>(src))); | |
157 if (num_bytes == 0) return; | 180 if (num_bytes == 0) return; |
158 | 181 |
159 // Use block copying OS::MemCopy if the segment we're copying is | 182 // Use block copying OS::MemCopy if the segment we're copying is |
160 // enough to justify the extra call/setup overhead. | 183 // enough to justify the extra call/setup overhead. |
161 static const int kBlockCopyLimit = OS::kMinComplexMemCopy; | 184 static const int kBlockCopyLimit = OS::kMinComplexMemCopy; |
162 | 185 |
163 if (num_bytes >= static_cast<size_t>(kBlockCopyLimit)) { | 186 if (num_bytes >= static_cast<size_t>(kBlockCopyLimit)) { |
Michael Starzinger
2013/04/16 09:41:42
nit: Can we also flip the predicate in this condit
Jakob Kummerow
2013/04/16 12:29:42
Done.
| |
164 OS::MemCopy(dst, src, num_bytes); | 187 OS::MemCopy(dst, src, num_bytes); |
165 } else { | 188 } else { |
166 size_t remaining = num_bytes; | |
167 do { | 189 do { |
168 remaining--; | 190 num_bytes--; |
169 *dst++ = *src++; | 191 *dst++ = *src++; |
170 } while (remaining > 0); | 192 } while (num_bytes > 0); |
171 } | 193 } |
172 } | 194 } |
173 | 195 |
196 | |
197 // Copies data from |src| to |dst|. No restrictions. | |
198 template <typename T> | |
199 inline void MoveBytes(T* dst, const T* src, size_t num_bytes) { | |
200 STATIC_ASSERT(sizeof(T) == 1); | |
201 switch (num_bytes) { | |
202 case 0: return; | |
203 case 1: | |
204 *dst = *src; | |
205 return; | |
206 case 2: | |
207 *reinterpret_cast<uint16_t*>(dst) = *reinterpret_cast<const uint16_t*>(src); | |
Michael Starzinger
2013/04/16 09:41:42
On architectures that don't support unaligned acce
Jakob Kummerow
2013/04/16 12:29:42
Done.
| |
208 return; | |
209 case 3: { | |
210 uint16_t part1 = *reinterpret_cast<const uint16_t*>(src); | |
211 byte part2 = *(src + 2); | |
212 *reinterpret_cast<uint16_t*>(dst) = part1; | |
213 *(dst + 2) = part2; | |
214 return; | |
215 } | |
216 case 4: | |
217 *reinterpret_cast<uint32_t*>(dst) = *reinterpret_cast<const uint32_t*>(src); | |
218 return; | |
219 case 5: | |
220 case 6: | |
221 case 7: | |
222 case 8: { | |
223 uint32_t part1 = *reinterpret_cast<const uint32_t*>(src); | |
224 uint32_t part2 = *reinterpret_cast<const uint32_t*>(src + num_bytes - 4); | |
225 *reinterpret_cast<uint32_t*>(dst) = part1; | |
226 *reinterpret_cast<uint32_t*>(dst + num_bytes - 4) = part2; | |
227 return; | |
228 } | |
229 case 9: | |
230 case 10: | |
231 case 11: | |
232 case 12: | |
233 case 13: | |
234 case 14: | |
235 case 15: | |
236 case 16: { | |
237 double part1 = *reinterpret_cast<const double*>(src); | |
238 double part2 = *reinterpret_cast<const double*>(src + num_bytes - 8); | |
239 *reinterpret_cast<double*>(dst) = part1; | |
240 *reinterpret_cast<double*>(dst + num_bytes - 8) = part2; | |
241 return; | |
242 } | |
243 default: | |
244 OS::MemMove(dst, src, num_bytes); | |
245 return; | |
246 } | |
247 } | |
248 | |
174 | 249 |
175 template <typename T, typename U> | 250 template <typename T, typename U> |
176 inline void MemsetPointer(T** dest, U* value, int counter) { | 251 inline void MemsetPointer(T** dest, U* value, int counter) { |
177 #ifdef DEBUG | 252 #ifdef DEBUG |
178 T* a = NULL; | 253 T* a = NULL; |
179 U* b = NULL; | 254 U* b = NULL; |
180 a = b; // Fake assignment to check assignability. | 255 a = b; // Fake assignment to check assignability. |
181 USE(a); | 256 USE(a); |
182 #endif // DEBUG | 257 #endif // DEBUG |
183 #if defined(V8_HOST_ARCH_IA32) | 258 #if defined(V8_HOST_ARCH_IA32) |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 | 383 |
309 // Add formatted contents like printf based on a va_list. | 384 // Add formatted contents like printf based on a va_list. |
310 void AddFormattedList(const char* format, va_list list); | 385 void AddFormattedList(const char* format, va_list list); |
311 private: | 386 private: |
312 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); | 387 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); |
313 }; | 388 }; |
314 | 389 |
315 } } // namespace v8::internal | 390 } } // namespace v8::internal |
316 | 391 |
317 #endif // V8_V8UTILS_H_ | 392 #endif // V8_V8UTILS_H_ |
OLD | NEW |