Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: src/utils.h

Issue 1581223002: MIPS: Fix unaligned read/write operations in wasm. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/wasm/ast-decoder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | src/wasm/ast-decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698