68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
((uint64_t)i & UINT64_C(0x000000000000FF00)) << 40 | \
((uint64_t)i & UINT64_C(0x00000000000000FF)) << 56)
static OF_INLINE uint16_t
OF_BSWAP16_NONCONST(uint16_t i)
{
#if defined(OF_X86_ASM) || defined(OF_AMD64_ASM)
asm("xchgb %h0, %b0" : "=Q"(i) : "Q"(i));
#elif defined(OF_PPC_ASM)
asm("lhbrx %0, 0, %1" : "=r"(i) : "r"(&i), "m"(i));
#elif defined(OF_ARM_ASM)
asm("rev16 %0, %0" : "=r"(i) : "0"(i));
#else
i = (i & UINT16_C(0xFF00)) >> 8 |
(i & UINT16_C(0x00FF)) << 8;
#endif
return i;
}
static OF_INLINE uint32_t
OF_BSWAP32_NONCONST(uint32_t i)
{
#if defined(OF_X86_ASM) || defined(OF_AMD64_ASM)
asm("bswap %0" : "=q"(i) : "q"(i));
#elif defined(OF_PPC_ASM)
asm("lwbrx %0, 0, %1" : "=r"(i) : "r"(&i), "m"(i));
#elif defined(OF_ARM_ASM)
asm("rev %0, %0" : "=r"(i) : "0"(i));
#else
i = (i & UINT32_C(0xFF000000)) >> 24 |
(i & UINT32_C(0x00FF0000)) >> 8 |
(i & UINT32_C(0x0000FF00)) << 8 |
(i & UINT32_C(0x000000FF)) << 24;
#endif
return i;
}
static OF_INLINE uint64_t
OF_BSWAP64_NONCONST(uint64_t i)
{
#if defined(OF_AMD64_ASM)
asm("bswap %0" : "=r"(i) : "r"(i));
#elif defined(OF_X86_ASM)
asm("bswap %%eax\n\t"
"bswap %%edx\n\t"
"xchgl %%eax, %%edx" : "=A"(i): "A"(i));
#else
i = (uint64_t)OF_BSWAP32(i & 0xFFFFFFFF) << 32 | OF_BSWAP32(i >> 32);
#endif
return i;
}
#ifdef __GNUC__
|
|
|
|
|
|
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
((uint64_t)i & UINT64_C(0x000000000000FF00)) << 40 | \
((uint64_t)i & UINT64_C(0x00000000000000FF)) << 56)
static OF_INLINE uint16_t
OF_BSWAP16_NONCONST(uint16_t i)
{
#if defined(OF_X86_ASM) || defined(OF_AMD64_ASM)
asm("xchgb %h0, %b0" : "=Q"(i) : "0"(i));
#elif defined(OF_PPC_ASM)
asm("lhbrx %0, 0, %1" : "=r"(i) : "r"(&i), "m"(i));
#elif defined(OF_ARM_ASM)
asm("rev16 %0, %0" : "=r"(i) : "0"(i));
#else
i = (i & UINT16_C(0xFF00)) >> 8 |
(i & UINT16_C(0x00FF)) << 8;
#endif
return i;
}
static OF_INLINE uint32_t
OF_BSWAP32_NONCONST(uint32_t i)
{
#if defined(OF_X86_ASM) || defined(OF_AMD64_ASM)
asm("bswap %0" : "=q"(i) : "0"(i));
#elif defined(OF_PPC_ASM)
asm("lwbrx %0, 0, %1" : "=r"(i) : "r"(&i), "m"(i));
#elif defined(OF_ARM_ASM)
asm("rev %0, %0" : "=r"(i) : "0"(i));
#else
i = (i & UINT32_C(0xFF000000)) >> 24 |
(i & UINT32_C(0x00FF0000)) >> 8 |
(i & UINT32_C(0x0000FF00)) << 8 |
(i & UINT32_C(0x000000FF)) << 24;
#endif
return i;
}
static OF_INLINE uint64_t
OF_BSWAP64_NONCONST(uint64_t i)
{
#if defined(OF_AMD64_ASM)
asm("bswap %0" : "=r"(i) : "0"(i));
#elif defined(OF_X86_ASM)
asm("bswap %%eax\n\t"
"bswap %%edx\n\t"
"xchgl %%eax, %%edx" : "=A"(i): "0"(i));
#else
i = (uint64_t)OF_BSWAP32(i & 0xFFFFFFFF) << 32 | OF_BSWAP32(i >> 32);
#endif
return i;
}
#ifdef __GNUC__
|