x86中不同数学函数的性能? [英] Performance of different math functions in x86?

查看:52
本文介绍了x86中不同数学函数的性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写3D碰撞,想知道基本数学函数(如+-*/sqrt pwr三角函数,如sin cos tan arcsin)的性能差异.

I am writing a 3D collision, and want to know the difference in performance of basic math functions like + - * / sqrt pwr trigonometry like sin cos tan arcsin..

我听说这取决于许多其他因素,所以我只想大致了解哪一个速度较慢,需要在寻找解决问题的不同方法时避免使用.我也想知道差异的顺序和大小

I heard it depends on many other things so I just want to get a rough idea about which one is slower and need to avoid while finding different ways to solve the problem. Also I want to know the order and the magnitude of the difference

谢谢

我用VC ++编写x86.但是,其他架构和一般情况下的知识也很不错.我主要是在单个浮点中进行计算以进行实时应用.

I write in VC++ for x86. But knowledge in other architectures and general picture are good, too. Mainly I calculate in single floating point for real time application.

问题是某些算法需要sqrt或三角函数,但是我可以通过其他方法绕过它们.每个人都有自己的进步,我想知道足以进行权衡.我想要一个一般的知识来解决自己的问题,做了一个google却什么也没找到,所以请回答

The problem is that some algorithms need sqrt, or trigonometry, but I can bypass them by other methods. Each one has its own advances and I want to know is enough to do trade off. I want a general knowledge to solve my own problem, did a google but found nothing so please let it be answered

推荐答案

讲得很广泛,概括一下最近的常见硬件:

Speaking very broadly, and generalizing about recent common hardware:

  • 加法,减法和乘法非常快(每个内核每个周期至少可以执行一个运算).
  • 分度和平方根通常要慢一个数量级(每个操作数十个周期).对于特定用途,可以使用许多近似算法来缩小此差距.
  • 调用数学库函数( sin cos exp log 等)的差异很大,具体取决于您正在使用什么数学库实现以及在什么硬件上.在当前的i7上,典型的情况是每20个周期的操作与每200个周期的操作之间的某个时间,具体取决于实现的质量和所调用的特定功能.
  • addition, subtraction and multiplication are fast (capable of at least one operation per cycle per core).
  • division and square root are typically about an order of magnitude slower (tens of cycles per operation). There are many approximation algorithms that can be used to narrow this gap somewhat for specific usages.
  • calling math library functions (sin, cos, exp, log, etc) varies significantly depending on what math library implementation you are using and on what hardware. On (say) a current i7, something between an operation every ~20 cycles and an operation every ~200 cycles is typical, depending on the quality of the implementation and the specific function being called.

这篇关于x86中不同数学函数的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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