在 64 位操作系统上使用 32 位编译器编译的 64 位浮点数

发布于 2024-09-18 03:55:18 字数 368 浏览 2 评论 0原文

我希望之前没有涉及到这一点,但是如果我用 C++ 编译一个使用 64 位浮点数 (double) 的 32 位程序,并在 64 位操作系统上运行它,将会将 64 位浮点移至 CPU 并移回 RAM 仍需要与 32 位操作系统上一样多的时钟周期,因为它是针对 32 位编译的。或者会花费更少的时钟周期,因为操作系统一次移动到 64 位,即使程序是在 32 位编译器中编译的。

我问的原因是因为我使用的是 VS Express,它只有 32 位,我想知道我是否可以在保持速度的同时使用 64 位浮点数,或者 32 位浮点数是否会更快,即使我使用 64 位操作系统,相信我,我想要编写的程序将使用数万个浮点数,这些浮点数将对其执行许多计算和按位运算(研究神经网络)。

谢谢。

I hope this has not been covered before, but if I compile a 32-bit program in C++ that uses 64-bit floating point numbers (double), and run it on a 64-bit OS, will it still take as many clock cycles to move the 64-bit float to the CPU and back to RAM as it would on a 32-bit OS because it's compiled for 32-bit. Or would it take less clock cycles to because the OS moves in 64-bit at a time, even though the program is compiled in 32-bit compiler.

The reason I ask is because I'm using VS express which has 32-bit only, and I'm wondering if I can use 64-bit floats while maintaining speed or if 32-bit floats will be faster, even though I'm using a 64-bit OS, and trust me, the program that I want to write will use tens of thousand of floating-point numbers that will have many calculations and bitwise operations performed on them (looking into neural networks).

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紧拥背影 2024-09-25 03:55:18

您所听到的 32 位与 64 位是地址中有多少位。它与用多少位来表示双精度数没有什么关系。特别是,32 位程序仍然表示 64 位中的双精度数,并且现代处理器具有可以本机处理 64 位浮点的硬件(即使它们只能本机处理 32 位整数)。

所以回答你的问题,不,这不重要。浮点运算的速度不应取决于操作系统或编译器的 32 位或 64 位。

The 32 vs 64 bits you're hearing about is how many bits are in the address. It has little to do with how many bits are used to represent a double. In particular, 32-bit programs still represent a double in 64 bits, and modern processors have hardware that can process 64 bit floats natively (even if they can only process 32 bit integers natively).

So to answer your question, no it shouldn't matter. The speed of floating point operations should not depend on the 32 or 64 -bitness of either the OS or the compiler.

内心激荡 2024-09-25 03:55:18

一般来说,双精度数比浮点数慢。

A)数据移入和移出内存需要更长的时间。如今,总线确实很宽,但传输“更多”数据仍然需要“更多”时间。

B) 双精度数需要更多时间来计算,因为硬件在进行数学计算时往往一次对位组进行操作,而不是同时操作所有位。

C) 4 字节浮点数有更多的用途,因此,有更多的门向它们抛出。请注意,x86 芯片上的 SSE 一次运行 4 个浮点数,通常每条指令需要 4 个时钟,有一些 SSE 指令使用双精度数,但一次只能使用两个,

但是,如果您需要额外的精度,则使用双精度数,并且吃性能成本。

您可能想研究 GPGPU 来处理大型数据集,只有最新的硬件才能加倍,但它们的一般 GPU 浮点性能非常出色。

Doubles are slower than floats as a general rule.

A) it takes longer for the data to be moved in and out of memory. Busses are really wide nowadays, but it still takes 'more' time to move 'more' data.

B) Doubles take more time to compute, since the hardware tends to operate on groups of bits at a time when doing math, not all at once.

C) 4byte floats have had more use and therefore, more gates thrown at them. Note that SSE on x86 chips operate on 4 floats at once, usually in 4 clocks per instruction, There are some SSE instructions that use doubles, but only two at a time,

However, if you need the extra precision, then use doubles, and eat the performance cost.

You may want to look into GPGPU for crunching large datasets, Only the latest hardware does doubles, but their genearly GPU float performance is outstanding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文