高性能的32位与64位运算 [英] Performance 32 bit vs. 64 bit arithmetic

查看:180
本文介绍了高性能的32位与64位运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是本机 64位整数运算指令比 32位零件计数器较慢(对 x86_64的 64位 OS)?

Are native 64 bit integer arithmetic instructions slower than their 32 bit counter parts (on x86_64 machine with 64 bit OS)?

编辑:在当前这样的CPU英特尔酷睿双核,酷睿i5 / i7处理器等

On current CPUs such Intel Core2 Duo, i5/i7 etc.

推荐答案

这取决于CPU准确和运营上。在64位奔腾的IV,例如,64位寄存器乘法是相当慢一点。酷睿2及更高版本的CPU已经被设计为从根本上64位操作。

It depends on the exact CPU and operation. On 64-bit Pentium IVs, for example, multiplication of 64-bit registers was quite a bit slower. Core 2 and later CPUs have been designed for 64-bit operation from the ground up.

一般情况下,即使是64位平台编写code采用32位变量,其中值将适合他们。这并非主要是因为运算速度更快(在现代的CPU,它一般不会),而是因为它使用较少的内存和内存带宽。

Generally, even code written for a 64-bit platform uses 32-bit variables where values will fit in them. This isn't primarily because arithmetic is faster (on modern CPUs, it generally isn't) but because it uses less memory and memory bandwidth.

一个包含了十几个整数结构将一半的大小,如果这些整数是32位的比,如果他们是64位。这意味着它需要一半的字节来存储,在高速缓存一半的空间,等等。

A structure containing a dozen integers will be half the size if those integers are 32-bit than if they are 64-bit. This means it will take half as many bytes to store, half as much space in the cache, and so on.

64位本地寄存器和算术都用到哪里值可能不适合32位。但主要的性能优点来自在x86_64的指令集提供额外的通用寄存器。当然,也有来自于64位指针的所有好处。

64-bit native registers and arithmetic are used where values may not fit into 32-bits. But the main performance benefits come from the extra general purpose registers available in the x86_64 instruction set. And of course, there are all the benefits that come from 64-bit pointers.

所以真正的答案是,它并不重要。即使你使用x86_64的模式,您可以(而且一般)仍然使用32位运算的地方就行了,你会得到更大的指针和通用寄存器的好处。当您使用64位本机的操作,这是因为你需要64位操作,你知道他们会比用多个32位运算伪造更快 - 你唯一的其他选择。因此,32位与64位寄存器的相对表现不应该是任何实现决策的决定性因素。

So the real answer is that it doesn't matter. Even if you use x86_64 mode, you can (and generally do) still use 32-bit arithmetic where it will do, and you get the benefits of larger pointers and more general purpose registers. When you use 64-bit native operations, it's because you need 64-bit operations, and you know they'll be faster than faking it with multiple 32-bit operations -- your only other choice. So the relative performance of 32-bit versus 64-bit registers should never be a deciding factor in any implementation decision.

这篇关于高性能的32位与64位运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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