login
Header Space

 
 

Re: [PATCH] x86: generic versions of find_first_(zero_)bit, convert i386

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Alexander van Heukelum <heukelum@...>
Cc: Ingo Molnar <mingo@...>, Andi Kleen <andi@...>, LKML <linux-kernel@...>, Alexander van Heukelum <heukelum@...>
Date: Sunday, April 6, 2008 - 1:03 pm

fwiw there's a way to do ffz / ntz which can do lg(n) conditional moves in 
parallel... i'm not sure what (non-x86) architectures this might be best 
on, but it might be a good choice for the generic code... although maybe 
the large number of constants required will be a burden on RISC 
processors.

take a look at figure 5-17 here http://hackersdelight.org/revisions.pdf

int ntz(unsigned x) {
	unsigned y, bz, b4, b3, b2, b1, b0;
	y = x & -x; // Isolate rightmost 1-bit.
	bz = y ? 0 : 1; // 1 if y = 0.
	b4 = (y & 0x0000FFFF) ? 0 : 16;
	b3 = (y & 0x00FF00FF) ? 0 : 8;
	b2 = (y & 0x0F0F0F0F) ? 0 : 4;
	b1 = (y & 0x33333333) ? 0 : 2;
	b0 = (y & 0x55555555) ? 0 : 1;
	return bz + b4 + b3 + b2 + b1 + b0;
}

-dean
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] x86: generic versions of find_first_(zero_)bit, conv..., Alexander van Heukelum, (Mon Mar 31, 1:15 pm)
Re: [PATCH] x86: generic versions of find_first_(zero_)bit, ..., Alexander van Heukelum, (Tue Apr 1, 5:46 am)
Re: [PATCH] x86: generic versions of find_first_(zero_)bit, ..., dean gaudet, (Sun Apr 6, 1:03 pm)
Re: [PATCH] x86: generic versions of find_first_(zero_)bit, ..., Alexander van Heukelum, (Sun Apr 6, 2:51 pm)
Re: [PATCH] x86: generic versions of find_first_(zero_)bit, ..., Alexander van Heukelum, (Mon Apr 7, 6:25 am)
Alternative implementation of the generic __ffs, Alexander van Heukelum, (Fri Apr 18, 4:18 pm)
Re: Alternative implementation of the generic __ffs, dean gaudet, (Fri Apr 18, 7:46 pm)
Re: Alternative implementation of the generic __ffs, Harvey Harrison, (Fri Apr 18, 8:09 pm)
Re: Alternative implementation of the generic __ffs, dean gaudet, (Fri Apr 18, 8:20 pm)
Re: Alternative implementation of the generic __ffs, Joe Perches, (Fri Apr 18, 8:58 pm)
Re: Alternative implementation of the generic __ffs, Harvey Harrison, (Fri Apr 18, 9:04 pm)
Re: Alternative implementation of the generic __ffs, dean gaudet, (Fri Apr 18, 9:11 pm)
Re: Alternative implementation of the generic __ffs, Joe Perches, (Fri Apr 18, 10:55 pm)
Re: Alternative implementation of the generic __ffs, Matti Aarnio, (Sat Apr 19, 6:29 pm)
Re: Alternative implementation of the generic __ffs, Joe Perches, (Sat Apr 19, 11:06 pm)
Re: Alternative implementation of the generic __ffs, Alexander van Heukelum, (Sun Apr 20, 4:42 am)
Re: Alternative implementation of the generic __ffs, Matti Aarnio, (Sun Apr 20, 8:31 am)
Re: Alternative implementation of the generic __ffs, Alexander van Heukelum, (Mon Apr 21, 7:43 am)
Re: Alternative implementation of the generic __ffs, dean gaudet, (Sat Apr 19, 12:13 am)
Re: Alternative implementation of the generic __ffs, Alexander van Heukelum, (Sat Apr 19, 8:10 am)
Re: Alternative implementation of the generic __ffs, Joe Perches, (Sat Apr 19, 2:17 pm)
Re: Alternative implementation of the generic __ffs, Alexander van Heukelum, (Sat Apr 19, 4:26 pm)
Re: Alternative implementation of the generic __ffs, Mikael Pettersson, (Sat Apr 19, 6:05 am)
[PATCH] x86: switch x86_64 to generic find_first_bit, Alexander van Heukelum, (Tue Apr 1, 11:41 am)
[PATCH] x86: optimize find_first_bit for small bitmaps, Alexander van Heukelum, (Tue Apr 1, 11:42 am)
[PATCH] x86: remove x86-specific implementations of find_fir..., Alexander van Heukelum, (Tue Apr 1, 11:47 am)
Re: [PATCH] x86: remove x86-specific implementations of find..., Alexander van Heukelum, (Thu Apr 3, 5:34 am)
Re: [PATCH] x86: generic versions of find_first_(zero_)bit, ..., Stephen Hemminger, (Mon Mar 31, 1:22 pm)
Re: [PATCH] x86: generic versions of find_first_(zero_)bit, ..., Alexander van Heukelum, (Mon Mar 31, 3:38 pm)
speck-geostationary