This is the mail archive of the
sid@sources.redhat.com
mailing list for the SID project.
RFA: add byte-swapping instructions for AMD64
- From: Jim Blandy <jimb at redhat dot com>
- To: sid at sources dot redhat dot com
- Date: 16 Dec 2004 08:33:48 -0500
- Subject: RFA: add byte-swapping instructions for AMD64
2004-12-10 Jim Blandy <jimb@redhat.com>
* sidtypes.h: (bytereverse (host_int_2)): The x86-64 has an
xchgb instruction, too.
(bytereverse (host_int_4)): The x86-64 has a bswap instruction, too.
(bytereverse (host_int_8)): Use bswap on the x86-64.
Index: sid/include/sidtypes.h
===================================================================
RCS file: /cvs/src/src/sid/include/sidtypes.h,v
retrieving revision 1.1
diff -c -p -r1.1 sidtypes.h
*** sid/include/sidtypes.h 7 Dec 2000 19:31:09 -0000 1.1
--- sid/include/sidtypes.h 10 Dec 2004 21:40:38 -0000
*************** namespace sid {
*** 62,68 ****
bytereverse(host_int_2 value)
{
// This is a 386 instruction.
! #if defined(__i386__) && defined(__GNUC__)
__asm__("xchgb %b0,%h0" : "=q" (value) : "0" (value));
#else
value = ( ((value & 0xff00U) >> 8)
--- 62,68 ----
bytereverse(host_int_2 value)
{
// This is a 386 instruction.
! #if defined(__GNUC__) && (defined(__i386__) || defined (__x86_64__))
__asm__("xchgb %b0,%h0" : "=q" (value) : "0" (value));
#else
value = ( ((value & 0xff00U) >> 8)
*************** namespace sid {
*** 74,80 ****
inline host_int_4
bytereverse(host_int_4 value)
{
! #if defined(__GNUC__) && (defined(__i486__) || defined(__i586__) || defined(__i686__))
// This is a 486+ instruction
__asm__ ("bswap %0" : "=r" (value) : "0" (value));
#else
--- 74,80 ----
inline host_int_4
bytereverse(host_int_4 value)
{
! #if defined(__GNUC__) && (defined(__i486__) || defined(__i586__) || defined(__i686__) || defined (__x86_64__))
// This is a 486+ instruction
__asm__ ("bswap %0" : "=r" (value) : "0" (value));
#else
*************** namespace sid {
*** 89,99 ****
--- 89,104 ----
inline host_int_8
bytereverse(host_int_8 value)
{
+ #if defined (__GNUC__) && defined (__x86_64__)
+ // This is an x86_64 instruction.
+ __asm__ ("bswap %0" : "=r" (value) : "0" (value));
+ #else
host_int_4 upper = (value & 0xffffffff00000000ULL) >> 32;
host_int_4 lower = (value & 0x00000000ffffffffULL);
upper = bytereverse(upper);
lower = bytereverse(lower);
value = ((host_int_8)lower) << 32 | (host_int_8)upper;
+ #endif
return value;
}