March 28, 2008
Optimizing Math-Intensive Applications with Fixed-Point ArithmeticCORDIC
The single biggest gain was achieved by optimizing the trigonometric and exponential functions. For the trig functions, the CORDIC method was used. (For more information on CORDIC, which is short for "COordinate Rotation DIgital Computer," see "Implementing CORDIC Algorithms," by Pitt Jarvis; www.ddj.com/architect/184408428.) CORDIC gets its name because it uses properties of rotations on a plane to calculate sines and cosines. A vector can be rotated counterclockwise by an angle q using a rotation matrix.
Equivalently, if you have two angles
The rotation by
As written, this is fine for some fixed angle theta, but what about a general angle? It can be shown that provided that:
and
then any angle
As a final simplifying step, if you choose the angles
We only need to handle angles in the range -
The sine and cosine of an angle can thus be calculated simply by rotating the unit vector from the x axis by the required angle as described: The cosine and sine are the x and y coordinates of the rotated vector.
Calculating arctan
The inverse tangent can easily be calculated with the CORDIC rotation tables. This time, rather than rotating the unit vector, a vector with an x component of 1 and a y component of the value for which we want the arctan is rotated until it has a y value of 0.
|
|
||||||||||||||||||||||||||||||
|
|
|
|