<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Advanced bit manipulation-fu</title>
	<link>http://realtimecollisiondetection.net/blog/?p=78</link>
	<description>Coding wisdom and rants of Christer Ericson</description>
	<pubDate>Tue, 07 Sep 2010 20:53:28 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>

	<item>
		<title>By: LordHavoc</title>
		<link>http://realtimecollisiondetection.net/blog/?p=78#comment-2645</link>
		<author>LordHavoc</author>
		<pubDate>Sun, 08 Feb 2009 10:43:06 +0000</pubDate>
		<guid>http://realtimecollisiondetection.net/blog/?p=78#comment-2645</guid>
		<description>Note: my above log2i macro requires that n be a power of 2, it only identifies which one.</description>
		<content:encoded><![CDATA[<p>Note: my above log2i macro requires that n be a power of 2, it only identifies which one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LordHavoc</title>
		<link>http://realtimecollisiondetection.net/blog/?p=78#comment-2644</link>
		<author>LordHavoc</author>
		<pubDate>Sun, 08 Feb 2009 10:39:09 +0000</pubDate>
		<guid>http://realtimecollisiondetection.net/blog/?p=78#comment-2644</guid>
		<description>In response to ARBaboon's question about a faster int log2 - how fast is your current one?

The method I use (for unsigned int) is branch based at the C code level but the compiler tends to use conditional moves for it on x86, here it is for reference:
#define log2i(n) ((((n) &#38; 0xAAAAAAAA) != 0 ? 1 : 0) &#124; (((n) &#38; 0xCCCCCCCC) != 0 ? 2 : 0) &#124; (((n) &#38; 0xF0F0F0F0) != 0 ? 4 : 0) &#124; (((n) &#38; 0xFF00FF00) != 0 ? 8 : 0) &#124; (((n) &#38; 0xFFFF0000) != 0 ? 16 : 0))

I'd be curious to see a truly branchless version, although I think that one is fine if the compiler does a decent job :)</description>
		<content:encoded><![CDATA[<p>In response to ARBaboon&#8217;s question about a faster int log2 - how fast is your current one?</p>
<p>The method I use (for unsigned int) is branch based at the C code level but the compiler tends to use conditional moves for it on x86, here it is for reference:<br />
#define log2i(n) ((((n) &amp; 0xAAAAAAAA) != 0 ? 1 : 0) | (((n) &amp; 0xCCCCCCCC) != 0 ? 2 : 0) | (((n) &amp; 0xF0F0F0F0) != 0 ? 4 : 0) | (((n) &amp; 0xFF00FF00) != 0 ? 8 : 0) | (((n) &amp; 0xFFFF0000) != 0 ? 16 : 0))</p>
<p>I&#8217;d be curious to see a truly branchless version, although I think that one is fine if the compiler does a decent job :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matrix67: My Blog &#187; Blog Archive &#187; ??????????????k?1?????</title>
		<link>http://realtimecollisiondetection.net/blog/?p=78#comment-2371</link>
		<author>Matrix67: My Blog &#187; Blog Archive &#187; ??????????????k?1?????</author>
		<pubDate>Wed, 24 Sep 2008 04:25:24 +0000</pubDate>
		<guid>http://realtimecollisiondetection.net/blog/?p=78#comment-2371</guid>
		<description>[...] &#160;&#160;&#160;&#160;???http://realtimecollisiondetection.net/blog/?p=78       Posted in Program Impossible  Tags: ??, ??, ??, ???Trackback: [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] &nbsp;&nbsp;&nbsp;&nbsp;???http://realtimecollisiondetection.net/blog/?p=78       Posted in Program Impossible  Tags: ??, ??, ??, ???Trackback: [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jtlien</title>
		<link>http://realtimecollisiondetection.net/blog/?p=78#comment-2367</link>
		<author>jtlien</author>
		<pubDate>Tue, 23 Sep 2008 15:01:32 +0000</pubDate>
		<guid>http://realtimecollisiondetection.net/blog/?p=78#comment-2367</guid>
		<description>One of the best sights for bit manipulation routines is Georg Arnt's web page and book at

http://www.jjj.de/bitwizardry/bitwizardrypage.html</description>
		<content:encoded><![CDATA[<p>One of the best sights for bit manipulation routines is Georg Arnt&#8217;s web page and book at</p>
<p><a href="http://www.jjj.de/bitwizardry/bitwizardrypage.html" rel="nofollow">http://www.jjj.de/bitwizardry/bitwizardrypage.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The More You Know</title>
		<link>http://realtimecollisiondetection.net/blog/?p=78#comment-2365</link>
		<author>The More You Know</author>
		<pubDate>Tue, 23 Sep 2008 12:26:53 +0000</pubDate>
		<guid>http://realtimecollisiondetection.net/blog/?p=78#comment-2365</guid>
		<description>[...] In truth most programmers know that bit manipulation more akin to a peasant flipping some switches. Even so, having those switches flipped at the right moment sure is useful. This was taken orginally in part from http://realtimecollisiondetection.net/blog/?p=78 [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] In truth most programmers know that bit manipulation more akin to a peasant flipping some switches. Even so, having those switches flipped at the right moment sure is useful. This was taken orginally in part from <a href="http://realtimecollisiondetection.net/blog/?p=78" rel="nofollow">http://realtimecollisiondetection.net/blog/?p=78</a> [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Norm</title>
		<link>http://realtimecollisiondetection.net/blog/?p=78#comment-2362</link>
		<author>Norm</author>
		<pubDate>Tue, 23 Sep 2008 08:31:27 +0000</pubDate>
		<guid>http://realtimecollisiondetection.net/blog/?p=78#comment-2362</guid>
		<description>Thanks christer. I want to be good enough to produce something for &lt;a href="http://www.pouet.net/" rel="nofollow"&gt;pouet&lt;/a&gt; someday. It seems like this sort of low level tuning has become a hobby as computing power has become expendable for simplicity, but I have a passion for it, nevertheless.</description>
		<content:encoded><![CDATA[<p>Thanks christer. I want to be good enough to produce something for <a href="http://www.pouet.net/" rel="nofollow">pouet</a> someday. It seems like this sort of low level tuning has become a hobby as computing power has become expendable for simplicity, but I have a passion for it, nevertheless.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: christer</title>
		<link>http://realtimecollisiondetection.net/blog/?p=78#comment-2361</link>
		<author>christer</author>
		<pubDate>Tue, 23 Sep 2008 07:43:08 +0000</pubDate>
		<guid>http://realtimecollisiondetection.net/blog/?p=78#comment-2361</guid>
		<description>Norm, &lt;a href="http://graphics.stanford.edu/~seander/bithacks.html" rel="nofollow"&gt;This page&lt;/a&gt; is a summary of well-known "tricks" gathered from &lt;a href="http://groups.google.com/groups?hl=en&#038;ie=UTF-8&#038;q=%22bit+trick%22+OR+%22bit+tricks%22+OR+%22bit+hacks%22&#038;btnG=Search" rel="nofollow"&gt;usenet&lt;/a&gt;, &lt;a href="http://inwap.com/pdp10/hbaker/hakmem/hakmem.html" rel="nofollow"&gt;HAKMEM&lt;/a&gt;, and many other sources. Jörg Arndt's &lt;a href="http://www.jjj.de/fxt/" rel="nofollow"&gt;FXT book&lt;/a&gt; also contains a lot of info.

All those aside, I highly recommend Henry Warren Jr's book &lt;b&gt;&lt;a href="http://www.amazon.com/exec/obidos/tg/detail/-/0201914654?tag=realtimecolli-20" rel="nofollow"&gt;Hacker's Delight&lt;/a&gt;&lt;/b&gt; as the ultimate resource. It is &lt;b&gt;well&lt;/b&gt; worth the ~$40 it costs.</description>
		<content:encoded><![CDATA[<p>Norm, <a href="http://graphics.stanford.edu/~seander/bithacks.html" rel="nofollow">This page</a> is a summary of well-known &#8220;tricks&#8221; gathered from <a href="http://groups.google.com/groups?hl=en&#038;ie=UTF-8&#038;q=%22bit+trick%22+OR+%22bit+tricks%22+OR+%22bit+hacks%22&#038;btnG=Search" rel="nofollow">usenet</a>, <a href="http://inwap.com/pdp10/hbaker/hakmem/hakmem.html" rel="nofollow">HAKMEM</a>, and many other sources. Jörg Arndt&#8217;s <a href="http://www.jjj.de/fxt/" rel="nofollow">FXT book</a> also contains a lot of info.</p>
<p>All those aside, I highly recommend Henry Warren Jr&#8217;s book <b><a href="http://www.amazon.com/exec/obidos/tg/detail/-/0201914654?tag=realtimecolli-20" rel="nofollow">Hacker&#8217;s Delight</a></b> as the ultimate resource. It is <b>well</b> worth the ~$40 it costs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Norm</title>
		<link>http://realtimecollisiondetection.net/blog/?p=78#comment-2360</link>
		<author>Norm</author>
		<pubDate>Tue, 23 Sep 2008 06:56:12 +0000</pubDate>
		<guid>http://realtimecollisiondetection.net/blog/?p=78#comment-2360</guid>
		<description>Hi there,

Can anyone direct me to e-books, pdfs, articles, etc. on low level language tricks? Like, I read an article some while back about doing subtraction with clever addition and making use of the overflow. I lost the link to that article though.. 

I am interested in that kind of stuff. Mostly about tricks that are employed in writing code for embedded systems where every byte counts. 

Thanks,
Norm</description>
		<content:encoded><![CDATA[<p>Hi there,</p>
<p>Can anyone direct me to e-books, pdfs, articles, etc. on low level language tricks? Like, I read an article some while back about doing subtraction with clever addition and making use of the overflow. I lost the link to that article though.. </p>
<p>I am interested in that kind of stuff. Mostly about tricks that are employed in writing code for embedded systems where every byte counts. </p>
<p>Thanks,<br />
Norm</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gowrikumar</title>
		<link>http://realtimecollisiondetection.net/blog/?p=78#comment-2357</link>
		<author>gowrikumar</author>
		<pubDate>Tue, 23 Sep 2008 05:09:03 +0000</pubDate>
		<guid>http://realtimecollisiondetection.net/blog/?p=78#comment-2357</guid>
		<description>Recently I prepared a presentation explaining the next kth number:
http://www.slideshare.net/gkumar007/bits-next-higher-presentation/</description>
		<content:encoded><![CDATA[<p>Recently I prepared a presentation explaining the next kth number:<br />
<a href="http://www.slideshare.net/gkumar007/bits-next-higher-presentation/" rel="nofollow">http://www.slideshare.net/gkumar007/bits-next-higher-presentation/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fatlimey</title>
		<link>http://realtimecollisiondetection.net/blog/?p=78#comment-2297</link>
		<author>fatlimey</author>
		<pubDate>Tue, 02 Sep 2008 18:26:11 +0000</pubDate>
		<guid>http://realtimecollisiondetection.net/blog/?p=78#comment-2297</guid>
		<description>A faster log2?

BitLog is the integer log2 of an integer value
Given an N-bit value, locate the leftmost nonzero bit.
b = the bitwise position of this bit, where 0 = LSB.
n = the NEXT three bits (ignoring the highest 1)

bitlog(x) = 8 x (b-1) + n

Bitlog is exactly 8 times larger than log2(x)-1</description>
		<content:encoded><![CDATA[<p>A faster log2?</p>
<p>BitLog is the integer log2 of an integer value<br />
Given an N-bit value, locate the leftmost nonzero bit.<br />
b = the bitwise position of this bit, where 0 = LSB.<br />
n = the NEXT three bits (ignoring the highest 1)</p>
<p>bitlog(x) = 8 x (b-1) + n</p>
<p>Bitlog is exactly 8 times larger than log2(x)-1</p>
]]></content:encoded>
	</item>
</channel>
</rss>
