Chromium Code Reviews| Index: src/utils.h |
| diff --git a/src/utils.h b/src/utils.h |
| index b16730b8c46d750c1e264ad07713868c2b32d804..50af2597c7d00866f57da223a086f3acda35dddb 100644 |
| --- a/src/utils.h |
| +++ b/src/utils.h |
| @@ -246,6 +246,46 @@ inline int StrLength(const char* string) { |
| } |
| +template <typename T> |
| +inline void Swizzle(T* value) { |
| + char* start = reinterpret_cast<char*>(value); |
| + char* end = start + sizeof(*value) - 1; |
| + while (start < end) { |
| + char t = *start; |
| + *start++ = *end; |
| + *end-- = t; |
| + } |
| +} |
| + |
| + |
| +enum Endianness { |
| + kLittleEndian, // _Not_ LITTLE_ENDIAN, clashes with endian.h. |
| + kBigEndian |
| +}; |
| + |
| + |
| +inline enum Endianness GetEndianness() { |
|
Dmitry Lomov (no reviews)
2013/06/03 13:09:04
This belongs to cpu.h. Should be a #define with po
bnoordhuis
2013/06/03 13:48:12
I'll move it but is turning it into a macro necess
Dmitry Lomov (no reviews)
2013/06/03 14:42:49
Explicitly define expected endianness using V8_TAR
|
| + // Constant-folded by the compiler. |
| + const union { |
| + uint8_t u8[2]; |
| + uint16_t u16; |
| + } u = { |
| + { 1, 0 } |
| + }; |
| + return u.u16 == 1 ? kLittleEndian : kBigEndian; |
| +} |
| + |
| + |
| +inline bool IsLittleEndian() { |
| + return GetEndianness() == kLittleEndian; |
| +} |
| + |
| + |
| +inline bool IsBigEndian() { |
| + return GetEndianness() == kBigEndian; |
| +} |
| + |
| + |
| // ---------------------------------------------------------------------------- |
| // BitField is a help template for encoding and decode bitfield with |
| // unsigned content. |