{"id":21490,"date":"2018-05-10T16:52:04","date_gmt":"2018-05-10T20:52:04","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=21490"},"modified":"2018-07-04T16:27:24","modified_gmt":"2018-07-04T20:27:24","slug":"c-is-not-a-low-level-language","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2018\/05\/10\/c-is-not-a-low-level-language\/","title":{"rendered":"C Is Not a Low-level Language"},"content":{"rendered":"<p><a href=\"https:\/\/queue.acm.org\/detail.cfm?id=3212479\">David Chisnall<\/a> (<a href=\"https:\/\/news.ycombinator.com\/item?id=16967675\">Hacker News<\/a>):<\/p>\n<blockquote cite=\"https:\/\/queue.acm.org\/detail.cfm?id=3212479\">\n<p>In the wake of the recent Meltdown and Spectre vulnerabilities, it's worth spending some time looking at root causes. Both of these vulnerabilities involved processors speculatively executing instructions past some kind of access check and allowing the attacker to observe the results via a side channel. The features that led to these vulnerabilities, along with several others, were added to let C programmers continue to believe they were programming in a low-level language, when this hasn't been the case for decades.<\/p>\n<p>[&#8230;]<\/p>\n<p>A modern Intel processor has up to 180 instructions in flight at a time (in stark contrast to a sequential C abstract machine, which expects each operation to complete before the next one begins). A typical heuristic for C code is that there is a branch, on average, every seven instructions. If you wish to keep such a pipeline full from a single thread, then you must guess the targets of the next 25 branches.<\/p>\n<p>[&#8230;]<\/p>\n<p>Consider another core part of the C abstract machine's memory model: flat memory. This hasn't been true for more than two decades. A modern processor often has three levels of cache in between registers and main memory, which attempt to hide latency.<\/p>\n<p>[&#8230;]<\/p>\n<p>A processor designed purely for speed, not for a compromise between speed and C support, would likely support large numbers of threads, have wide vector units, and have a much simpler memory model. Running C code on such a system would be problematic, so, given the large amount of legacy C code in the world, it would not likely be a commercial success.<\/p>\n<\/blockquote>\n<p>Previously: <a href=\"https:\/\/mjtsai.com\/blog\/2018\/01\/03\/intel-cpu-design-flaw-necessitates-kernel-page-table-isolation\/\">Intel CPU Design Flaw Necessitates Kernel Page Table Isolation<\/a>.<\/p>\n\n<p>Update (2018-07-04): See also: <a href=\"http:\/\/lambda-the-ultimate.org\/node\/5534\">Lambda the Ultimate<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>David Chisnall (Hacker News): In the wake of the recent Meltdown and Spectre vulnerabilities, it's worth spending some time looking at root causes. Both of these vulnerabilities involved processors speculatively executing instructions past some kind of access check and allowing the attacker to observe the results via a side channel. The features that led to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2018-07-04T20:27:26Z","apple_news_api_id":"53b26d94-75d1-48f2-85a2-94404dc2205a","apple_news_api_modified_at":"2018-07-04T20:27:28Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAQ==","apple_news_api_share_url":"https:\/\/apple.news\/AU7JtlHXRSPKFopRATcIgWg","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[45,800,46,260,71],"class_list":["post-21490","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-c","tag-concurrency","tag-languagedesign","tag-processors","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/21490","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=21490"}],"version-history":[{"count":3,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/21490\/revisions"}],"predecessor-version":[{"id":22022,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/21490\/revisions\/22022"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=21490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=21490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=21490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}