1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
12 inline typename std::enable_if<sizeof(T) == sizeof(uint16_t), T>::type
14 return __builtin_bswap16(val);
17 inline typename std::enable_if<sizeof(T) == sizeof(uint32_t), T>::type
19 return __builtin_bswap32(val);
22 inline typename std::enable_if<sizeof(T) == sizeof(uint64_t), T>::type
24 return __builtin_bswap64(val);
28 inline typename std::enable_if<sizeof(T) == sizeof(uint16_t), T>::type
30 return (val >> 8) | (val << 8);
33 inline typename std::enable_if<sizeof(T) == sizeof(uint32_t), T>::type
35 return (( val >> 24) |
36 ((val >> 8) & 0xff00) |
37 ((val << 8) & 0xff0000) |
41 inline typename std::enable_if<sizeof(T) == sizeof(uint64_t), T>::type
43 return (( val >> 56) |
44 ((val >> 40) & 0xff00ull) |
45 ((val >> 24) & 0xff0000ull) |
46 ((val >> 8) & 0xff000000ull) |
47 ((val << 8) & 0xff00000000ull) |
48 ((val << 24) & 0xff0000000000ull) |
49 ((val << 40) & 0xff000000000000ull) |
54 // mswab == maybe swab (if not LE)
55 #ifdef CEPH_BIG_ENDIAN
57 inline T mswab(T val) {
62 inline T mswab(T val) {
70 ceph_le<T>& operator=(T nv) {
74 operator T() const { return mswab(v); }
75 } __attribute__ ((packed));
78 inline bool operator==(ceph_le<T> a, ceph_le<T> b) {
82 using ceph_le64 = ceph_le<__u64>;
83 using ceph_le32 = ceph_le<__u32>;
84 using ceph_le16 = ceph_le<__u16>;
86 inline __u64 init_le64(__u64 x) {
87 return mswab<__u64>(x);
89 inline __u32 init_le32(__u32 x) {
90 return mswab<__u32>(x);
92 inline __u16 init_le16(__u16 x) {
93 return mswab<__u16>(x);
97 #define cpu_to_le64(x) (x)
98 #define cpu_to_le32(x) (x)
99 #define cpu_to_le16(x) (x)
101 #define le64_to_cpu(x) ((uint64_t)x)
102 #define le32_to_cpu(x) ((__u32)x)
103 #define le16_to_cpu(x) ((__u16)x)