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 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 INLINE(static void CopyCharsUnsigned(sinkchar* dest, | 1317 INLINE(static void CopyCharsUnsigned(sinkchar* dest, |
1318 const sourcechar* src, | 1318 const sourcechar* src, |
1319 int chars)); | 1319 int chars)); |
1320 #if defined(V8_HOST_ARCH_ARM) | 1320 #if defined(V8_HOST_ARCH_ARM) |
1321 INLINE(void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, int chars)); | 1321 INLINE(void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, int chars)); |
1322 INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint8_t* src, int chars)); | 1322 INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint8_t* src, int chars)); |
1323 INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, int chars)); | 1323 INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, int chars)); |
1324 #elif defined(V8_HOST_ARCH_MIPS) | 1324 #elif defined(V8_HOST_ARCH_MIPS) |
1325 INLINE(void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, int chars)); | 1325 INLINE(void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, int chars)); |
1326 INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, int chars)); | 1326 INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, int chars)); |
| 1327 #elif defined(V8_HOST_ARCH_PPC) |
| 1328 INLINE(void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, int chars)); |
| 1329 INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, int chars)); |
1327 #endif | 1330 #endif |
1328 | 1331 |
1329 // Copy from 8bit/16bit chars to 8bit/16bit chars. | 1332 // Copy from 8bit/16bit chars to 8bit/16bit chars. |
1330 template <typename sourcechar, typename sinkchar> | 1333 template <typename sourcechar, typename sinkchar> |
1331 INLINE(void CopyChars(sinkchar* dest, const sourcechar* src, int chars)); | 1334 INLINE(void CopyChars(sinkchar* dest, const sourcechar* src, int chars)); |
1332 | 1335 |
1333 template<typename sourcechar, typename sinkchar> | 1336 template<typename sourcechar, typename sinkchar> |
1334 void CopyChars(sinkchar* dest, const sourcechar* src, int chars) { | 1337 void CopyChars(sinkchar* dest, const sourcechar* src, int chars) { |
1335 DCHECK(sizeof(sourcechar) <= 2); | 1338 DCHECK(sizeof(sourcechar) <= 2); |
1336 DCHECK(sizeof(sinkchar) <= 2); | 1339 DCHECK(sizeof(sinkchar) <= 2); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1476 } | 1479 } |
1477 } | 1480 } |
1478 | 1481 |
1479 void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, int chars) { | 1482 void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, int chars) { |
1480 if (chars < kMinComplexMemCopy) { | 1483 if (chars < kMinComplexMemCopy) { |
1481 memcpy(dest, src, chars * sizeof(*dest)); | 1484 memcpy(dest, src, chars * sizeof(*dest)); |
1482 } else { | 1485 } else { |
1483 MemCopy(dest, src, chars * sizeof(*dest)); | 1486 MemCopy(dest, src, chars * sizeof(*dest)); |
1484 } | 1487 } |
1485 } | 1488 } |
| 1489 #elif defined(V8_HOST_ARCH_PPC) |
| 1490 #define CASE(n) \ |
| 1491 case n: \ |
| 1492 memcpy(dest, src, n); \ |
| 1493 break |
| 1494 void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, int chars) { |
| 1495 switch (static_cast<unsigned>(chars)) { |
| 1496 case 0: |
| 1497 break; |
| 1498 case 1: |
| 1499 *dest = *src; |
| 1500 break; |
| 1501 CASE(2); |
| 1502 CASE(3); |
| 1503 CASE(4); |
| 1504 CASE(5); |
| 1505 CASE(6); |
| 1506 CASE(7); |
| 1507 CASE(8); |
| 1508 CASE(9); |
| 1509 CASE(10); |
| 1510 CASE(11); |
| 1511 CASE(12); |
| 1512 CASE(13); |
| 1513 CASE(14); |
| 1514 CASE(15); |
| 1515 CASE(16); |
| 1516 CASE(17); |
| 1517 CASE(18); |
| 1518 CASE(19); |
| 1519 CASE(20); |
| 1520 CASE(21); |
| 1521 CASE(22); |
| 1522 CASE(23); |
| 1523 CASE(24); |
| 1524 CASE(25); |
| 1525 CASE(26); |
| 1526 CASE(27); |
| 1527 CASE(28); |
| 1528 CASE(29); |
| 1529 CASE(30); |
| 1530 CASE(31); |
| 1531 CASE(32); |
| 1532 CASE(33); |
| 1533 CASE(34); |
| 1534 CASE(35); |
| 1535 CASE(36); |
| 1536 CASE(37); |
| 1537 CASE(38); |
| 1538 CASE(39); |
| 1539 CASE(40); |
| 1540 CASE(41); |
| 1541 CASE(42); |
| 1542 CASE(43); |
| 1543 CASE(44); |
| 1544 CASE(45); |
| 1545 CASE(46); |
| 1546 CASE(47); |
| 1547 CASE(48); |
| 1548 CASE(49); |
| 1549 CASE(50); |
| 1550 CASE(51); |
| 1551 CASE(52); |
| 1552 CASE(53); |
| 1553 CASE(54); |
| 1554 CASE(55); |
| 1555 CASE(56); |
| 1556 CASE(57); |
| 1557 CASE(58); |
| 1558 CASE(59); |
| 1559 CASE(60); |
| 1560 CASE(61); |
| 1561 CASE(62); |
| 1562 CASE(63); |
| 1563 CASE(64); |
| 1564 default: |
| 1565 memcpy(dest, src, chars); |
| 1566 break; |
| 1567 } |
| 1568 } |
| 1569 #undef CASE |
| 1570 |
| 1571 #define CASE(n) \ |
| 1572 case n: \ |
| 1573 memcpy(dest, src, n * 2); \ |
| 1574 break |
| 1575 void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, int chars) { |
| 1576 switch (static_cast<unsigned>(chars)) { |
| 1577 case 0: |
| 1578 break; |
| 1579 case 1: |
| 1580 *dest = *src; |
| 1581 break; |
| 1582 CASE(2); |
| 1583 CASE(3); |
| 1584 CASE(4); |
| 1585 CASE(5); |
| 1586 CASE(6); |
| 1587 CASE(7); |
| 1588 CASE(8); |
| 1589 CASE(9); |
| 1590 CASE(10); |
| 1591 CASE(11); |
| 1592 CASE(12); |
| 1593 CASE(13); |
| 1594 CASE(14); |
| 1595 CASE(15); |
| 1596 CASE(16); |
| 1597 CASE(17); |
| 1598 CASE(18); |
| 1599 CASE(19); |
| 1600 CASE(20); |
| 1601 CASE(21); |
| 1602 CASE(22); |
| 1603 CASE(23); |
| 1604 CASE(24); |
| 1605 CASE(25); |
| 1606 CASE(26); |
| 1607 CASE(27); |
| 1608 CASE(28); |
| 1609 CASE(29); |
| 1610 CASE(30); |
| 1611 CASE(31); |
| 1612 CASE(32); |
| 1613 default: |
| 1614 memcpy(dest, src, chars * 2); |
| 1615 break; |
| 1616 } |
| 1617 } |
| 1618 #undef CASE |
1486 #endif | 1619 #endif |
1487 | 1620 |
1488 | 1621 |
1489 class StringBuilder : public SimpleStringBuilder { | 1622 class StringBuilder : public SimpleStringBuilder { |
1490 public: | 1623 public: |
1491 explicit StringBuilder(int size) : SimpleStringBuilder(size) { } | 1624 explicit StringBuilder(int size) : SimpleStringBuilder(size) { } |
1492 StringBuilder(char* buffer, int size) : SimpleStringBuilder(buffer, size) { } | 1625 StringBuilder(char* buffer, int size) : SimpleStringBuilder(buffer, size) { } |
1493 | 1626 |
1494 // Add formatted contents to the builder just like printf(). | 1627 // Add formatted contents to the builder just like printf(). |
1495 void AddFormatted(const char* format, ...); | 1628 void AddFormatted(const char* format, ...); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1537 // Takes the address of the limit variable in order to find out where | 1670 // Takes the address of the limit variable in order to find out where |
1538 // the top of stack is right now. | 1671 // the top of stack is right now. |
1539 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit); | 1672 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit); |
1540 return limit; | 1673 return limit; |
1541 } | 1674 } |
1542 | 1675 |
1543 } // namespace internal | 1676 } // namespace internal |
1544 } // namespace v8 | 1677 } // namespace v8 |
1545 | 1678 |
1546 #endif // V8_UTILS_H_ | 1679 #endif // V8_UTILS_H_ |
OLD | NEW |