All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arjan van de Ven <arjanv@redhat.com>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org, torvalds@osdl.org
Subject: Re: using gcc built-ins for bitops?
Date: Thu, 24 Jun 2004 13:31:51 +0200	[thread overview]
Message-ID: <20040624113151.GA21376@devserv.devel.redhat.com> (raw)
In-Reply-To: <20040624020022.0601d4ae.akpm@osdl.org>

On Thu, Jun 24, 2004 at 02:00:22AM -0700, Andrew Morton wrote:
> For the implementation it would be nice to have the old-style
> implementations in one header and the new-style ones in a separate header. 
> That would create a bit of an all-or-nothing situation, but that should be
> OK?

In addition I stuck those in asm-generic since they no longer are
architecture specific....

diff -purN linux-2.6.7/include/asm-i386/bitops.h linux/include/asm-i386/bitops.h
--- linux-2.6.7/include/asm-i386/bitops.h	2004-06-24 17:26:10.030404507 +0200
+++ linux/include/asm-i386/bitops.h	2004-06-24 18:47:26.582837487 +0200
@@ -338,34 +338,6 @@ static inline int find_first_bit(const u
  */
 int find_next_bit(const unsigned long *addr, int size, int offset);
 
-/**
- * ffz - find first zero in word.
- * @word: The word to search
- *
- * Undefined if no zero exists, so code should check against ~0UL first.
- */
-static inline unsigned long ffz(unsigned long word)
-{
-	__asm__("bsfl %1,%0"
-		:"=r" (word)
-		:"r" (~word));
-	return word;
-}
-
-/**
- * __ffs - find first bit in word.
- * @word: The word to search
- *
- * Undefined if no bit exists, so code should check against 0 first.
- */
-static inline unsigned long __ffs(unsigned long word)
-{
-	__asm__("bsfl %1,%0"
-		:"=r" (word)
-		:"rm" (word));
-	return word;
-}
-
 /*
  * fls: find last bit set.
  */
@@ -374,6 +346,12 @@ static inline unsigned long __ffs(unsign
 
 #ifdef __KERNEL__
 
+#ifdef USE_BUILTIN_BITOPS
+#include <asm-generic/bitops_gcc.h>
+#else
+#include <asm/bitops_asm.h>
+#endif
+
 /*
  * Every architecture must define this function. It's the fastest
  * way of searching a 140-bit bitmap where the first 100 bits are
@@ -394,25 +372,6 @@ static inline int sched_find_first_bit(c
 }
 
 /**
- * ffs - find first bit set
- * @x: the word to search
- *
- * This is defined the same way as
- * the libc and compiler builtin ffs routines, therefore
- * differs in spirit from the above ffz (man ffs).
- */
-static inline int ffs(int x)
-{
-	int r;
-
-	__asm__("bsfl %1,%0\n\t"
-		"jnz 1f\n\t"
-		"movl $-1,%0\n"
-		"1:" : "=r" (r) : "rm" (x));
-	return r+1;
-}
-
-/**
  * hweightN - returns the hamming weight of a N-bit word
  * @x: the word to weigh
  *
diff -purN linux-2.6.7/include/asm-generic/bitops_gcc.h linux/include/asm-generic/bitops_gcc.h
--- linux-2.6.7/include/asm-generic/bitops_gcc.h	1970-01-01 01:00:00.000000000 +0100
+++ linux/include/asm-generic/bitops_gcc.h	2004-06-24 18:45:03.483991176 +0200
@@ -0,0 +1,61 @@
+#ifndef _I386_BITOPS_GCC_H
+#define _I386_BITOPS_GCC_H
+
+/*
+ * Copyright 1992, Linus Torvalds.
+ * 
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *   the GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program;  if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * June 2004 - Modified by Arjan van de Ven <arjanv@redhat.com> to use gcc builtin's
+ *
+ */
+
+
+/**
+ * ffz - find first zero in word.
+ * @word: The word to search
+ *
+ * Undefined if no zero exists, so code should check against ~0UL first.
+ */
+static inline unsigned long ffz(unsigned long word)
+{
+	return __builtin_ctzl(~word);
+}
+
+/**
+ * __ffs - find first bit in word.
+ * @word: The word to search
+ *
+ * Undefined if no bit exists, so code should check against 0 first.
+ */
+static inline unsigned long __ffs(unsigned long word)
+{
+	return __builtin_ctzl(word);
+}
+
+/**
+ * ffs - find first bit set
+ * @x: the word to search
+ *
+ * This is defined the same way as
+ * the libc and compiler builtin ffs routines, therefore
+ * differs in spirit from the above ffz (man ffs).
+ */
+static inline int ffs(int x)
+{
+	return __builtin_ffs(x);
+}
+
+#endif /* _I386_BITOPS_GCC_H */
diff -purN linux-2.6.7/include/asm-i386/bitops_asm.h linux/include/asm-i386/bitops_asm.h
--- linux-2.6.7/include/asm-i386/bitops_asm.h	1970-01-01 01:00:00.000000000 +0100
+++ linux/include/asm-i386/bitops_asm.h	2004-06-24 18:45:15.669530459 +0200
@@ -0,0 +1,56 @@
+#ifndef _I386_BITOPS_ASM_H
+#define _I386_BITOPS_ASM_H
+
+/*
+ * Copyright 1992, Linus Torvalds.
+ */
+
+
+/**
+ * ffz - find first zero in word.
+ * @word: The word to search
+ *
+ * Undefined if no zero exists, so code should check against ~0UL first.
+ */
+static inline unsigned long ffz(unsigned long word)
+{
+	__asm__("bsfl %1,%0"
+		:"=r" (word)
+		:"r" (~word));
+	return word;
+}
+
+/**
+ * __ffs - find first bit in word.
+ * @word: The word to search
+ *
+ * Undefined if no bit exists, so code should check against 0 first.
+ */
+static inline unsigned long __ffs(unsigned long word)
+{
+	__asm__("bsfl %1,%0"
+		:"=r" (word)
+		:"rm" (word));
+	return word;
+}
+
+/**
+ * ffs - find first bit set
+ * @x: the word to search
+ *
+ * This is defined the same way as
+ * the libc and compiler builtin ffs routines, therefore
+ * differs in spirit from the above ffz (man ffs).
+ */
+static inline int ffs(int x)
+{
+	int r;
+
+	__asm__("bsfl %1,%0\n\t"
+		"jnz 1f\n\t"
+		"movl $-1,%0\n"
+		"1:" : "=r" (r) : "rm" (x));
+	return r+1;
+}
+
+#endif /* _I386_BITOPS_ASM_H */
diff -purN linux-2.6.7/include/linux/compiler-gcc+.h linux/include/linux/compiler-gcc+.h
--- linux-2.6.7/include/linux/compiler-gcc+.h	2004-06-24 17:26:10.513346616 +0200
+++ linux/include/linux/compiler-gcc+.h	2004-06-24 18:48:29.266323429 +0200
@@ -6,6 +6,7 @@
  */
 #include <linux/compiler-gcc.h>
 
+#define USE_BUILTIN_BITOPS
 #define inline			__inline__ __attribute__((always_inline))
 #define __inline__		__inline__ __attribute__((always_inline))
 #define __inline		__inline__ __attribute__((always_inline))
diff -purN linux-2.6.7/include/linux/compiler-gcc3.h linux/include/linux/compiler-gcc3.h
--- linux-2.6.7/include/linux/compiler-gcc3.h	2004-06-24 17:26:10.511346855 +0200
+++ linux/include/linux/compiler-gcc3.h	2004-06-24 18:48:16.189890940 +0200
@@ -19,6 +19,10 @@
 # define __attribute_used__	__attribute__((__unused__))
 #endif
 
+#if __GNUC_MINOR__ >= 4
+#define USE_BUILTIN_BITOPS
+#endif
+
 #define __attribute_pure__	__attribute__((pure))
 #define __attribute_const__	__attribute__((__const__))
 

  parent reply	other threads:[~2004-06-24 11:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-24  7:09 using gcc built-ins for bitops? Arjan van de Ven
2004-06-24  9:00 ` Andrew Morton
2004-06-24  9:06   ` Arjan van de Ven
2004-06-24 13:41     ` Ben Collins
2004-06-24  9:17   ` Arjan van de Ven
2004-06-24 11:31   ` Arjan van de Ven [this message]
2004-06-24 12:05     ` Jakub Jelinek
2004-06-24 12:35       ` Arjan van de Ven
2004-06-24 15:30         ` Linus Torvalds
2004-06-24  9:31 ` Paul Jackson
2004-06-24 10:36   ` Jakub Jelinek
2004-06-24 15:25     ` Linus Torvalds
2004-06-24 11:51 ` Gabriel Paubert
2004-06-24 12:21   ` Arjan van de Ven
     [not found] <2awGH-DF-17@gated-at.bofh.it>
2004-06-24 13:46 ` Pascal Schmidt
2004-06-24 13:49   ` Arjan van de Ven
2004-06-24 13:51     ` Pascal Schmidt

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=20040624113151.GA21376@devserv.devel.redhat.com \
    --to=arjanv@redhat.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.