diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2014-08-26 15:53:49 -0400 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2014-08-26 15:53:49 -0400 |
commit | 25f73d62079b63e4420fd037ad9460004179b026 (patch) | |
tree | eb8473cdad8ae4bcf471bd57c9ed31efa7f6c7d5 /firmware/include | |
parent | 69df56504e7dfc8ba7e283901aadde6ebdada5b1 (diff) | |
download | rockbox-25f73d62079b63e4420fd037ad9460004179b026.tar.gz rockbox-25f73d62079b63e4420fd037ad9460004179b026.zip |
Patch up rbendian.h for Win32 cross-compile
MingW doesn't provide that stuff.
Change-Id: Ifa8310ed00f4f79f06adb71db71e58b70e7d2b60
Diffstat (limited to 'firmware/include')
-rw-r--r-- | firmware/include/rbendian.h | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/firmware/include/rbendian.h b/firmware/include/rbendian.h index 21d3cae68d..861db7d082 100644 --- a/firmware/include/rbendian.h +++ b/firmware/include/rbendian.h | |||
@@ -22,7 +22,10 @@ | |||
22 | #define _RBENDIAN_H_ | 22 | #define _RBENDIAN_H_ |
23 | 23 | ||
24 | #include "config.h" | 24 | #include "config.h" |
25 | |||
26 | #ifndef __MINGW32__ | ||
25 | #include <endian.h> | 27 | #include <endian.h> |
28 | #endif | ||
26 | 29 | ||
27 | /* clear these out since we redefine them to be truely constant compatible */ | 30 | /* clear these out since we redefine them to be truely constant compatible */ |
28 | #undef swap16 | 31 | #undef swap16 |
@@ -42,6 +45,34 @@ | |||
42 | #undef htobe32 | 45 | #undef htobe32 |
43 | #undef htobe64 | 46 | #undef htobe64 |
44 | 47 | ||
48 | /* static/generic endianness conversion */ | ||
49 | #define SWAP16_CONST(x) \ | ||
50 | ((typeof(x))( ((uint16_t)(x) >> 8) | ((uint16_t)(x) << 8) )) | ||
51 | |||
52 | #define SWAP32_CONST(x) \ | ||
53 | ((typeof(x))( (((uint32_t)(x) & 0xff000000) >> 24) | \ | ||
54 | (((uint32_t)(x) & 0x00ff0000) >> 8) | \ | ||
55 | (((uint32_t)(x) & 0x0000ff00) << 8) | \ | ||
56 | (((uint32_t)(x) & 0x000000ff) << 24) )) | ||
57 | |||
58 | #define SWAP64_CONST(x) \ | ||
59 | ((typeof(x))( (((uint64_t)(x) & 0xff00000000000000ull) >> 56) | \ | ||
60 | (((uint64_t)(x) & 0x00ff000000000000ull) >> 40) | \ | ||
61 | (((uint64_t)(x) & 0x0000ff0000000000ull) >> 24) | \ | ||
62 | (((uint64_t)(x) & 0x000000ff00000000ull) >> 8) | \ | ||
63 | (((uint64_t)(x) & 0x00000000ff000000ull) << 8) | \ | ||
64 | (((uint64_t)(x) & 0x0000000000ff0000ull) << 24) | \ | ||
65 | (((uint64_t)(x) & 0x000000000000ff00ull) << 40) | \ | ||
66 | (((uint64_t)(x) & 0x00000000000000ffull) << 56) )) | ||
67 | |||
68 | #define SWAP_ODD_EVEN32_CONST(x) \ | ||
69 | ((typeof(x))( ((uint32_t)SWAP16_CONST((uint32_t)(x) >> 16) << 16) | \ | ||
70 | SWAP16_CONST((uint32_t)(x))) ) | ||
71 | |||
72 | #define SWAW32_CONST(x) \ | ||
73 | ((typeof(x))( ((uint32_t)(x) << 16) | ((uint32_t)(x) >> 16) )) | ||
74 | |||
75 | |||
45 | #ifndef __ENDIAN_H_NATIVE_RB | 76 | #ifndef __ENDIAN_H_NATIVE_RB |
46 | 77 | ||
47 | #if defined (__bswap_16) | 78 | #if defined (__bswap_16) |
@@ -52,11 +83,16 @@ | |||
52 | #define __swap16_os(x) __swap16(x) | 83 | #define __swap16_os(x) __swap16(x) |
53 | #define __swap32_os(x) __swap32(x) | 84 | #define __swap32_os(x) __swap32(x) |
54 | #define __swap64_os(x) __swap64(x) | 85 | #define __swap64_os(x) __swap64(x) |
86 | #elif defined (__MINGW32__) | ||
87 | /* kinda hacky but works */ | ||
88 | #define __swap16_os(x) SWAP16_CONST(x) | ||
89 | #define __swap32_os(x) SWAP32_CONST(x) | ||
90 | #define __swap64_os(x) SWAP64_CONST(x) | ||
55 | #else | 91 | #else |
56 | #error "Missing OS swap defines." | 92 | #error "Missing OS swap defines." |
57 | #endif | 93 | #endif |
58 | 94 | ||
59 | /* wrap these because they aren't compatible with compound initializers */ | 95 | /* wrap these because they aren't always compatible with compound initializers */ |
60 | static FORCE_INLINE uint16_t swap16_hw(uint16_t x) | 96 | static FORCE_INLINE uint16_t swap16_hw(uint16_t x) |
61 | { return __swap16_os(x); } | 97 | { return __swap16_os(x); } |
62 | static FORCE_INLINE uint32_t swap32_hw(uint32_t x) | 98 | static FORCE_INLINE uint32_t swap32_hw(uint32_t x) |
@@ -88,33 +124,6 @@ static inline uint32_t swaw32_hw(uint32_t value) | |||
88 | } | 124 | } |
89 | #endif /* Generic */ | 125 | #endif /* Generic */ |
90 | 126 | ||
91 | /* static endianness conversion */ | ||
92 | #define SWAP16_CONST(x) \ | ||
93 | ((typeof(x))( ((uint16_t)(x) >> 8) | ((uint16_t)(x) << 8) )) | ||
94 | |||
95 | #define SWAP32_CONST(x) \ | ||
96 | ((typeof(x))( (((uint32_t)(x) & 0xff000000) >> 24) | \ | ||
97 | (((uint32_t)(x) & 0x00ff0000) >> 8) | \ | ||
98 | (((uint32_t)(x) & 0x0000ff00) << 8) | \ | ||
99 | (((uint32_t)(x) & 0x000000ff) << 24) )) | ||
100 | |||
101 | #define SWAP64_CONST(x) \ | ||
102 | ((typeof(x))( (((uint64_t)(x) & 0xff00000000000000ull) >> 56) | \ | ||
103 | (((uint64_t)(x) & 0x00ff000000000000ull) >> 40) | \ | ||
104 | (((uint64_t)(x) & 0x0000ff0000000000ull) >> 24) | \ | ||
105 | (((uint64_t)(x) & 0x000000ff00000000ull) >> 8) | \ | ||
106 | (((uint64_t)(x) & 0x00000000ff000000ull) << 8) | \ | ||
107 | (((uint64_t)(x) & 0x0000000000ff0000ull) << 24) | \ | ||
108 | (((uint64_t)(x) & 0x000000000000ff00ull) << 40) | \ | ||
109 | (((uint64_t)(x) & 0x00000000000000ffull) << 56) )) | ||
110 | |||
111 | #define SWAP_ODD_EVEN32_CONST(x) \ | ||
112 | ((typeof(x))( ((uint32_t)SWAP16_CONST((uint32_t)(x) >> 16) << 16) | \ | ||
113 | SWAP16_CONST((uint32_t)(x))) ) | ||
114 | |||
115 | #define SWAW32_CONST(x) \ | ||
116 | ((typeof(x))( ((uint32_t)(x) << 16) | ((uint32_t)(x) >> 16) )) | ||
117 | |||
118 | /* select best method based upon whether x is a constant expression */ | 127 | /* select best method based upon whether x is a constant expression */ |
119 | #define swap16(x) \ | 128 | #define swap16(x) \ |
120 | ( __builtin_constant_p(x) ? SWAP16_CONST(x) : (typeof(x))swap16_hw(x) ) | 129 | ( __builtin_constant_p(x) ? SWAP16_CONST(x) : (typeof(x))swap16_hw(x) ) |