0% found this document useful (0 votes)
85 views22 pages

CSE 575 Computer Arithmetic Spring 2003: Mary Jane Irwin (WWW - Cse.psu - Edu/ Mji)

The document discusses Cordic algorithms which use circular rotations to evaluate trigonometric functions using only additions, subtractions and shifts. It describes real and pseudo Cordic rotations, and how to select angles to simplify the rotations. Examples are given to demonstrate computing trigonometric functions and inverse trigonometric functions using Cordic iterations.

Uploaded by

Aysh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views22 pages

CSE 575 Computer Arithmetic Spring 2003: Mary Jane Irwin (WWW - Cse.psu - Edu/ Mji)

The document discusses Cordic algorithms which use circular rotations to evaluate trigonometric functions using only additions, subtractions and shifts. It describes real and pseudo Cordic rotations, and how to select angles to simplify the rotations. Examples are given to demonstrate computing trigonometric functions and inverse trigonometric functions using Cordic iterations.

Uploaded by

Aysh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 22

CSE 575

Computer Arithmetic

Spring 2003
Mary Jane Irwin
(www.cse.psu.edu/~mji)

Computer Arithmetic CSE575 CORDIC.1 © MJIrwin, PSU, 2003


Cordic Algorithms
 A convergence method for evaluating
trigonometric (and other) functions
» if a unit-length vector with end point at
(X,Y) = (1,0) is rotated by an angle Z, its new
end point will be at (X,Y) = (cos Z, sin Z)
» simple hardware - shifters, adders, lookup
table
 Family of algorithms: rotation, vector mode
» circular rotations
» linear rotations
» hyperbolic rotations
Computer Arithmetic CSE575 CORDIC.2 © MJIrwin, PSU, 2003
Real Cordic Rotations
If vector OEi is rotated about
Ei+1 the origin by an angle i, the
(Xi+1, Yi+1)
new vector OEi+1 will have the
Ri+1 Ei coordinates
(Xi, Yi) Real rotation: Ei+1
i Xi+1 = Xi cos i - Yi sin i
Ri
O Yi+1 = Yi cos i + Xi sin i
Zi+1 = Zi - i
The variable Z allows us to keep track of the total
rotation over several steps. If Z0 is the initial rotation
goal and if the i angles are selected at each step such
that after n iterations Zn tends to 0, then En will be the
end point after rotation by angle Z0
Computer Arithmetic CSE575 CORDIC.3 © MJIrwin, PSU, 2003
Pseudo Cordic Rotations
Pseudo rotations increase the
E’i+1
(Xi+1, Yi+1) vector length to
Ri+1 = Ri(1 + tan2i)1/2
Ri+1 Pseudo rotation: E’i+1
Ei
(Xi, Yi) Xi+1 = Xi - Yi tan i
i
Ri Yi+1 = Yi + Xi tan i
O Zi+1 = Zi - i

Expansion factor K = (1 + tan2 i)1/2 depends on


the rotation angles 1 ,2 …, n. If we always
rotate by the same angles, K is a constant.
Computer Arithmetic CSE575 CORDIC.4 © MJIrwin, PSU, 2003
Basic Cordic Rotations
 To simplify pseudo rotations, pick i such
that tan i = di 2-i where di  {-1,1}. Then
Xi+1 = Xi - di Yi 2-i
Yi+1 = Yi + di Xi 2-i
Zi+1 = Zi - di tan-12-i

 Computation of Xi+1 and Yi+1 requires an i-bit


right shift and an add/subtract; Zi+1 only
requires an add/subtract and one table lookup
 Precompute and store the function tan -12-i

Computer Arithmetic CSE575 CORDIC.5 © MJIrwin, PSU, 2003


Choosing the Angles
i i = 2-i Ei=tan-12-i di Zi - diEi = Zi+1
0 1.000 000 45.000000 1 30.00 – 45.00 = -15.00
1 0.500000 26.565051 -1 -15.00 + 26.57 = 11.57
2 0.250000 14.036243 1 11.57 – 14.04 = -2.47

Zi+1  zero
3 0.125000 7.125016 -1 -2.47 + 7.13 = 4.66
4 0.062500 3.576334 1 4.66 – 3.58 = 1.08
5 0.031250 1.789910 1 1.08 -1.79 = -0.71
6 0.015625 0.895174 -1 -0.71 + 0.90 = 0.19
7 0.007813 0.447614 1 0.19 - 0.45 = -0.26
8 0.003906 0.223811 -1 -0.26 + 0.22 = -0.04
9 0.001953 0.111906 -1 -0.04 + 0.11 = 0.07
Computer Arithmetic CSE575 CORDIC.6 © MJIrwin, PSU, 2003
Rotating the Angles
 Illustration of the first three rotations for a
Z of 30

(X0, Y0)
(X2, Y2)

-45
-14
30
O
+26.6 (X3, Y3)

(X1, Y1)

Computer Arithmetic CSE575 CORDIC.8 © MJIrwin, PSU, 2003


Circular Rotation Mode
 Choosing di = sign(Zi)  {-1,1} to force Z to 0
gives the rotation mode Cordic iterations
Xi+1 = Xi - di Yi 2-i
Yi+1 = Yi + di Xi 2-i
Zi+1 = Zi - di Ei where Ei = tan-12-i
 After n iterations, when Zn is sufficiently close to 0,
then we have Z = i and
Xn = K(X cos Z - Y sin Z) where K = 1.646 760 258 …
Yn = K(Y cos Z + X sin Z)
Zn = 0
Rule: Choose di  {-1,1} such that Z  0
 Computes cos Z and sin Z by starting with
X = 1/K = 0.607 252 935 … and Y = 0
 For k bits of precision, run it k iterations since for
large i > k, tan-12-i  2-i
Computer Arithmetic CSE575 CORDIC.9 © MJIrwin, PSU, 2003
Convergence Domain
 Convergence of Z to 0 happens because each
angle is more than half the previous angle.
 The domain of convergence is
0  Z  99.7
which is the sum of all the angles given in
slide 6
 Outside this range, we can use trig identities
to convert to the range
cos (Z  2j) = cos Z sin (Z  2j) = sin Z
cos (Z - ) = - cos Z sin (Z - ) = - sin Z

Computer Arithmetic CSE575 CORDIC.10 © MJIrwin, PSU, 2003


Rotation Example
Computing cos 30 (= 0.866 025) and sin 30 (=0.500 000)
i di Xi+1  cos Yi+1  sin Zi+1  0
1/K = 0.607 253 0.000 000 30.000 000
0 1 0.607 253 0.607 253 -15.000 000
1 -1 0.910 880 0.303 627 11.565 051
2 1 0.834 973 0.531 347 -2.471 192
3 -1 0.901 391 0.426 975 4.653 824
4 1 0.874 705 0.483 312 1.077 490
5 1 0.859 602 0.510 647 -0.712 420
6 -1 0.867 581 0.497 216 0.182 754
7 1 0.863 697 0.503 994 -0.264 860
8 -1 0.865 666 0.500 620 -0.041 049
... ... ... ... ...

Computer Arithmetic CSE575 CORDIC.11 © MJIrwin, PSU, 2003


Circular Vector Mode
 Choosing di = - sign(Xi Yi)  {-1,1} to force Y to 0
gives the vector mode Cordic iterations
Xi+1 = Xi - di Yi 2-i
Yi+1 = Yi + di Xi 2-i
Zi+1 = Zi - di Ei where Ei = tan-12-i
 After n iterations, when Yn is sufficiently close to 0,
then we have tan (i) = -Y/Z
Xn = K (X2 + Y2) where K = 1.646 760 258 …
Yn = 0
Zn = Z + tan-1 (Y/X)
Rule: Choose di  {-1,1} such that Y  0
 Computes tan-1 Y by starting with X = 1 and Z = 0
 For k bits of precision, run it k iterations since for
large i > k, tan-12-i  2-i
Computer Arithmetic CSE575 CORDIC.12 © MJIrwin, PSU, 2003
Vector Example
Computing tan-1 0.414 210 (= 22.499 830)
di Xi+1  K(X2 + Y2) Yi+1  0 Zi+1  tan-1
1.000 000 0.414 210 0.000 000
0 -1 1.414 210 -0.585 790 45.000 000
1 1 1.707 105 0.121 315 18.434 949
2 -1 1.737 434 -0.305 461 32.471 192
3 1 1.775 617 -0.088 282 25.346 176
4 1 1.781 135 0.022 694 21.769 842
5 -1 1.781 844 -0.032 966 23.559 752
6 1 1.782 359 -0.005 125 22.664 578
7 1 1.782 399 0.008 800 22.216 964
8 -1 1.782 433 0.000 184 22.440 775
... ... ... ... ...

Computer Arithmetic CSE575 CORDIC.13 © MJIrwin, PSU, 2003


Circular Cordic Hardware

X
shift

Xi+1 = Xi – di Yi 2-i
i counter
shift
Yi+1 = Yi – di Xi 2-i

Y

Z

lookup Zi+1 = Zi – di Ei
values of
Ei= tan-12-i table
di control
Computer Arithmetic CSE575 CORDIC.14 © MJIrwin, PSU, 2003
Generalized Cordic
 Generalized Cordic defined as
Xi+1 = Xi -  di Yi 2-i
Yi+1 = Yi + di Xi 2-i
Zi+1 = Zi - di Ei

 Defining  and Ei gives


=1 Circular rotations (basic) Ei = tan-12-i
=0 Linear rotations Ei = 2-i
 = -1 Hyperbolic rotations Ei = tanh-12-i

Computer Arithmetic CSE575 CORDIC.15 © MJIrwin, PSU, 2003


Generalized Rotations
2(area AOB) 2(area EOF)
angle AOB = -------------- angle EOF = ---------------
(OU)2 (OW)2
B =1
A
F
 = -1
E
O
W V U
=0

vector OV

Computer Arithmetic CSE575 CORDIC.16 © MJIrwin, PSU, 2003


Enhanced Cordic Hardware

X
X Xi+1 = Xi – di Yi 2-i 
shift
i counter
shift
Yi+1 = Yi + di Xi 2 -i
Y 
Y

Zi+1 = Zi - di Ei
Z
Z 
Ei lookup table
 (tan-12-i, 2-i, tanh-12-i)
di control

Computer Arithmetic CSE575 CORDIC.17 © MJIrwin, PSU, 2003


Circular Mode ( = 1)
 Circular rotation mode
Xn = K(X cos Z - Y sin Z) Computes functions
cos Z and sin Z
Yn = K(Y cos Z + X sin Z) X = 1/K and Y = 0
Zn = 0
Rule: Choose di  {-1,1} such that Z  0
 Circular vector mode
Xn = K(X2 + Y2)1/2 Computes function
Yn = 0 tan-1 Y
X = 1 and Z = 0
Zn = Z + tan-1 (Y/X)
Rule: Choose di  {-1,1} such that Y  0
Computer Arithmetic CSE575 CORDIC.18 © MJIrwin, PSU, 2003
Linear Mode ( = 0)
 Linear rotation mode
Xn = X Computes functions
Yn = Y + X * Z multiply and multiply-add
Y=0
Zn = 0
Rule: Choose di  {-1,1} such that Z  0
 Linear vector mode
Xn = X Computes functions
Yn = 0 divide and divide-add
Z=0
Zn = Z + Y/X
Rule: Choose di  {-1,1} such that Y  0
Computer Arithmetic CSE575 CORDIC.19 © MJIrwin, PSU, 2003
Hyperbolic Mode ( = -1)
 Hyperbolic rotation mode
Xn = K’(X cosh Z + Y sinh Z) Computes functions
Yn = K’(Y cosh Z + X sinh Z) hyperbolic sin and cos
X = 1/K’ and Y = 0
Zn = 0
Rule: Choose di  {-1,1} such that Z  0
K’ = 0.828 159 360 …
 Hyperbolic vector mode
Computes functions
Xn = K’(X - Y )
2 2 1/2
hyperbolic tanh-1 y
Yn = 0 X = 1 and Z = 0
Zn = Z + tanh-1 (Y/X)
Rule: Choose di  {-1,1} such that Y  0
Computer Arithmetic CSE575 CORDIC.20 © MJIrwin, PSU, 2003
Cordic Computation Unit
Rotation mode: di=sign(Zi); Zi0 Vector mode: di= -sign(Xi  Yi); Yi0
CORDIC

CORDIC
Ciclr X K(X cosZ – Y sinZ) X K (X2 + Y2)
=1 Y K(Y cosZ + X sinZ) Y 0
Z 0 Z Z + tan -1(Y/X)
Ei = For cos & sin, set X=1/K, Y=0 For tan-1, set X=1, Z=0
tan-12-i tanZ=sinZ/cosZ cos-1W=tan-1[(1-W2)/W];sin-1W=tan-1[W/(1-W2)]
Linear X X X X
CORDIC

CORDIC
=0 Y Y + X*Z Y 0
Z 0 Z Z + Y/X
Ei = 2-i For multiply, set Y=0 For divide, set Z=0
Hprblc X K’(X coshZ – Y sinhZ) X K’ (X2 - Y2)
CORDIC

CORDIC
 = -1 Y K’(Y coshZ + X sinhZ) Y 0
Z 0 Z Z + tanh -1(Y/X)
Ei = For cosh & sinh, set X=1/K’, Y=0 For tanh-1, set X=1, Z=0
tanh-1 cosh-1W=ln[W+(1-W2)];sinh-1W=ln[W+(1+W2)]
2-i tanhZ=sinhZ/coshZ; Wt=Et lnW
Ez=sinhZ+coshZ lnW=2tanh-1|(W-1)/(W+1)|;W=((W+¼)2-(W-¼)2)
In executing the iterations for  = -1, steps 4, 13, 40, 121, …, j, 3j+1, … must be repeated.

Computer Arithmetic CSE575 CORDIC.21 © MJIrwin, PSU, 2003


Cordic Summary
 Can compute virtually all trig functions of
common interest
 When the number of iterations is fixed,
K and K’ are constants
» Thus, we can not stop computing if Z (or Y)
becomes 0 (except when  = 0); we always
need k iterations for k digits of precision
 Cordic can be extended to higher radices
(e.g., for base 4, di{-2,-1,1,2} and the
number of iterations will be cut in half
with essentially the same hardware)
Computer Arithmetic CSE575 CORDIC.22 © MJIrwin, PSU, 2003
Key References
Duprat and Muller, The CORDIC algorithm: New results for
fast VLSI implementation, IEEE Trans. on Computers,
42(2):168-178, 1993.
Parhami, Computer Arithmetic, Oxford Univ. Press, 1999.
Phatak, Double step branching CORDIC, IEEE Trans. on
Computers, 47(5)587-603, May 1998.
Vachss, The CORDIC magnification function, IEEE Micro,
7(5):83-83, Oct. 1987.
Volder, The CORDIC trigonometric computing technique,
IRE Trans. Elecronic Computers, Vol 8, pp. 330-335,
Sept. 1959.
Walther, A unified algorithm for elementary functions,
Proc. Spring Joint Computer Conf, pp. 379-385, 1971.

Computer Arithmetic CSE575 CORDIC.23 © MJIrwin, PSU, 2003

You might also like