From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?Q?Maciej_=C5=BBenczykowski?= Subject: Re: [PATCH] net: pfifo_fast - use ffs(x)-1 instead of array lookup Date: Tue, 13 Mar 2012 13:37:25 -0700 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: netdev@vger.kernel.org To: David Laight Return-path: Received: from mail-ee0-f46.google.com ([74.125.83.46]:44798 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752823Ab2CMUh2 convert rfc822-to-8bit (ORCPT ); Tue, 13 Mar 2012 16:37:28 -0400 Received: by eekc41 with SMTP id c41so621771eek.19 for ; Tue, 13 Mar 2012 13:37:26 -0700 (PDT) In-Reply-To: Sender: netdev-owner@vger.kernel.org List-ID: but a 16-bit constant will be better than a 32-bit one on 16-bit platfo= rms On Tue, Mar 13, 2012 at 9:55 AM, David Laight = wrote: > >> > + =C2=A0 /* For i in 0..7 returns {-1, 0, 1, 0, 2, 0, 1, 0}[i] */ >> > + =C2=A0 return ((26468 >> (i+i)) & 3) - 1; >> >> That expression doesn't seem quite right to me ... >> =C2=A0 =C2=A0 =C2=A0 return (int)(0x12131210 >> (i * 4)) & 3) - 1; >> probably does what is 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. > > =C2=A0 =C2=A0 =C2=A0 =C2=A0David > > --=20 Maciej A. =C5=BBenczykowski Kernel Networking Developer @ Google 1600 Amphitheatre Parkway, Mountain View, CA 94043 tel: +1 (650) 253-0062