Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: David Laight <David.Laight@ACULAB.COM>
Cc: Maciej Zenczykowski <zenczykowski@gmail.com>,
	Maciej Zenczykowski <maze@google.com>,
	netdev@vger.kernel.org
Subject: RE: [PATCH] net: pfifo_fast - use ffs(x)-1 instead of array lookup
Date: Tue, 13 Mar 2012 10:34:23 -0700	[thread overview]
Message-ID: <1331660063.4449.23.camel@edumazet-glaptop> (raw)
In-Reply-To: <AE90C24D6B3A694183C094C60CF0A2F6026B6EA1@saturn3.aculab.com>

On Tue, 2012-03-13 at 16:55 +0000, David Laight wrote:
> > > +	/* For i in 0..7 returns {-1, 0, 1, 0, 2, 0, 1, 0}[i] */
> > > +	return ((26468 >> (i+i)) & 3) - 1;
> > 
> > That expression doesn't seem quite right to me ...
> > 	return (int)(0x12131210 >> (i * 4)) & 3) - 1;
> > probably does whats wanted.
> 
> Hmmm... I'm going blind - I read that as 'i+1' not 'i+i'.
> But using 'i * 4' and putting the constant in base 16
> make the code rather less obscure.

Point was to get short/fast code.

26458 can probably be expressed with a macro so that it is self
explained.

Check asm output if your way is better. Its probably not the case
because some arches can use smaller code to manipulate small constants.

I am not sure the memory lookup is that expensive anyway
(we probably could use 'char' instead of 'int' to reduce the siwe of
this memory blob)

Code is also read from memory, so you have to trade icache/dcache
issues.

  reply	other threads:[~2012-03-13 17:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-13  5:12 [PATCH] net: pfifo_fast - use ffs(x)-1 instead of array lookup Maciej Żenczykowski
2012-03-13  5:13 ` Maciej Żenczykowski
2012-03-13  5:54 ` David Miller
2012-03-13  7:21   ` Maciej Żenczykowski
2012-03-13  7:23     ` Maciej Żenczykowski
2012-03-13  7:25       ` David Miller
2012-03-13  7:25     ` David Miller
2012-03-13 11:04 ` David Laight
2012-03-13 16:55   ` David Laight
2012-03-13 17:34     ` Eric Dumazet [this message]
2012-03-13 20:37     ` Maciej Żenczykowski

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=1331660063.4449.23.camel@edumazet-glaptop \
    --to=eric.dumazet@gmail.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=maze@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=zenczykowski@gmail.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