Is it possible to do any better?
Aug. 27th, 2011 12:19 pm#if __GNUC__ && __i386__
/* This is not entirely satisfactory: the xchgl would be unnecessary, if only
* we had some way of communicating the detailed input and output assignments
* of the registers to the compiler. */
#define BSWAP64(N) \
({uint64_t __n = (N); __asm__("xchgl %%eax,%%edx\n" \
"\tbswap %%eax\n" \
"\tbswap %%edx" \
: "+A"(__n)); \
__n;})
#endif
The trouble is, the result ends up looking something like this:
movl 0x04(%eax),%edx
movl (%eax),%eax
xchgl %edx,%eax
bswap %eax
bswap %edx
movl 0x0c(%ebp),%esi
movl %eax,(%esi)
movl %edx,0x04(%esi)
…when obviously it would be better to:
movl 0x04(%eax),%edx
movl (%eax),%eax
bswap %eax
bswap %edx
movl 0x0c(%ebp),%esi
movl %edx,(%esi)
movl %eax,0x04(%esi)
However as far as I can see A is the only available constraint letter for 64-bit values on x86.
(no subject)
Date: 2011-08-28 09:21 pm (UTC)__builtin_bswap64instead.