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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 case 5: | 220 case 5: |
221 case 6: | 221 case 6: |
222 case 7: | 222 case 7: |
223 case 8: { | 223 case 8: { |
224 uint32_t part1 = *reinterpret_cast<const uint32_t*>(src); | 224 uint32_t part1 = *reinterpret_cast<const uint32_t*>(src); |
225 uint32_t part2 = *reinterpret_cast<const uint32_t*>(src + num_bytes - 4); | 225 uint32_t part2 = *reinterpret_cast<const uint32_t*>(src + num_bytes - 4); |
226 *reinterpret_cast<uint32_t*>(dst) = part1; | 226 *reinterpret_cast<uint32_t*>(dst) = part1; |
227 *reinterpret_cast<uint32_t*>(dst + num_bytes - 4) = part2; | 227 *reinterpret_cast<uint32_t*>(dst + num_bytes - 4) = part2; |
228 return; | 228 return; |
229 } | 229 } |
| 230 #ifdef V8_TARGET_ARCH_ARM |
230 case 9: | 231 case 9: |
231 case 10: | 232 case 10: |
232 case 11: | 233 case 11: |
| 234 case 12: { |
| 235 uint32_t part1 = *reinterpret_cast<const uint32_t*>(src); |
| 236 uint32_t part2 = *reinterpret_cast<const uint32_t*>(src + 4); |
| 237 uint32_t part3 = *reinterpret_cast<const uint32_t*>(src + num_bytes - 4); |
| 238 *reinterpret_cast<uint32_t*>(dst) = part1; |
| 239 *reinterpret_cast<uint32_t*>(dst + 4) = part2; |
| 240 *reinterpret_cast<uint32_t*>(dst + num_bytes - 4) = part3; |
| 241 return; |
| 242 } |
| 243 case 13: |
| 244 case 14: |
| 245 case 15: |
| 246 case 16: { |
| 247 uint32_t part1 = *reinterpret_cast<const uint32_t*>(src); |
| 248 uint32_t part2 = *reinterpret_cast<const uint32_t*>(src + 4); |
| 249 uint32_t part3 = *reinterpret_cast<const uint32_t*>(src + 8); |
| 250 uint32_t part4 = *reinterpret_cast<const uint32_t*>(src + num_bytes - 4); |
| 251 *reinterpret_cast<uint32_t*>(dst) = part1; |
| 252 *reinterpret_cast<uint32_t*>(dst + 4) = part2; |
| 253 *reinterpret_cast<uint32_t*>(dst + 8) = part3; |
| 254 *reinterpret_cast<uint32_t*>(dst + num_bytes - 4) = part4; |
| 255 return; |
| 256 } |
| 257 #else |
| 258 case 9: |
| 259 case 10: |
| 260 case 11: |
233 case 12: | 261 case 12: |
234 case 13: | 262 case 13: |
235 case 14: | 263 case 14: |
236 case 15: | 264 case 15: |
237 case 16: { | 265 case 16: { |
238 double part1 = *reinterpret_cast<const double*>(src); | 266 double part1 = *reinterpret_cast<const double*>(src); |
239 double part2 = *reinterpret_cast<const double*>(src + num_bytes - 8); | 267 double part2 = *reinterpret_cast<const double*>(src + num_bytes - 8); |
240 *reinterpret_cast<double*>(dst) = part1; | 268 *reinterpret_cast<double*>(dst) = part1; |
241 *reinterpret_cast<double*>(dst + num_bytes - 8) = part2; | 269 *reinterpret_cast<double*>(dst + num_bytes - 8) = part2; |
242 return; | 270 return; |
243 } | 271 } |
244 #endif | 272 #endif |
| 273 #endif |
245 default: | 274 default: |
246 OS::MemMove(dst, src, num_bytes); | 275 OS::MemMove(dst, src, num_bytes); |
247 return; | 276 return; |
248 } | 277 } |
249 } | 278 } |
250 | 279 |
251 | 280 |
252 template <typename T, typename U> | 281 template <typename T, typename U> |
253 inline void MemsetPointer(T** dest, U* value, int counter) { | 282 inline void MemsetPointer(T** dest, U* value, int counter) { |
254 #ifdef DEBUG | 283 #ifdef DEBUG |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 bool verbose = true); | 339 bool verbose = true); |
311 Vector<const char> ReadFile(FILE* file, | 340 Vector<const char> ReadFile(FILE* file, |
312 bool* exists, | 341 bool* exists, |
313 bool verbose = true); | 342 bool verbose = true); |
314 | 343 |
315 | 344 |
316 template <typename sourcechar, typename sinkchar> | 345 template <typename sourcechar, typename sinkchar> |
317 INLINE(static void CopyCharsUnsigned(sinkchar* dest, | 346 INLINE(static void CopyCharsUnsigned(sinkchar* dest, |
318 const sourcechar* src, | 347 const sourcechar* src, |
319 int chars)); | 348 int chars)); |
| 349 #if defined(V8_HOST_ARCH_ARM) && defined (V8_HOST_CAN_READ_UNALIGNED) |
| 350 INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint8_t* src, int chars)); |
| 351 #endif |
320 | 352 |
321 // Copy from ASCII/16bit chars to ASCII/16bit chars. | 353 // Copy from ASCII/16bit chars to ASCII/16bit chars. |
322 template <typename sourcechar, typename sinkchar> | 354 template <typename sourcechar, typename sinkchar> |
323 INLINE(void CopyChars(sinkchar* dest, const sourcechar* src, int chars)); | 355 INLINE(void CopyChars(sinkchar* dest, const sourcechar* src, int chars)); |
324 | 356 |
325 template<typename sourcechar, typename sinkchar> | 357 template<typename sourcechar, typename sinkchar> |
326 void CopyChars(sinkchar* dest, const sourcechar* src, int chars) { | 358 void CopyChars(sinkchar* dest, const sourcechar* src, int chars) { |
327 ASSERT(sizeof(sourcechar) <= 2); | 359 ASSERT(sizeof(sourcechar) <= 2); |
328 ASSERT(sizeof(sinkchar) <= 2); | 360 ASSERT(sizeof(sinkchar) <= 2); |
329 if (sizeof(sinkchar) == 1) { | 361 if (sizeof(sinkchar) == 1) { |
(...skipping 14 matching lines...) Expand all Loading... |
344 } else { | 376 } else { |
345 CopyCharsUnsigned(reinterpret_cast<uint16_t*>(dest), | 377 CopyCharsUnsigned(reinterpret_cast<uint16_t*>(dest), |
346 reinterpret_cast<const uint16_t*>(src), | 378 reinterpret_cast<const uint16_t*>(src), |
347 chars); | 379 chars); |
348 } | 380 } |
349 } | 381 } |
350 } | 382 } |
351 | 383 |
352 template <typename sourcechar, typename sinkchar> | 384 template <typename sourcechar, typename sinkchar> |
353 void CopyCharsUnsigned(sinkchar* dest, const sourcechar* src, int chars) { | 385 void CopyCharsUnsigned(sinkchar* dest, const sourcechar* src, int chars) { |
354 sinkchar* limit = dest + chars; | |
355 #ifdef V8_HOST_CAN_READ_UNALIGNED | 386 #ifdef V8_HOST_CAN_READ_UNALIGNED |
356 if (sizeof(*dest) == sizeof(*src)) { | 387 if (sizeof(*dest) == sizeof(*src)) { |
357 if (chars >= static_cast<int>(OS::kMinComplexMemCopy / sizeof(*dest))) { | 388 if (chars >= static_cast<int>(OS::kMinComplexMemCopy / sizeof(*dest))) { |
358 OS::MemCopy(dest, src, chars * sizeof(*dest)); | 389 OS::MemCopy(dest, src, chars * sizeof(*dest)); |
359 return; | 390 return; |
360 } | 391 } |
| 392 sinkchar* limit = dest + chars; |
361 // Number of characters in a uintptr_t. | 393 // Number of characters in a uintptr_t. |
362 static const int kStepSize = sizeof(uintptr_t) / sizeof(*dest); // NOLINT | 394 static const int kStepSize = sizeof(uintptr_t) / sizeof(*dest); // NOLINT |
363 ASSERT(dest + kStepSize > dest); // Check for overflow. | 395 if (chars >= kStepSize) { |
364 while (dest + kStepSize <= limit) { | 396 sinkchar* limit2 = limit - kStepSize; |
365 *reinterpret_cast<uintptr_t*>(dest) = | 397 while (dest <= limit2) { |
366 *reinterpret_cast<const uintptr_t*>(src); | 398 *reinterpret_cast<uintptr_t*>(dest) = |
367 dest += kStepSize; | 399 *reinterpret_cast<const uintptr_t*>(src); |
368 src += kStepSize; | 400 dest += kStepSize; |
| 401 src += kStepSize; |
| 402 } |
369 } | 403 } |
| 404 while (dest < limit) { |
| 405 *dest++ = static_cast<sinkchar>(*src++); |
| 406 } |
| 407 return; |
370 } | 408 } |
371 #endif | 409 #endif |
| 410 sinkchar* limit = dest + chars; |
372 while (dest < limit) { | 411 while (dest < limit) { |
373 *dest++ = static_cast<sinkchar>(*src++); | 412 *dest++ = static_cast<sinkchar>(*src++); |
374 } | 413 } |
375 } | 414 } |
376 | 415 |
377 | 416 |
| 417 #if defined(V8_HOST_ARCH_ARM) && defined (V8_HOST_CAN_READ_UNALIGNED) |
| 418 void CopyCharsUnsigned(uint16_t* dest, const uint8_t* src, int chars) { |
| 419 if (chars >= OS::kMinComplexConvertMemCopy) { |
| 420 OS::MemCopyUint16Uint8(dest, src, chars); |
| 421 } else { |
| 422 OS::MemCopyUint16Uint8Wrapper(dest, src, chars); |
| 423 } |
| 424 } |
| 425 #endif |
| 426 |
| 427 |
378 class StringBuilder : public SimpleStringBuilder { | 428 class StringBuilder : public SimpleStringBuilder { |
379 public: | 429 public: |
380 explicit StringBuilder(int size) : SimpleStringBuilder(size) { } | 430 explicit StringBuilder(int size) : SimpleStringBuilder(size) { } |
381 StringBuilder(char* buffer, int size) : SimpleStringBuilder(buffer, size) { } | 431 StringBuilder(char* buffer, int size) : SimpleStringBuilder(buffer, size) { } |
382 | 432 |
383 // Add formatted contents to the builder just like printf(). | 433 // Add formatted contents to the builder just like printf(). |
384 void AddFormatted(const char* format, ...); | 434 void AddFormatted(const char* format, ...); |
385 | 435 |
386 // Add formatted contents like printf based on a va_list. | 436 // Add formatted contents like printf based on a va_list. |
387 void AddFormattedList(const char* format, va_list list); | 437 void AddFormattedList(const char* format, va_list list); |
388 private: | 438 private: |
389 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); | 439 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); |
390 }; | 440 }; |
391 | 441 |
392 } } // namespace v8::internal | 442 } } // namespace v8::internal |
393 | 443 |
394 #endif // V8_V8UTILS_H_ | 444 #endif // V8_V8UTILS_H_ |
OLD | NEW |