tags:

views:

79

answers:

4

Does anyone know what math methods are implemnted by the hardware of the processor for .net? For example, I have an algorithm that makes a lot of use of atan. I can easily write a lookup table for this, but if math.net implements this using an fpu or other hardware extensions, it's not going to be worth it.

+2  A: 

Why not just benchmark your look-up table approach against the atan() provided with .net. Then you'll be able to clearly tell how much of a speed difference using a look-up table really makes.

Armed with that, you won't need to know how the underlying VM does things in order to identify the fastest method. You'll even be able to quantify the speedup.

Adam Luchjenbroers
I am currently doing this, but I hope that someone has already done it, potentially saving me time. Either way, an answer should appear soon!
Nick R
Although you cannot take my word for it, I tried using lookup tables for sine and cosine, and it was very much slower than Math.Cos/Sin().
Cecil Has a Name
+1  A: 

According to this blog, Microsoft's JIT compiler does take advantage of FPU instructions on the x86 platform:

http://blogs.msdn.com/davidnotario/archive/2004/10/26/247792.aspx

It's a pretty elementary thing to do, since FPUs have been standard on x86 CPUs for over a decade now.

richardtallent
A: 

With a small benchmark application, it appears that even if the fpu is used, the performance of Math.Atan2 is not as good as an alternative approximisation function.

In my simple benchmark, the Math.Atan2 loop is taking 8 seconds, whilst the approximate version is taking 5.5 seconds.

Nick R
+1  A: 

Whether or not the methods are implemented using the x87 hardware instructions isn't the issue, because the hardware transcendental function instructions are slow.

The "Intel 64 and IA-32 Architectures Optimization Reference Manual" (download here) lists fpatan as having a latency of 150-300 cycles on recent hardware. A well written software implementation can deliver a full accuracy double-precision result in substantially less time -- indeed, high-quality math libraries do just that.

Stephen Canon