Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Count bits



On 28-Nov-05, at 11:41 AM, Martin Taylor wrote:

inline int countBits (int i)
{
	i = (i & 0x55555555) + ((i >> 1) & 0x55555555);
	i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
	i = (i & 0x0F0F0F0F) + ((i >> 4) & 0x0F0F0F0F);
	i = (i & 0x00FF00FF) + ((i >> 8) & 0x00FF00FF);
	return (i & 0x0000FFFF) + ((i >> 16) & 0x0000FFFF);
}

That looks quite similar to the "Nifty Parallel Count" method on the page by Gurmeet Singh Manku that I referred to earlier. In his tests, this method came out a lot slower than the pre-computed array method I mentioned.


--
Cameron Hayne
email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. PerfOptimization-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/perfoptimization-dev/email@hidden

This email sent to email@hidden
References: 
 >Count bits (From: Bruno Causse <email@hidden>)
 >Re: Count bits (From: Cameron Hayne <email@hidden>)
 >Re: Count bits (From: Martin Taylor <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.