Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 575 Computer Arithmetic Spring 2003 Mary Jane Irwin (www. cse. psu

Similar presentations


Presentation on theme: "CSE 575 Computer Arithmetic Spring 2003 Mary Jane Irwin (www. cse. psu"— Presentation transcript:

1 CSE 575 Computer Arithmetic Spring 2003 Mary Jane Irwin (www. cse. psu
CSE 575 Computer Arithmetic Spring Mary Jane Irwin (

2 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 COordinate Rotations DIgital Computer Family of algorithms: rotation, vector mode circular rotations linear rotations hyperbolic rotations

3 Real Cordic Rotations If vector OEi is rotated about the origin by an angle i, the new vector OEi+1 will have the coordinates Ei+1 (Xi+1, Yi+1) Ei Ri+1 Real rotation: Ei+1 (Xi, Yi) i Xi+1 = Xi cos i - Yi sin i Yi+1 = Yi cos i + Xi sin i Zi+1 = Zi - i Ri O The problem is that the iterations are not simple operations - have two multiply operations in each = 4 multipliers, plus have to store a lot of constants (cos’s alpha i’s and sin’s of alpha i’s) 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

4 Pseudo Cordic Rotations
Pseudo rotations increase the vector length to Ri+1 = Ri(1 + tan2i)1/2 E’i+1 (Xi+1, Yi+1) Ri+1 Pseudo rotation: E’i+1 Ei (Xi, Yi) Xi+1 = Xi - Yi tan i Yi+1 = Yi + Xi tan i Zi+1 = Zi - i i Ri O Now have simpler operations - at first glance looks like two multipliers and a table with the tan alpha values. The R term simplifies since the expansion factor is a constant for a constant set of angles - that is the real key. So, if we have a constant set of angles, we know the tan alpha values to store (and they are a relatively small set). Additionally, if we choose the alpha’s correctly, we can simplify the multiplications to shift (and add) operations! (a + tan2a(i))1/2 = 1/cos a(i) Hi,    I downloaded your CSE 757 CORDIC PPS-turned-PDF as guided by Google. It helped me understand CORDIC better. However, there is an error on slide 4, the squared term within the expansion faction K should be alpha[i]^2 without calculating any tangent.    Ernesto 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.

5 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

6 Choosing the Angles i i = 2-i Ei=tan-12-i di Zi - diEi = Zi+1
1 30.00 – = -1 = 11.57 2 11.57 – = -2.47 3 = 4.66 4 4.66 – 3.58 = 1.08 5 = -0.71 6 = 0.19 7 = -0.26 8 = -0.04 9 = 0.07 Zi+1  zero

7 Rotating the Angles Illustration of the first three rotations for a Z of 30 30 O (X0, Y0) for class handout

8 Rotating the Angles Illustration of the first three rotations for a Z of 30 30 O (X0, Y0) -45 (X1, Y1) (X2, Y2) +26.6 (X3, Y3) -14 for lecture

9 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 = … 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 = … and Y = 0 For k bits of precision, run it k iterations since for large i > k, tan-12-i  2-i

10 Convergence Domain Convergence of Z to 0 happens because each angle is more than half the previous angle. The domain of convergence is   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 transformations are particularly easy if angles are represented and manipulated in multiples of pi radians E.g., z = 0.2pi radian or 36degrees gives a domain of convergences of -1/2 to +1/2

11 Rotation Example Computing cos 30 (= ) and sin 30 (= ) i di Xi+1  cos Yi+1  sin Zi+1  0 1/K = 1 -1 2 3 4 5 6 7 8 . . .

12 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 = … 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

13 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 1 2 3 4 5 6 7 8 . . . Need to check answers for bugs !!!

14 Circular Cordic Hardware
X shift Xi+1 = Xi – di Yi 2-i i counter shift Yi+1 = Yi – di Xi 2-i Y lookup table stores values of tan-1 2-i Z lookup table Zi+1 = Zi – di Ei values of Ei= tan-12-i di control

15 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

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

17 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

18 Circular Mode ( = 1) Circular vector mode Circular rotation mode
Xn = K(X cos Z - Y sin Z) Yn = K(Y cos Z + X sin Z) 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} such that Y  0 Computes functions cos Z and sin Z X = 1/K and Y = 0 Computes function tan-1 Y X = 1 and Z = 0

19 Linear Mode ( = 0) Linear vector mode Linear rotation mode Xn = X
Yn = Y + X * Z Zn = 0 Rule: Choose di  {-1,1} such that Z  0 Linear vector mode Yn = 0 Zn = Z + Y/X Rule: Choose di  {-1,1} such that Y  0 Computes functions multiply and multiply-add Y = 0 End point of the vector is kept on the line x = x(0) and the vector length is defined by R(i) = x(i) Hence the true length of OV of the scaling factor is 1 (pseudorotations are true linear rotations) Converges trivially for suitably restricted values of z (rotation) or y (vector) Computes functions divide and divide-add Z = 0

20 Hyperbolic Mode ( = -1) Hyperbolic vector mode
Hyperbolic rotation mode Xn = K’(X cosh Z + Y sinh Z) Yn = K’(Y cosh Z + X sinh Z) Zn = 0 Rule: Choose di  {-1,1} such that Z  0 K’ = … Hyperbolic vector mode Xn = K’(X2 - Y2)1/2 Yn = 0 Zn = Z + tanh-1 (Y/X) Rule: Choose di  {-1,1} such that Y  0 Computes functions hyperbolic sin and cos X = 1/K’ and Y = 0 Vector length actually shrinks because cosh a(i) > 1 More difficult convergence guarantee – for details see book section 22.4 By repeating iterations 4, 13, 40, 121, …, j, 3j+1 (K’ has been computed to take these extra iterations into account) then convergence is guaranteed for |z| < 1.13 (rotation) or |y| < 0.81 (vector) Computes functions hyperbolic tanh-1 y X = 1 and Z = 0

21 Cordic Computation Unit
Rotation mode: di=sign(Zi); Zi0 Vector mode: di= -sign(Xi  Yi); Yi0 Ciclr  = 1 Ei = tan-12-i X K(X cosZ – Y sinZ) Y K(Y cosZ + X sinZ) Z For cos & sin, set X=1/K, Y=0 tanZ=sinZ/cosZ X K (X2 + Y2) Y Z Z + tan-1(Y/X) For tan-1, set X=1, Z=0 cos-1W=tan-1[(1-W2)/W];sin-1W=tan-1[W/(1-W2)] Linear  = 0 Ei = 2-i X X Y Y + X*Z For multiply, set Y=0 X X Y Z Z + Y/X For divide, set Z=0 Hprblc  = -1 tanh-1 2-i X K’(X coshZ – Y sinhZ) Y K’(Y coshZ + X sinhZ) For cosh & sinh, set X=1/K’, Y=0 tanhZ=sinhZ/coshZ; Wt=Et lnW Ez=sinhZ+coshZ X K’ (X2 - Y2) Y Z Z + tanh-1(Y/X) 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. CORDIC CORDIC CORDIC CORDIC CORDIC CORDIC

22 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)

23 Key References Duprat and Muller, The CORDIC algorithm: New results for fast VLSI implementation, IEEE Trans. on Computers, 42(2): , 1993. Parhami, Computer Arithmetic, Oxford Univ. Press, 1999. Phatak, Double step branching CORDIC, IEEE Trans. on Computers, 47(5) , May 1998. Vachss, The CORDIC magnification function, IEEE Micro, 7(5):83-83, Oct Volder, The CORDIC trigonometric computing technique, IRE Trans. Elecronic Computers, Vol 8, pp , Sept Walther, A unified algorithm for elementary functions, Proc. Spring Joint Computer Conf, pp , 1971.


Download ppt "CSE 575 Computer Arithmetic Spring 2003 Mary Jane Irwin (www. cse. psu"

Similar presentations


Ads by Google