zl程序教程

您现在的位置是:首页 >  其他

当前栏目

汇编:寄存器/register,基础概念

概念基础寄存器 汇编 register
2023-09-14 09:13:12 时间


如果想将所有的信息放到一篇里,会发现这个文章会变得难于管理。所以要分开,要wiki。
关于寄存器的一些说明;https://handwiki.org/wiki/Processor%20register

cpu register

这个算是一个通用词,就是CPU的寄存器,x86有x86的寄存器;arm有arm的寄存器。

hard register

就是CPU含有的寄存器。硬件上实际存在的寄存器。和伪寄存器相对。
https://gcc.gnu.org/git/?p=gcc.git&a=commit;h=d321551cea11f27a9afd67ece9bbda095a579950
这个提到了硬件寄存器与伪寄存器之间的一个区别与应用。有助于理解概念。

i386: Separate costs of pseudo registers from hard registers
processor_costs has costs of RTL expressions with pseudo registers and
and costs of hard register moves:

1. Costs of RTL expressions are used to generate the most efficient RTL
operations with pseudo registers.

2. Costs of hard register moves are used by register allocator to
decide how to allocate and move hard registers.

Since relative costs of pseudo register load and store versus pseudo
register moves in RTL expressions can be different from relative costs
of hard registers, we should separate costs of RTL expressions with
pseudo registers from costs of hard registers so that register allocator
and RTL expressions can be improved independently.

This patch moves costs of hard register moves to the new hard_register
field and duplicates costs of moves which are also used for costs of RTL
expressions.

PR target/90878
* config/i386/i386.c (inline_memory_move_cost): Use hard_register
for costs of hard register moves.
(ix86_register_move_cost): Likewise.
* config/i386/i386.h (processor_costs): Move costs of hard
register moves to hard_register.  Add int_load, int_store,
xmm_move, ymm_move, zmm_move, sse_to_integer, integer_to_sse,
sse_load, sse_store, sse_unaligned_load and sse_unaligned_store
for costs of RTL expressions.
* config/i386/x86-tune-costs.h: Move costs of hard register
moves to hard_register.  Duplicate int_load, int_store,
xmm_move, ymm_move, zmm_move, sse_to_integer, integer_to_sse,
sse_load, sse_store for costs of RTL expressions.

general register

这个是一般寄存器,可以用来存放临时数据,做计算用的寄存器。当然是相对于特殊寄存器来说的一个概念。有些寄存器有特殊的用途。

整数寄存器

当有人写了一段代码,做了代码描述,怎样才能更好的理解其产生的作用;还是要从理解基本概念开始,理解了所有的基本概念之后,才能从整体理解改动到底是改了个啥事情。比如下面这个commit提到整数寄存器,与SSE寄存器。
整数寄存器就是和浮点寄存器相对应的一种寄存器。

commit d321551cea11f27a9afd67ece9bbda095a579950
Author: H.J. Lu <hongjiu.lu@intel.com>
Date:   Thu Aug 15 18:15:33 2019 +0000

+      const int int_store[3];  /* cost of storing integer register
+                                  in QImode, HImode and SImode */
+       const int sse_to_integer;        /* cost of moving SSE register to integer.  */

这个整数寄存器其实说的是GPR,一般目的寄存器,可以存放整数的寄存器,没有什么特殊的含义。
http://x86asm.net/articles/using-xmm-for-general-purpose-simd-with-gpr/index.html
https://handwiki.org/wiki/Processor%20register

Intel 手册里出现的情况,还将GP(general-purpose)与整数寄存器放到了一块。

15.6.2 OpMask Instructions

• Mask read/write instructions: These instructions move data between a general-purpose integer register or memory and an opmask mask register, or between two opmask registers. For example:

si Doubleword integer register (for example: eax).

SSE 寄存器

这个是CPU的一个功能,专门用来做

register file

https://handwiki.org/wiki/Register_file

伪寄存器

https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/pseudo-register-syntax?redirectedfrom=MSDN
https://www.cnblogs.com/awpatp/archive/2011/01/01/1923726.html

许多寄存器的名字取决于处理器的架构, 因此对于那些偶尔使用调试器的用户来说很难记住所有平台上的寄存器名字. 为了克服这个问题, 调试器的开发团队引入了各种伪寄存器(Pseudo-Register), 由调试器将这些伪寄存器对应到不同的硬件架构上.

在编译器内部也是在实际转换到硬件语言之前,有一个伪寄存器使用的一个阶段,用来做一些优化功能。
https://gcc.gnu.org/git/?p=gcc.git&a=commit;h=d321551cea11f27a9afd67ece9bbda095a579950