Float versus Integer arithmetic performance on modern chips

眉间皱痕 提交于 2019-12-23 16:13:23

问题


Consider a Viterbi decoder on an additive model. It spends its time doing additions and comparisons. Now, consider two: one with C/C++ float as the data type, and another with int. On modern chips, would you expect int to run significantly faster than float? Or will the wonders of pipelining (and the absence of multiplication and division) make it all come out about even?


回答1:


Depends on what you mean by significantly. I usually expect to see ints perform about 2x faster, but it all depends on what else is going on. Modern processors that can handle the AMD64 (AMD/Core2) instruction set can usually do effectively 1 float operation per cycle if they can keep the pipeline fed

They can also usually do 2 or 3 integer operations in the same amount of time. and even can do both at once.

But it's not that hard to write code that stalls the pipeline, you have to avoid using the result of a calculation immediately after it's complete or the pipeline will stall and you get more like 3 cycles per multiply rather than 1.

The instructions per cycle for the PowerPC is the same or better than AMD/Intel in most cases.

Addendum:

By the way, you may discover that the comparisons (or rather the branches that the comparisons imply) end up costing a lot more than the additions. mis-predicted branches are expensive, especially on the Pentium 4 processor.



来源:https://stackoverflow.com/questions/2010252/float-versus-integer-arithmetic-performance-on-modern-chips

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!