编程与软件工程queue.acm.org编辑精选
C 不是低级语言
C Is Not a Low-Level Language
2018 — 2021,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这篇文章讨论为什么 C 语言今天已不再算真正的“底层语言”:它诞生时贴近 PDP-11 的平坦内存模型,而现代 CPU 依赖缓存层级、乱序与推测执行、寄存器重命名等微架构机制,这些在汇编和机器码层面也并不可见。CPU 和编译器长期努力维持“仍在面向简单机器编程”的假象,但这种抽象会泄漏,并带来性能与安全代价,例如 Spectre。
为什么经久不衰:它点破了许多程序员对 C 与硬件一一对应的错觉,并用现代微架构的现实说明抽象层的代价,因此每隔几年仍值得重读。
HN 评论精选
反驳:这些微架构特性对汇编同样不可见,问题更多来自向后兼容而非 C 本身。
文章有些观点成立,但整体相当误导。它说 C 不是底层的几乎全部理由,同样适用于 x86/x64 汇编:寄存器重命名、缓存层级、乱序和推测执行在汇编/机器码层面也不可见。若 C 不算底层,现代 CPU 上就没有底层语言了;多数限制其实来自指令集/架构的向后兼容,GPU 靠放弃部分兼容性和通用性绕开一些限制,这也是它们没取代通用 CPU 的部分原因。
mattnewport查看英文原文
This article makes some valid points but is overall rather misleading I think. Almost all of the reasons given why C is "not a low-level language" also apply to x86/x64 assembly. Register renaming, cache hierarchies, out of order and speculative execution etc are not visible at the assembly / machine code level either on Intel or other mainstream CPU architectures like ARM or Power PC. If C is not a low level language then a low level language does not exist for modern CPUs and since all other languages ultimately compile down to the same instruction sets they all suffer from some of the same limitations. It's really backwards compatibility of instruction sets / architectures that imposes most of these limitations. Processors that get around them to some degree like GPUs do so by abandoning some amount of backwards compatibility and/or general purpose functionality and that is in part why they haven't displaced general purpose CPUs for general purpose use.
支持作者:抽象层是必要幻觉但已泄漏,标题针对常见误解。
我很喜欢这篇文章,但看评论很惊讶。文章有力指出:芯片设计者和编译器厂商花了大量人力维持“我们仍在面向类 PDP-11 平台”的错觉,而平台早已越来越不像;随着 Spectre 和缓存未命中的性能代价,这层抽象会以可能灾难性的方式泄漏。只是他们维持得太好,我们忘了它不是现实。标题也合理,因为今天很多程序员仍以为 C 紧贴芯片的工作方式。
munificent查看英文原文
I really really liked this article, and reading the comments here is blowing my mind. Did we read the same thing? I think it's a strong insight that insight that chip designers and compiler vendors have spent person-millenia maintaining the illusion that we are targeting a PDP-11-like platform even while the platform has grown less and less like that. And, it turns out, with things like Spectre and the performance cost of cache misses, that abstraction layer is quite leaky in potentially disastrous ways. But, at the same time, they have done such a good job of maintaining that illusion that we forget it isn't actually reality. I like the title of the article because many programmers today do still think C is a close mapping to how chips work. If you happen to be one of the enlightening minority who know that hasn't been true for a while, that's great, but I don't think it's good to criticize the title based on that.
Itanium 的失败说明市场更重视向后兼容,而非按微架构重设计指令集。
Intel 和 HP 曾尝试实现文章主张:全新处理元素和编译器架构,承诺高性能、低复杂度,即 EPIC/Itanium。行业联盟投入数十亿美元和顶尖人才也没成功,最后一颗 Itanium 一年前出货。市场已经表态:今年造的 z15 仍能跑 1960 年代编译的 OS/360 代码;市场更看重已有工具和代码,而不是理想化计算模型。
topspin查看英文原文
Intel and HP attempted to deliver what this paper advocates. They designed an entirely new processing element and compiler architecture that promised to deliver high performance with less complexity. It was called EPIC and manifested as Itanium. Billions of dollars and the best minds at the disposal of an industry wide consortium couldn't make it work; one year ago the last Itanium shipped. The market has spoken. You can run unmodified, compiled OS/360 code from the 1960s on a z15 machine built this year. The market values the tools and code it has invested in far more than any idealized computing model you care to speculate about. The flaws in contemporary CPUs that device manufacturers perpetrated on their customers for almost 20 years are not the fault of C and its users. They are the fault of reckless manufacturers that squandered their reputation in the name of performance and, ironically, helped perpetuate the lack of innovation in programming techniques called out in this paper.
文章真正主张是 x86 为兼容 C 而扭曲,并呼吁更贴近真实微架构的指令集。
我觉得大家读出的东西和我不同。作者用“C 不是底层语言”当标题党,真正论点是 x86 ISA 的结构纯粹是为了让海量既有 C 代码跑得更快;底层程序员不是妄想,而是被芯片厂商有意误导。C 和 x86 汇编不算底层,是因为它们与现代 CPU 实际架构只有很少关系。作者随后设想一种能更清楚呈现真实架构、面向多核/分层内存/流水线的 ISA。
throwaway17_17查看英文原文
I have read through the comments already posted and the comments from the previous HN discussion linked also. I can’t help but feel like I got something completely different from this article than everyone else. I am convinced that Chisnall used the ‘C is not a Low-Level Language’ title as click bait. The actual point of the article is to push the view that the x86 ISA, which according to him, is structured the way it is due purely to the desire to make the massive amount of existing C code run faster. His argument is essentially that ‘low-level’ programmers are not delusional, but are purposely being deluded by chip manufacturers. C, and x86 assembly, according to The article are not low level because they have only a passing relevance to the actual architecture of modern CPUs. Chisnall then goes on to argue that a low level language would require an ISA that presents a clearer picture of the actual architecture and would be geared for performance given the actual functionality of the CPU. He then bats around several features that could be a part of an ISA for a multi core, hierarchical memory, pipelined chip. His references to alternate memory models, changes in register structure and amount, a push for immutability and other features to adapt the ISA to reflect what would constitute actual performant code. I’m all for his vision, it seems like there could be an x86 ISA translation layer or a portion of cores dedicated to maintaining X86 compatibility l, while transitioning to a new ISA. In fact, just have a new ISA be the target the CPU reducers x86 to and also expose that underlying ISA. But as said elsewhere in the thread, it’s been tried before and it hasn’t worked yet.
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选