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