Line 0
Link Here
|
|
|
1 |
--- src/utils/endian.hh.orig 2020-08-25 21:16:08 UTC |
2 |
+++ src/utils/endian.hh |
3 |
@@ -9,23 +9,23 @@ |
4 |
namespace Endian { |
5 |
|
6 |
// Reverse bytes in a 16-bit number: 0x1234 becomes 0x3412 |
7 |
-[[nodiscard]] static inline uint16_t bswap16(uint16_t x) |
8 |
+[[nodiscard]] static inline uint16_t byteswap16(uint16_t x) |
9 |
{ |
10 |
// This sequence generates 'optimal' code on a wide range of gcc/clang |
11 |
// versions (a single rotate instruction on x86). The newer compiler |
12 |
// versions also do 'the right thing' for the simpler expression below. |
13 |
- // Those newer compilers also support __builtin_bswap16() but that |
14 |
+ // Those newer compilers also support __builtin_byteswap16() but that |
15 |
// doesn't generate better code (and is less portable). |
16 |
return ((x & 0x00FF) << 8) | ((x & 0xFF00) >> 8); |
17 |
//return (x << 8) | (x >> 8); |
18 |
} |
19 |
|
20 |
// Reverse bytes in a 32-bit number: 0x12345678 becomes 0x78563412 |
21 |
-[[nodiscard]] static inline uint32_t bswap32(uint32_t x) |
22 |
+[[nodiscard]] static inline uint32_t byteswap32(uint32_t x) |
23 |
{ |
24 |
#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) |
25 |
// Starting from gcc-4.3 there's a builtin function for this. |
26 |
- // E.g. on x86 this is translated to a single 'bswap' instruction. |
27 |
+ // E.g. on x86 this is translated to a single 'byteswap' instruction. |
28 |
return __builtin_bswap32(x); |
29 |
#else |
30 |
return (x << 24) | |
31 |
@@ -36,22 +36,22 @@ namespace Endian { |
32 |
} |
33 |
|
34 |
// Reverse bytes in a 64-bit value: 0x1122334455667788 becomes 0x8877665544332211 |
35 |
-[[nodiscard]] static inline uint64_t bswap64(uint64_t x) |
36 |
+[[nodiscard]] static inline uint64_t byteswap64(uint64_t x) |
37 |
{ |
38 |
#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) |
39 |
// Starting from gcc-4.3 there's a builtin function for this. |
40 |
- // E.g. on x86 this is translated to a single 'bswap' instruction. |
41 |
+ // E.g. on x86 this is translated to a single 'byteswap' instruction. |
42 |
return __builtin_bswap64(x); |
43 |
#else |
44 |
- return (uint64_t(bswap32(x >> 0)) << 32) | |
45 |
- (uint64_t(bswap32(x >> 32)) << 0); |
46 |
+ return (uint64_t(byteswap32(x >> 0)) << 32) | |
47 |
+ (uint64_t(byteswap32(x >> 32)) << 0); |
48 |
#endif |
49 |
} |
50 |
|
51 |
-// Use overloading to get a (statically) polymorphic bswap() function. |
52 |
-[[nodiscard]] static inline uint16_t bswap(uint16_t x) { return bswap16(x); } |
53 |
-[[nodiscard]] static inline uint32_t bswap(uint32_t x) { return bswap32(x); } |
54 |
-[[nodiscard]] static inline uint64_t bswap(uint64_t x) { return bswap64(x); } |
55 |
+// Use overloading to get a (statically) polymorphic byteswap() function. |
56 |
+[[nodiscard]] static inline uint16_t byteswap(uint16_t x) { return byteswap16(x); } |
57 |
+[[nodiscard]] static inline uint32_t byteswap(uint32_t x) { return byteswap32(x); } |
58 |
+[[nodiscard]] static inline uint64_t byteswap(uint64_t x) { return byteswap64(x); } |
59 |
|
60 |
|
61 |
// Identity operator, simply returns the given value. |
62 |
@@ -61,7 +61,7 @@ struct Ident { |
63 |
|
64 |
// Byte-swap operator, swap bytes in the given value (16 or 32 bit). |
65 |
struct BSwap { |
66 |
- template <typename T> [[nodiscard]] inline T operator()(T t) const { return bswap(t); } |
67 |
+ template <typename T> [[nodiscard]] inline T operator()(T t) const { return byteswap(t); } |
68 |
}; |
69 |
|
70 |
// Helper class that stores a value and allows to read/write that value. Though |
71 |
@@ -165,7 +165,7 @@ static inline void writeL32(void* p, uint32_t x) |
72 |
|
73 |
template<bool SWAP, typename T> static ALWAYS_INLINE void write_UA(void* p, T x) |
74 |
{ |
75 |
- if (SWAP) x = bswap(x); |
76 |
+ if (SWAP) x = byteswap(x); |
77 |
memcpy(p, &x, sizeof(x)); |
78 |
} |
79 |
static ALWAYS_INLINE void write_UA_B16(void* p, uint16_t x) |
80 |
@@ -197,7 +197,7 @@ template<bool SWAP, typename T> [[nodiscard]] static A |
81 |
{ |
82 |
T x; |
83 |
memcpy(&x, p, sizeof(x)); |
84 |
- if (SWAP) x = bswap(x); |
85 |
+ if (SWAP) x = byteswap(x); |
86 |
return x; |
87 |
} |
88 |
[[nodiscard]] static ALWAYS_INLINE uint16_t read_UA_B16(const void* p) |