From 1b5543281301f3fe29896d8cb761e4ad735bc0e2 Mon Sep 17 00:00:00 2001 From: jimb Date: Thu, 16 Dec 2004 21:16:34 +0000 Subject: [PATCH] * 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. --- sid/include/ChangeLog | 7 +++++++ sid/include/sidtypes.h | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sid/include/ChangeLog b/sid/include/ChangeLog index 6800c1b799..abf86d0b87 100644 --- a/sid/include/ChangeLog +++ b/sid/include/ChangeLog @@ -1,3 +1,10 @@ +2004-12-16 Jim Blandy + + * 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. + 2004-12-09 Jim Blandy * sidtypes.h: Recognize AMD64 (x86-64) as a little-endian machine. diff --git a/sid/include/sidtypes.h b/sid/include/sidtypes.h index 217393946b..4dc30d8e16 100644 --- a/sid/include/sidtypes.h +++ b/sid/include/sidtypes.h @@ -62,7 +62,7 @@ namespace sid { bytereverse(host_int_2 value) { // This is a 386 instruction. -#if defined(__i386__) && defined(__GNUC__) +#if defined(__GNUC__) && (defined(__i386__) || defined (__x86_64__)) __asm__("xchgb %b0,%h0" : "=q" (value) : "0" (value)); #else value = ( ((value & 0xff00U) >> 8) @@ -74,7 +74,7 @@ namespace sid { inline host_int_4 bytereverse(host_int_4 value) { -#if defined(__GNUC__) && (defined(__i486__) || defined(__i586__) || defined(__i686__)) +#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 @@ -89,11 +89,16 @@ namespace sid { 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; } -- 2.11.0