2 Learning Objectives Numerical issues and data formats. Fixed point. Fractional number.Floating point.Comparison of formats and dynamic ranges.
3 Numerical Issues and Data Formats C6000 Numerical RepresentationFixed point arithmetic:16-bit (integer or fractional).Signed or unsigned.Floating point arithmetic:32-bit single precision.64-bit double precision.
4 Fixed Point Arithmetic - Definition For simplicity a 4-bit representation is used:Decimal EquivalentBinary Number23222120Unsigned integer numbers
5 Fixed Point Arithmetic - Definition For simplicity a 4-bit representation is used:Decimal EquivalentBinary Number232221201Unsigned integer numbers11
6 Fixed Point Arithmetic - Definition For simplicity a 4-bit representation is used:Decimal EquivalentBinary Number232221201Unsigned integer numbers1112
7 Fixed Point Arithmetic - Definition For simplicity a 4-bit representation is used:Decimal EquivalentBinary Number232221201123456789101112131415Unsigned integer numbers
8 Fixed Point Arithmetic - Definition For simplicity a 4-bit representation is used:Decimal EquivalentBinary Number-23222120Signed integer numbers
9 Fixed Point Arithmetic - Definition For simplicity a 4-bit representation is used:Decimal EquivalentBinary Number-232221201Signed integer numbers11
10 Fixed Point Arithmetic - Definition For simplicity a 4-bit representation is used:Decimal EquivalentBinary Number-232221201Signed integer numbers1112
11 Fixed Point Arithmetic - Definition For simplicity a 4-bit representation is used:Decimal EquivalentBinary Number-232221201Signed integer numbers11121314151617
12 Fixed Point Arithmetic - Definition For simplicity a 4-bit representation is used:Decimal EquivalentBinary Number-232221201Signed integer numbers111213141516171-8
13 Fixed Point Arithmetic - Definition For simplicity a 4-bit representation is used:Decimal EquivalentBinary Number-232221201Signed integer numbers111213141516171-81-7
14 Fixed Point Arithmetic - Definition For simplicity a 4-bit representation is used:Decimal EquivalentBinary Number-232221201Signed integer numbers111213141516171-81-71-61-51-41-31-21-1
15 Fixed Point Arithmetic - Problems The following equation is the basis of many DSP algorithms (See Chapter 1):Two problems arise when using signed and unsigned integers:Multiplication overflow.Addition overflow.
16 Multiplication Overflow 16-bit x 16-bit = 32-bitExample: using 4-bit representation24 cannot be represented with 4-bits.131xx82411
17 Addition Overflow 32-bit + 32-bit = 33-bit Example: using 4-bit representation16 cannot be represented with 4-bits.181++8161
18 Fixed Point Arithmetic - Solution The solutions for reducing the overflow problem are:Saturate the result.Use double precision result.Use fractional arithmetic.Use floating point arithmetic.
19 Solution - Saturate the result Unsigned numbers:If A x B 15 result = A x BIf A x B > 15 result = 151318x1124Saturated115
20 Solution - Saturate the result Signed numbers:If -8 A x B 7 result = A x BIf A x B > 7 result = 7If A x B < -8 result = -8131-8x11-24Saturated1-8
21 Solution - Double precision result For a 4-bit x 4-bit multiplication hold the result in an 8-bit location.Problems:Uses more memory for storing data.If the result is used in another multiplication the data needs to be represented into single precision format (e.g. prod = prod x sum).Results need to be scaled down if it is to be sent to an A/D converter.
22 Solution - Fractional arithmetic If A and B are fractional then:A x B < min(A, B)i.e. The result is less than the operands hence it will never overflow.Examples:0.6 x 0.2 = 0.12 (0.12 < 0.6 and 0.12 < 0.2)0.9 x 0.9 = 0.81 (0.81 < 0.9)0.1 x 0.1 = 0.01 (0.01 < 0.1)
23 Fractional numbers Definition: What is the largest number? -202-12-22-(N-1)-10.50.2511What is the largest number?Largest Number:-202-12-22-(N-1)+1= MAX1= 2-(N-1)1= MAX+2-(N-1) = 1MAX = 1-2-(N-1)
24 Fractional numbers Definition: What is the smallest number? 1-202-12-22-(N-1)What is the smallest number?Smallest Number:1-202-12-22-(N-1)= MIN = -1For 16-bit representation:MAX = =MIN = -1-1 x < 1
25 Fractional numbers - Sign Extension 1a== = 0.75b== = -0.25x126.96.36.199Sign extensionTo keep the same resolution as the operands we need to select these 4-bits:1
26 Fractional numbers - Sign Extension 11= = 0.75xb=111= = -0.2511.11..Sign extension bits111...1Sign extensionThe way to do it is to shift left by one bit and store upper 4-bits or right shift by three and store the lower 4-bits:111
30 Fractional numbers - Problems There are some problems that need to be resolved when using fractional numbers.These are:Result of -1 x -1 = 1Accumulative overflow.
31 Problem of -1 x -1 We have seen that: Solution: -1 x < 1 -1 x -1 = 1 which cannot be represented.Solution:There are two instructions that saturate the result if you have -1 x -1:SMPYSMPYH
32 Problem of -1 x -1 In one cycle these instructions do the following: Multiply.Shift left by 1-bit.Saturate if the sign bits are 01.It can be shown that:Positive ResultNegative Result-1 x -1 ResultResult of MPY(H)00.xxx-xb11.xxx-xb01.xxx-xbResult of SMPY(H)0.xxx-xb1.xxx-xb
33 Problem of Accumulative Overflow In this case the overflow is due to the summation.Examples of overflow:0x00000xffff0x7fff0x80010x7ffe0x7fff + 0x0002 = 0x8001(positive number + positive number = negative number!)0xffff + 0x0002 = 0x0001(negative number + positive number = negative number!)
34 Problem of Accumulative Overflow Solutions:(1) Saturate the intermediate results by using these add instructions:If saturation occurs the SAT bit in the CSR is set to 1. You must clear it.(2) Use guard bits:e.g. ADD A1, A2, A1:A0SADDSSUB
35 Problem of Accumulative Overflow Solutions:(3) Do nothing if the system is Non-Gain:With a non-gain system the final result is always less than unity.Example system:This will be non-gain if:
36 Floating Point Arithmetic The C67xx support both single and double precision floating point formats.The single precision format is as follows:s31e302221m...1-bit8-bits23-bitss = sign bite = exponent (8-bit biased : -127)m = mantissa (23-bit normalised fraction)value = (-1)sign * (1.mantissa) * 2(exponent-127)
37 Floating Point Arithmetic Example Example: Conversion between integer and floating point.Convert ‘dd’ to the IEEE floating point format:int dd = 0x ;flot1 = (float) dd;
38 Floating Point Arithmetic Example To view the value of “flot1” use:View: Memory:Address= &flot1flot1 = 0x4EC0 0000We find:
39 Floating Point Arithmetic Example Let us check to see if we have the same number:s = 0e = b = = 157m = 0.100b = 0.5float1 = (-1)0 * (1.5) * 2( ) = 1.5 * 230= decimal= 0x
40 Floating Point Arithmetic Example The previous example can be seen in:numerical.pjtNumerical_.wsUse the mixed mode display to see the assembly code.
41 Floating Point IEEE Standard Special values:s1e0<e<255255m0Number-0(-1)s * 0.m * 2-126(-1)s * 1.m * 2e-127+-NaN (not a number)
44 Floating/Fixed Point Summary Floating point single precision:Floating point double precision:s31e302322m...1-bit8-bits23-bitsvalue = (-1)s * 1.m * 2e-12763625251see...eemm...mm1-bit11-bits52-bitsodd:even registersvalue = (-1)s * 1.m * 2e-1023
45 Floating/Fixed Point Summary (Short: N = 16; Int: N = 32) Unsigned integer:Signed integer:Signed fractional:x2N-120...21x-2N-120...21x-202-(N-1)...2-12-2
46 Floating/Fixed Point Dynamic Range Smallest Number (positive)Largest Number (positive)Smallest Number (negative)Floating Point Single Precision3.4 x 10388.8 x 10-39-3.4 x 10381-21616-bit-23232-bit1-2-152-15-11-2-312-31IntegerFixed PointFractional
47 Numerical Issues - Useful Tips Multiply by 2: Use shift leftDivide by 2: Use shift rightLog2N: Use shiftSine, Cosine, Log: Use look up tablesTo convert a fractional number to hex:Num x 215Then convert to hexe.g: convert 0.5 to hex0.5 x 215 = 16384(16384)dec = (0x4000)hex
48 Numerical Issues - 32-bit Multiplication It is possible to perform 32-bit multiplication using 16-bit multipliers.Example: c = a x b (with 32-bit values).a =ahalbhblb =32-bitsa * b = (ah << al)* (bh << 16 + bl)= [(ah * bh) << 32] + [(al * bh) << 16] +[(ah * bl) << 16] [al * bl ]
Your consent to our cookies if you continue to use this website.