# 硬件寄存器

硬件寄存器是处理器或其他数字设备内部一种小的、有名字的存储位置，由触发器或类似电路构成，用于保存硬件能在单个周期内读取或写入的位。在CPU中，这一术语涵盖两个不同的层次：软件在指令中显式命名的架构寄存器，以及实现内部使用的微架构寄存器，例如物理寄存器堆和重命名表。<sup>[1](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-1-manual.pdf)</sup><sup> • </sup><sup>[2](https://docs.boom-core.org/en/latest/sections/rename-stage.html)</sup>

| 关键事实 | 详情 |
|---|---|
| Intel 64通用寄存器 | 64位模式下有16个：RAX、RBX、RCX、RDX、RDI、RSI、RBP、RSP以及R8-R15；默认操作数大小为32位<sup>[1](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-1-manual.pdf)</sup> |
| 遗留命名 | 低16位映射到8086和Intel 286的寄存器名AX、BX、CX、DX、BP、SI、DI和SP，字节半部分为AL/AH至DL/DH<sup>[1](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-1-manual.pdf)</sup> |
| RISC-V基础ISA | 31个通用寄存器x1-x31，加上硬连线为常量0的x0，以及32个浮点寄存器f0-f31<sup>[3](https://docs.riscv.org/reference/isa/original/_attachments/riscv-unprivileged.pdf)</sup> |
| 模型特定寄存器 | Intel处理器提供MSR，用RDMSR和WRMSR指令读写；SDM第4卷按处理器家族编目<sup>[4](https://www.intel.com/content/dam/develop/external/us/en/documents/335592-sdm-vol-4.pdf)</sup> |
| 寄存器重命名 | 乱序核心将ISA寄存器说明符映射到更大的物理寄存器池，消除写后写和读后写冒险<sup>[2](https://docs.boom-core.org/en/latest/sections/rename-stage.html)</sup> |
| 功耗成本 | 在32纳米Westmere核心上，寄存器堆约占动态功耗和漏电功耗的30%<sup>[5](https://www.sciencedirect.com/science/article/abs/pii/S014193311500006X)</sup> |
| 编译器视角 | 寄存器分配将无界虚拟寄存器集映射到有限物理寄存器集；放不下的值溢出到内存<sup>[6](https://llvm.org/docs/CodeGenerator.html)</sup> |

## 架构寄存器

架构寄存器是指令集架构（ISA）定义且软件可以直接命名的寄存器。Intel 64和IA-32架构定义了通用寄存器、段寄存器、[EFLAGS](https://www.edgepedia.org/zh/flags-register)状态寄存器、指令指针以及浮点和SIMD寄存器组。<sup>[1](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-1-manual.pdf)</sup> 在64位模式下有16个通用寄存器，默认操作数大小为32位；REX前缀生成64位操作数大小或引用新寄存器R8-R15。<sup>[1](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-1-manual.pdf)</sup>

**向后兼容命名。** Intel通用寄存器的低16位直接映射到8086和Intel 286的寄存器组，可以按AX、BX、CX、DX、BP、SI、DI和SP引用。EAX、EBX、ECX和EDX的低两个字节各有自己的名称：高字节为AH、BH、CH和DH，低字节为AL、BL、CL和DL。<sup>[1](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-1-manual.pdf)</sup> 若干寄存器还承担传统角色：EAX是操作数和结果的累加器，ECX是字符串和循环操作的计数器，EDX是I/O指针，ESP是栈指针，EBP是指向栈上数据的指针。<sup>[1](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-1-manual.pdf)</sup>

**RISC-V寄存器。** RISC-V基础ISA形态不同：31个通用寄存器x1-x31保存整数值，寄存器x0硬连线为常量0，32个寄存器f0-f31保存单精度或双精度浮点值。规范指出，选择32个整数加32个浮点寄存器是基于标准编译器在现有代码上的行为。<sup>[3](https://docs.riscv.org/reference/isa/original/_attachments/riscv-unprivileged.pdf)</sup> 基础整数ISA中没有专用栈指针或返回地址链接寄存器；标准调用约定将这些角色分配给x2和x1。<sup>[3](https://docs.riscv.org/reference/isa/original/_attachments/riscv-unprivileged.pdf)</sup>

**控制和状态寄存器。** 除数据寄存器外，ISA还定义用于配置和报告处理器自身状态的寄存器。Intel的模型特定寄存器（MSR）用RDMSR和WRMSR指令读写，涵盖扩展功能启用、系统调用目标地址和电源管理等功能；该集合因处理器家族而异，因此Intel的SDM第4卷按Pentium、P6、Core 2、Atom及后续微架构分别列出MSR。<sup>[4](https://www.intel.com/content/dam/develop/external/us/en/documents/335592-sdm-vol-4.pdf)</sup> RISC-V使用控制和状态寄存器（CSR）实现类似目的，包括周期计数、退役指令计数、状态、异常PC和异常向量寄存器。<sup>[7](https://docs.boom-core.org/en/latest/sections/execution-stages.html)</sup>

## 微架构寄存器与重命名

实现内部使用的寄存器不必与架构寄存器集匹配。[寄存器重命名](https://www.edgepedia.org/zh/register-renaming)是一种微架构技术，将每条指令的ISA寄存器说明符映射到更大池中的物理寄存器；Berkeley乱序机器（BOOM）是一个RISC-V研究核心，在物理寄存器堆中同时保存已提交架构状态和推测状态，其寄存器数量远多于ISA规定。<sup>[2](https://docs.boom-core.org/en/latest/sections/rename-stage.html)</sup> 重命名消除写后写（WAW）和读后写（WAR）冒险，这些冒险源于ISA寄存器说明符数量有限以及循环在每次迭代中重用相同说明符，只留下真正的写后读依赖。<sup>[2](https://docs.boom-core.org/en/latest/sections/rename-stage.html)</sup>

Intel的优化手册在其核心中描述了相同机制：重命名器将微操作从前端移动到执行核心，将架构寄存器重命名为更大的微架构寄存器集，并消除称为读后读和读后写冒险的假依赖。<sup>[8](https://www.intel.com/content/dam/doc/manual/64-ia-32-architectures-optimization-manual.pdf)</sup> 物理寄存器数量是实现细节：Intel指出，命名寄存器映射到的物理寄存器数量有时在技术出版物中提及，但无法通过CPUID等机制看到。<sup>[9](https://community.intel.com/t5/Software-Tuning-Performance/How-to-know-how-many-registers-in-a-CPU/m-p/1135131)</sup>

重命名也适用于通用寄存器堆之外的类寄存器结构。当软件写入Intel段寄存器时，段描述符中的基地址和限长被缓存在称为段寄存器堆的微架构结构中，写入会分配新条目而不是覆盖旧条目；依赖指令可以推测性地消费新分配的条目。<sup>[10](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/technical-documentation/speculative-behavior-swapgs-and-segment-registers.html)</sup>

## 作为电路的寄存器堆

在物理上，架构寄存器位于寄存器堆中，这是一种多端口存储单元阵列，以处理器全速运行，必须足够小且足够快，以便在请求的周期内访问数据。<sup>[11](https://engineering.purdue.edu/~ece437l/lab1/lab1.html)</sup> 基本设计在其逻辑寄存器上提供两个读端口和一个写端口，读为组合逻辑，写为同步。<sup>[12](https://cs315-f25.cs.usfca.edu/lectures/11-cs315-2025-10-28-processor-components/)</sup> 扩展端口成本高昂：位单元面积随端口数量呈二次方增长，随着处理器发射宽度增加，寄存器堆复杂度增长超过线性，增加访问时间和功耗。<sup>[13](https://www.sciencedirect.com/science/article/abs/pii/S0167926016000316)</sup><sup> • </sup><sup>[14](https://www.sciencedirect.com/science/article/abs/pii/S0141933106001232)</sup> 在32纳米Westmere核心上，寄存器堆约占动态功耗和漏电功耗的30%，这推动了动态停用非活跃寄存器等技术。<sup>[5](https://www.sciencedirect.com/science/article/abs/pii/S014193311500006X)</sup>

寄存器堆也通过专门化来扩展。Intel当前GPU世代有128个通用寄存器，每个XVE线程默认每个寄存器32字节宽，那里的寄存器压力影响所选SIMD宽度，并可能强制溢出。<sup>[15](https://www.intel.com/content/www/us/en/docs/oneapi/optimization-guide-gpu/2023-1/registerization-and-avoid-register-spills.html)</sup> 针对向量和GPU工作负载的研究提案包括标量化向量寄存器堆，将标量语义向量值重定向到专用标量堆，在评估配置中将向量寄存器堆面积减少最多15.8%，总功耗减少最多12%。<sup>[16](https://arxiv.org/abs/2610.07078)</sup>

## 软件如何访问寄存器

编译器位于源程序和架构寄存器集之间。在LLVM中，针对无界虚拟寄存器集编写的程序必须映射到每个目标的有限物理寄存器；放不下的虚拟寄存器映射到内存，称为溢出虚拟寄存器。<sup>[6](https://llvm.org/docs/CodeGenerator.html)</sup> LLVM中的物理寄存器用整数表示，某些架构对共享存储的寄存器进行别名处理：在X86上，EAX、AX和AL共享前八位。<sup>[6](https://llvm.org/docs/CodeGenerator.html)</sup> 溢出增加了在寄存器和内存之间传输值的指令，增加代码大小，热循环内的溢出可能导致显著性能下降。<sup>[17](https://llvm.org/pubs/2009-10-CASES-ProgressiveSpill.pdf)</sup><sup> • </sup><sup>[15](https://www.intel.com/content/www/us/en/docs/oneapi/optimization-guide-gpu/2023-1/registerization-and-avoid-register-spills.html)</sup>

有些寄存器完全不可分配。栈指针或条件码寄存器不被LLVM分配器作为一般资源跟踪，预着色物理寄存器（例如用于传递函数调用参数的寄存器）限制分配，因为分配器在它们活跃时不得覆盖它们。<sup>[6](https://llvm.org/docs/CodeGenerator.html)</sup>

## 寄存器与安全

由于寄存器状态由微架构管理，它可能跨越安全边界泄露信息。LazyFP攻击利用操作系统优化，该优化将FPU和SIMD寄存器集的保存和恢复推迟到进程首次触碰它时，允许对手通过微架构侧信道恢复任意进程或虚拟机的FPU和SIMD寄存器状态。<sup>[18](https://arxiv.org/abs/1806.07480)</sup> Intel的安全指南同样记录了重命名段寄存器条目的推测性消费如何瞬时暴露陈旧描述符值，这就是为什么要记录此类微架构行为，供软件编写者参考。<sup>[10](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/technical-documentation/speculative-behavior-swapgs-and-segment-registers.html)</sup>

## References

1. [Intel® 64 and IA-32 Architectures Software Developer's Manual, Volume 1: Basic Architecture, Intel](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-1-manual.pdf)
2. [The Rename Stage, RISCV-BOOM documentation](https://docs.boom-core.org/en/latest/sections/rename-stage.html)
3. [The RISC-V Instruction Set Manual, Volume I: Unprivileged Architecture](https://docs.riscv.org/reference/isa/original/_attachments/riscv-unprivileged.pdf)
4. [Intel® 64 and IA-32 Architectures Software Developer's Manual, Volume 4: Model-Specific Registers, Intel](https://www.intel.com/content/dam/develop/external/us/en/documents/335592-sdm-vol-4.pdf)
5. [Dynamically adaptive register file architecture for energy reduction in embedded processors, ScienceDirect](https://www.sciencedirect.com/science/article/abs/pii/S014193311500006X)
6. [The LLVM Target-Independent Code Generator, LLVM](https://llvm.org/docs/CodeGenerator.html)
7. [The Execute Pipeline, RISCV-BOOM documentation](https://docs.boom-core.org/en/latest/sections/execution-stages.html)
8. [Intel(R) 64 and IA-32 Architectures Optimization Reference Manual, Intel](https://www.intel.com/content/dam/doc/manual/64-ia-32-architectures-optimization-manual.pdf)
9. [How to know how many registers in a CPU, Intel Community](https://community.intel.com/t5/Software-Tuning-Performance/How-to-know-how-many-registers-in-a-CPU/m-p/1135131)
10. [Speculative Behavior of SWAPGS and Segment Registers, Intel Software Security Guidance](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/technical-documentation/speculative-behavior-swapgs-and-segment-registers.html)
11. [Tutorial and Register File, Purdue University ECE 437L](https://engineering.purdue.edu/~ece437l/lab1/lab1.html)
12. [Processor Components, CS 315 Computer Architecture, University of San Francisco](https://cs315-f25.cs.usfca.edu/lectures/11-cs315-2025-10-28-processor-components/)
13. [A compact low-power 4-port register file with grounded write bitlines and single-ended read operations, ScienceDirect](https://www.sciencedirect.com/science/article/abs/pii/S0167926016000316)
14. [Register port complexity reduction in wide-issue processors with selective instruction execution, ScienceDirect](https://www.sciencedirect.com/science/article/abs/pii/S0141933106001232)
15. [Registerization and Avoid Register Spills, oneAPI GPU Optimization Guide, Intel](https://www.intel.com/content/www/us/en/docs/oneapi/optimization-guide-gpu/2023-1/registerization-and-avoid-register-spills.html)
16. [SVRF: Efficient Register Storage for Long-Vector Architectures, arXiv](https://arxiv.org/abs/2610.07078)
17. [Progressive spill code placement, LLVM publications](https://llvm.org/pubs/2009-10-CASES-ProgressiveSpill.pdf)
18. [LazyFP: Leaking FPU Register State using Microarchitectural Side-Channels, arXiv](https://arxiv.org/abs/1806.07480)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Processors & processor engineering › Microarchitecture & implementation › Intel microarchitectures

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/hardware-register

English original: https://www.edgepedia.org/hardware-register
