Nick Randell
Nick Randell

Reputation: 18305

What math methods are implemented in fpu hardware with .net?

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.

Upvotes: 1

Views: 229

Answers (4)

Stephen Canon
Stephen Canon

Reputation: 106247

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.

Upvotes: 1

Nick Randell
Nick Randell

Reputation: 18305

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.

Upvotes: 0

richardtallent
richardtallent

Reputation: 35374

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.

Upvotes: 1

Adam Luchjenbroers
Adam Luchjenbroers

Reputation: 5029

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.

Upvotes: 2

Related Questions