sin和cos如何在硬件上实现? [英] How are sin and cos implemented hardware wise?

查看:257
本文介绍了sin和cos如何在硬件上实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究如何计算正弦和余弦.我发现了几种标准"方法,包括查找表,CORDIC算法和泰勒级数.我还发现,大多数现代处理器都具有用于计算三角函数的汇编指令.我想知道的是这些命令是如何工作的.

所以,我的问题是: 当前的发电处理器使用什么特定算法来计算正弦和余弦?

解决方案

此处的相关但不同的问题的答案讨论FPU如何执行此类指令:

一旦减少了论点,大多数芯片都会使用CORDIC算法来计算正弦和余弦.您可能会听到人们说计算机使用泰勒级数.这听起来很合理,但事实并非如此. CORDIC算法更适合高效的硬件实现. (例如,软件库可能在不支持触发功能的硬件上使用泰勒级数.)可能会有一些额外的处理,使用CORDIC算法可获得相当好的答案,但随后可以做一些其他事情以提高准确性.

请注意,尽管它说的是大多数芯片",但提高性能,准确性或(理想情况下)两者的尝试显然是芯片制造商所追求的目标,因此,两者之间会有差异.

这些差异会以降低准确性为代价来提高性能,反之亦然(当然,由于我们生活在一个不完美的世界中,它们两者都可能很不利),因此有时一个人可能会喜欢在CPU中执行该算法(如果您自己编写算法,就会发生这种情况),而不是像 fsin 传递给FPU那样在FPU中执行.

此已归档的博客文章讨论了Sun在Intel上对JVM的实现如何仅使用对fsin的普通调用以及一定范围内的输入,因为该实现存在缺陷.与此文章相关的论文大概讨论了fsin的实现,并且更详细地讨论了它的问题,但是您需要成为订阅者或付费才能阅读该文章(因此我尚未完成).

I have been doing some research as to how sine and cosine can be calculated. I found a couple of "standard" methods, including a lookup table, a CORDIC algorithm, and Taylor series. I also found that most modern processors have an assembler instruction calculating trigonometric functions. What I want to know is how those commands work.

So, my question is: What specific algorithm do current gen processors use for calculating sine and cosine?

解决方案

The answer to a related, but different question here talks of how FPUs perform such instructions:

Once you've reduced your argument, most chips use a CORDIC algorithm to compute the sines and cosines. You may hear people say that computers use Taylor series. That sounds reasonable, but it's not true. The CORDIC algorithms are much better suited to efficient hardware implementation. (Software libraries may use Taylor series, say on hardware that doesn't support trig functions.) There may be some additional processing, using the CORDIC algorithm to get fairly good answers but then doing something else to improve accuracy.

Note though that it says "most chips", as attempts to improve performance, accuracy or (ideally) both would obviously be something that chip manufacturers strive for, and so, there will be differences between them.

Those differences my well lead to greater performance at the cost of less accuracy, or vice-versa (and of course, they can just be plain bad at both, since we live in an imperfect world) so there would be times when one might favour performing the algorithm in the CPU (as would happen if you coded the algorithm yourself) rather than in the FPU like fsin passes to.

This archived blog post talks of how Sun's implementation of the JVM on Intel only uses a plain call to fsin with inputs of a certain range, because of flaws in that implementation. The paper linked to from that article presumably discusses that implementation of fsin, and it's issues, in more detail, but you'll need to be a subscriber or pay to read that article (which I have hence not done).

这篇关于sin和cos如何在硬件上实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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