Module 04

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 19

Module 4: Numerical Systems

Digital Signal Controller


TMS320F2833x

4-1
Floating-Point, Integer and Fixed-Point
 Two basic categories of
processors:
 Floating-Point
 Integer/Fixed-Point
 What is the difference?
 What are advantages /
disadvantages ?
 Real-Time Control:
 Most microcontrollers are Fixed-Point!
 F2833x supports both worlds in
hardware!
4-2
Processor Types
 Floating-Point Processors
 Internal Hardware Unit to support Floating -
Point Operations
 Examples: Intel’s Pentium Series , Texas
Instruments C6000 DSP
 High dynamic range for numeric calculation
 Usually more expensive
 Integer / Fixed-Point Processors
 Fixed-Point Arithmetic Unit
 Almost all embedded controllers are fixed
point machines
 Examples: all microcontroller families, e.g.
Freescale S12X, Infineon C166, Texas
Instruments MSP430, Atmel AVR
 Lowest price per MIPS 4-3
Standard IEEE-754 Single Precision
Floating-Point
31 30 23 22 0
s eeeeeeee fffffffffffffffffffffff
1 bit sign 8 bit exponent 23 bit mantissa (fraction)

Case 1: if e = 255 and f =/ 0, then v = NaN


Case 2: if e = 255 and f = 0, then v = [(-1)s]*infinity

Case 3: if 0 < e < 255, then v = [(-1)s]*[2(e-127)]*(1.f)


Case 4: if e = 0 and f =/ 0, then v = [(-1)s]*[2(-126)]*(0.f)
Case 5: if e = 0 and f = 0, then v = [(-1)s]*0

Advantage  Exponent gives large dynamic range


Disadvantage  Precision of a number depends on its exponent

4-4
Floating-Point does not solve
everything!
Example: x = 10.0 (0x41200000)
+ y = 0.000000240 (0x3480D959)

z = 10.000000240 WRONG!
RIGHT?
You cannot represent 10.000000240 with
single-precision floating-point

0x412000000 = 10.000000000
10.000000240  can’t represent!
0x412000001 = 10.000001000

So z gets rounded down to 10.000000000


4-5
Integer Numbering System Basics

 Binary Numbers
01102 = (0*8)+(1*4)+(1*2)+(0*1) = 610
111102 = (1*16)+(1*8)+(1*4)+(1*2)+(0*1) = 3010

 Two’s Complement Numbers


01102 = (0*-8)+(1*4)+(1*2)+(0*1) = 610
111102 = (1*-16)+(1*8)+(1*4)+(1*2)+(0*1) = -210

4-6
Four-Bit Integer Multiplication
0100 4
x 1101 x -3
00000100
0000000
000100
+ 11100
11110100 -12
Accumulator 11110100
11110100
Data Memory ?
Is there another (superior) numbering system? 4-7
Binary Fractions

11 00 11 11

-1
• 1/2 1/4 1/8

= -1 + 1/4 + 1/8 = -5/8

Fractions have the nice property that


fraction x fraction = fraction

4-8
Four-Bit IQ - Multiplication
0100
. 1/2
x 1101
. x - 3/8
00000100
0000000
000100
11100
11110100 -3/16
Accumulator 11110100
11110100

Data Memory 1110


. -1/4
4-9
Fractional Representation
31 0
S IIIIIIII fffffffffffffffffffffff
32 bit mantissa

.
-2I + 2I-1 + … + 21 + 20 2-1 + 2-2 + … + 2-Q

“IQ” – Format
“I”  INTEGER – Fraction
“Q”  QUOTIENT – Fraction

Advantage  Precision same for all numbers in an IQ format


Disadvantage  Limited dynamic range compared to Floating-Point

4 - 10
IQ - Examples
I1Q3 – Format:
3 0

S fff
Most negative decimal number: -1.0 = 1.000 B

Most positive decimal number: + 0.875 = 0.111 B

Smallest negative decimal number: -1*2-3 (-0.125) = 1.111 B

Smallest positive decimal number: 2-3 (+0.125) = 0.001 B

Range: -1.0 …. 0.875 ( + 1.0)


Resolution: 2-3

4 - 11
IQ - Examples
I3Q1 – Format:
3 0
SII f
Most negative decimal number: -4.0 = 100.0 B

Most positive decimal number: + 3.5 = 011.1 B

Smallest negative decimal number: -1 * 2-1 (- 0.5) = 111.1 B

Smallest positive decimal number: 2-1 (+0.5) = 000.1 B

Range: -4.0 …. +3.5 ( + 4.0)


Resolution: 2-1

4 - 12
IQ - Examples
I1Q31 – Format:
31 0

S fff ffff ffff ffff ffff ffff ffff ffff


Most negative decimal number: -1.0
1.000 0000 0000 0000 0000 0000 0000 0000 B

Most positive decimal number:  + 1.0


0.111 1111 1111 1111 1111 1111 1111 1111 B

Smallest negative decimal number: -1*2-31


1.111 1111 1111 1111 1111 1111 1111 1111 B

Smallest positive decimal number: 2-31


0.000 0000 0000 0000 0000 0000 0000 0001 B

Range: -1.0 …. (+1.0)


Resolution: 2-31

4 - 13
IQ - Examples
I8Q24 – Format:
31 0

S III IIII ffff ffff ffff ffff ffff


Most negative decimal number: -128
1000 0000. 0000 0000 0000 0000 0000 0000 B

Most positive decimal number:  + 128


0111 1111. 1111 1111 1111 1111 1111 1111 B

Smallest negative decimal number: -1*2-24


1111 1111. 1111 1111 1111 1111 1111 1111 B

Smallest positive decimal number: 2-24


0000 0000. 0000 0000 0000 0000 0000 0001 B

Range: -128 …. (+128)


Resolution: 2-24

4 - 14
IQ-Math can do better!

I8Q24 Example: x = 10.0 (0x0A000000)


+ y = 0.000000240 (0x00000004)

z = 10.000000240 (0x0A000004)

Exact Result (this example)

4 - 15
How is a fraction coded?
~1 ~ 32K 7FFF

½ 16K 4000

0
 0 0000
*32768
–½ –16K C000

–1 –32K 8000
Fractions Integers Hex

 Example: represent the fraction number 0.707


void main(void) {
int coef = 32768 * 707 / 1000;
}
4 - 16
Fractional vs. Integer
 Range
 Integers have a maximum range
determined by the number of bits
 Fractions have a maximum range of ±1
 Precision
 Integers have a maximum precision of 1
 Fractional precision is determined by
the number of bits

4 - 17
Lab4: Fixed-point and Floating-point
 Benchmark Multiply Operation
 k=i*i
 Test setup:
1. Integer multiply operation
2. Floating-Point multiply by Floating-Point Library
3. Floating-Point multiply by Floating-Point
Hardware unit
Benchmark result:
Fixed-point Floating-Point- Floating-Point-
Library Hardware
code size (words) 3 89 9
clock cycles (6.67 ns) 3 112 5
4 - 18

You might also like