在this topic提到了以下内容:
The fast type (int_fast#_t) gives you an integer that’s the fastest type with a width of at least # bits (where # = 8, 16, 32, or 64). For example, int_fast32_t will give you the fastest integer type that’s at least 32 bits.
他所说的最快的整数类型是什么意思?什么定义了速度?
我假设并非所有整数都以相同的方式访问,有些整数比其他整数更容易访问,但我需要知道什么可以导致这种访问速度?
我在一个问题中读到:
On some processors, if a variable gets stored in a register which is longer, the compiler may have to add extra code to lop off any extra bits. For example, if uint16_t x; gets stored in a 32-bit register on the ARM7-TDMI, the code x++; may need to be evaluated as x=((x+1)<<16)>>16);. On compilers for that platform, uint_fast16_t would most likely be defined as synonymous with uint32_t to avoid that.
是什么让它更快?在任何一种情况下,32 位都将在寄存器级别循环。
最佳答案
一些 64 位机器对所有东西都使用 64 位,因此在 32 位空间中进行数学计算需要额外的成本(例如,必须模拟无符号溢出)。在这样的机器上,int_fast32_t
可以是 64 位。同样对于一些 32 位机器——int_fast8_t
可能是 32 位。
x86-64 在这里并没有真正受到影响——它保留了 8 位、16 位和 32 位指令,因此编译器可以只说“在这些寄存器上进行 8 位数学运算”,而寄存器的变化并不重要更宽。如果您在商用台式机或服务器上编程,您可能不需要关心“快速”整数类型。
关于c++ - 什么是快速整数?什么定义了一个整数有多快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46446453/