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

Unified Diff: test/cctest/wasm/wasm-run-utils.h

Issue 2034093002: Implement WASM big-endian support (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add byte swapping TODO mark 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
« src/wasm/wasm-interpreter.cc ('K') | « test/cctest/wasm/test-run-wasm-64.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/wasm/wasm-run-utils.h
diff --git a/test/cctest/wasm/wasm-run-utils.h b/test/cctest/wasm/wasm-run-utils.h
index 8aa8cff940d050a7aff1ead5d5367569bcae970c..1721c97cfcefa36a3f473d0d941b9159aa3adf6c 100644
--- a/test/cctest/wasm/wasm-run-utils.h
+++ b/test/cctest/wasm/wasm-run-utils.h
@@ -147,14 +147,57 @@ class TestingModule : public ModuleEnv {
template <typename T>
T raw_mem_at(int i) {
DCHECK(instance->mem_start);
- return reinterpret_cast<T*>(instance->mem_start)[i];
+ return ReadMemory(&(reinterpret_cast<T*>(instance->mem_start)[i]));
}
template <typename T>
T raw_val_at(int i) {
- T val;
- memcpy(&val, reinterpret_cast<void*>(instance->mem_start + i), sizeof(T));
- return val;
+ return ReadMemory(reinterpret_cast<T*>(instance->mem_start + i));
+ }
+
+ template <typename T>
+ void WriteMemory(T* p, T val) {
titzer 2016/06/06 07:44:00 Can we unify these routines with the others?
ivica.bogosavljevic 2016/06/13 14:59:02 We could use ReadLittleEndianValue and WriteLittle
+#if defined(V8_TARGET_LITTLE_ENDIAN)
+ memcpy(p, &val, sizeof(T));
+#elif defined(V8_TARGET_BIG_ENDIAN)
+ byte* src = reinterpret_cast<byte*>(&val);
+ byte* dst = reinterpret_cast<byte*>(p);
+ for (int i = 0; i < sizeof(T); i++) {
+ dst[i] = src[sizeof(T) - i - 1];
+ }
+#else
+#error Unsupported endianness
+#endif
ivica.bogosavljevic 2016/06/13 14:59:02 For myself: Commented code, needs to be removed
+ // byte * tmp = reinterpret_cast<byte*>(p);
+ // T v = val;
+ // for (int i = 0; i < sizeof(T); i++) {
+ // tmp[i] = v & 0xff;
+ // v = v >> 8;
+ // }
+ }
+
+ template <typename T>
+ T ReadMemory(T* p) {
+ T ret;
+#if defined(V8_TARGET_LITTLE_ENDIAN)
+ memcpy(&ret, p, sizeof(T));
+#elif defined(V8_TARGET_BIG_ENDIAN)
+ byte* src = reinterpret_cast<byte*>(p);
+ byte* dst = reinterpret_cast<byte*>(&ret);
+ for (int i = 0; i < sizeof(T); i++) {
+ dst[i] = src[sizeof(T) - i - 1];
+ }
+#else
+#error Unsupported endianness
+#endif
+ return ret;
+ // T val = 0;
+ // byte * tmp = reinterpret_cast<byte*>(p);
+ // for (int i = sizeof(T) - 1; i >= 0; i--) {
+ // val = val << 8;
+ // val = val | tmp[i];
+ // }
+ // return val;
}
// Zero-initialize the memory.
« src/wasm/wasm-interpreter.cc ('K') | « test/cctest/wasm/test-run-wasm-64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698