{"id":171,"date":"2010-11-30T17:19:57","date_gmt":"2010-11-30T16:19:57","guid":{"rendered":"http:\/\/blog.blockos.org\/?p=171"},"modified":"2014-09-21T17:11:34","modified_gmt":"2014-09-21T16:11:34","slug":"the-last-man-on-earth-sat-alone-in-a-room","status":"publish","type":"post","link":"https:\/\/blog.blockos.org\/?p=171","title":{"rendered":"The last man on Earth sat alone in a room&#8230;"},"content":{"rendered":"<p>This is what is supposed to be the shortest post on this blog.<br \/>\nRemember last post where I used <strong>__builtin_ctz<\/strong> to compute GCD? Well&#8230; Here&#8217;s a way to compute the log2 of an integer using another gcc builtin. Let me introduce <strong>__builtin_clz<\/strong>. <strong>clz<\/strong> stands for <strong>count leading zeroes<\/strong>. So this wonderful thing counts 0 bits starting from the most significant bit. Please note that the result is undefined for 0.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">inline uint32_t ilog2(uint32_t i)\r\n{\r\n\treturn (32-__builtin_clz(i));\r\n}\r\n<\/pre>\n<p>Check the section <a href=\"http:\/\/gcc.gnu.org\/onlinedocs\/gcc-4.3.2\/gcc\/Other-Builtins.html\">5.49 of GCC doc<\/a> for more builtins.<\/p>\n<p>By the way the title of this post comes from a short novel by Fredric Brown called Knock.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is what is supposed to be the shortest post on this blog. Remember last post where I used __builtin_ctz to compute GCD? Well&#8230; Here&#8217;s a way to compute the log2 of an integer using another gcc builtin. Let me introduce __builtin_clz. clz stands for count leading zeroes. So this\u2026 <a class=\"continue-reading-link\" href=\"https:\/\/blog.blockos.org\/?p=171\">Continue reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[27,21],"_links":{"self":[{"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/posts\/171"}],"collection":[{"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=171"}],"version-history":[{"count":7,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions"}],"predecessor-version":[{"id":178,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions\/178"}],"wp:attachment":[{"href":"https:\/\/blog.blockos.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}