6

虽然我知道(有人告诉我)浮点协处理器的工作速度比任何浮点运算的软件实现都要快,但我完全没有直觉这种差异有多大,在数量级上。

答案可能取决于微处理器和超级计算机之间的应用程序和工作地点。我对计算机模拟特别感兴趣。

你能指出这个问题的文章或论文吗?

4

1 回答 1

6

一般的答案显然会很模糊,因为性能取决于很多因素。

但是,根据我的理解,在没有在硬件中实现浮点 (FP) 运算的处理器中,软件实现通常比整数运算慢 10 到 100 倍(或者更糟,如果实现不好),整数运算是总是在 CPU 上的硬件中实现。

确切的性能将取决于许多因素,例如整数硬件的特性——一些 CPU 缺少 FPU,但在整数运算中具有有助于实现 FP 计算的快速软件仿真的特性。

njuffa、Cristina Iordache 和 Ping Tak Peter Tang 提到的论文 An Overview of Floating-Point Support and Math Library on the Intel XScale Architecture支持这一点。对于英特尔XScale处理器,延迟列表(摘录):

integer addition or subtraction:  1 cycle
integer multiplication:           2-6 cycles
fp addition (emulated):           34 cycles
fp multiplication (emulated):     35 cycles

因此,这将导致整数和 FP 算术之间的因子约为 10-30。该论文还提到 GNU 实现(GNU 编译器默认使用的那个)慢了大约 10 倍,总因子为 100-300。

最后,请注意,以上是针对 FP 仿真被编译器编译到程序中的情况。一些操作系统(例如 Linux 和 WindowsCE)在操作系统内核中也有一个 FP 仿真。优点是即使没有 FP 仿真(即使用 FPU 指令)编译的代码也可以在没有 FPU 的进程上运行——内核将透明地在软件中仿真不受支持的 FPU 指令。但是,由于额外的开销,这种仿真甚至比编译到程序中的软件仿真还要慢(大约是另一个因素 10)。显然,这种情况只适用于一些处理器有 FPU 而一些没有(例如 x86 和 ARM)的处理器架构。

Note: This answer compares the performance of (emulated) FP operations with integer operations on the same processor. Your question might also be read to be about the performance of (emulated) FP operations compared to hardware FP operations (not sure what you meant). However, the result would be about the same, because if FP is implemented in hardware, it is typically (almost) as fast as integer operations.

于 2013-03-23T10:00:20.773 回答