The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH V2 mmots] fs/hfsplus/wrapper.c: replace shift loop by fls
@ 2014-05-16 20:38 Fabian Frederick
  2014-05-19 23:09 ` Andrew Morton
  0 siblings, 1 reply; 7+ messages in thread
From: Fabian Frederick @ 2014-05-16 20:38 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm, Joe Perches

Replace while blocksize;shift by fls -1

Suggested-By: Joe Perches <joe@perches.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
v2: rebased on top of mmots
    compiles without including bitops

 fs/hfsplus/wrapper.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/hfsplus/wrapper.c b/fs/hfsplus/wrapper.c
index 284c90f..8e8cf50d 100644
--- a/fs/hfsplus/wrapper.c
+++ b/fs/hfsplus/wrapper.c
@@ -231,9 +231,7 @@ reread:
 	if (blocksize < HFSPLUS_SECTOR_SIZE || ((blocksize - 1) & blocksize))
 		goto out_free_backup_vhdr;
 	sbi->alloc_blksz = blocksize;
-	sbi->alloc_blksz_shift = 0;
-	while ((blocksize >>= 1) != 0)
-		sbi->alloc_blksz_shift++;
+	sbi->alloc_blksz_shift = fls(blocksize) - 1;
 	blocksize = min_t(u32, sbi->alloc_blksz, PAGE_SIZE);
 
 	/*
-- 
1.8.4.5


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

* Re: [PATCH V2 mmots] fs/hfsplus/wrapper.c: replace shift loop by fls
  2014-05-16 20:38 [PATCH V2 mmots] fs/hfsplus/wrapper.c: replace shift loop by fls Fabian Frederick
@ 2014-05-19 23:09 ` Andrew Morton
  2014-05-19 23:22   ` Joe Perches
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2014-05-19 23:09 UTC (permalink / raw)
  To: Fabian Frederick; +Cc: linux-kernel, Joe Perches

On Fri, 16 May 2014 22:38:15 +0200 Fabian Frederick <fabf@skynet.be> wrote:

> Replace while blocksize;shift by fls -1
> 
> Suggested-By: Joe Perches <joe@perches.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Fabian Frederick <fabf@skynet.be>
> ---
> v2: rebased on top of mmots
>     compiles without including bitops
> 
>  fs/hfsplus/wrapper.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/fs/hfsplus/wrapper.c b/fs/hfsplus/wrapper.c
> index 284c90f..8e8cf50d 100644
> --- a/fs/hfsplus/wrapper.c
> +++ b/fs/hfsplus/wrapper.c
> @@ -231,9 +231,7 @@ reread:
>  	if (blocksize < HFSPLUS_SECTOR_SIZE || ((blocksize - 1) & blocksize))
>  		goto out_free_backup_vhdr;
>  	sbi->alloc_blksz = blocksize;
> -	sbi->alloc_blksz_shift = 0;
> -	while ((blocksize >>= 1) != 0)
> -		sbi->alloc_blksz_shift++;
> +	sbi->alloc_blksz_shift = fls(blocksize) - 1;
>  	blocksize = min_t(u32, sbi->alloc_blksz, PAGE_SIZE);

fls() always makes my brain hurt.  ilog() is nicer?

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

* Re: [PATCH V2 mmots] fs/hfsplus/wrapper.c: replace shift loop by fls
  2014-05-19 23:09 ` Andrew Morton
@ 2014-05-19 23:22   ` Joe Perches
  2014-05-19 23:40     ` Andrew Morton
  0 siblings, 1 reply; 7+ messages in thread
From: Joe Perches @ 2014-05-19 23:22 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Fabian Frederick, linux-kernel

On Mon, 2014-05-19 at 16:09 -0700, Andrew Morton wrote:
> On Fri, 16 May 2014 22:38:15 +0200 Fabian Frederick <fabf@skynet.be> wrote:
> > Replace while blocksize;shift by fls -1
[]
> fls() always makes my brain hurt.  ilog() is nicer?

Maybe take an aspirin?

ilog2(n) is effectively fls(n) - 1 but n can be
either u64 or u64 and ilog2 is compile-time
optimized when n is constant.

blocksize is a non-const u32 here.



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

* Re: [PATCH V2 mmots] fs/hfsplus/wrapper.c: replace shift loop by fls
  2014-05-19 23:22   ` Joe Perches
@ 2014-05-19 23:40     ` Andrew Morton
  2014-05-19 23:50       ` Joe Perches
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2014-05-19 23:40 UTC (permalink / raw)
  To: Joe Perches; +Cc: Fabian Frederick, linux-kernel

On Mon, 19 May 2014 16:22:28 -0700 Joe Perches <joe@perches.com> wrote:

> On Mon, 2014-05-19 at 16:09 -0700, Andrew Morton wrote:
> > On Fri, 16 May 2014 22:38:15 +0200 Fabian Frederick <fabf@skynet.be> wrote:
> > > Replace while blocksize;shift by fls -1
> []
> > fls() always makes my brain hurt.  ilog() is nicer?
> 
> Maybe take an aspirin?
> 
> ilog2(n) is effectively fls(n) - 1

Precisely.  ilog2() means "integer log 2".  Whereas fls() is some weird
low-level bit-scanning thing.

What we want at this callsite is "integer log 2".  So use it.

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

* Re: [PATCH V2 mmots] fs/hfsplus/wrapper.c: replace shift loop by fls
  2014-05-19 23:40     ` Andrew Morton
@ 2014-05-19 23:50       ` Joe Perches
  2014-05-20  5:02         ` Fabian Frederick
  0 siblings, 1 reply; 7+ messages in thread
From: Joe Perches @ 2014-05-19 23:50 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Fabian Frederick, linux-kernel

On Mon, 2014-05-19 at 16:40 -0700, Andrew Morton wrote:
> On Mon, 19 May 2014 16:22:28 -0700 Joe Perches <joe@perches.com> wrote:
> 
> > On Mon, 2014-05-19 at 16:09 -0700, Andrew Morton wrote:
> > > On Fri, 16 May 2014 22:38:15 +0200 Fabian Frederick <fabf@skynet.be> wrote:
> > > > Replace while blocksize;shift by fls -1
> > []
> > > fls() always makes my brain hurt.  ilog() is nicer?
> > Maybe take an aspirin?
> > ilog2(n) is effectively fls(n) - 1
> Precisely.  ilog2() means "integer log 2".  Whereas fls() is some weird
> low-level bit-scanning thing.

<shrug>  find-last[bit]-set is pretty obvious to me.
ilog2(n) makes me think just a little more.

> What we want at this callsite is "integer log 2".  So use it.

Same thing.  Same ratio of use too.

$ git grep -w fls | wc -l
457
$ git grep -w ilog2 | wc -l
391



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

* Re: [PATCH V2 mmots] fs/hfsplus/wrapper.c: replace shift loop by fls
  2014-05-19 23:50       ` Joe Perches
@ 2014-05-20  5:02         ` Fabian Frederick
  2014-05-20  5:10           ` Joe Perches
  0 siblings, 1 reply; 7+ messages in thread
From: Fabian Frederick @ 2014-05-20  5:02 UTC (permalink / raw)
  To: Joe Perches; +Cc: Andrew Morton, linux-kernel

On Mon, 19 May 2014 16:50:05 -0700
Joe Perches <joe@perches.com> wrote:

> On Mon, 2014-05-19 at 16:40 -0700, Andrew Morton wrote:
> > On Mon, 19 May 2014 16:22:28 -0700 Joe Perches <joe@perches.com> wrote:
> > 
> > > On Mon, 2014-05-19 at 16:09 -0700, Andrew Morton wrote:
> > > > On Fri, 16 May 2014 22:38:15 +0200 Fabian Frederick <fabf@skynet.be> wrote:
> > > > > Replace while blocksize;shift by fls -1
> > > []
> > > > fls() always makes my brain hurt.  ilog() is nicer?
> > > Maybe take an aspirin?
> > > ilog2(n) is effectively fls(n) - 1
> > Precisely.  ilog2() means "integer log 2".  Whereas fls() is some weird
> > low-level bit-scanning thing.
> 
> <shrug>  find-last[bit]-set is pretty obvious to me.
> ilog2(n) makes me think just a little more.
> 
> > What we want at this callsite is "integer log 2".  So use it.
> 
> Same thing.  Same ratio of use too.
> 
> $ git grep -w fls | wc -l
> 457
> $ git grep -w ilog2 | wc -l
> 391
and the winner is ? :)
> 
> 

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

* Re: [PATCH V2 mmots] fs/hfsplus/wrapper.c: replace shift loop by fls
  2014-05-20  5:02         ` Fabian Frederick
@ 2014-05-20  5:10           ` Joe Perches
  0 siblings, 0 replies; 7+ messages in thread
From: Joe Perches @ 2014-05-20  5:10 UTC (permalink / raw)
  To: Fabian Frederick; +Cc: Andrew Morton, linux-kernel

On Tue, 2014-05-20 at 07:02 +0200, Fabian Frederick wrote:
> and the winner is ? :)

Either works.  You're the patch submitter.  Pick one.

But I'm sure you know I'm not pushing the patch upstream... :)


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

end of thread, other threads:[~2014-05-20  5:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-16 20:38 [PATCH V2 mmots] fs/hfsplus/wrapper.c: replace shift loop by fls Fabian Frederick
2014-05-19 23:09 ` Andrew Morton
2014-05-19 23:22   ` Joe Perches
2014-05-19 23:40     ` Andrew Morton
2014-05-19 23:50       ` Joe Perches
2014-05-20  5:02         ` Fabian Frederick
2014-05-20  5:10           ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox