summaryrefslogtreecommitdiff
path: root/user/llvm18/m68k-endianness.patch
blob: 49e96a9954c5e3e961abb0782da6e4fe3df0e57d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Upstream: https://github.com/llvm/llvm-project/issues/94726

diff --git a/lib/Target/M68k/MCTargetDesc/M68kBaseInfo.h b/lib/Target/M68k/MCTargetDesc/M68kBaseInfo.h
index 1376b06bef6f..62ea03cc9760 100644
--- a/lib/Target/M68k/MCTargetDesc/M68kBaseInfo.h
+++ b/lib/Target/M68k/MCTargetDesc/M68kBaseInfo.h
@@ -85,9 +85,16 @@ template <typename value_t> value_t swapWord(value_t Val) {
   Val = support::endian::byte_swap(Val, llvm::endianness::big);
   value_t NewVal = 0;
   for (unsigned i = 0U; i != NumWords; ++i) {
-    uint16_t Part = (Val >> (i * 16)) & 0xFFFF;
-    Part = support::endian::byte_swap(Part, llvm::endianness::big);
-    NewVal |= (Part << (i * 16));
+    if (llvm::endianness::native == llvm::endianness::big) {
+      uint16_t Lo = (Val >> (i * 16)) & 0xFFFF;
+      NewVal |= (Lo << (++i * 16));
+      uint16_t Hi = (Val >> (++i * 16)) & 0xFFFF;
+      NewVal |= (Hi << ((i - 1) * 16));
+    } else {
+      uint16_t Part = (Val >> (i * 16)) & 0xFFFF;
+      Part = support::endian::byte_swap(Part, llvm::endianness::big);
+      NewVal |= (Part << (i * 16));
+    }
   }
   return NewVal;
 }