哪种整数数据类型最有效地使用x64 CPU核心?

时间:2021-03-23 16:24:13

Adding up two 32-bit integers and two 64-bit integers takes the same instruction time in a x64 machine, doesn't it? If so, when I use 32-bit integers in a x64 CPU core, the other 32 bits do not do any good, do they? I want to do my calculations inside the largest possible numeric range that would fit in a 64-bit core. Which data type fits this criteria best?

在x64机器中添加两个32位整数和两个64位整数需要相同的指令时间,不是吗?如果是这样,当我在x64 CPU内核中使用32位整数时,其他32位没有任何好处,是吗?我想在适合64位内核的最大可能数值范围内进行计算。哪种数据类型最符合此标准?

My candidates are:

我的候选人是:

  • int
  • INT
  • long int
  • 长整数
  • int64_t
  • 的int64_t
  • ... (add if you have another one)
  • ...(如果你有另一个,请添加)

3 个解决方案

#1


3  

m128i

m128i

N 32-bit adds takes as long as N 64-bit adds only if you aren't using the SIMD unit.

只有在不使用SIMD单元时,N 32位添加才需要N 64位添加。

#2


4  

You really can't tell if 32-bit or 64-bit computations will perform identically without some sort of measurement. While in theory, you can drive twice as many bits through the ALU using 64-bit quantities instead of 32-bit, the memory requirements of your app will increase. Arithmetic operations typically take one cycle on the CPU. Accessing memory outside of the CPU's cache can take a hundred cycles, potentially causing a large slowdown when using 64-bit quantities.

如果没有某种测量,你真的无法判断32位或64位计算是否会表现相同。理论上,您可以使用64位而不是32位通过ALU驱动两倍的位,您的应用程序的内存要求将会增加。算术运算通常在CPU上占用一个周期。访问CPU缓存之外的内存可能需要一百个周期,在使用64位数量时可能会导致大幅减速。

#3


2  

int

By definition it is the type that is most efficient on the processor being compiled for. That is why int changes size on each processor.
<quote>"plain ints have the natural size suggested by the architecture of the execution environment</quote>

根据定义,它是在编译的处理器上最有效的类型。这就是为什么int改变每个处理器的大小。 “plain int具有执行环境体系结构建议的自然大小

Note: Any code is highly dependent on the OS being run. If the OS is compiled with a specific size of int then to maintain compatibility any code built for the OS must remain the same. Thus if the OS manufacturer maintains 32 bit int compatibility the size of int will remain 32 as the default (even if 64 is the same speed).

注意:任何代码都高度依赖于正在运行的操作系统。如果使用特定大小的int编译OS,那么为了保持兼容性,为OS构建的任何代码必须保持不变。因此,如果OS制造商保持32位int兼容性,则int的大小将保持为默认值32(即使64是相同的速度)。

Hopefully over time the OS manufacturers will update there offering to be true 64 bit.

希望随着时间的推移,操作系统制造商将更新那里提供真正的64位。

#1


3  

m128i

m128i

N 32-bit adds takes as long as N 64-bit adds only if you aren't using the SIMD unit.

只有在不使用SIMD单元时,N 32位添加才需要N 64位添加。

#2


4  

You really can't tell if 32-bit or 64-bit computations will perform identically without some sort of measurement. While in theory, you can drive twice as many bits through the ALU using 64-bit quantities instead of 32-bit, the memory requirements of your app will increase. Arithmetic operations typically take one cycle on the CPU. Accessing memory outside of the CPU's cache can take a hundred cycles, potentially causing a large slowdown when using 64-bit quantities.

如果没有某种测量,你真的无法判断32位或64位计算是否会表现相同。理论上,您可以使用64位而不是32位通过ALU驱动两倍的位,您的应用程序的内存要求将会增加。算术运算通常在CPU上占用一个周期。访问CPU缓存之外的内存可能需要一百个周期,在使用64位数量时可能会导致大幅减速。

#3


2  

int

By definition it is the type that is most efficient on the processor being compiled for. That is why int changes size on each processor.
<quote>"plain ints have the natural size suggested by the architecture of the execution environment</quote>

根据定义,它是在编译的处理器上最有效的类型。这就是为什么int改变每个处理器的大小。 “plain int具有执行环境体系结构建议的自然大小

Note: Any code is highly dependent on the OS being run. If the OS is compiled with a specific size of int then to maintain compatibility any code built for the OS must remain the same. Thus if the OS manufacturer maintains 32 bit int compatibility the size of int will remain 32 as the default (even if 64 is the same speed).

注意:任何代码都高度依赖于正在运行的操作系统。如果使用特定大小的int编译OS,那么为了保持兼容性,为OS构建的任何代码必须保持不变。因此,如果OS制造商保持32位int兼容性,则int的大小将保持为默认值32(即使64是相同的速度)。

Hopefully over time the OS manufacturers will update there offering to be true 64 bit.

希望随着时间的推移,操作系统制造商将更新那里提供真正的64位。