Home | History | Annotate | Download | only in amd64
      1 
      2 #include <stdio.h>
      3 
      4 typedef unsigned int UInt;
      5 typedef unsigned long long ULong;
      6 
      7 #if defined(__x86_64__)
      8 
      9 #define BSWAPQ(_lval) \
     10   do { \
     11   __asm__ __volatile__("bswapq %0" \
     12 		       : /*out*/ "+r"(_lval) ); \
     13   } while (0)
     14 
     15 ULong bswapq ( ULong x )
     16 {
     17   BSWAPQ(x); BSWAPQ(x);
     18   BSWAPQ(x); BSWAPQ(x);
     19   BSWAPQ(x); BSWAPQ(x);
     20   BSWAPQ(x); BSWAPQ(x);
     21   BSWAPQ(x); BSWAPQ(x);
     22   BSWAPQ(x); BSWAPQ(x);
     23   BSWAPQ(x); BSWAPQ(x);
     24   BSWAPQ(x); BSWAPQ(x);
     25   BSWAPQ(x); BSWAPQ(x);
     26   BSWAPQ(x); BSWAPQ(x);
     27   BSWAPQ(x); BSWAPQ(x);
     28   BSWAPQ(x); BSWAPQ(x);
     29   BSWAPQ(x); BSWAPQ(x);
     30   BSWAPQ(x); BSWAPQ(x);
     31   BSWAPQ(x); BSWAPQ(x);
     32   BSWAPQ(x); BSWAPQ(x);
     33   BSWAPQ(x); BSWAPQ(x);
     34   BSWAPQ(x); BSWAPQ(x);
     35   BSWAPQ(x); BSWAPQ(x);
     36   BSWAPQ(x); BSWAPQ(x);
     37   BSWAPQ(x); BSWAPQ(x);
     38   BSWAPQ(x); BSWAPQ(x);
     39   BSWAPQ(x); BSWAPQ(x);
     40   BSWAPQ(x); BSWAPQ(x);
     41   BSWAPQ(x); BSWAPQ(x);
     42   BSWAPQ(x); BSWAPQ(x);
     43   BSWAPQ(x); BSWAPQ(x);
     44   BSWAPQ(x); BSWAPQ(x);
     45   BSWAPQ(x); BSWAPQ(x);
     46   BSWAPQ(x); BSWAPQ(x);
     47   BSWAPQ(x); BSWAPQ(x);
     48   BSWAPQ(x); BSWAPQ(x);
     49   BSWAPQ(x);
     50   return x;
     51 }
     52 
     53 #endif /* defined(__x86_64__) */
     54 
     55 #define BSWAPL(_lval) \
     56   do { \
     57   __asm__ __volatile__("bswapl %0" \
     58 		       : /*out*/ "+r"(_lval) ); \
     59   } while (0)
     60 
     61 UInt bswapl ( UInt x )
     62 {
     63   BSWAPL(x); BSWAPL(x);
     64   BSWAPL(x); BSWAPL(x);
     65   BSWAPL(x); BSWAPL(x);
     66   BSWAPL(x); BSWAPL(x);
     67   BSWAPL(x); BSWAPL(x);
     68   BSWAPL(x); BSWAPL(x);
     69   BSWAPL(x); BSWAPL(x);
     70   BSWAPL(x); BSWAPL(x);
     71   BSWAPL(x); BSWAPL(x);
     72   BSWAPL(x); BSWAPL(x);
     73   BSWAPL(x); BSWAPL(x);
     74   BSWAPL(x); BSWAPL(x);
     75   BSWAPL(x); BSWAPL(x);
     76   BSWAPL(x); BSWAPL(x);
     77   BSWAPL(x); BSWAPL(x);
     78   BSWAPL(x); BSWAPL(x);
     79   BSWAPL(x); BSWAPL(x);
     80   BSWAPL(x); BSWAPL(x);
     81   BSWAPL(x); BSWAPL(x);
     82   BSWAPL(x); BSWAPL(x);
     83   BSWAPL(x); BSWAPL(x);
     84   BSWAPL(x); BSWAPL(x);
     85   BSWAPL(x); BSWAPL(x);
     86   BSWAPL(x); BSWAPL(x);
     87   BSWAPL(x); BSWAPL(x);
     88   BSWAPL(x); BSWAPL(x);
     89   BSWAPL(x); BSWAPL(x);
     90   BSWAPL(x); BSWAPL(x);
     91   BSWAPL(x); BSWAPL(x);
     92   BSWAPL(x); BSWAPL(x);
     93   BSWAPL(x); BSWAPL(x);
     94   BSWAPL(x); BSWAPL(x);
     95   BSWAPL(x);
     96   return x;
     97 }
     98 
     99 int main ( void )
    100 {
    101 #if defined(__x86_64__)
    102    printf("0x%llx\n", bswapq( 0x8877665544332211ULL ));
    103 #endif
    104    printf("0x%x\n", bswapl( 0x44332211ULL ));
    105    return 0;
    106 }
    107