mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Alexander van Heukelum" <heukelum@fastmail.fm>
To: "Matti Aarnio" <matti.aarnio@zmailer.org>
Cc: "Joe Perches" <joe@perches.com>,
	"Harvey Harrison" <harvey.harrison@gmail.com>,
	"Alexander van Heukelum" <heukelum@mailshack.com>,
	"LKML" <linux-kernel@vger.kernel.org>
Subject: Re: Alternative implementation of the generic __ffs
Date: Mon, 21 Apr 2008 13:43:16 +0200	[thread overview]
Message-ID: <1208778196.9210.1248995009@webmail.messagingengine.com> (raw)
In-Reply-To: <20080420123146.GN3700@mea-ext.zmailer.org>

On Sun, 20 Apr 2008 15:31:46 +0300, "Matti Aarnio"
<matti.aarnio@zmailer.org> said:
> On Sun, Apr 20, 2008 at 10:42:21AM +0200, Alexander van Heukelum wrote:
> > On Sat, 19 Apr 2008 20:06:57 -0700, "Joe Perches" <joe@perches.com>
> > said:
> > > On Sun, 2008-04-20 at 01:29 +0300, Matti Aarnio wrote:
> > > > I am curious, why not take the code already in glibc ffs() for ARM ?
> > > > That is, if the ffs() is all that important detail in kernel ?
> > 
> > Hi,
> > 
> > The glibc version is based on a table-lookup. This makes it
> > behave differently in hot and cold cache situations. That's
> > fine if __ffs is used in tight loops, but in the kernel such
> > use of __ffs is avoided because it might be slow. I added it
> > to the benchmark, but it would need testing for the cold
> > cache case too.
> > 
> > As for the importance of __ffs in the kernel: as far as I
> > know the hot-spots in the kernel using __ffs are the
> > schedular (sched_find_first_bit) and the cpu mask walking
> > code (for_each_cpu_mask).
> 
> Perhaps those hot-spots would benefit from more broadly
> accelerable algorithms.

That would be a possibility too ;). The advantages of bitmaps
are that they are so compact and so easy to understand.

>                      ARM architecture v5 introduced
> a CLZ instruction -- Count Leading Zeroes.

Yeah, if such an instruction exist, the arch should provide
optimized versions for the bit functions. The interest here
was to provide a (beter) generic version in pure C for
architectures without such instructions.

Inline assembly versions are indeed provided in
asm-arm/bitops.h for ARM5+.

Greetings,
    Alexander

> Well, gcc's  __builtin_ffs() for ARM Arch5 and up (including
> XScale) does things in a bit more interesting way:
> 
>   http://mail-index.netbsd.org/port-arm/2002/08/20/0001.html
> 
> $ cat try.c
> int foo(int i)
> {
>         return __builtin_ffs(i);
> }
> $ arm-gp2x-linux-gcc -S -O -march=armv5 try.c 
> $ more try.s 
>         .file   "try.c"
>         .text
>         .align  2
>         .global foo
>         .type   foo, %function
> foo:
>         @ args = 0, pretend = 0, frame = 0
>         @ frame_needed = 0, uses_anonymous_args = 0
>         @ link register save eliminated.
>         @ lr needed for prologue
>         rsb     r3, r0, #0
>         and     r3, r3, r0
>         clz     r3, r3
>         rsb     r0, r3, #32
>         bx      lr
>         .size   foo, .-foo
>         .ident  "GCC: (GNU) 4.1.2 (Fedora GP2X 4.1.2-8.fc9)"
> 
> 
> > Greetings,
> >     Alexander
> 
> /Matti Aarnio
-- 
  Alexander van Heukelum
  heukelum@fastmail.fm

-- 
http://www.fastmail.fm - I mean, what is it about a decent email service?


      reply	other threads:[~2008-04-21 11:43 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-31 17:15 [PATCH] x86: generic versions of find_first_(zero_)bit, convert i386 Alexander van Heukelum
2008-03-31 17:22 ` Stephen Hemminger
2008-03-31 19:38   ` Alexander van Heukelum
2008-03-31 21:58     ` Andi Kleen
2008-04-01  8:47 ` Ingo Molnar
2008-04-01  9:46   ` Alexander van Heukelum
2008-04-01 15:41     ` [PATCH] x86: switch x86_64 to generic find_first_bit Alexander van Heukelum
2008-04-01 15:42       ` [PATCH] x86: optimize find_first_bit for small bitmaps Alexander van Heukelum
2008-04-01 15:47         ` [PATCH] x86: remove x86-specific implementations of find_first_bit Alexander van Heukelum
2008-04-03  9:34           ` Alexander van Heukelum
2008-04-04  8:47           ` Ingo Molnar
2008-04-06 17:03     ` [PATCH] x86: generic versions of find_first_(zero_)bit, convert i386 dean gaudet
2008-04-06 18:51       ` Alexander van Heukelum
2008-04-06 20:22         ` dean gaudet
2008-04-07  8:43           ` Ingo Molnar
2008-04-07 10:25           ` Alexander van Heukelum
2008-04-18 20:18             ` Alternative implementation of the generic __ffs Alexander van Heukelum
2008-04-18 23:46               ` dean gaudet
2008-04-19  0:09                 ` Harvey Harrison
2008-04-19  0:20                   ` dean gaudet
2008-04-19  0:58                     ` Joe Perches
2008-04-19  1:04                       ` Harvey Harrison
2008-04-19  1:11                         ` dean gaudet
2008-04-19  2:55                           ` Joe Perches
2008-04-19  4:13                             ` dean gaudet
2008-04-19 10:05                               ` Mikael Pettersson
2008-04-19 12:10                               ` Alexander van Heukelum
2008-04-19 18:17                                 ` Joe Perches
2008-04-19 20:26                                   ` Alexander van Heukelum
2008-04-19 22:29                             ` Matti Aarnio
2008-04-20  3:06                               ` Joe Perches
2008-04-20  8:42                                 ` Alexander van Heukelum
2008-04-20 12:31                                   ` Matti Aarnio
2008-04-21 11:43                                     ` Alexander van Heukelum [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1208778196.9210.1248995009@webmail.messagingengine.com \
    --to=heukelum@fastmail.fm \
    --cc=harvey.harrison@gmail.com \
    --cc=heukelum@mailshack.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matti.aarnio@zmailer.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome