IQ-Math Virtual Floating-Point Engine Introduction & Application - 2nd Year Technical Competence -
06/23/2011 Advanced Motion Control Team
Copyright ⓒ 2011 Ajinextek Co., Ltd.
2011/06/23, Advanced Motion Control Team
1
Introduction
1. Introduction 2. IQ-Math vs. Floating Math and Fixed Math (ANSI C) 3. Implementation 4. Summary
Copyright ⓒ 2011 by Ajinextek Co., Ltd., All rights reserved.
2011/06/23, Advanced Motion Control Team
Copyright ⓒ 2011 by Ajinextek Co., Ltd., All rights reserved.
2011/06/23, Advanced Motion Control Team
3
1. IQMath Introduction Floating implementation in embedded application
Takes many days/weeks to convert (one way process) Fixed-Point Algorithm (ASM, C, C++)
Fixed-Point DSP
Copyright ⓒ 2011 Ajinextek Co., Ltd.
Simulation Platform (i.e. MatLab)
Floating-Point Algorithm (C or C++)
Natural development starts with simulation in floating-point
Can be easily ported to floating-point device
Floating-Point DSP
2011/06/23, Advanced Motion Control Team
4
1. IQMath Introduction
Floating-point Processor
Fixed-point Processor
- Hardware core unit floating point operation which follows IEEE 75 4 standard e.g: Intal’s Pentium Series, TI TMS32 0C6000, …
- Internal hardware integer da ta e.g: all microcontroller families (Motor ola HC68x, Infineon C166, …), TI TM S 430, TMS320C5000, C2000, …
- Efficient when operation with floating - Arithmetic unit and hardware multiply -point data unit (DSP) expect data to be in one of fixed-point type - Not efficient in control task (bit manip ulation, input/output control, interrupt r - Inexpensive esponse) - Expensive
Copyright ⓒ 2011 Ajinextek Co., Ltd.
2011/06/23, Advanced Motion Control Team
5
1. IQMath Introduction Fixed-Point format (Q Math) - A value of a fixed-point data type is essentially an integer that is scaled by a specific factor determined by the type. - The scaling factor is the same for all values of the same type, and does not change during the entire computation. - The scaling factor: 10^x, 2^x, 1/3600, …. - Notation: Qf : f is number of fraction digits Qm.f : m is number of integer digits Precision loss and overflow (e.g. multiplying (x) and dividing())
Floating-Point format - Describes a system for representing real numbers which s a wide range of values - Numbers are in general represented approximately to a fixed number of significant digits and scaled using an exponent - The base for the scaling is normally 2, 10 or 16 Significant digits × base exponent -The most common used format is IEEE standard 754 (discuss later) More storage to encode the position of the radix but larger precision
IQ-Math format IQxxx() or IQNxxx(): virtual floating-point engine + Based on lookup tables available in BOOTROM of F281x devices + Variable range and resolution (present later) + Achieve higher speed and precision, shorten DSP application development time when porting floating point algorithm into fixed point code Copyright ⓒ 2011 Ajinextek Co., Ltd.
2011/06/23, Advanced Motion Control Team
6
1. IQMath Introduction
The TI IQmath library offers usage in C/P program and it consists of 5 parts: 1) IQmath header file: IQmathLib.h 2) IQmath object library containing all function & look-up tables IQmath.lib 3) Linker Command File IQmath.cmd 4) IQmath GEL file for debugging IQmath.gel 5) Example programs
Copyright ⓒ 2011 Ajinextek Co., Ltd.
2011/06/23, Advanced Motion Control Team
7
Copyright ⓒ 2011 by Ajinextek Co., Ltd., All rights reserved.
2011/06/23, Advanced Motion Control Team
8
2.1 IQMath vs. Floating Math
IEEE Standard 754 Single Precision Floating Format 31 30
23 22
0
s eeeeeeee fffffffffffffffffffffff
1 bit sign
8 bit exponent
23 bit mantissa (fraction)
Z 1 .M .2 S
E Offset
23
M 1 fi 2 i i 1
“IQ” – Format (or Fractional Format) “I” INTEGER – Fraction “Q” QUOTIENT – Fraction
Z = -2I + 2I-1 + … + 21 + 20 . 2-1 + 2-2 + … + 2-Q Advantage
Disadvantage
Floating Math
Large dynamic range
Precision depends on exponent term
IQ Math
Same precision for same IQ format
Limited dynamic range
Copyright ⓒ 2011 Ajinextek Co., Ltd.
2011/06/23, Advanced Motion Control Team
9
2.1 IQMath vs. Floating Math Limitation of single precision floating format Example: +
x = 10.0 y = 0.000000238
(0x41200000) (0x347F8CF1)
z = 10.000000238 0x412000000
=
0x412000001
=
10.000000000 10.000000238 can’t represent! 10.000000950
The gap between two identified numbers in single floating-point format is about ten million times smaller than the numbers
Improve by IQ-math format I8Q24 Example:
x = 10.0 y = 0.000000238
(0x0A000000) (0x00000004)
z = 10.000000238
(0x0A000004)
Copyright ⓒ 2011 Ajinextek Co., Ltd.
2011/06/23, Advanced Motion Control Team
10
2.2 IQMath vs. Fixed-Point Math (QMath) Execute floating-point data or implement floating point algorithm on a fixed-point processor:
Y M *X B
ANSI C I16
.
Q48
x
ssssssssssssssssssI8 . Q24
<< 24
+
ssssI8
I16
.
.
>> 24
I16 I8 . Q24
I8 . Q24
.
Q48
X
>> 24
B
x
I8 . Q24
M
I8 . Q24
X
I8 . Q24
B
I8 . Q24
Y
Align Decimal Point Of Multiply
sssssssssssssssssI16 . Q24
Q48
+
Q48 I8
Align Decimal Point for Store I8 . Q24
Y = ((i64) M * (i64) X + (i64) B << Q) >> Q;
Copyright ⓒ 2011 Ajinextek Co., Ltd.
IQ-Math
M
Align Decimal Point for Add
sssssssssssssssssI16 . Q24
in C:
I8 . Q24
.
Q24
Y
in C:
Y = ((i64) M * (i64) X) >> Q + B; 2011/06/23, Advanced Motion Control Team
11
2.3 Programming Scope Comparison of floating format implementation
float
Y, M, X, B;
Floating-Point
Y = M * X + B; Traditional Fix-Point Q
“IQmath” In C
“IQmath” In C++
Copyright ⓒ 2011 Ajinextek Co., Ltd.
long Y, M, X, B; Y = ((i64) M * (i64) X + (i64) B << Q)) >> Q; _iq
Y, M, X, B;
Y = _IQmpy(M, X) + B;
iq
Y, M, X, B;
Y = M * X + B;
2011/06/23, Advanced Motion Control Team
12
Copyright ⓒ 2011 by Ajinextek Co., Ltd., All rights reserved.
2011/06/23, Advanced Motion Control Team
13
3. Implementation
IQ-Math application selects “Global Q” value for the whole application
based on the required dynamic range or resolution, for example: #define file _iq
GLOBAL_Q
18
// define in “IQmathLib.h”
Y, M, X, B;
Y = _IQmpy(M,X) + B;
// all values are in Q = 18
The can also explicitly specify the Q value to use: _iq20
Y, M, X, B;
Y = _IQ20mpy(M,X) + B;
Copyright ⓒ 2011 Ajinextek Co., Ltd.
// all values are in Q = 20
2011/06/23, Advanced Motion Control Team
14
3. Implementation IQ-Math range and resolution
Q range
Stability Range
Q31 - Q27
Unstable (not enough Dynamic range)
Q26 - Q19
Stable
Q18 – Q1
Unstable (low resolution, quantization problem)
Copyright ⓒ 2011 Ajinextek Co., Ltd.
2011/06/23, Advanced Motion Control Team
15
3. Implementation IQ-Math ed functions: s most of common floating-point functions
Copyright ⓒ 2011 Ajinextek Co., Ltd.
2011/06/23, Advanced Motion Control Team
16
3. Implementation Flexible portability between Fixed-point and Floating-point with IQ-Math
Y = _IQmpy(M, X) + B; selects target math type (in “IQmathLib.h” file) #if MATH_TYPE == IQ_MATH
#if MATH_TYPE == FLOAT_MATH
Y = (float)M * (float)X + (float)B;
Compile & Run using “IQ-math” on C28x
Copyright ⓒ 2011 Ajinextek Co., Ltd.
Compile & Run using floating-point math on C3x, C67x,C28x (RTS), PC,..
2011/06/23, Advanced Motion Control Team
17
Copyright ⓒ 2011 by Ajinextek Co., Ltd., All rights reserved.
2011/06/23, Advanced Motion Control Team
18
4. Summary “IQ-math” + 32-bit fixed-point processor Seamless portability of code between fixed and floating-point devices selects target math type in “IQmathLib.h” file #if MATH_TYPE == IQ_MATH #if MATH_TYPE == FLOAT_MATH
One source code set for simulation vs. target device Numerical resolution adjustability based on application requirement Set in “IQmathLib.h” file #define GLOBAL_Q 18
Explicitly specify Q value _iq20 X, Y, Z;
Numerical accuracy without sacrificing time and cycles Rapid conversion/porting and implementation of algorithms
Copyright ⓒ 2011 Ajinextek Co., Ltd.
2011/06/23, Advanced Motion Control Team
19
Thank you!
NOTICE: Proprietary and Confidential This material is proprietary to Ajinextek Co., Ltd.. It contains trade secret and confidential information which is solely the property of Ajinextek Co., Ltd. This material is for client’s internal use only. This material shall not be used, reproduced, copied, disclosed, transmitted, in whole or in part, without the express consent of Ajinextek Co., Ltd. Copyright © 2011 by Ajinextek Co., Ltd. All rights reserved.
http://www.ajinextek.com