为float的两倍慢?难道64位程序运行速度比32位程序更快吗? [英] Is float slower than double? Does 64 bit program run faster than 32 bit program?

查看:358
本文介绍了为float的两倍慢?难道64位程序运行速度比32位程序更快吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

中使用浮动键入比使用慢双击键入<?/ p>

我听说现代英特尔和AMD的CPU可以做双打计算比花车更快。

有关标准的数学函数(开方什么, POW 日志 COS 等)?在单precision计算他们应该是相当快,因为​​它要求较少的浮点运算。例如,单precision 开方可以使用简单的数学公式一倍以上precision 开方。另外,我听说(编译时和64位操作系统上运行)标准的数学函数是在64位模式快。什么是明确的答案在这?


解决方案

经典的x86体系结构使用浮点单元(FPU)进行浮点运算。 FPU的执行在其内部寄存器,其中有80位$ P $每个pcision所有计算。每当你尝试一起工作浮动双击,变量首先从内存中加载到的内部寄存器FPU。这意味着有绝对在实际计算的速度没有差别,因为在任何情况下的计算是全80位precision进行。这可能是唯一不同的是加载从内存中的价值和存储结果回内存的速度。当然,在32位平台上比浮动这可能需要更长的时间来载入/存储双击。在64位平台上不应该有任何区别。

现代x86架构上支持扩展指令集(SSE / SSE2)与可以不涉及旧FPU指令执行同样的浮点计算新的指令。但是,同样,我不希望看到的浮动双击在计算速度的任何差异。并且由于这些现代平台是64位的人,加载/存储速度应该是相同的,以及

在不同的硬件平台上,这种情况可能会有所不同。但通常较小的浮点类型,不应提供任何性能优势。较小的浮点类型的主要目的是为了节省存储器,而不是提高性能。

编辑:(为了解决@MSalters评论)
我上面说的适用于基​​本的算术运算。当涉及到库函数,答案将取决于几个实施细节。如果平台的浮点指令集包含实现给定库函数的功能的指令,那么我上面所说的,通常会应用到的功能,以及(通常会包括像 COS 开方)。对于其它功能,其功能不是在FP指令集立即支持,情况可能被证明是显著不同。这很可能是浮动这样的功能版本可以更有效地比他们的双击的版本中实现。

Is using float type slower than using double type?

I heard that modern Intel and AMD CPUs can do calculations with doubles faster than with floats.

What about standard math functions (sqrt, pow, log, sin, cos, etc.)? Computing them in single-precision should be considerably faster because it should require less floating-point operations. For example, single precision sqrt can use simpler math formula than double precision sqrt. Also, I heard that standard math functions are faster in 64 bit mode (when compiled and run on 64 bit OS). What is the definitive answer on this?

解决方案

The classic x86 architecture uses floating-point unit (FPU) to perform floating-point calculations. The FPU performs all calculations in its internal registers, which have 80-bit precision each. Every time you attempt to work with float or double, the variable is first loaded from memory into the internal register of the FPU. This means that there is absolutely no difference in the speed of the actual calculations, since in any case the calculations are carried out with full 80-bit precision. The only thing that might be different is the speed of loading the value from memory and storing the result back to memory. Naturally, on a 32-bit platform it might take longer to load/store a double as compared to float. On a 64-bit platform there shouldn't be any difference.

Modern x86 architectures support extended instruction sets (SSE/SSE2) with new instructions that can perform the very same floating-point calculations without involving the "old" FPU instructions. However, again, I wouldn't expect to see any difference in calculation speed for float and double. And since these modern platforms are 64-bit ones, the load/store speed is supposed to be the same as well.

On a different hardware platform the situation could be different. But normally a smaller floating-point type should not provide any performance benefits. The main purpose of smaller floating-point types is to save memory, not to improve performance.

Edit: (To address @MSalters comment) What I said above applies to fundamental arithmetical operations. When it comes to library functions, the answer will depend on several implementation details. If the platform's floating-point instruction set contains an instruction that implements the functionality of the given library function, then what I said above will normally apply to that function as well (that would normally include functions like sin, cos, sqrt). For other functions, whose functionality is not immediately supported in the FP instruction set, the situation might prove to be significantly different. It is quite possible that float versions of such functions can be implemented more efficiently than their double versions.

这篇关于为float的两倍慢?难道64位程序运行速度比32位程序更快吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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