现代芯片的浮点数与整数算术性能 [英] Float versus Integer arithmetic performance on modern chips

查看:181
本文介绍了现代芯片的浮点数与整数算术性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑添加剂模型上的维特比解码器。它花时间做补充和比较。现在,考虑两个:一个用C / C ++ float 作为数据类型,另一个用 int 。在现代芯片上,你会期望 int 运行速度明显快于 float ?或者将流水线的奇迹(以及不存在乘法和除法)使得所有的问题都解决了? 解决方案

取决于你的意思是 。我通常希望看到整数执行速度快两倍,但这一切都取决于还在发生什么。现代处理器可以处理AMD64(AMD / Core2)指令集,如果它们能够保持流水线进行,那么每个周期通常可以有效地进行1次浮动操作。

<他们通常也可以在相同的时间内做2或3个整数运算。甚至可以一次执行两个操作。


但编写阻塞管道的代码并不困难,必须在完成后立即避免使用计算结果或者流水线将会停顿,你会得到更多的像是每个乘法3个周期而不是1个。PowerPC的每个周期的指令与AMD / Intel相同或更好大多数情况下。

附录:

顺便说一下,您可能会发现,比较比较意味着)最终花费比添加更多。错误预测的分支是昂贵的,特别是在奔腾4处理器上。

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?

解决方案

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.

这篇关于现代芯片的浮点数与整数算术性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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