Platform Developer’s Kit
CORDIC Library
CORDIC Library
www.celoxica.com
Celoxica, the Celoxica logo and Handel-C are trademarks of Celoxica Limited.
All other products or services mentioned herein may be trademarks of their respective owners.
Neither the whole nor any part of the information contained in, or the product described in, this document may be adapted or reproduced in any material form except with the prior written permission of the copyright holder.
The product described in this document is subject to continuous development and improvement. All particulars of the product and its use contained in this document are given by Celoxica Limited in good faith. However, all warranties implied or express, including but not limited to implied warranties of merchantability, or fitness for purpose, are excluded.
This document is intended only to assist the reader in the use of the product. Celoxica Limited shall not be liable for any loss or damage arising from the use of any information in this document, or any incorrect use of the product.
The information contained herein is subject to change without notice and is for general guidance only.
Copyright © 2005 Celoxica Limited. All rights reserved.
Authors: RG
Document number: 1
Customer Support at http://www.celoxica.com/support/
Celoxica in Europe Celoxica in Japan Celoxica in the Americas
T: +44 (0) 1235 863 656 T: +81 (0) 45 331 0218 T: +1 800 570 7004
E: [email protected] E: [email protected] E: [email protected]
CORDIC Library
www.celoxica.com Page 1
Contents
1 CORDIC LIBRARY........................................................................... 4
2 CORDIC CORES ............................................................................. 5
3 PIPELINED CORDIC MACROS .......................................................... 11
4 NON-PIPELINED CORDIC MACROS ................................................... 14
5 NON-PIPELINED TRIGONOMETRIC MACROS........................................... 17
6 INDEX......................................................................................... 25
CORDIC Library
www.celoxica.com
Conventions A number of conventions are used in this document. These conventions are detailed below.
ssage. These messages warn you that actions may damage your Warning Mehardware.
Handy Note. These messages draw your attention to crucial pieces of information.
Hexadecimal numbers will appear throughout this document. The convention used is t fixing the numbhat of pre er with '0x' in common with standard C syntax.
ke this:
italics like this: DestinationFileName
urly brackets around an element show that it is optional but it may be repeated any umber of times.
string ::= "{character}"
Sections of code or commands that you must type are given in typewriter font li void main();
Information about a type of object you must specify is given in copy SourceFileName
Optional elements are enclosed in square brackets like this: struct [type_Name]
Cn
CORDIC Library
www.celoxica.com
Assumptions & Omissions This manual assumes that you:
• have used Handel-C or have the Handel-C Language Reference Manual
• are familiar with common programming terms (e.g. functions)
• are familiar with MS Windows
This manual does not include:
• instruction in VHDL or Verilog
• instruction in the use of place and route tools
• tutorial example programs. These are provided in the Handel-C User Manual
CORDIC Library
www.celoxica.com Page 4
1 CORDIC library The CORDIC algorithm is an iterative algorithm used to evaluate many mathematical functions, such as trigonometric functions, hyperbolic functions and planar rotations. CORDIC uses a sequence successive approximations to reach its results.
The library contains:
• Non-pipelined macro procedures to perform linear, hyperbolic and circular CORDIC.
• Non-pipelined macro procedures to perform trigonometric operations
• Pipelined macros procedures to perform linear, hyperbolic and circular CORDIC.
• CORDIC pipelined "cores" to create linear, hyperbolic and circular CORDIC cores.
To use the library, you need to include cordic.hch in your code and link cordic.hcl. The libraries are in InstallDir/PDK/Hardware/Lib.
• CORDIC cores
• Pipelined CORDIC macros
• Non-pipelined CORDIC macros
• Non-pipelined trigonometric macros
CORDIC Library
www.celoxica.com Page 5
2 CORDIC Cores The following macros are provided in the CORDIC library to create a "core".
extern macro expr CORDICPipeLinRotateCore; extern macro expr CORDICPipeLinVectorCore; extern macro expr CORDICPipeCircRotateCore; extern macro expr CORDICPipeCircVectorCore; extern macro expr CORDICPipeHypRotateCore; extern macro expr CORDICPipeHypVectorCore;
#define PipeCORDICCoreCreateHandle(Name) extern macro proc CORDICPipeCoreRun (CORDICHandle, Type); extern macro proc CORDICPipeCoreEnable (CORDICHandle); extern macro proc CORDICPipeCoreSet (CORDICHandle, Xin, YIn, ZIn, d_w); extern macro proc CORDICPipeCoreGet (CORDICHandle, XOut, YOut, ZOut, d_w);
2.1 CORDIC Cores types
The following pipelined CORDIC macros are provided in the Celoxica CORDIC Library:
• Pipelined Linear rotation
• Pipelined Linear vectoring
• Pipelined Circular rotation
• Pipelined Circular vectoring
• Pipelined Hyperbolic rotation
• Pipelined Hyperbolic vectoring
extern macro expr CORDICPipeLinRotateCore; extern macro expr CORDICPipeLinVectorCore; extern macro expr CORDICPipeCircRotateCore; extern macro expr CORDICPipeCircVectorCore; extern macro expr CORDICPipeHypRotateCore; extern macro expr CORDICPipeHypVectorCore;
CORDIC Library
www.celoxica.com Page 6
Arguments: None
Timing: Compile time
Description: Identifier for the type of operation selected as a core. Used as a parameter to CORDICPipeCoreRun.
Example:
CORDICPipeCoreRun (MyCircRotate, CORDICPipeLinRotateCore);
2.2 PipeCORDICCoreCreateHandle() #define PipeCORDICCoreCreateHandle(Name)
Arguments: Name:
Description: Creates a handle for a core operation to be created. The name should be intuitive of the type of operation to be created. Note that no space must exist between the name and the bracket encapsulating the name.
Example:
#define PipeCORDICCoreCreateHandle(MyCordicRotate)
CORDIC Library
www.celoxica.com Page 7
2.3 CORDICPipeCoreRun () extern macro proc CORDICPipeCoreRun (CORDICHandle, Type);
Arguments: CORDICHandle: Handle created
Type: Identifier of type of operation selected from the available core types.
Timing: Does not terminate
Description: Runs the selected operation. This is a never ending process and interacting code should be run in parallel.
Example:
.... PipeCORDICCoreCreateHandle(MyCircRotate); par { CordicPipeCoreRun (MyCircRotate, CORDICPipeLinRotateCore); seq { ...... } }
CORDIC Library
www.celoxica.com Page 8
2.4 CORDICPipeCoreEnable() extern macro proc CORDICPipeCoreEnable (CORDICHandlePtr);
Arguments: CORDICHandlePtr: Pointer to handle created
Timing: one clock cycle
Description: Enables the core
Example:
... PipeCORDICCoreCreateHandle(MyCircRotate); par { CordicPipeCoreRun (MyCircRotate, PipeCORDICCircRotateCore); seq { CORDICPipeCoreEnable(&MyCircRotate); ... } }
CORDIC Library
www.celoxica.com Page 9
2.5 CORDICPipeCoreSet () extern macro proc CORDICPipeCoreSet (CORDICHandle, Xin, YIn, ZIn, d_w);
Arguments: CORDICHandle: Handle created
XIn: Cordic input
YIn: Cordic input
ZIn: Cordic input
d_w: data-width
Description: Sets the input parameters for the operation. This must be done in parallel with the CordicPipeCoreRun macro.
Example:
.... PipeCORDICCoreCreateHandle(MyRotator); par { CordicPipeCoreRun (MyRotator, CORDICPipeLinRotateCore); seq { CORDICPipeCoreEnable(&MyRotator); CORDICPipeCoreSet(&MyRotator, x, y, z, width(x)); .... } }
CORDIC Library
www.celoxica.com Page 10
2.6 CORDICPipeCoreGet() extern macro proc CORDICPipeCoreGet (CORDICHandle, XOut, YOut, ZOut, d_w);
Arguments: CORDICHandle: Handle created
XOut: Cordic output
YOut: Cordic output
ZOut: Cordic output
d_w: data_width
Description: Gets the results from the pipeline, once the date is valid.
Example:
.... PipeCORDICCoreCreateHandle(MyRotator); par { CordicPipeCoreRun (MyRotator, CORDICPipeLinRotateCore); seq { CORDICPipeCoreEnable(&MyRotator); CORDICPipeCoreSet(&MyRotator, x, y, z, width(x)); while (!CORDICPipeCoreResult (&MyRotator)) { delay; } CORDICPipeCoreGet(&MyRotator,xout, yout, zout, width(x)); } }
CORDIC Library
www.celoxica.com Page 11
3 Pipelined CORDIC macros The following pipelined CORDIC macros are provided in the Celoxica CORDIC Library:
Inputs most be fixed point numbers, with a even number of bits. The integer and fractional parts must be equally sized and less than 64-bits.
• Linear rotation
• Linear vectoring
• Circular rotation
• Circular vectoring
• Hyperbolic rotation
• Hyperbolic vectoring
extern macro proc PipeLinRotate (pipe_cordic_data, d_w); extern macro proc PipeLinVector (pipe_cordic_data, d_w); extern macro proc PipeCircRotate (pipe_cordic_data, d_w); extern macro proc PipeCircVector (pipe_cordic_data, d_w); extern macro proc PipeHypRotate (pipe_cordic_data, d_w); extern macro proc PipeHypVector (pipe_cordic_data, d_w);
CORDIC Library
www.celoxica.com Page 12
Arguments: pipe_cordic_data:
Structure containing cordic data:
pipe_cordic_data.XIn;
pipe_cordic_data.YIn;
pipe_cordic_data.ZIn;
pipe_cordic_data.XOut;
pipe_cordic_data.YOut;
pipe_cordic_data.ZOut;
pipe_cordic_data.XPtr;
pipe_cordic_data.YPtr;
pipe_cordic_data.ZPtr;
d_w:
data-width
Description: Vectoring and Rotational mode Linear, Hyperbolic and Circular pipelined CORDIC.
Example:
pipe_cordic_data MyData; signed 16 x; signed 16 y; signed 16 z; ... MyData.XIn = x; MyData.YIn = y; MyData.ZIn = z; ... while(1) { PipeCircRotate (MyData, width(x)); } ...
Macro: Description:
PipeCircRotate() Pipelined circular rotation
CORDIC Library
www.celoxica.com Page 13
PipeCircVector() Pipelined circular vectoring
PipeLinRotate() Pipelined linear rotation
PipeLinVector() Pipelined linear vectoring
PipeHypRotate() Pipelined hyperbolic rotation
PipeHypVector() Pipelined hyperbolic vectoring
CORDIC Library
www.celoxica.com Page 14
4 Non-pipelined CORDIC macros The following non-pipelined CORDIC macros are provided in the Celoxica CORDIC Library.
Inputs must be fixed point numbers, with a even number of bits. The integer and fractional parts must be equally sized and less than 64-bits.
• Linear rotation
• Linear vectoring
• Circular rotation
• Circular vectoring
• Hyperbolic rotation
• Hyperbolic vectoring
extern macro proc LinRotate (cordic_data, d_w); extern macro proc LinVector (cordic_data, d_w); extern macro proc CircRotate (cordic_data, d_w); extern macro proc CircVector (cordic_data, d_w); extern macro proc HypRotate (cordic_data, d_w); extern macro proc HypVector (cordic_data, d_w);
CORDIC Library
www.celoxica.com Page 15
Arguments: cordic_data:
Structure containing cordic data:
cordic_data.XIn;
cordic_data.YIn;
cordic_data.ZIn;
cordic_data.XOut;
cordic_data.YOut;
cordic_data.ZOut;
d_w
The data-width
Description: Vectoring and Rotational mode Linear, Hyperbolic and Circular CORDIC.
Example:
#include "cordic.hch" #include "stdlib.hch" cordic_data MyData; static signed 16 x = 0x200; static signed 16 y =0x0; static signed 16 z = 0x80; ... MyData.XIn = x; MyData.YIn = y; MyData.ZIn = z; LinRotate(MyData, width(x)); ....
Macro: Description:
CircRotate() Circular rotation
CircVector() Circular vectoring
LinRotate() Linear rotation
CORDIC Library
www.celoxica.com Page 16
LinVector() Linear vectoring
HypRotate() Hyperbolic rotation
HypVector() Hyperbolic vecotring
CORDIC Library
www.celoxica.com Page 17
5 Non-pipelined trigonometric macros The following non-pipelined trigonometric macros are provided in the Celoxica CORDIC Library:
The trigonometric library inputs most be fixed point numbers, with a even number of bits. The integer and fractional parts must be equally sized.
• Sine
• Cosine
• Sine and Cosine simultaneously
• Tangent
• Inverse Sine
• Inverse Cosine
• Inverse Tangent
• Multiply
• Divide
• Hyperbolic Sine
• Hyperbolic Cosine
• Hyperbolic Sine and Hyperbolic Cosine simultaneously
• Hyperbolic Tangent
• Hyperbolic Inverse Sine
• Hyperbolic Inverse Cosine
• Hyperbolic Inverse Tangent
• Natural Log
• Exponent
• Magnitude
• Cartesian to polar form
CORDIC Library
www.celoxica.com Page 18
5.1 Non-pipelined Natural Log extern macro proc NaturalLog(Input, Ln, d_w);
Arguments: Input: Fixed-point input
Ln: Fixed-point output
d_w: data-width
Description: Computes the natural log of the input
Example:
signed int 64 Input; signed int 64 Ln; .... NaturalLog(Input, Ln, width(Input));
5.2 Non-pipelined Exponent extern macro proc Exponent (Input, Exp, d_w);
Arguments: Input: Fixed-point input
Exp: Fixed-point input
d_w: data-width
Description: Computes the exponent of the input.
Example:
signed int 64 Input; signed int 64 Exp; .... Exponent (Input, Exp, width(Input));
5.3 Non-pipelined Magnitude extern macro proc Magnitude (X, Y, Result, d_w);
Arguments: X: Fixed-point input
Y: Fixed-point input
CORDIC Library
www.celoxica.com Page 19
Result: Fixed-point output
d_w: data_width
Description: Computes magnitude of x and y-
sqrt (x^2 + y^2).
Example:
signed int 64 X; signed int 64 Y; signed int 64 Result; .... Magnitude (X, Y, Result, width(X));
5.4 Non-pipelined Cartesian to polar conversion extern macro proc CartesianToPolar (X, Y, Magnitude, Phase, d_w);
Arguments: X: Fixed-point input
Y: Fixed-point input
Magnitude: Fixed-point output
Phase: Fixed-point output
d_w: data_width
Description: Converts Cartesian co-ordinates (X, Y) to polar form (Magnitude,Phase)
Example:
signed int 16 X; signed int 16 Y; signed int 16 Magnitude; signed int 16 Phase; ... CartesianToPolar (X, Y, Magnitude, Phase, width(X) );
CORDIC Library
www.celoxica.com Page 20
5.5 Non-pipelined inverse hyperbolic Sine, Cosine and Tangent
extern macro proc HypArcsine (Sinh, Angle, d_w); extern macro proc HypArccosine (Cosh, Angle, d_w); extern macro proc HypArctan (Tanh, Angle, d_w);
Arguments: Angle: Fixed-point input
Sinh: Fixed-point output
Cosh: Fixed-point output
Tanh: Fixed-point output
d_w: data-width
Description: Calculates the inverse hyperbolic Sine, Tangent or Cosine.
Example:
signed int 64 Angle; signed int 64 Cosh; signed int 64 Sinh; Sinh = 0x80000000; HypArcsine (Sinh, Angle, width(Sinh));
Macro: Description:
HypArcsine() Calculate the hyperbolic Sine of the input angle.
HypArccosine() Calculate the hyperbolic Cosine of the input angle.
HypArctan() Calculate the hyperbolic Tangent of the input angle.
5.6 Non-pipelined hyperbolic Sine, Cosine and Tangent
extern macro proc HypSine (Sinh, Angle, d_w); extern macro proc HypCosine (Cosh, Angle, d_w); extern macro proc HypSineCosine (Cosh, Sinh, Angle, d_w); extern macro proc HypTangent (Tanh, Angle, d_w);
CORDIC Library
www.celoxica.com Page 21
Arguments: Angle: Fixed-point input
Sinh: Fixed-point output
Cosh: Fixed-point output
Tanh: Fixed-point output
d_w: data-width
Description: Calculates the hyperbolic Sine, Tangent or Cosine of the input Angle. HypSineCosine calculates hyperbolic Sine and Cosine simultaneously.
Example:
signed int 64 Angle; signed int 64 Cosh; signed int 64 Sinh; Angle = 0x80000000; HypSineCosine (Cosh, Sinh, Angle, width(Angle));
Macro: Description:
HypSine() Calculate the hyperbolic Sine of the input angle.
HypCosine() Calculate the hyperbolic Cosine of the input angle.
HypTangent() Calculate the hyperbolic Tangent of the input angle.
HypSineCosine() Calculate the hyperbolic Sine and Cosine of the input angle simultaneously.
5.7 Non-pipelined inverse Sine, Cosine and Tangent
extern macro proc Arcsine (Sin, Angle, d_w); extern macro proc Arccosine (Cos, Angle, d_w); extern macro proc Arctan (Tan, Angle, d_w);
Arguments: Angle: Fixed-point output
Sin: Fixed-point input
Cos: Fixed-point input
CORDIC Library
www.celoxica.com Page 22
Tan: Fixed-point input
d_w: data_width
Description: Calculates the Inverse Sine, Tangent or Cosine of the fixed-point input.
Example:
signed int 64 Angle; signed int 64 Sin; Sin = 0x80000000; ArcSine (Sin, Angle, width(Sin));
Macro: Description:
Arcsine() Calculate the Arcsine of the input.
Arccosine() Calculate the Arccosine of the input.
Arctan() Calculate the Arctan of the input.
5.8 Non-pipelined Sine, Cosine and Tangent extern macro proc Sine (Sin, Angle, d_w); extern macro proc Cosine (Cos, Angle, d_w); extern macro proc SineCosine (Cos, Sin, Angle, d_w); extern macro proc Tangent (Tan, Angle, d_w);
Arguments: Angle: Fixed-point input
Sin: Fixed-point output
Cos: Fixed-point output
Tan: Fixed-point output
CORDIC Library
www.celoxica.com Page 23
d_w: data-width
Description: Calculates the Sine, Tangent or Cosine of the fixed point input Angle. SineCosine calculates Sine and Cosine simultaneously.
Example:
signed int 64 Angle; signed int 64 Cos; signed int 64 Sin; Angle = 0x2D00000000; SineCosine (Cos, Sin, Angle, width(Angle));
Macro: Description:
Sine() Calculate the Sine of the input angle.
Cosine() Calculate the Cosine of the input angle.
Tangent() Calculate the Tangent of the input angle.
SineCosine() Calculate the Sine and Cosine of the input angle simultaneously.
5.9 Non-pipelined CORDIC multiply and divide extern macro proc Multiply (A, B, Result, d_w); extern macro proc Divide (A, B, Result, d_w);
Arguments: A: Fixed-point input
B: Fixed-point input
Result: Fixed-point output
d_w: data_width
CORDIC Library
www.celoxica.com Page 24
Description: CORDIC fixed-point divide and multiply macro.
Example:
signed int 64 A; signed int 64 B; signed int 64 Result; par { A = 0x80000000; B = 0x80000000; } Multiply (A, B, Result, width(A));
Macro: Description:
Multiply() Calculate A * B.
Divide() Calculate B / A.
CORDIC Library
www.celoxica.com Page 25
6 Index C
CORDIC ...........................................4
CORDIC Cores 5
non-pipelined CORDIC macros 14
Non-pipelined trigonometric CORDIC macros 17
Pipelined CORDIC macros 11