All of lore.kernel.org
 help / color / mirror / Atom feed
* using gcc built-ins for bitops?
@ 2004-06-24  7:09 Arjan van de Ven
  2004-06-24  9:00 ` Andrew Morton
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Arjan van de Ven @ 2004-06-24  7:09 UTC (permalink / raw)
  To: linux-kernel; +Cc: torvalds, akpm

Hi,

gcc 3.4 gained support for several typical bitops as builtin directives.
Using these over inline asm has a few advantages:
* gcc can optimize constants into these better
* gcc can reorder and schedule the code better
* gcc can allocate registers etc better for the code

The question is if we consider it desirable to go down this road or not. In
order to help that discussion I've attached a patch below that switches the
i386 ffz() function to the gcc builtin version, conditional on gcc having
support for this. Before I go down the road of converting more functions
and/or architectures.... is this worth doing?

Greetings,
   Arjan van de Ven


--- linux-2.6.7/include/asm-i386/bitops.h~	2004-06-23 23:45:06.048614387 +0200
+++ linux-2.6.7/include/asm-i386/bitops.h	2004-06-23 23:45:06.048614387 +0200
@@ -344,6 +344,8 @@
  *
  * Undefined if no zero exists, so code should check against ~0UL first.
  */
+ 
+#ifndef HAVE_BUILTIN_CTZL
 static inline unsigned long ffz(unsigned long word)
 {
 	__asm__("bsfl %1,%0"
@@ -351,6 +353,12 @@
 		:"r" (~word));
 	return word;
 }
+#else
+static inline unsigned long ffz (unsigned long word) 
+{ 
+	return __builtin_ctzl (~word); 
+}
+#endif
 
 /**
  * __ffs - find first bit in word.
--- linux-2.6.7/include/linux/compiler-gcc3.h~	2004-06-24 09:26:04.123455290 +0200
+++ linux-2.6.7/include/linux/compiler-gcc3.h	2004-06-24 09:26:04.123455290 +0200
@@ -19,6 +19,11 @@
 # define __attribute_used__	__attribute__((__unused__))
 #endif
 
+#if __GNUC_MINOR__ >= 4
+#define HAVE_BUILTIN_CTZL
+#endif
+
+
 #define __attribute_pure__	__attribute__((pure))
 #define __attribute_const__	__attribute__((__const__))
 

^ permalink raw reply	[flat|nested] 17+ messages in thread
[parent not found: <2awGH-DF-17@gated-at.bofh.it>]

end of thread, other threads:[~2004-06-24 16:02 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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.