Commit | Line | Data |
---|---|---|
00fb3c8d JA |
1 | #ifndef FIO_BSWAP_H |
2 | #define FIO_BSWAP_H | |
3 | ||
4 | #include <inttypes.h> | |
5 | ||
6 | #if __BYTE_ORDER == __LITTLE_ENDIAN | |
7 | static inline uint32_t __be32_to_cpu(uint32_t val) | |
8 | { | |
9 | uint32_t c1, c2, c3, c4; | |
10 | ||
11 | c1 = (val >> 24) & 0xff; | |
12 | c2 = (val >> 16) & 0xff; | |
13 | c3 = (val >> 8) & 0xff; | |
14 | c4 = val & 0xff; | |
15 | ||
16 | return c1 | c2 << 8 | c3 << 16 | c4 << 24; | |
17 | } | |
18 | ||
19 | static inline uint64_t __be64_to_cpu(uint64_t val) | |
20 | { | |
21 | uint64_t c1, c2, c3, c4, c5, c6, c7, c8; | |
22 | ||
23 | c1 = (val >> 56) & 0xff; | |
24 | c2 = (val >> 48) & 0xff; | |
25 | c3 = (val >> 40) & 0xff; | |
26 | c4 = (val >> 32) & 0xff; | |
27 | c5 = (val >> 24) & 0xff; | |
28 | c6 = (val >> 16) & 0xff; | |
29 | c7 = (val >> 8) & 0xff; | |
30 | c8 = val & 0xff; | |
31 | ||
32 | return c1 | c2 << 8 | c3 << 16 | c4 << 24 | c5 << 32 | c6 << 40 | c7 << 48 | c8 << 56; | |
33 | } | |
34 | #else | |
35 | static inline uint64_t __be64_to_cpu(uint64_t val) | |
36 | { | |
37 | return val; | |
38 | } | |
39 | ||
40 | static inline uint32_t __be32_to_cpu(uint32_t val) | |
41 | { | |
42 | return val; | |
43 | } | |
44 | #endif | |
45 | ||
46 | #endif |