public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: Harvey Harrison <harvey.harrison@gmail.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"H. Peter Anvin" <hpa@kernel.org>,
	Jaswinder Singh Rajput <jaswinder@kernel.org>,
	Ingo Molnar <mingo@elte.hu>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Sam Ravnborg <sam@ravnborg.org>,
	Jaswinder Singh Rajput <jaswinderrajput@gmail.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH] x86: do not expose CONFIG_BSWAP to userspace
Date: Tue, 3 Feb 2009 19:19:55 +0100	[thread overview]
Message-ID: <200902031919.57107.arnd@arndb.de> (raw)
In-Reply-To: <4980EEA0.4050802@zytor.com>

On Thursday 29 January 2009, H. Peter Anvin wrote:
> Harvey Harrison wrote:
> > On Wed, 2009-01-28 at 15:27 -0800, H. Peter Anvin wrote:
> >> Harvey Harrison wrote:
> >>> Well, that's unfortunate, how about we just export the BSWAP version
> >>> unconditionally and hope pure i386 just goes away someday?
> >>>
> >> Well, we already have MOVBE coming up, too...
> >>
> > 
> > Is someone already working on an __arch_swab{16|32|64}p to use them?
> > 
> 
> Not that I know of, but it's trivial enough.  They can also be used for 
> all-register swapping, too, with the advantage that you get register 
> decoupling.

I just realized that gcc-4.3 and higher have the __builtin_bswap{16,32,64}
functions on x86, which are supposed to do the right thing on any
platform. Maybe a patch like the one below can solve this for both the
kernel and for other users of the byteorder headers. Unfortunately, I
could not find out whether the builtins are available on all other
platforms as well.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

--- a/arch/x86/include/asm/swab.h
+++ b/arch/x86/include/asm/swab.h
@@ -4,9 +4,17 @@
 #include <linux/types.h>
 #include <linux/compiler.h>
 
+#ifdef __CHECKER__
+extern unsigned long __builtin_bswap_32(unsigned long x);
+extern unsigned long long __builtin_bswap_64(unsigned long long x);
+#endif
+
 static inline __attribute_const__ __u32 __arch_swab32(__u32 val)
 {
-#ifdef __i386__
+#if defined(__GNUC__) && ((__GNUC__ > 4) || \
+		((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)))
+	val = __builtin_bswap32(val);
+#elif defined (__i386__)
 # ifdef CONFIG_X86_BSWAP
 	asm("bswap %0" : "=r" (val) : "0" (val));
 # else
@@ -28,7 +36,10 @@ static inline __attribute_const__ __u32 __arch_swab32(__u32 val)
 
 static inline __attribute_const__ __u64 __arch_swab64(__u64 val)
 {
-#ifdef __i386__
+#if defined(__GNUC__) && ((__GNUC__ > 4) || \
+		((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)))
+	return __builtin_bswap64(val);
+#elif defined (__i386__)
 	union {
 		struct {
 			__u32 a;

  reply	other threads:[~2009-02-03 18:20 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20090127222825.GA27097@elte.hu>
2009-01-27 22:57 ` [mingo@elte.hu: [git pull] headers_check fixes] Linus Torvalds
2009-01-27 23:22   ` H. Peter Anvin
2009-01-27 23:29     ` Linus Torvalds
2009-01-28  0:12       ` H. Peter Anvin
2009-01-28  0:19         ` Linus Torvalds
2009-01-28  1:02           ` H. Peter Anvin
2009-01-27 23:31   ` Ingo Molnar
2009-01-27 23:43     ` Linus Torvalds
2009-01-27 23:51     ` Vegard Nossum
2009-01-30 14:01     ` Jaswinder Singh Rajput
2009-01-30 18:20       ` Ingo Molnar
2009-01-28  0:03   ` Harvey Harrison
2009-01-28  1:36   ` Jaswinder Singh Rajput
2009-01-28 12:37     ` Arnd Bergmann
2009-01-28 17:48       ` H. Peter Anvin
2009-01-28 19:22         ` Harvey Harrison
2009-01-28 19:44           ` Linus Torvalds
2009-01-28 20:03             ` Harvey Harrison
2009-01-28 21:25               ` H. Peter Anvin
2009-01-28 21:58                 ` [PATCH] x86: do not expose CONFIG_BSWAP to userspace Harvey Harrison
2009-01-28 22:13                   ` Linus Torvalds
2009-01-28 22:40                     ` Harvey Harrison
2009-01-30 20:37                       ` Pavel Machek
2009-01-28 22:15                   ` H. Peter Anvin
2009-01-28 22:38                     ` Harvey Harrison
2009-01-28 23:04                       ` Ben Pfaff
2009-01-30 18:20                         ` H. Peter Anvin
2009-01-28 23:27                       ` H. Peter Anvin
2009-01-28 23:36                         ` Harvey Harrison
2009-01-28 23:47                           ` H. Peter Anvin
2009-02-03 18:19                             ` Arnd Bergmann [this message]
2009-01-31 18:43                       ` Maciej W. Rozycki
2009-01-31 20:24                         ` H. Peter Anvin
2009-01-28 23:24                     ` Arnd Bergmann
2009-01-28 23:30                       ` H. Peter Anvin
2009-01-28 20:49             ` [mingo@elte.hu: [git pull] headers_check fixes] Sam Ravnborg
2009-01-28 21:23           ` H. Peter Anvin
2009-01-28 21:06   ` Sam Ravnborg

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=200902031919.57107.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=harvey.harrison@gmail.com \
    --cc=hpa@kernel.org \
    --cc=hpa@zytor.com \
    --cc=jaswinder@kernel.org \
    --cc=jaswinderrajput@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=sam@ravnborg.org \
    --cc=torvalds@linux-foundation.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