The CORDIC Examples The Division by Convergence Examples June 2007 Computer Arithmetic, Function Evaluation Slide 1 Rotations (cos z, sin z) (1, y) –1 z tan y Key ideas in CORDIC (1, 0) start at (1, 0) rotate by z get cos z, sin z start at (1, y) rotate until y = 0 rotation amount is tan–1y If we have a computationally efficient way of rotating a vector, we can evaluate cos, sin, and tan–1 functions - Rotation by an arbitrary angle is difficult, so we: Perform psuedorotations that require simpler operations Use special angles to synthesize the desired angle z z = a (1) + a (2) + . . . + a (m) June 2007 Computer Arithmetic, Function Evaluation Slide 2 Rotating a Vector (x (i), y (i)) by the Angle a (i) x(i+1) = x(i) cos a(i) – y(i) sin a(i) = (x(i) – y(i) tan a(i)) / (1 + tan2 a(i))1/2 y(i+1) = y(i) cos a(i) + x(i) sin a(i) = (y(i) + x(i) tan a(i)) / (1 + tan2 a(i))1/2 z(i+1) = z(i) – a(i) Recall that cos q = 1 / (1 + tan2 q)1/2 E(i+1) y E(i+1) y (i+1) Rotation Pseudorotation R (i+1) y (i) E(i) a (i) R (i) O x (i+1) June 2007 x (i) Computer Arithmetic, Function Evaluation x Slide 3 Rotating a Vector (x (i), y (i)) by the Angle a (i) x(i+1) = x(i) cos a(i) – y(i) sin a(i) = (x(i) – y(i) tan a(i)) / (1 + tan2 a(i))1/2 y(i+1) = y(i) cos a(i) + x(i) sin a(i) = (y(i) + x(i) tan a(i)) / (1 + tan2 a(i))1/2 z(i+1) = z(i) – a(i) Our strategy: - Eliminate the terms (1 + tan2 a(i))1/2 and - Choose the angles a(i) so that tan a(i) is a power of 2 Then: Need two shift-adds (one for x(i+1) and the other for y(i+1) ) Slide 4 CORDIC Iterations ––––––––––––––––––––––––––––––––––––––––– a(i) in degrees tan a(i) tan a(i) i –––––––––––––––––––––––––––––––-––––––––– 0 45.0 1 20 1 26.6 0.5 2-1 2 14.0 0.25 2-2 3 7.1 0.125 2-3 4 3.6 0.062 5 2-4 5 1.8 0.031 25 2-5 6 0.9 0.015 625 2-6 7 0.4 0.007 812 5 2-7 8 0.2 0.003 906 25 2-8 9 0.1 0.001 953 125 2-9 ––––––––––––––––––––––––––––––––––––––––– x(i+1) = (x(i) – y(i) tan a(i)) / (1 + tan2 a(i))1/2 y(i+1) = (y(i) + x(i) tan a(i)) / (1 + tan2 a(i))1/2 z(i+1) = z(i) – a(i) Computer Arithmetic, Function Evaluation Slide 5 CORDIC Circular Rotation Mode Given: q = 30O Find: cos q Let x(0) = cos0O = 1 x(i+1) = (x(i) – y(i) tan a(i)) / (1 + tan2 a(i))1/2 y(i+1) = (y(i) + x(i) tan a(i)) / (1 + tan2 a(i))1/2 z(i+1) = z(i) – a(i) Start at (1,0) and z = 0o Rotate by z i Until Z q o To Obtain cos q, sin q Computer Arithmetic, Function Evaluation Slide 6 Basic CORDIC Iterations x(i+1) = (x(i) – y(i) tan a(i)) / (1 + tan2 a(i))1/2 y(i+1) = (y(i) + x(i) tan a(i)) / (1 + tan2 a(i))1/2 z(i+1) = z(i) – a(i) x0 = 1, y0 = 0, z0 = 0 Let a0= 45o i.e. Rotate 45o and tana0 = tan45o = 1 Then x1= (x0 – y0 tan a0) / (1 + tan2 a0)1/2 = 1 (1 + tan2 45o)-1/2 =1 k0 y1= (y0 + x0 tan a0) / (1 + tan2 a0)1/2 = 1 (1 + tan2 45o)-1/2 =1 k0 z1 = z0 – a0 = 45o where k0 = (1 + tan2 45o)-1/2 45O Computer Arithmetic, Function Evaluation Slide 7 CORDIC Iterations x1= 1k0 y1= 1k0 z1 = 45o Since 45 > 30 Rotate too much, rotate -26.6O Let a1= -26.6o i.e. Rotate -26.6o and tana1 = tan-26.6O = -1/2 Then x2= (x1 – y1 tan a1) / (1 + tan2 a1)1/2 = (1k0 – 1k0 (-1/2)) / (1 + tan2 a1)1/2 =1.5 k0 k1 y2= (y1 + x1 tan a1) / (1 + tan2 a1)1/2 = (1k0 + 1k0 (-1/2)) / (1 + tan2 a1)1/2 = 0.5 k0 k1 z2 = z1 – a1 = 45o-26.6o = 18.4o +45o-26.6o Basic CORDIC Iterations x2= 1.5k0K1 y2= 0.5k0K1 z2 = 18.4o Since 18.4<30 RotateCCW 14.0 O Let a2= 14.0o i.e. Rotate +14.0o and tana2 = tan14O = 1/4 Then x3= (x2 – y2 tan a2) / (1 + tan2 a2)1/2 = (1.5k0K1 – 0.5k0K1 1/4) / (1 + tan2 a2)1/2 =1.375 k0 k1 K2 y3= (y2 + x2 tan a2) / (1 + tan2 a2)1/2 = (0.5k0K1 + 1.5k0K1 1/4) / (1 + tan2 a1)1/2 = 0.875 k0 k1 K2 z2 = z1 – a1 = 18.4o+14o = 32.4o 1 3 2 +45o-26.6o +14O CORDIC Iterations x2= 1.375k0K1 y2= 0.875k0K1 z2 = 32.4o Since 32.4>30 Rotate CW 7.1 O Let a3= 7.1o i.e. Rotate -7.1o and tana3 = tan-7.1O = -1/8 Then x3= (x2 – y2 tan a2) / (1 + tan2 a2)1/2 = (1.375k0K1 – 0.875k0K1 (-1/8)) / (1 + tan2 a3)1/2 = 1.484375 k0 k1 K2 K3 y3= (y2 + x2 tan a2) / (1 + tan2 a2)1/2 = (0.875k0K1 + 1.3755k0K1 (-1/8)) / (1 + tan2 a3)1/2 = 0.7030625 k0 k1 K2 K3 z3 = z1 – a1 = 32.4o -7.1o = 25.3O CORDIC Iterations k0, k1 , K2 , K3 , and are always the same - No matter CW or CCW the vector is rotated , tan2 ai are always positive. We can calculate k0 k1 K2 K3 in advance and store it for retrieval. In this example, we set z0 = 0O and we rotate it to obtain z m = 30O Conversely, we can set z0 = 30O and we rotate it to obtain z m = 0O CORDIC Linear Vectoring Mode Given: k Find: tan-1 k Let x(0) = 1 y(0) = k x(i+1) = (x(i) – y(i) tan a(i)) / (1 + tan2 a(i))1/2 y(i+1) = (y(i) + x(i) tan a(i)) / (1 + tan2 a(i))1/2 z(i+1) = z(i) – a(i) Start at (1,k ) and z = 0 o Rotate by z i Until y m 0 To Obtain zm = tan-1 k/1 Computer Arithmetic, Function Evaluation Slide 12 CORDIC Linear Vectoring Mode Given: k Find: tan-1 k Start at (1,k ) and z = 0 o Rotate by 45 o, 26.6 o, 14.0 o, … if yk > 0 Rotate -q else Rotate + q And Calculate xk, yk, zk Until y m 0 To Obtain zm = tan-1k Computer Arithmetic, Function Evaluation Slide 13 Formulation for Division as a Convergence Computation Idea: z zx (0 ) x (1) x ( m 1) q (0 ) (1) d dx x x ( m 1) Converges to q Force to 1 d (i+1) = d (i) x (i) Set d (0) = d; make d (m) converge to 1 z (i+1) = z (i) x (i) Set z (0) = z; obtain z/d = q z (m) May 2007 Computer Arithmetic, Division Slide 15 Formulation for Division as a Convergence Computation z zx (0 ) x (1) x ( m 1) q (0 ) (1) d dx x x ( m 1) Question 1: How to select the multipliers x (i) ? Answer: x (i) = 2 – d (i) if d [1/2, 1) Note: d [1/2, 1) d =0.1xxxxxxxxxxx…|binary This choice transforms the recurrence equations into: d (i+1) = d (i) (2 d (i)) z (i+1) = z (i) (2 d (i)) May 2007 Set d (0) = d; iterate until d (m) 1 Set z (0) = z; obtain z/d = q z (m) Computer Arithmetic, Division Slide 16 Example of a Convergence Computation for Division Given: z 18.0 q d 0.7 Z(0) = 18.0 d(0) = 0.7 x (0) = 2 – d (0) = 1.3 z 18*1.3 23.4 q d 0.7 *1.3 0.91 May 2007 Computer Arithmetic, Division Slide 17 Example of a Convergence Computation for Division Given: z 18.0 q d 0.7 Z(1) = 23.4 d(1) = 0.91 x (1) = 2 – d (1) = 1.09 z 18 (1.3) 23.4 23.4 1.09 25.506 q d 0.7 (1.3) 0.91 0.91 1.09 0.9919 May 2007 Computer Arithmetic, Division Slide 18 Example of a Convergence Computation for Division Z(1) = 25.506 d(1) = 0.9919 x (1) = 2 – d (1) = 1.0081 z 18*1.3*1.09 25.506 25.506*1.0081 25.7125986 q d 0.7 *1.3*1.09 0.9919 0.9919*1.0081 0.99993439 25.7142857 May 2007 Computer Arithmetic, Division Slide 19