快速整数类型存储在CPU寄存器中时是否更快? [英] Are the fast integer types faster when stored in the CPU registers?

查看:106
本文介绍了快速整数类型存储在CPU寄存器中时是否更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在考虑快速整数类型:

I have been thinking about the fast integer types:

int_fast8_t int_fast16_t int_fast32_t int_fast64_t uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t

在过去的几天里,我问了一个关于为什么的问题(如果是的话),这些类型比其他整数类型要快:

over the last days and I asked a question about why (if so) these types are faster than the other integer types:

为什么快速整数类型比其他整数类型快?

我进一步考虑过的问题现在是 if

Something I have further thought about now is, if:


  1. 更快的类型 在特定环境下(

  2. 对象为 regist类的对象,因此该环境反映了此问题的理想环境er 存储在CPU的寄存器中(但通常在使用寄存器类),它们在相同的环境下速度更快,并且

  3. CPU的寄存器能够保存所需的整数值

  1. Faster types are faster on a certain environment (implementation/architecture-dependent) and thus that environment reflects an ideal environment for this question,
  2. Objects with the class of register are stored inside a register of the CPU (but in general do not always need to be stored there when declared with the register class), they are faster on the same environment, and
  3. A register of the CPU is capable of holding the required integer value,


  • 如果使用寄存器声明,快速整数类型甚至*更快?存储类?

  • Are the fast integer types even *faster if declared with the register storage class?

就像:

register int_fastY_t i;

*(表示上面的前提。

还是它们相互干扰并降低性能?

Or do they interfere with each other and decrease the performance?

推荐答案

寄存器不会导致编译器将值存储在寄存器中。 注册绝对没有任何作用。只有极老的编译器才使用 register 来知道要在寄存器中存储哪些变量。新的编译器会自动执行此操作。甚至20岁的编译器也会自动执行此操作。

register does not cause the compiler to store a value in a register. register does absolutely nothing. Only extremely old compilers used register to know which variables to store in registers. New compilers do it automatically. Even 20-year-old compilers do it automatically.

听起来您正在尝试使程序更快,但您不了解程序的实际作用,因此,您要问的是您听说过的所有与速度有关的事情。

It sounds like you are trying to make a program faster but you don't understand what the program is actually doing, so you are asking about all the speed-related things that you have ever heard about.

我提醒您,例如,如果您使用的是使用GCC的x86-64, ,则 int_fast16_t int64_t 相同,与 int register 绝对没有任何作用,因此 register int_fast16_t int相同。这不是一个神奇的加速命令。

I remind you that if you're on x86-64 using GCC, for example, then int_fast16_t is the same as int64_t, which is the same as int and register does absolutely nothing, so register int_fast16_t is the same as int. It's not a magic speed-up command.

如果您想使用这些技巧来使程序更快,则应先阅读编译器的汇编代码。生产。 GCC信息 Visual C ++ 。然后,您可以寻找效率低下的汇编代码,找到一些汇编代码后,便可以了解如何加快汇编代码的速度。现在,您在风车上倾斜

If you want to use these kinds of tricks to make your program faster, you should start by reading the assembly code that your compiler produces. Information for GCC or Visual C++. Then you can look for inefficient assembly code, and when you find some, you can find out how to speed it up. Right now, you are tilting at windmills.

这篇关于快速整数类型存储在CPU寄存器中时是否更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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