32 位操作与 64 位机器/操作系统上的 64 位操作 [英] 32 bit operation vs 64 bit operation on a 64bit machine/OS

查看:47
本文介绍了32 位操作与 64 位机器/操作系统上的 64 位操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪个操作,即 32 位操作或 64 位操作(例如屏蔽 32 位标志或 64 位标志),在 64 位机器上会更便宜吗?

Which operation i.e a 32 bit operation or a 64 bit operation (like masking a 32 bit flag or a 64 bit flag), would be cheaper on a 64 bit machine?

推荐答案

由于您没有指定架构,所以我只能建议一般性的答案,因为这取决于操作和所讨论的处理器架构.一旦您在 CPU 寄存器中有数据,那么无论该值最初是 32 位还是 64 位,大多数操作通常会花费相同的时间.

As you don;t specify an architecture, I can suggest only a general answer, as it depends on the operation and on the processor architecture in question. Once you have the data in a CPU register, then most operations will usually take the same amount of time regardless of whether the value was originally 32 or 64 bit.

但是,数据进入寄存器的方式在某些架构上可能存在一些差异.以下是在某些硬件上本机"值可能比较小值更快的一些情况:

However, there can be some differences on some architectures in how the data gets into a register. Here are some situations where a "native" value may be faster than a smaller value on some hardware:

获取数据

  • 获取本机大小"的值可能比获取较小的值更快.也就是说,处理器可能无论如何都需要获取 64 位,然后屏蔽/移出其中的 32 位以加载"一个 32 位值.在处理 64 位值时不需要这种掩码/移位,因此它可能加载得更快.(这违背了直觉的想法,即两倍大的东西可能需要两倍的时间来加载).

  • Fetching a "native sized" value may be faster than fetching a smaller value. That is, the processor may need to fetch 64 bits regardless, and then mask/shift off 32 bits of it to "load" a 32-bit value. This masking/shifting is not required when working on a 64 bit value, so it can possibly be loaded faster. (This goes against the intuitive idea that something twice as big might take twice as long to load).

或者,如果总线可以处理半角读取,则可以在加载 64 位值的同时加载 32 位.

Alternatively, if the bus can handle half-width fetches, then 32 bits may be loaded in the same time as a 64 bit value.

更令人困惑的是,CPU 缓存也会改变结果.通常,当您从内存中读取一个值时,会将多个内存位置的一行"读入缓存,以便可以从快速缓存提供后续读取,而不需要从 RAM 中完全提取.在这种情况下,如果您按顺序访问多个值,则使用 32 位值会更快,因为其中的两倍将被缓存,从而减少缓存未命中.

To confuse matters more, the CPU caches can change results as well. Usually when you read one value from memory, a "line" of several memory locations are read into the cache, so that subsequent reads can be supplied from fast cache memory instead of requiring a full fetch from RAM. In which case using 32 bit values will work out faster if you are accessing many values in sequence, as twice as many of them will be cached, resulting in fewer cache misses.

计算

  • 处理器硬件针对处理 64 位值进行了优化,因此使用 32 位计算值可能会带来更多麻烦,从而可能会减慢速度.例如它可能能够本地"处理双精度(64 位)值,但必须先将浮点(32 位)值转换为双精度,然后才能处理它,然后再将结果转换回浮点.

  • the processor hardware is optimised for dealing with 64-bit values, so calculating values using 32 bits may cause it more trouble, and thus could slow things down. e.g. It might be able to process a double (64-bit) value "natively" but have to convert a float (32-bit) value into a double before it can process it, then convert the result back to a float afterwards.

或者,可能有 32 位和 64 位路径通过 CPU,或者 CPU 可能能够以不影响指令整体执行时间的方式进行任何所需的转换,在在这种情况下,它们可以以相同的速度计算.

Alternatively, there may be 32-bit and 64-bit paths through the CPU, or the CPU may be able to do any conversions required in a way that does not affect the overall execution time of the instruction, in which case they may be calculated at the same speed.

这可能会影响复杂的运算(浮点),但不太可能是简单的运算(AND、OR 等)的问题

This may affect complex operations (floating point) but is unlikely to be a problem with simple ops (AND, OR, etc)

这篇关于32 位操作与 64 位机器/操作系统上的 64 位操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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