summarylogtreecommitdiffstats
path: root/crc.diff
blob: b2d1351f140ce9f008eb915df429b427e9a66e95 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
--- a/src/util/crypto/crc32.cpp
+++ b/src/util/crypto/crc32.cpp
@@ -322,29 +322,34 @@ unsigned int crc32_calc_slice_by_8(unsigned int previousCrc32, const void* data,
 	// process eight bytes at once (Slicing-by-8)
 	while (length >= 8)
 	{
-#if __BYTE_ORDER == __BIG_ENDIAN
-		uint32_t one = *current++ ^ swap(crc);
-		uint32_t two = *current++;
-		crc = Crc32Lookup[0][two & 0xFF] ^
-			Crc32Lookup[1][(two >> 8) & 0xFF] ^
-			Crc32Lookup[2][(two >> 16) & 0xFF] ^
-			Crc32Lookup[3][(two >> 24) & 0xFF] ^
-			Crc32Lookup[4][one & 0xFF] ^
-			Crc32Lookup[5][(one >> 8) & 0xFF] ^
-			Crc32Lookup[6][(one >> 16) & 0xFF] ^
-			Crc32Lookup[7][(one >> 24) & 0xFF];
-#else
-		uint32_t one = *current++ ^ crc;
-		uint32_t two = *current++;
-		crc = Crc32Lookup[0][(two >> 24) & 0xFF] ^
-			Crc32Lookup[1][(two >> 16) & 0xFF] ^
-			Crc32Lookup[2][(two >> 8) & 0xFF] ^
-			Crc32Lookup[3][two & 0xFF] ^
-			Crc32Lookup[4][(one >> 24) & 0xFF] ^
-			Crc32Lookup[5][(one >> 16) & 0xFF] ^
-			Crc32Lookup[6][(one >> 8) & 0xFF] ^
-			Crc32Lookup[7][one & 0xFF];
-#endif
+		if constexpr (std::endian::native == std::endian::big){
+			uint32_t one = *current++ ^ swap(crc);
+			uint32_t two = *current++;
+			crc = Crc32Lookup[0][two & 0xFF] ^
+				  Crc32Lookup[1][(two >> 8) & 0xFF] ^
+				  Crc32Lookup[2][(two >> 16) & 0xFF] ^
+				  Crc32Lookup[3][(two >> 24) & 0xFF] ^
+				  Crc32Lookup[4][one & 0xFF] ^
+				  Crc32Lookup[5][(one >> 8) & 0xFF] ^
+				  Crc32Lookup[6][(one >> 16) & 0xFF] ^
+				  Crc32Lookup[7][(one >> 24) & 0xFF];
+		}
+		else if constexpr (std::endian::native == std::endian::little)
+		{
+			uint32_t one = *current++ ^ crc;
+			uint32_t two = *current++;
+			crc = Crc32Lookup[0][(two >> 24) & 0xFF] ^
+				  Crc32Lookup[1][(two >> 16) & 0xFF] ^
+				  Crc32Lookup[2][(two >> 8) & 0xFF] ^
+				  Crc32Lookup[3][two & 0xFF] ^
+				  Crc32Lookup[4][(one >> 24) & 0xFF] ^
+				  Crc32Lookup[5][(one >> 16) & 0xFF] ^
+				  Crc32Lookup[6][(one >> 8) & 0xFF] ^
+				  Crc32Lookup[7][one & 0xFF];
+		}
+		else {
+			cemu_assert(false);
+		}
 
 		length -= 8;
 	}