From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23557 invoked by alias); 16 Dec 2004 13:35:52 -0000 Mailing-List: contact sid-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: sid-owner@sources.redhat.com Received: (qmail 23459 invoked from network); 16 Dec 2004 13:35:39 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org with SMTP; 16 Dec 2004 13:35:39 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id iBGDZdEY010216 for ; Thu, 16 Dec 2004 08:35:39 -0500 Received: from zenia.home.redhat.com (sebastian-int.corp.redhat.com [172.16.52.221]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id iBGDZcr08141; Thu, 16 Dec 2004 08:35:39 -0500 To: sid@sources.redhat.com Subject: RFA: add byte-swapping instructions for AMD64 From: Jim Blandy Date: Thu, 16 Dec 2004 13:35:00 -0000 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2004-q4/txt/msg00026.txt.bz2 2004-12-10 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. 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; }