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

Unified Diff: src/utils.h

Issue 2083523002: Reland of "Implement WASM big-endian support". (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase to master Created 4 years, 6 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 | « src/compiler/wasm-compiler.cc ('k') | src/wasm/decoder.h » ('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 9b94a2feb1de6a7e9fcc8910ec3008e93f4a3bca..8e5ddf8896c7956f0f53f3511297bf8e568f06e8 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -1506,22 +1506,22 @@ inline uintptr_t GetCurrentStackPosition() {
template <typename V>
static inline V ReadUnalignedValue(const void* p) {
-#if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64)
+#if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM)
return *reinterpret_cast<const V*>(p);
-#else
+#else // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM
V r;
memmove(&r, p, sizeof(V));
return r;
-#endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64
+#endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM
}
template <typename V>
static inline void WriteUnalignedValue(void* p, V value) {
-#if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64)
+#if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM)
*(reinterpret_cast<V*>(p)) = value;
-#else // V8_TARGET_ARCH_MIPS
+#else // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM
memmove(p, &value, sizeof(V));
-#endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64
+#endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM
}
static inline double ReadFloatValue(const void* p) {
@@ -1552,6 +1552,33 @@ static inline void WriteUnalignedUInt32(void* p, uint32_t value) {
WriteUnalignedValue(p, value);
}
+template <typename V>
+static inline V ReadLittleEndianValue(const void* p) {
+#if defined(V8_TARGET_LITTLE_ENDIAN)
+ return ReadUnalignedValue<V>(p);
+#elif defined(V8_TARGET_BIG_ENDIAN)
+ V ret = 0;
+ const byte* src = reinterpret_cast<const byte*>(p);
+ byte* dst = reinterpret_cast<byte*>(&ret);
+ for (size_t i = 0; i < sizeof(V); i++) {
+ dst[i] = src[sizeof(V) - i - 1];
+ }
+ return ret;
+#endif // V8_TARGET_LITTLE_ENDIAN
+}
+
+template <typename V>
+static inline void WriteLittleEndianValue(void* p, V value) {
+#if defined(V8_TARGET_LITTLE_ENDIAN)
+ WriteUnalignedValue<V>(p, value);
+#elif defined(V8_TARGET_BIG_ENDIAN)
+ byte* src = reinterpret_cast<byte*>(&value);
+ byte* dst = reinterpret_cast<byte*>(p);
+ for (size_t i = 0; i < sizeof(V); i++) {
+ dst[i] = src[sizeof(V) - i - 1];
+ }
+#endif // V8_TARGET_LITTLE_ENDIAN
+}
} // namespace internal
} // namespace v8
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/wasm/decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698