It is currently Sat Feb 24, 2018 8:49 am

All times are UTC - 5 hours

 Page 1 of 1 [ 2 posts ] 
Author Message
 Post subject: Helping with VMK's
PostPosted: Sun Feb 11, 2007 9:15 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1106
Location: Ontario Canada
The ability to map one set of numbers to another set of numbers is very useful in many applications. This VMK shows you how to set up a linear relationship between the input and the output values.

 Post subject: Don't be mad about MADD
PostPosted: Mon Feb 09, 2009 12:41 pm 

Joined: Wed Aug 06, 2008 7:53 pm
Posts: 182
Location: Russia
It would be interesting to note that in some cases general formulae mentioned in this VMK, namely (in short form)
Y = M * X + B                   (*)

might be more efficient even when it is used for two particular cases (when output is in the range [0, 1] and [1, 0]) than the formula for those cases, i.e.:
Y = (X - Ax) / (Bx - Ax)        (**)

The point is that modern hardware can have a dedicated instruction MADD, stands for Multiply then ADD. It has three arguments: MADD(a, b, c) and equivalent to a * b + c.
The multiplication-add (MADD) is merely a multiplication followed by a summation. Some processors, such as AltiVec, do not support a stand-alone multiplication, some support only the multiplication-add, and some support both. But it is much more efficient to call a MADD-type instruction when appropriate, instead of separately.

So, to use MADD for (*) one can write
Y = MADD(X, M, B).

But to extract MADDs' arguments from the formula (**), although that formula seems more compact then full version of (*), one has to convert it back to (**) anyway, i.e.:
Y = (X - Ax) / (Bx - Ax)  =>

// preliminaries
M = 1 / ( Bx - Ax )
B = - Ax * M

// maybe in cycle
Y = MADD(X, M, B).

Quite importantly, MADD is available on most modern GPU and accessible via shader's assembly languages (for shader programming mostly). For instance, OpenGL HLSL syntax for MADD is:
mad dst, src0, src1, src2

OK, this is just a side thought. I like this VMK.

Display posts from previous:  Sort by  
 Page 1 of 1 [ 2 posts ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: No registered users and 0 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to: