irrMath addition suggestion

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

irrMath addition suggestion

Post by MasterGod »

Optimization

You can save a bit of time by precalculating sine and cosine values for 360 degrees and storing them in an array. Then you use your own sine/cosine function that returns the corresponding field from the array, which is faster than calculating the same values over and over.
From this site.

I believe it could be a nice and simple addition?

And don't tell me "If it's that good then do it yourself and upload a patch" cause I don't have the time.
I've got a close deadline for my project and I'm barely gonna make it.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The sine array has been outperformed by most vector math extensions, such as SSE. And math libraries for the embedded platforms usually do such things already, depending on the memory interface performance and other stuff. So better save your time for other stuff.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

So to be sure I understand you right, the following is wrong?
Halifax wrote:Yeah, one thing I have to say, that you addressed, is the fact that you use cos() and sin(). I don't know if you know anything about how these are calculated, but these are very expensive (It uses multiple divisions, factorials, and exponents)...
@Halifax: Sorry you just really got me worried about it :wink:

P.S
This quote is taken from here:
http://irrlicht.sourceforge.net/phpBB2/ ... p?p=150619
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

You have to profile it - realistically- on each target platform. Realistically doesn't mean running through the table, it means letting it swap in and out of the cache, as the cost of loading the table into L1 cache may be higher then doing the calculation.

I tried this a couple of years back using Windows / Microsoft cl.exe (Athlon XP 1400), and the platform / math.h sin() and cos() were faster than table lookups (when interspersed with other memory-reliant operations) or any "fast approximate" equivalent that I could find.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Let me clarify my statement, which was taken out of context. They are expensive in regards to the simple calculations of dot products and cross products. These can also be calculated with math extensions like SSE as well.

As stated above tables wouldn't really cut it. First of all you would have to decide the precision of your table, which can increase the size drastically. For example, what if you input 3.5 or 3.54245? So usually tables do have the exactness that the real functions contain.

The only time that I would recommend using tables, from my own experience, is when you can use a integer precision table on a processor such as z80 or 68k.
TheQuestion = 2B || !2B
Post Reply