Overview
| Comment: | Add assembly implementation for OF_BSWAP{16,32,64} for x86 and AMD64. |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
42aaecc3cdfdf8572f35d48d549cc3cc |
| User & Date: | js on 2009-08-28 02:12:23 |
| Other Links: | manifest | tags |
Context
|
2009-08-28
| ||
| 17:57 | Fix a bug in OFHashing (SHA1 didn't cache correctly in -[digit]). (check-in: 6a0ac6a3f1 user: js tags: trunk) | |
| 02:12 | Add assembly implementation for OF_BSWAP{16,32,64} for x86 and AMD64. (check-in: 42aaecc3cd user: js tags: trunk) | |
| 00:33 | Add OF_BSWAP{16,32,64}_IF_{BE,LE} for conditional byte swap. (check-in: 30f6c422ad user: js tags: trunk) | |
Changes
Modified src/OFMacros.h from [8a995369a7] to [7562b69891].
| ︙ | ︙ | |||
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
#define OF_LIKELY(cond) __builtin_expect(!!(cond), 1)
#define OF_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
#else
#define OF_INLINE inline
#define OF_LIKELY(cond) cond
#define OF_UNLIKELY(cond) cond
#endif
static OF_INLINE uint16_t
OF_BSWAP16(uint16_t i)
{
i = (i & UINT16_C(0xFF00)) >> 8 |
(i & UINT16_C(0x00FF)) << 8;
return i;
}
static OF_INLINE uint32_t
OF_BSWAP32(uint32_t i)
{
i = (i & UINT32_C(0xFF000000)) >> 24 |
(i & UINT32_C(0x00FF0000)) >> 8 |
(i & UINT32_C(0x0000FF00)) << 8 |
(i & UINT32_C(0x000000FF)) << 24;
return i;
}
static OF_INLINE uint64_t
OF_BSWAP64(uint64_t i)
{
i = (i & UINT64_C(0xFF00000000000000)) >> 56 |
(i & UINT64_C(0x00FF000000000000)) >> 40 |
(i & UINT64_C(0x0000FF0000000000)) >> 24 |
(i & UINT64_C(0x000000FF00000000)) >> 8 |
(i & UINT64_C(0x00000000FF000000)) << 8 |
(i & UINT64_C(0x0000000000FF0000)) << 24 |
(i & UINT64_C(0x000000000000FF00)) << 40 |
(i & UINT64_C(0x00000000000000FF)) << 56;
return i;
}
static OF_INLINE void
OF_BSWAP32_V(uint32_t *buf, size_t len)
{
while (len--) {
| > > > > > > > > > > > > > > > > > > > > > > > > | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
#define OF_LIKELY(cond) __builtin_expect(!!(cond), 1)
#define OF_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
#else
#define OF_INLINE inline
#define OF_LIKELY(cond) cond
#define OF_UNLIKELY(cond) cond
#endif
#ifdef __GNUC__
#if defined(__amd64__) || defined(__x86_64__)
#define OF_AMD64_ASM
#elif defined(__i386__)
#define OF_X86_ASM
#endif
#endif
static OF_INLINE uint16_t
OF_BSWAP16(uint16_t i)
{
#if defined(OF_X86_ASM) || defined(OF_AMD64_ASM)
asm("xchgb %h0, %b0" : "=Q"(i) : "Q"(i));
#else
i = (i & UINT16_C(0xFF00)) >> 8 |
(i & UINT16_C(0x00FF)) << 8;
#endif
return i;
}
static OF_INLINE uint32_t
OF_BSWAP32(uint32_t i)
{
#if defined(OF_X86_ASM) || defined(OF_AMD64_ASM)
asm("bswap %0" : "=q"(i) : "q"(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(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 = (i & UINT64_C(0xFF00000000000000)) >> 56 |
(i & UINT64_C(0x00FF000000000000)) >> 40 |
(i & UINT64_C(0x0000FF0000000000)) >> 24 |
(i & UINT64_C(0x000000FF00000000)) >> 8 |
(i & UINT64_C(0x00000000FF000000)) << 8 |
(i & UINT64_C(0x0000000000FF0000)) << 24 |
(i & UINT64_C(0x000000000000FF00)) << 40 |
(i & UINT64_C(0x00000000000000FF)) << 56;
#endif
return i;
}
static OF_INLINE void
OF_BSWAP32_V(uint32_t *buf, size_t len)
{
while (len--) {
|
| ︙ | ︙ |