blob: 1fe5194729a6541bb8c8795ad15899bce7052d00 [file] [log] [blame]
Jens Axboe00fb3c82008-05-30 22:17:45 +02001#ifndef FIO_BSWAP_H
2#define FIO_BSWAP_H
3
4#include <inttypes.h>
5
Jens Axboe0dcebdf2013-01-23 15:42:16 -07006#ifdef CONFIG_LITTLE_ENDIAN
Jens Axboe00fb3c82008-05-30 22:17:45 +02007static 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
19static 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
35static inline uint64_t __be64_to_cpu(uint64_t val)
36{
37 return val;
38}
39
40static inline uint32_t __be32_to_cpu(uint32_t val)
41{
42 return val;
43}
44#endif
45
46#endif