{"id":102828,"date":"2019-09-02T07:00:00","date_gmt":"2019-09-02T14:00:00","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/oldnewthing\/?p=102828"},"modified":"2019-08-31T14:22:04","modified_gmt":"2019-08-31T21:22:04","slug":"20190902-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190902-00\/?p=102828","title":{"rendered":"If FlushInstructionCache doesn&#8217;t do anything, why do you have to call it, revisited"},"content":{"rendered":"<p>You are supposed to call the <code>Flush\u00adInstruction\u00adCache<\/code> function when you generate or modify code at runtime, so that when the CPU tries to execute the newly-generated or newly-modified modified code, it will read the instructions you wrote, rather than any instructions that may be hanging around in the instruction cache.<\/p>\n<p>Some time ago, we saw that on Windows 95, the <code>Flush\u00adInstruction\u00adCache<\/code> function didn&#8217;t do anything aside from returning. That&#8217;s because <a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20031208-00\/?p=41583\"> the mere act of calling a function was sufficient to flush the instruction cache<\/a>.<\/p>\n<p>On Windows NT, however, the <code>Flush\u00adInstruction\u00adCache<\/code> function does actual work, since it needs to notify all the other processors of the need to flush their instruction caches, too.<\/p>\n<p>But if you look at Windows 10, you may find that the <code>Flush\u00adInstruction\u00adCache<\/code> function looks like the Windows 95 version: It doesn&#8217;t do anything.<\/p>\n<p>What&#8217;s going on?<\/p>\n<p>Whether the <code>Flush\u00adInstruction\u00adCache<\/code> function &#8220;does anything&#8221; depends on which processor you&#8217;re using. Some processors have an integrated data and instruction cache, in which case the <code>Flush\u00adInstruction\u00adCache<\/code> function doesn&#8217;t need to do anything. Others such as ARM still have separate instruction and data caches, and in those cases, flushing does real work. Whether the <code>Flush\u00adInstruction\u00adCache<\/code> function &#8220;does anything&#8221; depends on the processor architecture it was compiled for.<\/p>\n<p>As a programmer, you should just call the <code>Flush\u00adInstruction\u00adCache<\/code> function and let the operating system figure out whether flushing will actually need to &#8220;do anything&#8221;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The elixir of forgetfulness.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-102828","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The elixir of forgetfulness.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/102828","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=102828"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/102828\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=102828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=102828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=102828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}