使用double比float快吗? [英] Is using double faster than float?

查看:358
本文介绍了使用double比float快吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

双值存储更高的精度,是浮点大小的两倍,但英特尔CPU是针对浮点优化的?

Double values store higher precision and are double the size of a float, but are Intel CPUs optimized for floats?

也就是说, +, - ,*和/?

That is, are double operations just as fast or faster than float operations for +, -, *, and /?

64位体系结构的答案是否改变?

Does the answer change for 64-bit architectures?

推荐答案

没有一个intel CPU,特别是在哪些操作相对于其他操作进行优化,但大多数操作都是在CPU级别FPU)是这样的,你的问题的答案:

There isn't a single "intel CPU", especially in terms of what operations are optimized with respect to others!, but most of them, at CPU level (specifically within the FPU), are such that the answer to your question:


是双重操作,就像快速或
比float操作更快对于+, - ,
*和/?

are double operations just as fast or faster than float operations for +, -, *, and /?

/ strong>。 ,但是每个数字占用两倍的内存显然意味着高速缓存上的更多负载和更多的内存带宽,以填充这些高速缓存行,并将这些高速缓存行从RAM中溢出;您关心浮点运算效能的时间是您进行很多这类操作的时间,因此内存和缓存的注意事项至关重要。

is "yes" -- within the CPU. However, taking up twice the memory for each number clearly implies heavier load on the cache(s) and more memory bandwidth to fill and spill those cache lines from/to RAM; the time you care about performance of a floating-point operation is when you're doing a lot of such operations, so the memory and cache considerations are crucial.

@ Richard的回答指出,还有其他方法来执行FP操作( SSE 说明);旧的 MMX 是整数),特别适用于大量数据的简单操作(SIMD,单指令/多数据),其中每个寄存器可以包装4个单精度浮动或只有两个双精度的,所以这个效果会更加明显。

@Richard's answer points out that there are also other ways to perform FP operations (the SSE instructions; good old MMX was integers-only), especially suitable for simple ops on lot of data ("SIMD", single instruction / multiple data) where each register can pack 4 single-precision floats or only 2 double-precision ones, so this effect will be even more marked.

最后,你必须做基准,但我的预测是, (例如, large ;-)基准,你会发现有一个优点是坚持单精度(假设你不需要精度的额外的位) )。

In the end, you do have to benchmark, but my prediction is that for reasonable (i.e., large;-) benchmarks, you'll find advantage to sticking with single precision (assuming of course that you don't need the extra bits of precision!-).

这篇关于使用double比float快吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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