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 1534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 } | 1545 } |
1546 | 1546 |
1547 static inline uint32_t ReadUnalignedUInt32(const void* p) { | 1547 static inline uint32_t ReadUnalignedUInt32(const void* p) { |
1548 return ReadUnalignedValue<uint32_t>(p); | 1548 return ReadUnalignedValue<uint32_t>(p); |
1549 } | 1549 } |
1550 | 1550 |
1551 static inline void WriteUnalignedUInt32(void* p, uint32_t value) { | 1551 static inline void WriteUnalignedUInt32(void* p, uint32_t value) { |
1552 WriteUnalignedValue(p, value); | 1552 WriteUnalignedValue(p, value); |
1553 } | 1553 } |
1554 | 1554 |
| 1555 template <typename V> |
| 1556 static inline V ReadLittleEndianValue(const void* p) { |
| 1557 #if defined(V8_TARGET_LITTLE_ENDIAN) |
| 1558 return ReadUnalignedValue<V>(p); |
| 1559 #elif defined(V8_TARGET_BIG_ENDIAN) |
| 1560 V ret = 0; |
| 1561 const byte* src = reinterpret_cast<const byte*>(p); |
| 1562 byte* dst = reinterpret_cast<byte*>(&ret); |
| 1563 for (size_t i = 0; i < sizeof(V); i++) { |
| 1564 dst[i] = src[sizeof(V) - i - 1]; |
| 1565 } |
| 1566 return ret; |
| 1567 #endif // V8_TARGET_LITTLE_ENDIAN |
| 1568 } |
| 1569 |
| 1570 template <typename V> |
| 1571 static inline void WriteLittleEndianValue(void* p, V value) { |
| 1572 #if defined(V8_TARGET_LITTLE_ENDIAN) |
| 1573 WriteUnalignedValue<V>(p, value); |
| 1574 #elif defined(V8_TARGET_BIG_ENDIAN) |
| 1575 byte* src = reinterpret_cast<byte*>(&value); |
| 1576 byte* dst = reinterpret_cast<byte*>(p); |
| 1577 for (size_t i = 0; i < sizeof(V); i++) { |
| 1578 dst[i] = src[sizeof(V) - i - 1]; |
| 1579 } |
| 1580 #endif // V8_TARGET_LITTLE_ENDIAN |
| 1581 } |
1555 } // namespace internal | 1582 } // namespace internal |
1556 } // namespace v8 | 1583 } // namespace v8 |
1557 | 1584 |
1558 #endif // V8_UTILS_H_ | 1585 #endif // V8_UTILS_H_ |
OLD | NEW |