lkml.org 
[lkml]   [2004]   [Jun]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subjectusing gcc built-ins for bitops?
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__))

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 14:04    [W:0.212 / U:0.316 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site