{"id":5536,"date":"2014-03-30T23:49:34","date_gmt":"2014-03-30T23:49:34","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-branch-prediction-collection-of-common-programming-errors\/"},"modified":"2014-03-30T23:49:34","modified_gmt":"2014-03-30T23:49:34","slug":"problem-about-branch-prediction-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-branch-prediction-collection-of-common-programming-errors\/","title":{"rendered":"problem about branch-prediction-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f4e97f0ea1536e2f3dd5905cd646c9ad?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBrian Vandenberg<br \/>\nassembly pipeline branch-prediction<br \/>\nupdatedChanged the 2nd line of assembly to the mnemonic actually being used (mflr) and added more info at the bottom.I ran across some code (using gcc) resembling the following (paraphrased):#define SOME_MACRO( someVar ) \\ do { \\__asm__ ( \\&#8221; b 0f\\n&#8221; \\&#8221;0: mflr %0\\n&#8221; \\: &#8220;=r&#8221;( someVar ) \\); \\ } while(0)&#8230; where the b instruction (ppc) is a short jmp and mflr is getting the contents of the &#8216;link r<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8428511b65515cc8498ef53b3f198504?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nmarshall<br \/>\noptimization assembly compiler branch-prediction pentium<br \/>\nOn a modern Pentium it is no longer possible to give branching hints to the processor it seems. Assuming that a profiling compiler such as gcc with profile-guided optimization gains information about likely branching behavior, what can it do to produce code that will execute more quickly?The only option I know of is to move unlikely branches to the end of a function. Is there anything else?Update.http:\/\/download.intel.com\/products\/processor\/manual\/325462.pdf volume 2a, section 2.1.1 says&#8221;Branch<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brian Vandenberg assembly pipeline branch-prediction updatedChanged the 2nd line of assembly to the mnemonic actually being used (mflr) and added more info at the bottom.I ran across some code (using gcc) resembling the following (paraphrased):#define SOME_MACRO( someVar ) \\ do { \\__asm__ ( \\&#8221; b 0f\\n&#8221; \\&#8221;0: mflr %0\\n&#8221; \\: &#8220;=r&#8221;( someVar ) \\); \\ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5536","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5536","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5536"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5536\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}