Index: src/utils.h |
diff --git a/src/utils.h b/src/utils.h |
index 0426ce51cb7dd1ea5e49663fb4c71dcc1a6a8b2f..1fe6a3213c776251dd96121f242ef363d49f0c60 100644 |
--- a/src/utils.h |
+++ b/src/utils.h |
@@ -1734,6 +1734,42 @@ static inline void WriteDoubleValue(void* p, double value) { |
#endif // V8_TARGET_ARCH_MIPS |
} |
+ |
+static inline uint16_t ReadUnalignedUInt16(const void* p) { |
+#if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64) |
+ return *reinterpret_cast<const uint16_t*>(p); |
+#else // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 |
+ // Prevent compiler from using load-half (mips lh) on (possibly) |
+ // non-16-bit aligned address. |
+ union conversion { |
+ uint16_t h; |
+ uint8_t b[2]; |
+ } c; |
+ const uint8_t* ptr = reinterpret_cast<const uint8_t*>(p); |
+ c.b[0] = *ptr; |
+ c.b[1] = *(ptr + 1); |
+ return c.h; |
+#endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 |
+} |
+ |
+ |
+static inline void WriteUnalignedUInt16(void* p, uint16_t value) { |
+#if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64) |
+ *(reinterpret_cast<uint16_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 { |
+ uint16_t h; |
+ uint8_t b[2]; |
+ } c; |
+ c.h = value; |
+ uint8_t* ptr = reinterpret_cast<uint8_t*>(p); |
+ *ptr = c.b[0]; |
+ *(ptr + 1) = c.b[1]; |
+#endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 |
+} |
+ |
} // namespace internal |
} // namespace v8 |