diff options
author | Joakim Tjernlund <joakim.tjernlund@transmode.se> | 2004-09-23 07:23:26 +0000 |
---|---|---|
committer | Joakim Tjernlund <joakim.tjernlund@transmode.se> | 2004-09-23 07:23:26 +0000 |
commit | e6c7d1de2a601b0c630df62e02c27a05962669d8 (patch) | |
tree | 55cdd7f9bc15daf363a7c6570ef85b1843b3de0a /libc/sysdeps/linux/cris/bits/byteswap.h | |
parent | 553bc05e524989e5e7567a07240900375067f9ff (diff) |
Add bswap_64 macro and uClibc_page.h. From Peter Kjellerstedt.
Diffstat (limited to 'libc/sysdeps/linux/cris/bits/byteswap.h')
-rw-r--r-- | libc/sysdeps/linux/cris/bits/byteswap.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/libc/sysdeps/linux/cris/bits/byteswap.h b/libc/sysdeps/linux/cris/bits/byteswap.h index f152d73e8..e35c4b63f 100644 --- a/libc/sysdeps/linux/cris/bits/byteswap.h +++ b/libc/sysdeps/linux/cris/bits/byteswap.h @@ -45,4 +45,31 @@ static inline unsigned long __fswab32(unsigned long x) ___swab32((x)) : \ __fswab32((x))) +#if defined __GNUC__ && __GNUC__ >= 2 +/* Swap bytes in 64 bit value. */ +# define __bswap_constant_64(x) \ + ((((x) & 0xff00000000000000ull) >> 56) \ + | (((x) & 0x00ff000000000000ull) >> 40) \ + | (((x) & 0x0000ff0000000000ull) >> 24) \ + | (((x) & 0x000000ff00000000ull) >> 8) \ + | (((x) & 0x00000000ff000000ull) << 8) \ + | (((x) & 0x0000000000ff0000ull) << 24) \ + | (((x) & 0x000000000000ff00ull) << 40) \ + | (((x) & 0x00000000000000ffull) << 56)) + +# define __bswap_64(x) \ + (__extension__ \ + ({ union { __extension__ unsigned long long int __ll; \ + unsigned int __l[2]; } __w, __r; \ + if (__builtin_constant_p (x)) \ + __r.__ll = __bswap_constant_64 (x); \ + else \ + { \ + __w.__ll = (x); \ + __r.__l[0] = __bswap_32 (__w.__l[1]); \ + __r.__l[1] = __bswap_32 (__w.__l[0]); \ + } \ + __r.__ll; })) +#endif + #endif /* _BITS_BYTESWAP_H */ |