public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oliver Xymoron <oxymoron@waste.org>
To: Abramo Bagnara <abramo.bagnara@libero.it>
Cc: Linus Torvalds <torvalds@transmeta.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] (1/7) entropy, take 2 - log2
Date: Sat, 24 Aug 2002 10:05:36 -0500	[thread overview]
Message-ID: <20020824150535.GA2436@waste.org> (raw)
In-Reply-To: <3D675042.A2F163D5@libero.it>

On Sat, Aug 24, 2002 at 11:22:10AM +0200, Abramo Bagnara wrote:
> Oliver Xymoron wrote:
> > 
> >> +static inline __u32 int_log2_16bits(__u32 word)
> >  {
> >         /* Smear msbit right to make an n-bit mask */
> >         word |= word >> 8;
> >         word |= word >> 4;
> >         word |= word >> 2;
> >         word |= word >> 1;
...
> > +       return hweight16(word)-1;
> >  }
> > -#endif
> 
> I suggest you to use a more efficient version like that below:
> 
> static inline int ld2_16(__u16 v)
> {
>         unsigned r = 0;
> 
>         if (v >= 0x100) {
>                 v >>= 8;
>                 r += 8;
>         }
>         if (v >= 0x10) {
>                 v >>= 4;
>                 r += 4;
>         }
>         if (v >= 4) {
>                 v >>= 2;
>                 r += 2;
>         }
>         if (v >= 2)
>                 r++;
>         return r;

Four branches are almost certainly less efficient. In any case, the
intent above is not to optimize the code, but to replace it with a
call to identical code that exists in bitops so that optimizations can
be made globally, and arch-specific if necessary.

-- 
 "Love the dolphins," she advised him. "Write by W.A.S.T.E.." 

      reply	other threads:[~2002-08-24 15:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-23 18:26 [PATCH] (1/7) entropy, take 2 - log2 Oliver Xymoron
2002-08-24  9:22 ` Abramo Bagnara
2002-08-24 15:05   ` Oliver Xymoron [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=20020824150535.GA2436@waste.org \
    --to=oxymoron@waste.org \
    --cc=abramo.bagnara@libero.it \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /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