{"id":5442,"date":"2014-03-30T22:00:27","date_gmt":"2014-03-30T22:00:27","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/find-number-of-floating-point-register-programmaticaly-in-c-closed-collection-of-common-programming-errors\/"},"modified":"2014-03-30T22:00:27","modified_gmt":"2014-03-30T22:00:27","slug":"find-number-of-floating-point-register-programmaticaly-in-c-closed-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/find-number-of-floating-point-register-programmaticaly-in-c-closed-collection-of-common-programming-errors\/","title":{"rendered":"find number of floating point register programmaticaly in c++ [closed]-Collection of common programming errors"},"content":{"rendered":"<p>In general, compilers do know this sort of stuff (and how to best use it), so I&#8217;m slightly surprised that you think that you can outsmart the compiler &#8211; unless I have very high domain knowledge, and start writing assembler code, I very rarely outsmart the compiler.<\/p>\n<p>Since writing assembler code is highly unportable, I don&#8217;t think that counts as a solution for optimising the code using knowledge as to how many registers, etc. It is very difficult to know how the compiler uses registers. If you have <code>int x = y + z;<\/code> as a simple example, how many registers does it take? Depends on the compiler &#8211; it could use none, one, two, three, four, five or six, without being below optimal register usage &#8211; it all depends on how the compiler decides to deal with things, machine architecture, where\/how variables are being stored, etc. The same principle applies to number of floating point registers if we change <code>int<\/code> to <code>double<\/code>. There is no obvious way to tell how many registers are being used in this statement (although I suspect no more than three &#8211; however, it could be zero or one, depending on what the compiler decides to do).<\/p>\n<p>It&#8217;s probably possible to do some clever tricks if you know the processor architecture and how the compiler deals with certain types of code &#8211; but that also assumes that the compiler doesn&#8217;t change its behaviour in the next release. But if you know what processor architecture it is, then you also know the number of registers of various kinds&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In general, compilers do know this sort of stuff (and how to best use it), so I&#8217;m slightly surprised that you think that you can outsmart the compiler &#8211; unless I have very high domain knowledge, and start writing assembler code, I very rarely outsmart the compiler. Since writing assembler code is highly unportable, I [&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-5442","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5442","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=5442"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5442\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}