public inbox for sid@sourceware.org
 help / color / mirror / Atom feed
* RFA: add byte-swapping instructions for AMD64
@ 2004-12-16 13:35 Jim Blandy
  0 siblings, 0 replies; only message in thread
From: Jim Blandy @ 2004-12-16 13:35 UTC (permalink / raw)
  To: sid


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;
    }
  

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-12-16 13:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-16 13:35 RFA: add byte-swapping instructions for AMD64 Jim Blandy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).