* [PATCH] gcc-3.1 ffs problem, kernel 2.4.18
@ 2002-03-20 17:42 Michal Moskal
2002-03-29 5:10 ` Richard Henderson
0 siblings, 1 reply; 5+ messages in thread
From: Michal Moskal @ 2002-03-20 17:42 UTC (permalink / raw)
To: linux-kernel
Following patch is needed to compile linux-2.4.18 with xfs patch with
recent gcc 3.1 snapshot. It is clearly bug in linux includes (they use
asm code unconditionally, even on constants, and they can get constants
if exposed to tree-inliner). Other asm includes might need fixing too,
I saw asm-cris is fixed already.
Beside this linux-2.4.18 compiled with gcc-3.1 20020311 works fine for
me.
diff -ur linux-/include/asm-i386/bitops.h linux/include/asm-i386/bitops.h
--- linux-/include/asm-i386/bitops.h Thu Nov 22 20:46:18 2001
+++ linux/include/asm-i386/bitops.h Tue Mar 5 21:08:15 2002
@@ -316,6 +316,8 @@
return (offset + set + res);
}
+#include <linux/bitops.h>
+
/**
* ffz - find first zero in word.
* @word: The word to search
@@ -324,10 +326,16 @@
*/
static __inline__ unsigned long ffz(unsigned long word)
{
- __asm__("bsfl %1,%0"
- :"=r" (word)
- :"r" (~word));
- return word;
+ /* The generic_ffs function is used to avoid the asm when the
+ argument is a constant. */
+ if (__builtin_constant_p (word)) {
+ return (~word ? (unsigned long) generic_ffs ((int) ~word) - 1 : 32);
+ } else {
+ __asm__("bsfl %1,%0"
+ :"=r" (word)
+ :"r" (~word));
+ return word;
+ }
}
#ifdef __KERNEL__
@@ -342,13 +350,19 @@
*/
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) : "g" (x));
- return r+1;
+ /* The generic_ffs function is used to avoid the asm when the
+ argument is a constant. */
+ if (__builtin_constant_p (x)) {
+ return generic_ffs (x);
+ } else {
+ int r;
+
+ __asm__("bsfl %1,%0\n\t"
+ "jnz 1f\n\t"
+ "movl $-1,%0\n"
+ "1:" : "=r" (r) : "g" (x));
+ return r+1;
+ }
}
/**
--
: Michal Moskal :::::::: malekith/at/pld.org.pl : GCS {C,UL}++++$ a? !tv
: PLD Linux ::::::: Wroclaw University, CS Dept : {E-,w}-- {b++,e}>+++ h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gcc-3.1 ffs problem, kernel 2.4.18
2002-03-20 17:42 [PATCH] gcc-3.1 ffs problem, kernel 2.4.18 Michal Moskal
@ 2002-03-29 5:10 ` Richard Henderson
[not found] ` <20020329115731.GA3227@ep09.kernel.pl>
0 siblings, 1 reply; 5+ messages in thread
From: Richard Henderson @ 2002-03-29 5:10 UTC (permalink / raw)
To: Michal Moskal; +Cc: linux-kernel
On Wed, Mar 20, 2002 at 06:42:38PM +0100, Michal Moskal wrote:
> Following patch is needed to compile linux-2.4.18 with xfs patch with
> recent gcc 3.1 snapshot.
What is the failure mode?
> It is clearly bug in linux includes (they use asm code unconditionally,
> even on constants, ...
So? I don't see that that's a *bug* at all. A missed optimization
opportunity yes, bug no.
> Beside this linux-2.4.18 compiled with gcc-3.1 20020311 works fine for
> me.
Thanks for testing though.
r~
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gcc-3.1 ffs problem, kernel 2.4.18
[not found] ` <20020402114848.GA9004@ep09.kernel.pl>
@ 2002-04-02 22:59 ` Richard Henderson
2002-04-03 0:04 ` Linus Torvalds
0 siblings, 1 reply; 5+ messages in thread
From: Richard Henderson @ 2002-04-02 22:59 UTC (permalink / raw)
To: Michal Moskal; +Cc: torvalds, linux-kernel
On Tue, Apr 02, 2002 at 01:48:48PM +0200, Michal Moskal wrote:
> Could you please check if it compiles for you?
Ah, I see the bug. I was looking at ffz (which is correct),
not ffs (which isn't).
> __asm__("bsfl %1,%0\n\t"
> "jnz 1f\n\t"
> "movl $-1,%0\n"
> "1:" : "=r" (r) : "g" (x));
The problem is ^^^
That sez any of register, memory, or immediate is ok.
It should be "r" instead, just like in ffz.
That said, we should probably be using __builtin_ffs
instead. The compiler knows how to do bsfl plus the
adjustment. Plus, it knows how to evaluate it at
compile-time for constants.
r~
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gcc-3.1 ffs problem, kernel 2.4.18
2002-04-02 22:59 ` Richard Henderson
@ 2002-04-03 0:04 ` Linus Torvalds
2002-04-03 11:00 ` Richard Henderson
0 siblings, 1 reply; 5+ messages in thread
From: Linus Torvalds @ 2002-04-03 0:04 UTC (permalink / raw)
To: Richard Henderson; +Cc: Michal Moskal, linux-kernel
On Tue, 2 Apr 2002, Richard Henderson wrote:
>
> That said, we should probably be using __builtin_ffs
> instead. The compiler knows how to do bsfl plus the
> adjustment. Plus, it knows how to evaluate it at
> compile-time for constants.
When was __builtin_ffs introduced? I know it didn't use to exist, but
we've obviously bumped up the gcc requirements several times, so..
Linus
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gcc-3.1 ffs problem, kernel 2.4.18
2002-04-03 0:04 ` Linus Torvalds
@ 2002-04-03 11:00 ` Richard Henderson
0 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2002-04-03 11:00 UTC (permalink / raw)
To: Linus Torvalds; +Cc: Michal Moskal, linux-kernel
On Tue, Apr 02, 2002 at 04:04:58PM -0800, Linus Torvalds wrote:
> When was __builtin_ffs introduced? I know it didn't use to exist, but
> we've obviously bumped up the gcc requirements several times, so..
Dunno. Before egcs forked.
r~
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-04-03 11:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-03-20 17:42 [PATCH] gcc-3.1 ffs problem, kernel 2.4.18 Michal Moskal
2002-03-29 5:10 ` Richard Henderson
[not found] ` <20020329115731.GA3227@ep09.kernel.pl>
[not found] ` <20020329144232.A495@twiddle.net>
[not found] ` <20020402114848.GA9004@ep09.kernel.pl>
2002-04-02 22:59 ` Richard Henderson
2002-04-03 0:04 ` Linus Torvalds
2002-04-03 11:00 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox