Chromium Code Reviews| Index: src/utils.h |
| diff --git a/src/utils.h b/src/utils.h |
| index 1ea2d56fbfd44c4b139871bd29fd64cac104eb1d..a80d77268b9cd52b209a74d6c432a768258d2417 100644 |
| --- a/src/utils.h |
| +++ b/src/utils.h |
| @@ -1786,6 +1786,45 @@ static inline void WriteUnalignedUInt16(void* p, uint16_t value) { |
| #endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 |
| } |
| + |
| +static inline void WriteUnalignedUInt32(void* p, uint32_t value) { |
|
titzer
2016/01/19 16:00:55
Would it be enough to just do a memmove(p, &value,
ivica.bogosavljevic
2016/01/20 10:32:57
I would like to point out that the MIPS specific c
akos.palfi.imgtec
2016/01/21 21:00:22
Thanks, great idea. I've removed the unions and ha
akos.palfi.imgtec
2016/01/21 21:07:35
I think other archs support unaligned fixups in ha
|
| +#if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64) |
| + *(reinterpret_cast<uint32_t*>(p)) = value; |
| +#else // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 |
| + // Prevent compiler from using store-half (mips sh) on (possibly) |
| + // non-16-bit aligned address. |
| + union conversion { |
| + uint32_t h; |
| + uint8_t b[4]; |
| + } c; |
| + c.h = value; |
| + uint8_t* ptr = reinterpret_cast<uint8_t*>(p); |
| + *ptr = c.b[0]; |
| + *(ptr + 1) = c.b[1]; |
| + *(ptr + 2) = c.b[2]; |
| + *(ptr + 3) = c.b[3]; |
| +#endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 |
| +} |
| + |
| + |
| +template <typename V> |
| +static inline V ReadUnalignedValue(const void* p) { |
| +#if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64) |
| + return *reinterpret_cast<const V*>(p); |
| +#else |
| + union conversion { |
| + V d; |
| + uint8_t u[sizeof(V)]; |
| + } c; |
| + const uint8_t* ptr = reinterpret_cast<const uint8_t*>(p); |
| + for (int i = 0; i < sizeof(V); i++) { |
| + c.u[i] = *(ptr + i); |
| + } |
| + return c.d; |
| +#endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 |
| +} |
| + |
| + |
| } // namespace internal |
| } // namespace v8 |