ewx: (geek)
[personal profile] ewx
#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.

(will be screened)
(will be screened if not validated)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org

November 2025

S M T W T F S
      1
2345678
91011121314 15
1617 181920 2122
23242526272829
30      

Most Popular Tags

Expand Cut Tags

No cut tags