public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paweł Sikora" <pluto@agmk.net>
To: linux-kernel@vger.kernel.org
Subject: include/arch/x86/swab.h badness?
Date: Fri, 7 Oct 2011 21:13:09 +0200	[thread overview]
Message-ID: <201110072113.09495.pluto@agmk.net> (raw)

Hi,

during compiling some byte-order related code for 32-bit x86 which uses glibc's
#include <byteorder.h> i've noticed that __be*_to_cpu uses a generic i386 (ror+xchg) impl.
quick investigation shows that #include <linux/asm/swab.h> sucks a little ;)

please look at the current linux implementation:

static __inline__ __u32 __arch_swab32(__u32 val)
{
#ifdef __i386__
# ifdef CONFIG_X86_BSWAP
        __asm__("bswap %0" : "=r" (val) : "0" (val));
# else
        __asm__("xchgb %b0,%h0\n\t"     /* swap lower bytes     */
            "rorl $16,%0\n\t"   /* swap words           */
            "xchgb %b0,%h0"     /* swap higher bytes    */
            : "=q" (val)
            : "0" (val));
# endif

#else /* __i386__ */
        __asm__("bswapl %0"
            : "=r" (val)
            : "0" (val));
#endif
        return val;
}

in the userspace, the __i386__ is always defined by gcc for any -march=i486/i586/...
and the CONFIG_X86_BSWAP is never defined, so the userspace always ends with inlined
assembly with generic i386 implementation :(

could you please improve this #ifdefs to get bswap opcodes for i486+ ?
maybe the __builtin_bswap* should be used in recent kernel tree?

BR,
Paweł.


                 reply	other threads:[~2011-10-07 19:13 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=201110072113.09495.pluto@agmk.net \
    --to=pluto@agmk.net \
    --cc=linux-kernel@vger.kernel.org \
    /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