OLD | NEW |
---|---|
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 private: | 518 private: |
519 Vector<char> buffer_; | 519 Vector<char> buffer_; |
520 int position_; | 520 int position_; |
521 | 521 |
522 bool is_finalized() const { return position_ < 0; } | 522 bool is_finalized() const { return position_ < 0; } |
523 | 523 |
524 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); | 524 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); |
525 }; | 525 }; |
526 | 526 |
527 | 527 |
528 // Custom memcpy implementation for platforms where the standard version | |
529 // may not be good enough. | |
530 // TODO(lrn): Check whether some IA32 platforms should be excluded. | |
531 #if defined(V8_TARGET_ARCH_IA32) | |
532 | |
533 // TODO(lrn): Extend to other platforms as needed, especially X64. | |
Erik Corry
2010/06/04 07:07:40
I resent that "especially x64"!
Lasse Reichstein
2010/06/04 11:52:13
You think it's more needed on ARM than on X64? :P
| |
534 | |
535 typedef void (*MemCopyFunction)(void* dest, const void* src, size_t size); | |
536 | |
537 // Implemented in codegen-<arch>.cc. | |
538 MemCopyFunction CreateMemCopyFunction(); | |
539 | |
540 // Copy memory area to disjoint memory area. | |
541 static inline void MemCopy(void* dest, const void* src, size_t size) { | |
542 static MemCopyFunction memcopy = CreateMemCopyFunction(); | |
543 (*memcopy)(dest, src, size); | |
544 } | |
545 | |
546 | |
547 // Limit below which the extra overhead of the MemCopy function is likely | |
548 // to outweigh the benefits of faster copying. | |
549 // TODO(lrn): Try to find a more precise value. | |
550 static const int kMinComplexMemCopy = 256; | |
551 | |
552 #else // V8_TARGET_ARCH_IA32 | |
553 | |
554 static inline void MemCopy(void* dest, const void* src, size_t size) { | |
555 memcpy(dest, src, size); | |
556 } | |
557 | |
558 static const int kMinComplexMemCopy = 256; | |
559 | |
560 #endif // V8_TARGET_ARCH_IA32 | |
561 | |
562 | |
528 // Copy from ASCII/16bit chars to ASCII/16bit chars. | 563 // Copy from ASCII/16bit chars to ASCII/16bit chars. |
529 template <typename sourcechar, typename sinkchar> | 564 template <typename sourcechar, typename sinkchar> |
530 static inline void CopyChars(sinkchar* dest, const sourcechar* src, int chars) { | 565 static inline void CopyChars(sinkchar* dest, const sourcechar* src, int chars) { |
531 sinkchar* limit = dest + chars; | 566 sinkchar* limit = dest + chars; |
532 #ifdef V8_HOST_CAN_READ_UNALIGNED | 567 #ifdef V8_HOST_CAN_READ_UNALIGNED |
533 if (sizeof(*dest) == sizeof(*src)) { | 568 if (sizeof(*dest) == sizeof(*src)) { |
569 if (chars >= kMinComplexMemCopy) { | |
Erik Corry
2010/06/04 07:07:40
This should surely be chars * sizeof(*dest).
Lasse Reichstein
2010/06/04 11:52:13
It would make sense to base the decision on the nu
| |
570 MemCopy(dest, src, chars * sizeof(*dest)); | |
571 return; | |
572 } | |
534 // Number of characters in a uintptr_t. | 573 // Number of characters in a uintptr_t. |
535 static const int kStepSize = sizeof(uintptr_t) / sizeof(*dest); // NOLINT | 574 static const int kStepSize = sizeof(uintptr_t) / sizeof(*dest); // NOLINT |
536 while (dest <= limit - kStepSize) { | 575 while (dest <= limit - kStepSize) { |
537 *reinterpret_cast<uintptr_t*>(dest) = | 576 *reinterpret_cast<uintptr_t*>(dest) = |
538 *reinterpret_cast<const uintptr_t*>(src); | 577 *reinterpret_cast<const uintptr_t*>(src); |
539 dest += kStepSize; | 578 dest += kStepSize; |
540 src += kStepSize; | 579 src += kStepSize; |
541 } | 580 } |
542 } | 581 } |
543 #endif | 582 #endif |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
603 // Copies data from |src| to |dst|. The data spans MUST not overlap. | 642 // Copies data from |src| to |dst|. The data spans MUST not overlap. |
604 inline void CopyWords(Object** dst, Object** src, int num_words) { | 643 inline void CopyWords(Object** dst, Object** src, int num_words) { |
605 ASSERT(Min(dst, src) + num_words <= Max(dst, src)); | 644 ASSERT(Min(dst, src) + num_words <= Max(dst, src)); |
606 ASSERT(num_words > 0); | 645 ASSERT(num_words > 0); |
607 | 646 |
608 // Use block copying memcpy if the segment we're copying is | 647 // Use block copying memcpy if the segment we're copying is |
609 // enough to justify the extra call/setup overhead. | 648 // enough to justify the extra call/setup overhead. |
610 static const int kBlockCopyLimit = 16; | 649 static const int kBlockCopyLimit = 16; |
611 | 650 |
612 if (num_words >= kBlockCopyLimit) { | 651 if (num_words >= kBlockCopyLimit) { |
613 memcpy(dst, src, num_words * kPointerSize); | 652 memcpy(dst, src, num_words * kPointerSize); |
antonm
2010/06/03 13:51:21
may I ask you to switch to your MemCpy here as wel
| |
614 } else { | 653 } else { |
615 int remaining = num_words; | 654 int remaining = num_words; |
616 do { | 655 do { |
617 remaining--; | 656 remaining--; |
618 *dst++ = *src++; | 657 *dst++ = *src++; |
619 } while (remaining > 0); | 658 } while (remaining > 0); |
620 } | 659 } |
621 } | 660 } |
622 | 661 |
623 | 662 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 | 696 |
658 Dest dest; | 697 Dest dest; |
659 memcpy(&dest, &source, sizeof(dest)); | 698 memcpy(&dest, &source, sizeof(dest)); |
660 return dest; | 699 return dest; |
661 } | 700 } |
662 | 701 |
663 } } // namespace v8::internal | 702 } } // namespace v8::internal |
664 | 703 |
665 | 704 |
666 #endif // V8_UTILS_H_ | 705 #endif // V8_UTILS_H_ |
OLD | NEW |