public inbox for sid@sourceware.org
 help / color / mirror / Atom feed
From: Jim Blandy <jimb@redhat.com>
To: sid@sources.redhat.com
Subject: RFA: add byte-swapping instructions for AMD64
Date: Thu, 16 Dec 2004 13:35:00 -0000	[thread overview]
Message-ID: <vt2mzwenz9f.fsf@zenia.home> (raw)


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

                 reply	other threads:[~2004-12-16 13:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=vt2mzwenz9f.fsf@zenia.home \
    --to=jimb@redhat.com \
    --cc=sid@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).