编程与软件工程swansontec.com
选择 Intel 寄存器的艺术
The Art of Picking Intel Registers (2003)
2013 — 2021,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这篇 2003 年的经典文章讲解 x86 汇编中各寄存器(EAX、EBX、ECX、EDX、ESI、EDI、ESP、EBP 等)的隐含用途与特殊约束,指导程序员如何根据指令的隐式行为选择合适的寄存器,从而写出更短、更高效的机器码。
为什么经久不衰:x86 寄存器的'个性'与隐式约定至今未变,对理解编译器输出、手写汇编和代码体积优化仍有实用价值。
HN 评论精选
指令集编码中寄存器的真实编号顺序与常见认知不同
关于 x86 寄存器还有一个有趣的冷知识:大多数程序员以为寄存器顺序是 EAX、EBX、ECX、EDX、ESI、EDI、ESP、EBP,但从指令集编码中的编号来看,真正的顺序是 EAX、ECX、EDX、EBX、ESP、EBP、ESI、EDI。
cesarb查看英文原文
Another interesting trivia about the x86 registers: while most programmers think of their order as being EAX, EBX, ECX, EDX, ESI, EDI, ESP, EBP, when you look at how the registers are numbered in the instruction set, you see that their true order is different: EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI.
手工选寄存器省下的字节未必带来性能提升
不过别想太多。这些指令虽然能让输出代码更小,但很可能让程序变慢。处理器是针对编译器生成的代码优化的,而编译器早就不再输出这类指令了。当然也有例外,比如代码很大时更小的代码可能更好地利用缓存,但这种情况不多。
aetherspawn查看英文原文
Don’t get any ideas though. Whilst these instructions might make the output code smaller, it will probably make the program slower (1). Processors are optimised to run code generated by compilers fast, and compilers stopped outputting these a long time ago. 1/ There are edge cases like when the code is very big then less code might fit in the cache better or perhaps dispatch better .. but probably not many.
用 GCC 内联汇编的寄存器约束可兼顾手写汇编与编译器优化
在 GCC 中写内联汇编时,你其实可以把寄存器选择交给编译器:只需声明需要什么类型的寄存器,GCC 会替你优化分配,然后用 % 记号引用,比如 movd %1, %2。想象一下在 C++ 里把它封装成内联函数,简单的算术操作调用就能就地优化,而不用建栈帧或在 eax 之间搬数据……这让我的 3D 软件渲染器提速了一倍多!
bitL查看英文原文
In GCC you can actually offload the decision about which registers to choose if you are writing inline assembly code. You just specify what type of registers you need and GCC optimizes the assignments for you. Then you reference them with % notation - e.g. movd %1, %2. Imagine you provide this as an inline function in C++; all the calls for simple functions like arithmetic operations will be optimized on the spot instead of building stacks or moving some value to/from eax... It sped up my 3D software renderer more than twice! :)
x86 的'通用寄存器'其实大多不通用
正因为这些原因,我常说 32 位 x86 的通用寄存器数量是零,最多也就一个。其他的寄存器里全是这类奇怪的用途限制。
gchpaco查看英文原文
For reasons like this I usually claim that 32-bit x86 chips have zero or at most one general purpose registers. Everything else is full of weird junk like this.
历次讨论
同类还值得读
开源应用架构
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编辑精选