Jens Axboe | 00fb3c8 | 2008-05-30 22:17:45 +0200 | [diff] [blame] | 1 | #ifndef FIO_BSWAP_H |
| 2 | #define FIO_BSWAP_H |
| 3 | |
| 4 | #include <inttypes.h> |
| 5 | |
Jens Axboe | 0dcebdf | 2013-01-23 15:42:16 -0700 | [diff] [blame] | 6 | #ifdef CONFIG_LITTLE_ENDIAN |
Jens Axboe | 00fb3c8 | 2008-05-30 22:17:45 +0200 | [diff] [blame] | 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 |