Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
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
(Xi+1, Yi+1)
Ei+1
Ei
Ri+1
i
O
(Xi, Yi)
Ri
If vector OEi is rotated about
the origin by an angle i, the
new vector OEi+1 will have the
coordinates
Real rotation: Ei+1
Xi+1 = Xi cos i - Yi sin i
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
(Xi+1, Yi+1)
Ri+1
i
O
Pseudo rotations increase the
vector length to
Ri+1 = Ri(1 + tan2i)1/2
E’i+1
Ei
(Xi, Yi)
Ri
Pseudo rotation: E’i+1
Xi+1 = Xi - Yi tan i
Yi+1 = Yi + Xi tan i
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
Computer Arithmetic
CSE575 CORDIC.5
© MJIrwin, PSU, 2003
Choosing the Angles
Computer Arithmetic
CSE575 CORDIC.6
Zi+1 zero
i
Ei=tan-12-i di
Zi - diEi = Zi+1
i = 2-i
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
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
© MJIrwin, PSU, 2003
Rotating the Angles
Illustration of the first three rotations for
a Z of 30
(X0, Y0)
O
30
-45
(X2, Y2)
-14
+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
-12-i 2-i
for
large
i
>
k,
tan
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
cos (Z - ) = - cos Z
Computer Arithmetic
sin (Z 2j) = sin Z
sin (Z - ) = - sin Z
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
i counter
shift
Y
Z
values of
Ei= tan-12-i
Computer Arithmetic
lookup
table
CSE575 CORDIC.14
Xi+1 = Xi – di Yi 2-i
Yi+1 = Yi – di Xi 2-i
Zi+1 = Zi – di Ei
di control
© 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)
= 0 Linear rotations
= -1 Hyperbolic rotations
Computer Arithmetic
CSE575 CORDIC.15
Ei = tan-12-i
Ei = 2-i
Ei = tanh-12-i
© MJIrwin, PSU, 2003
Generalized Rotations
2(area AOB)
angle AOB = -------------(OU)2
B
2(area EOF)
angle EOF = --------------(OW)2
=1
A
F
= -1
O
E
W
V U
=0
vector OV
Computer Arithmetic
CSE575 CORDIC.16
© MJIrwin, PSU, 2003
Enhanced Cordic Hardware
X
Xi+1
X
= Xi – di Yi 2-i
i counter
Y
Yi+1 = Yi + di Xi
2-i
shift
shift
Y
Zi+1 = Zi - di Ei
Z
Computer Arithmetic
Z
Ei lookup table
(tan-12-i, 2-i, tanh-12-i)
CSE575 CORDIC.17
di control
© MJIrwin, PSU, 2003
Circular Mode ( = 1)
Circular rotation mode
Computes functions
Xn = K(X cos Z - Y sin Z)
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
Yn = 0
Zn = Z + tan-1 (Y/X)
Rule: Choose di {-1,1}
Computer Arithmetic
CSE575 CORDIC.18
Computes function
tan-1 Y
X = 1 and Z = 0
such that Y 0
© MJIrwin, PSU, 2003
Linear Mode ( = 0)
Linear rotation mode
Xn = X
Computes functions
multiply and multiply-add
Yn = Y + X * Z
Y=0
Zn = 0
Rule: Choose di {-1,1} such that Z 0
Linear vector mode
Xn = X
Computes functions
divide and divide-add
Yn = 0
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
hyperbolic sin and cos
Yn = K’(Y cosh Z + X sinh Z)
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’(X2 - Y2)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
X
Y
Z
X
Y
Z
K(X cosZ – Y sinZ)
K(Y cosZ + X sinZ)
0
CORDIC
Ei =
tan-12-i
Vector mode: di= -sign(Xi Yi); Yi0
CORDIC
Ciclr
=1
Rotation mode: di=sign(Zi); Zi0
K (X2 + Y2)
0
Z + tan-1(Y/X)
For cos & sin, set X=1/K, Y=0
For tan-1, set X=1, Z=0
Linear
=0
X
Y
Z
X
Y
Z
Ei = 2-i
For multiply, set Y=0
CORDIC
K’(X coshZ – Y sinhZ)
K’(Y coshZ + X sinhZ)
0
cos-1W=tan-1[(1-W2)/W];sin-1W=tan-1[W/(1-W2)]
X
0
Z + Y/X
CORDIC
Ei =
tanh-1
2-i
CORDIC
Hprblc X
Y
= -1
Z
X
Y + X*Z
0
CORDIC
tanZ=sinZ/cosZ
K’ (X2 - Y2)
0
Z + tanh-1(Y/X)
For divide, set Z=0
For cosh & sinh, set X=1/K’, Y=0
tanhZ=sinhZ/coshZ; Wt=Et lnW
Ez=sinhZ+coshZ
X
Y
Z
For tanh-1, set X=1, Z=0
cosh-1W=ln[W+(1-W2)];sinh-1W=ln[W+(1+W2)]
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