AIFeed

x86 为何臃肿得令人难以置信

Translation(model translation, not the source's own text)

文章标题:为什么 x86 臃肿得难以想象

正文:

统计一个程序用到了 x86 ISA 的百分之几,难道不是很有意思吗?好吧,首先,我们需要定义在 x86 这个庞然大物面前,“指令”这个词到底指什么。想要详细了解,我强烈推荐阅读 Fabian “ryg” Giesen 的文章。1 在这篇文章里,我会沿用 XED2 对指令的定义,即:“Intel® XED 将指令归类为类型为 xed_iclass_enum_t 的 iclass(ADD、SUB、MUL 等)”。3 所有这些“iclass”都定义在 xed-iclass-enum.h 中,结果是在撰写本文时共有 1974 个(忽略 XED_ICLASS_INVALID 和 XED_ICLASS_LAST)。

现在,我们只需要构建 XED,给它一个可执行文件,然后统计唯一 iclass 的数量。下面的结果是使用以下脚本得到的(默认情况下,XED 最多解码 1 亿条指令,如果解码大文件,请务必提高这个上限):


        xed -i file | awk '/^XDIS/ {list[$6]++} END {printf "%.2f%%\n", length(list) / 1974 * 100}'
      
  • C 语言的 Hello world:0.91%
  • Busybox:5.83%
  • LLVM:13.12%

结果发现,实际用到的 x86 指令非常少,少到即使庞大如 LLVM,也只用到 1974 条指令中的 259 条。这就解释了为什么 x86 相比 ARM 或 RISC-V 如此耗电。

  • https://fgiesen.wordpress.com/2016/08/25/how-many-x86-instructions-are-there ↩︎
  • https://github.com/intelxed/xed ↩︎
  • https://intelxed.github.io/ref-manual/group__IFORM.html ↩︎

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by Lobsters
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗