summaryrefslogtreecommitdiff
path: root/experimental/spirv-llvm-translator/endian.patch
diff options
context:
space:
mode:
Diffstat (limited to 'experimental/spirv-llvm-translator/endian.patch')
-rw-r--r--experimental/spirv-llvm-translator/endian.patch37
1 files changed, 37 insertions, 0 deletions
diff --git a/experimental/spirv-llvm-translator/endian.patch b/experimental/spirv-llvm-translator/endian.patch
new file mode 100644
index 000000000..66a4e88bd
--- /dev/null
+++ b/experimental/spirv-llvm-translator/endian.patch
@@ -0,0 +1,37 @@
+--- SPIRV-LLVM-Translator-18.1.6/lib/SPIRV/libSPIRV/SPIRVStream.h.old 2024-10-30 05:39:48.000000000 -0500
++++ SPIRV-LLVM-Translator-18.1.6/lib/SPIRV/libSPIRV/SPIRVStream.h 2024-11-22 20:17:06.139226884 -0600
+@@ -43,6 +43,16 @@
+ #include "SPIRVDebug.h"
+ #include "SPIRVExtInst.h"
+ #include "SPIRVModule.h"
++#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
++#include <byteswap.h>
++#define cpu_to_le32(x) __bswap32(x)
++#define le32_to_cpu(x) __bswap32(x)
++#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
++#define cpu_to_le32(x) x
++#define le32_to_cpu(x) x
++#else
++#error Endianness unknown (neither big nor little)
++#endif
+ #include <cctype>
+ #include <cstdint>
+ #include <iostream>
+@@ -102,7 +112,7 @@
+ const SPIRVDecoder &decodeBinary(const SPIRVDecoder &I, T &V) {
+ uint32_t W;
+ I.IS.read(reinterpret_cast<char *>(&W), sizeof(W));
+- V = static_cast<T>(W);
++ V = static_cast<T>(le32_to_cpu(W));
+ SPIRVDBG(spvdbgs() << "Read word: W = " << W << " V = " << V << '\n');
+ return I;
+ }
+@@ -185,7 +195,7 @@
+ return O;
+ }
+ #endif
+- uint32_t W = static_cast<uint32_t>(V);
++ uint32_t W = cpu_to_le32(static_cast<uint32_t>(V));
+ O.OS.write(reinterpret_cast<char *>(&W), sizeof(W));
+ return O;
+ }