All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] __ffs64()
@ 2009-04-22 15:46 Steven Whitehouse
  2009-04-22 20:46 ` Willy Tarreau
  2009-04-22 20:59 ` Christoph Lameter
  0 siblings, 2 replies; 5+ messages in thread
From: Steven Whitehouse @ 2009-04-22 15:46 UTC (permalink / raw)
  To: linux-kernel

Hi,

I'd like to add a new bitop, __ffs64() which I need in order to fix a
bug in GFS2. The question is, where should it go?

On 64 bit arches, __ffs64() would be a synonym for __ffs(), but on 32
bit arches it degenerates to a conditional plus a call to __ffs(). I'm
assuming that there would not be a lot of point in optimising this
operation on 32 bit arches even if such an instruction was available, so
that I should do something like the below patch.

Does that seem reasonable, or should I give it a separate header file
under asm-generic/bitops/ like some of the similar operations? It looks
like I'd have to touch a lot of other files if I were to go that route,

Steve.

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 6182913..d15255f 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -112,6 +112,23 @@ static inline unsigned fls_long(unsigned long l)
 	return fls64(l);
 }
 
+/**
+ * __ffs64 - find first set bit in a 64 bit word
+ * @word: The 64 bit word
+ *
+ * On 64 bit arches this is a synomyn for __ffs
+ */
+static inline unsigned long __ffs64(u64 word)
+{
+#if BITS_PER_LONG == 32
+	if (((u32)word) == 0UL)
+		return __ffs((u32)(word >> 32)) + 32;
+#elif BITS_PER_LONG != 64
+#error BITS_PER_LONG not 32 or 64
+#endif
+	return __ffs((unsigned long)word);
+}
+
 #ifdef __KERNEL__
 #ifdef CONFIG_GENERIC_FIND_FIRST_BIT
 



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [RFC] __ffs64()
  2009-04-22 15:46 [RFC] __ffs64() Steven Whitehouse
@ 2009-04-22 20:46 ` Willy Tarreau
  2009-04-22 20:59 ` Christoph Lameter
  1 sibling, 0 replies; 5+ messages in thread
From: Willy Tarreau @ 2009-04-22 20:46 UTC (permalink / raw)
  To: Steven Whitehouse; +Cc: linux-kernel

Hi Steve,

On Wed, Apr 22, 2009 at 04:46:32PM +0100, Steven Whitehouse wrote:
> Hi,
> 
> I'd like to add a new bitop, __ffs64() which I need in order to fix a
> bug in GFS2. The question is, where should it go?
> 
> On 64 bit arches, __ffs64() would be a synonym for __ffs(), but on 32
> bit arches it degenerates to a conditional plus a call to __ffs(). I'm
> assuming that there would not be a lot of point in optimising this
> operation on 32 bit arches even if such an instruction was available, so
> that I should do something like the below patch.
> 
> Does that seem reasonable, or should I give it a separate header file
> under asm-generic/bitops/ like some of the similar operations? It looks
> like I'd have to touch a lot of other files if I were to go that route,

While I have no reply to your questions above, I have one minor comment :

> +/**
> + * __ffs64 - find first set bit in a 64 bit word
> + * @word: The 64 bit word
> + *
> + * On 64 bit arches this is a synomyn for __ffs
> + */

IMHO you should remind here that the result is undefined when word==0
and the caller must check against it first.

> +static inline unsigned long __ffs64(u64 word)
> +{
> +#if BITS_PER_LONG == 32
> +	if (((u32)word) == 0UL)
> +		return __ffs((u32)(word >> 32)) + 32;
> +#elif BITS_PER_LONG != 64
> +#error BITS_PER_LONG not 32 or 64
> +#endif
> +	return __ffs((unsigned long)word);
> +}
> +
>  #ifdef __KERNEL__
>  #ifdef CONFIG_GENERIC_FIND_FIRST_BIT

Regards,
Willy


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC] __ffs64()
  2009-04-22 15:46 [RFC] __ffs64() Steven Whitehouse
  2009-04-22 20:46 ` Willy Tarreau
@ 2009-04-22 20:59 ` Christoph Lameter
  2009-04-23  8:22   ` Steven Whitehouse
  1 sibling, 1 reply; 5+ messages in thread
From: Christoph Lameter @ 2009-04-22 20:59 UTC (permalink / raw)
  To: Steven Whitehouse; +Cc: linux-kernel

On Wed, 22 Apr 2009, Steven Whitehouse wrote:

> I'd like to add a new bitop, __ffs64() which I need in order to fix a
> bug in GFS2. The question is, where should it go?

I think the location is right.

> On 64 bit arches, __ffs64() would be a synonym for __ffs(), but on 32
> bit arches it degenerates to a conditional plus a call to __ffs(). I'm
> assuming that there would not be a lot of point in optimising this
> operation on 32 bit arches even if such an instruction was available, so
> that I should do something like the below patch.
>
> Does that seem reasonable, or should I give it a separate header file
> under asm-generic/bitops/ like some of the similar operations? It looks
> like I'd have to touch a lot of other files if I were to go that route,

One issue may be that some 32 bit architectures have a better way of doing
64 bit ffs.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC] __ffs64()
  2009-04-22 20:59 ` Christoph Lameter
@ 2009-04-23  8:22   ` Steven Whitehouse
  2009-04-23  9:07     ` Benny Halevy
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Whitehouse @ 2009-04-23  8:22 UTC (permalink / raw)
  To: Christoph Lameter; +Cc: linux-kernel

Hi,

On Wed, 2009-04-22 at 16:59 -0400, Christoph Lameter wrote:
> On Wed, 22 Apr 2009, Steven Whitehouse wrote:
> 
> > I'd like to add a new bitop, __ffs64() which I need in order to fix a
> > bug in GFS2. The question is, where should it go?
> 
> I think the location is right.
> 
> > On 64 bit arches, __ffs64() would be a synonym for __ffs(), but on 32
> > bit arches it degenerates to a conditional plus a call to __ffs(). I'm
> > assuming that there would not be a lot of point in optimising this
> > operation on 32 bit arches even if such an instruction was available, so
> > that I should do something like the below patch.
> >
> > Does that seem reasonable, or should I give it a separate header file
> > under asm-generic/bitops/ like some of the similar operations? It looks
> > like I'd have to touch a lot of other files if I were to go that route,
> 
> One issue may be that some 32 bit architectures have a better way of doing
> 64 bit ffs.
> 
Yes, thats what I was worried about. I don't have a wide enough
knowledge of the different architectures to make a judgement about
whether this is likely or not.

I guess maybe the right thing to do is to leave it as I did it in the
patch and if an arch wants to create its own implementation, then it
could be moved at that stage.

Steve.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC] __ffs64()
  2009-04-23  8:22   ` Steven Whitehouse
@ 2009-04-23  9:07     ` Benny Halevy
  0 siblings, 0 replies; 5+ messages in thread
From: Benny Halevy @ 2009-04-23  9:07 UTC (permalink / raw)
  To: Steven Whitehouse; +Cc: Christoph Lameter, linux-kernel

On Apr. 23, 2009, 11:22 +0300, Steven Whitehouse <swhiteho@redhat.com> wrote:
> Hi,
> 
> On Wed, 2009-04-22 at 16:59 -0400, Christoph Lameter wrote:
>> On Wed, 22 Apr 2009, Steven Whitehouse wrote:
>>
>>> I'd like to add a new bitop, __ffs64() which I need in order to fix a
>>> bug in GFS2. The question is, where should it go?
>> I think the location is right.
>>
>>> On 64 bit arches, __ffs64() would be a synonym for __ffs(), but on 32
>>> bit arches it degenerates to a conditional plus a call to __ffs(). I'm
>>> assuming that there would not be a lot of point in optimising this
>>> operation on 32 bit arches even if such an instruction was available, so
>>> that I should do something like the below patch.
>>>
>>> Does that seem reasonable, or should I give it a separate header file
>>> under asm-generic/bitops/ like some of the similar operations? It looks
>>> like I'd have to touch a lot of other files if I were to go that route,
>> One issue may be that some 32 bit architectures have a better way of doing
>> 64 bit ffs.
>>
> Yes, thats what I was worried about. I don't have a wide enough
> knowledge of the different architectures to make a judgement about
> whether this is likely or not.
> 
> I guess maybe the right thing to do is to leave it as I did it in the
> patch and if an arch wants to create its own implementation, then it
> could be moved at that stage.

Agreed.

Benny

> 
> Steve.
> 
> 
> --
> 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/


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-04-23  9:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-22 15:46 [RFC] __ffs64() Steven Whitehouse
2009-04-22 20:46 ` Willy Tarreau
2009-04-22 20:59 ` Christoph Lameter
2009-04-23  8:22   ` Steven Whitehouse
2009-04-23  9:07     ` Benny Halevy

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.