C语言中的存储类REGISTER有多少个寄存器和什么样的寄存器可用 [英] How many register and what kind of register are available for the storage class REGISTER in c language

查看:255
本文介绍了C语言中的存储类REGISTER有多少个寄存器和什么样的寄存器可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寄存器存储类用于快速访问变量,并且其内存分配在CPU中.但是cpu中的寄存器是有限的.我使用的是Intel Core i5-4260U处理器.我已经访问了英特尔网站以获取详细的注册信息.但是我找不到关于cpu包含多少个寄存器的任何此类规范 (要访问网站,请点击有多少寄存器8086/8088中有?)) 但是我不知道c存储类使用了多少个.

Register storage class is used to quicky access the variable and its memory is allocated in CPU. But the registers in the cpu are limited. I use an intel Core i5-4260U Processor. I've visited intel website for the details of the register. But I couldn't find any of such specification of how many registers does the cpu contain (to visit website click here). Even if i could find that the number of registers((from How many registers are there in 8086/8088?)) but I couldn't figure out how many of these are used by c storage classes.

推荐答案

在C中包含 register 关键字是因为创建C时,编译器并不总是很好地完成 register分配.寄存器分配是编译器的一部分,它将程序变量映射到CPU寄存器.

The register keyword in C was included because when C was created, compilers did not always do a good job of register allocation. Register allocation is the the part of the compiler which maps program variables to CPU registers.

如今,编译器用于寄存器分配的算法总体上非常出色.如此之多,以至于编译器经常忽略 register 关键字,理由是编译器比程序员更了解如何映射寄存器以最大化性能.

Nowadays, the algorithms compilers use for register allocation are on the whole excellent. So much so that compilers often ignore the register keyword, reasoning that the compiler knows better then the programmer on how to map registers to maximize performance.

我不确定编译器'mcleod_ideafix'在写EAXEDX对寄存器分配不可用时指的是什么. gcc 编译器使用32位x86代码(EAXEBXECXEDXESIEDI)中的6个整数寄存器.如果该函数未进行任何函数调用,并且您提供了正确的编译器选项,则它甚至将使用EBP. 64位模式增加了另外8个寄存器R8R15.如果使用的是 gcc ,只需使用-S选项编译文件,然后查看生成的代码以查看使用了哪些寄存器.

I'm not sure what compiler 'mcleod_ideafix' is referring to when he writes that EAX and EDX are not available for register allocation. The gcc compiler uses 6 integer registers in 32 bit x86 code (EAX, EBX, ECX, EDX, ESI, and EDI). It will even use EBP if the function does not make any function calls and you give the proper compiler option. 64 bit mode adds 8 more registers R8 through R15. If you are using gcc just compile your file with the -S option then look at the generated code to see what registers are used.

要考虑的另一件事是,英特尔处理器使用称为寄存器重命名的功能来降低性能.没有足够的寄存器的惩罚.

Another thing to consider is that Intel processors use a feature called register renaming to reduce the performance penalty of having not enough registers.

这篇关于C语言中的存储类REGISTER有多少个寄存器和什么样的寄存器可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆