OLD | NEW |
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 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 } | 673 } |
674 }; | 674 }; |
675 | 675 |
676 | 676 |
677 // Compare 8bit/16bit chars to 8bit/16bit chars. | 677 // Compare 8bit/16bit chars to 8bit/16bit chars. |
678 template <typename lchar, typename rchar> | 678 template <typename lchar, typename rchar> |
679 inline int CompareCharsUnsigned(const lchar* lhs, | 679 inline int CompareCharsUnsigned(const lchar* lhs, |
680 const rchar* rhs, | 680 const rchar* rhs, |
681 int chars) { | 681 int chars) { |
682 const lchar* limit = lhs + chars; | 682 const lchar* limit = lhs + chars; |
683 #ifdef V8_HOST_CAN_READ_UNALIGNED | |
684 if (sizeof(*lhs) == sizeof(*rhs)) { | 683 if (sizeof(*lhs) == sizeof(*rhs)) { |
685 // Number of characters in a uintptr_t. | 684 return memcmp(lhs, rhs, sizeof(*lhs) * chars); |
686 static const int kStepSize = sizeof(uintptr_t) / sizeof(*lhs); // NOLINT | |
687 while (lhs <= limit - kStepSize) { | |
688 if (*reinterpret_cast<const uintptr_t*>(lhs) != | |
689 *reinterpret_cast<const uintptr_t*>(rhs)) { | |
690 break; | |
691 } | |
692 lhs += kStepSize; | |
693 rhs += kStepSize; | |
694 } | |
695 } | 685 } |
696 #endif | |
697 while (lhs < limit) { | 686 while (lhs < limit) { |
698 int r = static_cast<int>(*lhs) - static_cast<int>(*rhs); | 687 int r = static_cast<int>(*lhs) - static_cast<int>(*rhs); |
699 if (r != 0) return r; | 688 if (r != 0) return r; |
700 ++lhs; | 689 ++lhs; |
701 ++rhs; | 690 ++rhs; |
702 } | 691 } |
703 return 0; | 692 return 0; |
704 } | 693 } |
705 | 694 |
706 template<typename lchar, typename rchar> | 695 template<typename lchar, typename rchar> |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 CopyCharsUnsigned(reinterpret_cast<uint16_t*>(dest), | 1268 CopyCharsUnsigned(reinterpret_cast<uint16_t*>(dest), |
1280 reinterpret_cast<const uint16_t*>(src), | 1269 reinterpret_cast<const uint16_t*>(src), |
1281 chars); | 1270 chars); |
1282 } | 1271 } |
1283 } | 1272 } |
1284 } | 1273 } |
1285 | 1274 |
1286 template <typename sourcechar, typename sinkchar> | 1275 template <typename sourcechar, typename sinkchar> |
1287 void CopyCharsUnsigned(sinkchar* dest, const sourcechar* src, int chars) { | 1276 void CopyCharsUnsigned(sinkchar* dest, const sourcechar* src, int chars) { |
1288 sinkchar* limit = dest + chars; | 1277 sinkchar* limit = dest + chars; |
1289 #ifdef V8_HOST_CAN_READ_UNALIGNED | |
1290 if ((sizeof(*dest) == sizeof(*src)) && | 1278 if ((sizeof(*dest) == sizeof(*src)) && |
1291 (chars >= static_cast<int>(kMinComplexMemCopy / sizeof(*dest)))) { | 1279 (chars >= static_cast<int>(kMinComplexMemCopy / sizeof(*dest)))) { |
1292 MemCopy(dest, src, chars * sizeof(*dest)); | 1280 MemCopy(dest, src, chars * sizeof(*dest)); |
1293 return; | 1281 } else { |
1294 } | 1282 while (dest < limit) *dest++ = static_cast<sinkchar>(*src++); |
1295 #endif | |
1296 while (dest < limit) { | |
1297 *dest++ = static_cast<sinkchar>(*src++); | |
1298 } | 1283 } |
1299 } | 1284 } |
1300 | 1285 |
1301 | 1286 |
1302 #if defined(V8_HOST_ARCH_ARM) | 1287 #if defined(V8_HOST_ARCH_ARM) |
1303 void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, int chars) { | 1288 void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, int chars) { |
1304 switch (static_cast<unsigned>(chars)) { | 1289 switch (static_cast<unsigned>(chars)) { |
1305 case 0: | 1290 case 0: |
1306 break; | 1291 break; |
1307 case 1: | 1292 case 1: |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 // Takes the address of the limit variable in order to find out where | 1452 // Takes the address of the limit variable in order to find out where |
1468 // the top of stack is right now. | 1453 // the top of stack is right now. |
1469 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit); | 1454 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit); |
1470 return limit; | 1455 return limit; |
1471 } | 1456 } |
1472 | 1457 |
1473 } // namespace internal | 1458 } // namespace internal |
1474 } // namespace v8 | 1459 } // namespace v8 |
1475 | 1460 |
1476 #endif // V8_UTILS_H_ | 1461 #endif // V8_UTILS_H_ |
OLD | NEW |