From: Kumar Gala Date: Wed, 11 Jun 2008 09:37:50 -0500 Subject: [U-Boot-Users] [PATCH] ppc: Added fls, fls64, __ilog2_u64, and ffs64 to bitops In-Reply-To: <20080611160351.01b7877c@hskinnemo-gx745.norway.atmel.com> References: <20080610235122.1BDBA2487D@gemini.denx.de> <20080611125445.016f9232@hskinnemo-gx745.norway.atmel.com> <112D3A34-AC19-4768-9081-F2662DE1D35A@kernel.crashing.org> <20080611160351.01b7877c@hskinnemo-gx745.norway.atmel.com> Message-ID: <54816434-0F53-44B1-9D3F-EBDD738ECE59@kernel.crashing.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Jun 11, 2008, at 9:03 AM, Haavard Skinnemoen wrote: > Kumar Gala wrote: >> >> On Jun 11, 2008, at 5:54 AM, Haavard Skinnemoen wrote: >> >>> Kumar Gala wrote: >>>> +/* >>>> + * fls: find last (most-significant) bit set. >>>> + * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. >>>> + */ >>>> +static __inline__ int fls(unsigned int x) >>>> +{ >>>> + return __ilog2(x) + 1; >>>> +} >>> >>> __ilog2(0) returns -1? >> >> it does. > > In general, or just on powerpc? If it's the latter, could you add a > comment so that people won't blindly copy it into their architecture's > bitops.h? I'm guessing on PPC (thus the __ilog2 rather than ilog2()). From the kernel headers: /* * non-constant log of base 2 calculators * - the arch may override these in asm/bitops.h if they can be implemented * more efficiently than using fls() and fls64() * - the arch is not required to handle n==0 if implementing the fallback */ #ifndef CONFIG_ARCH_HAS_ILOG2_U32 static inline __attribute__((const)) int __ilog2_u32(u32 n) { return fls(n) - 1; } #endif I'll add a comment. - k