{"id":672,"date":"2008-10-18T20:34:35","date_gmt":"2008-10-18T18:34:35","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=672"},"modified":"2008-10-18T20:34:35","modified_gmt":"2008-10-18T18:34:35","slug":"frame-pointer-omission-oy","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/672","title":{"rendered":"Frame-Pointer Omission \/Oy"},"content":{"rendered":"<p>I just read a post on frame pointer omission (FPO) optimization, also known as \/Oy compiler flag. And a comment from Vladimir Scherbina on problems getting the feature actually work. I wondered if there has been any improvement with a Visual Studio .NET 2008 SP1. latest compiler from Microsoft and briefly &#8211; the result is yes, the feature seems to be working.<\/p>\n<p>This is the reference code for the feature:<\/p>\n<pre>const volatile INT g_nValueA = 0;\r\nconst volatile INT g_nValueB = 0;\r\n\r\n#pragma optimize(\"y\", off)\r\n\r\n__declspec(dllexport) __declspec(noinline) BOOL STDMETHODCALLTYPE A(const volatile INT&amp; nValue = g_nValueA)\r\n{\r\n\treturn nValue != 0;\r\n}\r\n\r\n#pragma optimize(\"y\", on)\r\n\r\n__declspec(dllexport) __declspec(noinline) BOOL STDMETHODCALLTYPE B(const volatile INT&amp; nValue = g_nValueB)\r\n{\r\n\treturn nValue != 0;\r\n}\r\n\r\nint _tmain(int argc, _TCHAR* argv[])\r\n{\r\n\tA();\r\n\tB();\r\n\treturn 0;\r\n}<\/pre>\n<p>The code is to be compiled in Release and function A is to be not optimized while B is subject for optimization and omitting the frame pointer.<\/p>\n<p>Disassembly shows for A:<\/p>\n<p><!--more--><\/p>\n<pre>__declspec(dllexport) __declspec(noinline) BOOL STDMETHODCALLTYPE A(const volatile INT&amp; nValue = g_nValueA)\r\n{\r\n00401000  push        ebp\r\n00401001  mov         ebp,esp\r\n\treturn nValue != 0;\r\n00401003  mov         eax,dword ptr [nValue]\r\n00401006  mov         ecx,dword ptr [eax]\r\n00401008  xor         eax,eax\r\n0040100A  test        ecx,ecx\r\n0040100C  setne       al\r\n}\r\n0040100F  pop         ebp\r\n00401010  ret         4<\/pre>\n<p>and for B:<\/p>\n<pre>__declspec(dllexport) __declspec(noinline) BOOL STDMETHODCALLTYPE B(const volatile INT&amp; nValue = g_nValueB)\r\n{\r\n\treturn nValue != 0;\r\n00401020  mov         eax,dword ptr [esp+4]\r\n00401024  mov         ecx,dword ptr [eax]\r\n00401026  xor         eax,eax\r\n00401028  test        ecx,ecx\r\n0040102A  setne       al\r\n}\r\n0040102D  ret         4<\/pre>\n<p>and the difference is what was actually expected. It looked as it finally got to work but a check with Visual Studio versions 2003 and 2005 shown that optiomization makes a difference on older versions too.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just read a post on frame pointer omission (FPO) optimization, also known as \/Oy compiler flag. And a comment from Vladimir Scherbina on problems getting the feature actually work. I wondered if there has been any improvement with a Visual Studio .NET 2008 SP1. latest compiler from Microsoft and briefly &#8211; the result is&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/672\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,12],"tags":[38,131,59,135],"class_list":["post-672","post","type-post","status-publish","format-standard","hentry","category-seriously","category-technology","tag-c","tag-compiler","tag-microsoft","tag-optimization"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/672","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=672"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/672\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=672"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=672"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}