ECEn 621 Computer Arithmetic CORDIC History

advertisement
ECEn 621
Computer Arithmetic
Chapter 11: CORDIC Algorithms
Winter 2006
Slide #1
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
CORDIC History
●
●
●
●
●
Coordinate Rotation Digital Computer
Invented in late 1950’s
Based on the observation that:
▪ if you rotate a unit-length vector (1,0)
▪ by an angle z
▪ its new end-point will be at (cos z, sin z)
Can evaluate virtually all functions of interest
k iterations required for k-bits accuracy
Winter 2006
Slide #2
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
1959
Winter 2006
Slide #3
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
1971
Winter 2006
Slide #4
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
HP Journal 1977
HP-35 The first
scientific calculator
1972-1975
Winter 2006
Slide #5
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Perfect Rotations
z R = eiθ zin
⎡ xR ⎤ ⎡cos θ − sin θ ⎤ ⎡ xin ⎤
⎢ y ⎥ = ⎢ sin θ cos θ ⎥ ⎢ y ⎥
⎣ R ⎦ ⎣1442443⎦ ⎣ in ⎦
zR
Rotate by angle θ
zin
Winter 2006
Slide #6
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Micro-Rotations
Decompose the angle into a sum of elementary angles
n −1
θ = ∑ αi
i =0
Decompose the rotation into a product of elementary rotations
z R = eiαn −1 L eiα 2 eiα1 eiα0 zin
⎡ xR ⎤ ⎡cos α n −1 − sin α n −1 ⎤ ⎡cos α1 − sin α1 ⎤ ⎡cos α 0 − sin α 0 ⎤ ⎡ xin ⎤
L
⎢ y ⎥ = ⎢ sin α
cos α n −1 ⎥⎦ ⎢⎣ sin α1 cos α1 ⎥⎦ ⎢⎣ sin α 0 cos α 0 ⎥⎦ ⎢⎣ yin ⎥⎦
n −1
⎣ R ⎦ ⎣144
42444
3 144
424443 144
42444
3
Rotate by angle α1
angle αn- 1
angle α0
14Rotate
44by4
4444444
2444444Rotate
44by4
443
Rotate by angle θ
Winter 2006
Slide #7
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Simplifying the Rotations
1. Decompose the rotation into a
scaling operation, and a
pseudo-rotation
− tan α j ⎤ ⎡ xin ⎤
⎡ 1
⎡ xR ⎤ ⎡cos α j − sin α j ⎤ ⎡ xin ⎤
cos
α
=
⋅
=
j
⎢
⎢
⎥
⎢y ⎥
α j cos α j ⎦ ⎢⎣ yin ⎥⎦ 123 ⎣ tan α j
1 ⎥⎦ ⎢⎣ yin ⎥⎦
⎣ R⎦ 1
⎣ sin
Scale
44
42444
3
144
42444
3
Rotate by angle α j
Winter 2006
Slide #8
Pseudo- rotate by angle α j
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Pseudo-Rotations
Rotation by
⎡ 1
⎡x ⎤
− tan α ⎤ ⎡ x ⎤
j
in
αj : ⎢ R ⎥ = cos α j ⎢
⎥
⎢
23 ⎣ tan α j
1 ⎦ ⎣ yin ⎥⎦
⎣ y R ⎦ 1Scale
144
42444
3
Pseudo- rotate by angle α j
Pseudo Rotation by
(xPR, yPR)
y
− tan α j ⎤ ⎡ xin ⎤
⎡ xPR ⎤
1 ⎡ xR ⎤ ⎡ 1
=
=
⎥ cos α ⎢ y ⎥ ⎢ tan α
1 ⎥⎦ ⎢⎣ yin ⎥⎦
j
⎣ y PR ⎦ 1
⎣ 44
23j ⎣ R ⎦ 1
4
2444
3
αj : ⎢
Scale
Vector Scaling Constant
(xR, yR)
αj
Winter 2006
Slide #9
Pseudo- rotate by angle α j
(xin, yin)
⎡x ⎤
⎡x ⎤
1
len ⎢ PR ⎥ =
len ⎢ in ⎥
cos α j ⎣ yin ⎦
⎣ y PR ⎦ 1
23
x
Kj =
Kj
1
= 1 + tan 2 α j
cos α j
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Pseudo-Rotations of a Vector
Winter 2006
Slide #10
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Simplifying the Rotations
2. Carefully choose elementary angles ±α such that:
α 0 = σ 0 ⋅ arctan (20 ) where σ 0 = ±1
α1 = σ 1 ⋅ arctan (2 −1 ) where σ 1 = ±1
tan (α 0 ) = σ 0 20
tan (α1 ) = σ 1 2 −1
M
tan (α j ) = σ j 2
M
α j = σ j ⋅ arctan (2
−j
αj
j
−j
)
M
where σ j = ±1
tan α j = 2 − j
0 ± 45.0 ± 1.000
1 ± 26.6 ± 0.500
2 ± 14.0 ± 0.250
3 ± 7.1 ± 0.125
4 ± 3.6 ± 0.0625
Winter 2006
Slide #11
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Simplification by Choosing Elementary Angles
tan (α j ) = σ j 2 − j
α j = σ j ⋅ arctan (2 − j )
where σ j = ±1
− tan α j ⎤ ⎡ x j ⎤
⎡ x j +1 ⎤ ⎡ 1
⎢ y ⎥ = ⎢ tan α
1 ⎥⎦ ⎢⎣ y j ⎥⎦
j
⎣ j +1 ⎦ ⎣144
42444
3
Pseudo- rotate by angle α j
θ j +1 = θ j − α j
Stored in a constant table
K j +1 = K j 1 + tan α j
2
Winter 2006
Slide #12
− σ j 2− j ⎤ ⎡ x j ⎤
⎡ x j +1 ⎤ ⎡ 1
=
⎥⎢ ⎥
⎢y ⎥ ⎢
−j
1 ⎦⎣ y j ⎦
⎣ j +1 ⎦ ⎣σ j 2
arctan (2 − j )
θ j +1 = θ j − σ j ⋅1
42
4 43
4
K j +1 = K j 1 + 2 −2 j
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Computing the Expansion Factor K
∞
K = ∏ 1 + tan 2 α j
j =0
If α j = ± arctan (2 − j ) then
∞
K = ∏ 1 + 2 −2 j ≈ 1.6468
j =0
●
●
●
By product of pseudo-rotations
Depends on the rotation angles.
However, if we always uses the same rotation angles (with
positive and negative signs), then
▪ K is a constant
▪ Can be precomputed and stored
▪ Its reciprocal can also be computed and stored
Winter 2006
Slide #13
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
CORDIC Recurrence Equations (Pseudo-rotations)
Vector Recurrences
⎡ x j +1 ⎤ ⎡ 1
⎢y ⎥ = ⎢
−j
⎣ j +1 ⎦ ⎣σ j 2
− σ j 2− j ⎤ ⎡ x j ⎤
⎥⎢ ⎥
1 ⎦⎣ y j ⎦
θ j +1 = θ j − σ j ⋅ arctan (2 − j )
142
4 43
4
Stored in a constant table
Scalar Recurrences
x j +1 = x j − σ j 2 − j y j
y j +1 = y j + σ j 2 − j x j
θ j +1 = θ j − σ j ⋅ arctan (2 − j )
142
4 43
4
Stored in a constant table
Winter 2006
Slide #14
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Building the Basic CORDIC Iteration
−
−
●
●
Each CORDIC rotation requires:
▪ 2 shifts by j
▪ 1 table lookup
▪ 3 additions/subtractions
By rotating by the same set of angles (with + or − signs) , the expansion factor
K can be precomputed
Winter 2006
Slide #15
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
CORDIC Has Two Two Modes
●
●
Inputs are X, Y, and θ
Rotation Mode
σ j = sign(θ j )
xn = K ( X cos θ − Y sin θ )
yn = K ( X sin θ + Y cos θ )
n −1
zn = θ − ∑ σ j ⋅ arctan( 2 − j ) = 0
14243
j =0
αj
●
Vector Mode
σ j = − sign( y j )
xn = K X 2 + Y 2
yn = 0
⎛Y ⎞
zn = θ + arctan ⎜ ⎟
⎝X⎠
Winter 2006
Slide #16
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Running the CORDIC Recurrences in Rotation Mode
CORDIC Recurrences
Initialization
σ j = sign(θ j )
x0 = X
y0 = Y
x j +1 = x j − σ j 2 − j y j
z0 = θ
y j +1 = y j + σ j 2 − j x j
After All Pseudo-Rotations
xn = K ( X cos θ − Y sin θ )
z j +1 = z j − σ j ⋅ arctan (2 − j )
142
4 43
4
Stored in a constant table
Constant Scaling Factor
yn = K ( X sin θ + Y cos θ )
∞
n −1
zn = θ − ∑ σ j ⋅ arctan( 2 − j ) = 0
14243
j =0
K = ∏ 1 + 2 −2 j ≈ 1.6468
αj
Winter 2006
Slide #17
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Example
Winter 2006
Slide #18
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
j =0
Constant, and
independent of the
angle for σ = ±1
Trig Function Computation
●
●
●
Initialize:
▪ z0 = θ
▪ x0 = 1/K = 0.607 252 935 ….
▪ y0 = 0
Iterate with σi = sign( zi )
Finally (after n steps):
▪ zn ≈ 0
▪ xn ≈ cos(θ )
▪ yn ≈ sin(θ )
▪ yn/xn ≈ tan(θ )
Winter 2006
Slide #19
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Precision in CORDIC
●
●
●
●
●
For n bits of precision in trig functions,
n iterations are needed.
For large i > n/2, tan(2−i) ≈ 2−i (Angle in radians)
For i > n , change in z < ulp
Convergence is guaranteed for angles in
range −99.7 ≤ θ ≤ 99.7
▪ (99.7 is sum of all angles in the table)
For angles outside this range, use standard trig identities to
convert angle to one in the range (range reduction)
Proofs are omitted here, but they are in the book.
Winter 2006
Slide #20
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Compensation for Scale Factor K
Winter 2006
Slide #24
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
CORDIC Implementation
Winter 2006
Slide #25
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Pipelined CORDIC Implementation
Winter 2006
Slide #26
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Running the CORDIC Recurrences in Vector Mode
CORDIC Recurrences
Initialization
σ j = − sign( y j )
x0 = X
y0 = Y
x j +1 = x j − σ j 2 − j y j
z0 = θ
y j +1 = y j + σ j 2 − j x j
After All Pseudo-Rotations
xn = K X 2 + Y 2
yn = 0
Stored in a constant table
Constant Scaling Factor
∞
⎛Y ⎞
zn = θ + arctan ⎜ ⎟
⎝X⎠
Winter 2006
Slide #27
z j +1 = z j − σ j ⋅ arctan (2 − j )
142
4 43
4
K = ∏ 1 + 2 −2 j ≈ 1.6468
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
j =0
Constant, and
independent of the
angle for σ = ±1
Example
Winter 2006
Slide #28
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Trig Function Computation
●
●
●
Initialize:
▪ z0 = 0
▪ x0 = 1
▪ y0 = Y
Iterate with di = −sign( xi yi ) = −sign( yi )
Finally (after n steps):
▪ zn ≈ arctan(Y)
▪ Use identity:
to limit range of fixed-point numbers
⎛1⎞ π
arctan ⎜ ⎟ = − arctan (Y )
⎝Y ⎠ 2
Winter 2006
Slide #29
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Unified CORDIC Algorithms
Winter 2006
Slide #30
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Extension to Hyperbolic Functions
Winter 2006
Slide #31
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Pseudo-Rotation in Hyperbolic Coordinate System
Winter 2006
Slide #32
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Convergence Problem with Hyperbolic Rotations
Winter 2006
Slide #33
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Final Values for Hyperbolic CORDIC
Winter 2006
Slide #34
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Rotating in Linear Coordinates
Winter 2006
Slide #35
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Unified CORDIC Description
Winter 2006
Slide #36
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Unified CORDIC Summary Table
Winter 2006
Slide #37
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Functions Computed Directly with CORDIC
Directly computes :
sin
cos
−1
tan
sinh
cosh
tanh
×
÷
Also directly computes :
tan −1 ( y x)
y + xz
z+ y x
x2 + y2
x2 − y2
−1
e z = sinh z + cosh z
Winter 2006
Slide #38
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Functions Computed Indirectly with CORDIC
sin z
cos z
sinh z
tanh z =
cosh z
cos −1 w = tan −1
tan z =
sin −1 w = tan −1
w −1
w +1
logb w = C × ln w
ln w = 2 tanh −1
w =e
t
t ln w
Winter 2006
Slide #39
(
= ln (w +
1 − w2
w
w
1 − w2
)
1+ w )
cosh −1 = ln w + 1 − w2
sinh −1
2
w = ( w + 1 4) 2 − ( w − 1 4) 2
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Some Additional Functions
Winter 2006
Slide #40
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Variations in CORDIC Implementations
Winter 2006
Slide #41
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Bit-Serial CORDIC
●
For low cost, low speed, low power applications
(like hand held calculators) bit-serial implementations of
CORDIC are possible.
Winter 2006
Slide #42
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
High Speed CORDIC
●
Do first k/2 iterations as normal.
▪ z becomes very small for j > k/2
●
Combine remaining k/2 iterations into one step using
multiplication.
●
K doesn’t change.
Winter 2006
Slide #43
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
CORDIC with Redundant (Carry-Save) Numbers
Winter 2006
Slide #44
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Double Rotation Approach
Winter 2006
Slide #45
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Recurrences for Double Rotation
Winter 2006
Slide #46
ECEn 621 Computer Arithmetic
Dr. Doran Wilde
Download