Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Return Return
Version 3.8/27/07 For Academic Use Only in Accordance with Licence-to-Use, see readme.pdf
Top
Introduction 3.1
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Integer Number Representations 3.2
Number Representation
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Unsigned Integers - Positive Values Only 3.3
64 01000000
65 01000001
131 10000011
255 11111111
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
2’s Complement - the way forward 3.5
• The 9th bit generated for 0 can be ignored. Note that -128 can be
represented but +128 cannot.
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Fixed-point Binary Numbers 3.11
• Bits on the left of the binary point are termed integer bits, and bits on
the right of the binary point are termed fractional bits, for example:
aaa.bbbbb 3 integer bits, 5 fractional bits
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Fixed-point Quantisation 3.12
-2
• Looks much better. We must always take into account the quantisation
when using fixed point - it will be +/- 1/2 of the LSB (least significant bit).
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Notes:
Quantisation is simply the DSP term for the process of representing infinite precision numbers with finite
precision numbers. In the decimal world, it is familiar to most to work with a given number of decimal places.
The real number π can be represented as 3.14159265.... and so on. We can quantise or represent π to 4
decimal places as 3.1416. If we use “rounding” here and the error is:
If we truncated (just chopped off the bits below the 4th decimal place) then the error is larger:
Clearly rounding is most desirable to maintain best possible accuracy. However it comes at a cost. Albeit the
cost is relatively small, but it is however not “free”.
When multiplying fractional numbers we will choose to work to a given number of places. For example, if we
work to two decimal places then the calculation:
Once we start performing billions of multiplies and adds in a DSP system it is not difficult to see that these small
errors can begin to stack up.
Developed by:
Top
Fractional Motivation - Normalisation 3.13
16 bits
Truncating 7 LSBs
9 bits
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Rounding 3.15
9 bits 9 bits
+ 1
truncation rounding
1 1 0 0 0 0
1 1 0 0 0 0
0 0 1 1 0 0
0 -1.046875 1 0.0078125 1 0.0
0 1 1
0 0 0
0 0 0
0 no loss of precision 0 loss of precision 0 total loss of precision
0 0 0 (underflow)
LSB 0 0 0
-1.046875 0.013671875 0.005859375
The following rounding example is a fairly extreme (but perfectly valid) - 0.013671875 is very close to needing
to be rounded up (to 0.015625) so truncate makes a significantly larger error than rounding.
0 0 0
0 0 0 0
0
0 0 0 0
0
0 0 0 0
0
0 0 0 0
0
0 0 0 0
0
0 0 0 0
0
0 0 0 0
0 ROUNDING
1 1 TRUNCATE 0 1 1
0.0078125 1 0
1
1 1 0.015625
1 1
0
0 0
0 0
0 error=0.0078125-0.013671875=-0.005859375 0 error=0.015625-0.013671875=0.001953125
0 0
0.013671875 0
0.013671875 Developed by:
Top
A different approach: Trounding 3.16
• However, unlike rounding it cannot affect any bit beyond the new LSB:
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 1 1 1
1 0.0078125 1 0.0078125
1 1
0 0
0 0
0 0
0 0
0 0
0.005859375 0.013671875
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Trounding Explained 3.17
• First compare the logical OR operation with addition. Only when both
inputs are 1 does trounding differ from rounding:
k+1–N
n×2
K
K+1 exponent bits in range 1 – 2 ≤ k ≤ 2 K
N significant bits in range – 2 N ≤ n ≤ 2 N
Format K+1 N
single-precision 8 24
double-precision 11 53
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Notes:
Lots of information can be found at http://grouper.ieee.org/groups/754/
Although the above definition is as specified by the standard, a more intuitive definition can be gained when
analysing the encoding of floating-point numbers as a bit sequence:
S E E ... E E E F F ... F F F
Single precision: 0 1 8 9 31
Double precision: 0 1 11 12 63
E+B
These numbers are encoded as f ( S ) × 2 × ( 1.F )
where B is a bias term, 127 for single precision or 1023 for double precision. F is an unsigned fixed-point value
with no integer bits.
f ( S ) = – 1 when S = 1 , and f ( S ) = 1 when S = 0 . i.e. the S bit encodes the sign of the number.
Note: In accordance with the specification, the above description of floating-point numbers is only valid for
“normalised” values. There exists a class of numbers known as “subnormals”. These are not described here.
Some examples of floating point encoding (single precision floating point - 32 bits):
( 3 + 127 ) ( 3 + 127 ) ( – 4 + 127 )
10 ⇒ + 2 × 1.01 10.34 ⇒ + 2 × 1.0100101… – 0.078125 ⇒ – 2 × 1.01
Developed
Note that the 1 before the fraction is NOT encoded - it will always be a 1 so need not by:
be conveyed.
Top
Short Exponents 3.19
• In this case we have a 4-bit exponent and a 11-bit mantissa. With such
an exponent we have the ability to represent exponents in the range -7
to 8. This results in a huge increase in dynamic range at a relatively
small cost to precision:
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Floating-point Numbers for DSP 3.20
• Floating point is widely used in many DSP processors which have a
dedicated Floating Point Unit (FPU).
• It can also be simpler to design with floating point - fixed point design
requires care to best exploit the available dynamic range, but with
floating point being constrained to a dynamic range is not such a
concern.
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Wraparound Overflow & 2’s Complement 3.23
• With 2’s complement overflow will occur when the result to be produced
lies outside the range of the number of bits.
• Therefore for an 8 bit example the range is -128 to +127 (or in binary
this is 100000002 to 011111112:
-65 10111111 100 01100100
+ -112 +10010000 + 37 +00100101
-177 101001111 137 10001001
With an 8 bit result we lose the 9th bit With an 8 bit result the result “wraps
and the result “wraps around” to a around” to a negative value:
positive value: 01001111 = 47 . 10001001 = – 119 .
For example
10110111 01100100
(-73) + 127 = 54 +01111111 100 + 64 = 164 +01000000
1 00110110 10100100
Discard final 9th bit carry
No overflow MSB bit indicate -ve result! Overflow
Adding +ve and -ve will never overflow!
Adding +ve and +ve if a -ve result then overflow
Adding -ve and -ve if a +ve result then overflow
Developed by:
Top
Saturation 3.24
• When overflow is detected, the result is set to the close possible value
(i.e for the 8 bit case either -128 or +127).
• Therefore for every addition that is explicitly done with an adder block.
In Xilinx System Generator the user will get a checkbox choice to allow
results to either (i) Wraparound or (ii) Saturate.
10.375 10.375
+ 3.125 + 8.125
13.500 18.500
1010.011 1010.011
+ 0011.001 + 1000.001
1101.100 10010.100
• Note that for large operands, an extra bit may be required. Care must
be taken to interpret the binary point - it must stay in the same location
w.r.t. the LSB - this means a change of location w.r.t. the MSB.
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Constant ROM-based multipliers 3.35
• Consider a ROM multiplier with 8 bit inputs: 65,536 8-bit locations are
required
ROM
8 bits
A
16 bits 16 bits
address data P
B 8 bits 65,536 16-bit
locations
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
2’s complement Multiplication 3.37
• For one negative and one positive operand just remember to sign
extend the negative operand.
11010110 -42
x00101101 x45
1111111111010110
0000000000000000
1111111101011000
sign 1111111010110000
extends 0000000000000000
1111101011000000
0000000000000000
0000000000000000
1111100010011110 -1890
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
On-chip multipliers 3.39
• These are in hardware on the ASIC, not actually in the user FPGA area,
and therefore are permanently available, and they use no slices. They
also consume less power than a slice-based equivalent.
A
18x18 bit
multiply P
B
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Division (i) 3.40
q2
0
Q=B/A q1
0
q0
• Note that each cell can perform either addition or subtraction as shown
in an earlier slide ⇒ either Sin+ Bin or Sin - Bin can be selected.
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Notes:
A Direct method of computing division exists. This “paper and pencil” method may look familiar as it is often
taught in school. A binary example is given below. Note that each stage computes an addition or subtraction of
the divisor A. The quotient is made up of the carry bits from each addition/subtraction. If the quotient bit is a 0,
the next computation is an addition, and if it is a 1, the divisor is subtracted. It is not difficult to map this example
into the structure shown on the slide.
01011 R0 = B
q4 = 0 carry 10011 -A
11110 R1
0
11100 2.R1
q3 = 1 carry 01101 +A
01001 R2
0
10010 2.R2
q2 = 1 carry 10011 -A
00101 R3
0
01010 2.R3
q1 = 0 carry 10011 -A
11101 R4
0
11010 2.R4
q0 = 1 carry 01101 +A
00111 R5
• It is unlikely that the quotient can be passed on to the next stage until
all the bits are computed - hence slowing down the system!
• Note that we must wait for N full adder delays before the next row can
begin its calculations.
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Square Root (i) 3.44
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Notes:
Looking carefully at the non-restoring square root array, we can note that this array is essentially “half” of the
division array! If the division array above is cut diagonally from the left we can see the cells that are needed for
the square root array. The 2 extra cells on the right hand side are standard cells which can be simplified. So
square root can be performed twice as fast as divide using half of the hardware!
a4 a 3 a2 a1
A = 10 11 01 01
010 0a4
b3 = 1 carry 111 111
001 R1
0111 R1<<1 & a3
b2 = 1 carry 1011 1b311
0 a7 a6 R2
0 1 1 0010
1 0 0 01001 R2<<1 & a2
0 a5 a4 b1 = 0 c ar r y 10011 1b3b211
b5 1 1 11100 R3
0 0
b4 0 a3 a2 110001 R3<<1 & a1
1 1 b0 = 1 c ar r y 011011 0b3b2b111
0 0 001100 R4
b3 0 a1 a0
1 1
0 0
b2 0
1 0 1 0
0 0 sout
b1 0
1 0 1 0
0 0
b0
Developed by: 0
Top
Square Root - An Alternative Approach 3.45
• These are:
• Each row has to wait longer and longer for the data it needs
from the previous row.
• This can be fast but if the input wordlength is large this approach quickly
becomes unfeasible.
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Notes:
The Newton-Raphson equation can be used to find the square root of a number. It is an iterative technique
which can achieve accurate results with relatively few iterations. However, there are two parameters that make
it less than ideal for DSP.
• An initial guess is required to start the algorithm and the accuracy of this guess effects the accuracy of the
solution after n iterations.
x n + 1 = ⎛ x n + 1 + Input
-------------⎞ ⁄ 2
⎝ x ⎠ n
One approach that uses this algorithm is to take the first b MSB bits of the input and use them to address
memory containing values for the initial guess xn. This value is then fed into the Newton-Raphson algorithm for
n iterations.
Developed by:
Top
Complex Addition/Subtraction 3.47
( a + jb ) + ( c + jd ) = ( a + c ) + j ( b + d )
( a + jb ) – ( c + jd ) = ( a – c ) + j ( b – d )
a
+
_ Real
c
b
+
_ Imaginary
d
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Complex Multiplication 3.48
( a + jb ) × ( c + jd ) = ( ac – bd ) + j ( bc + ad )
a
x
+ Imaginary
b x
c
x
_
Real
d
x
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Notes:
The total number of operations that must be performed for a complex multiplication is 6. But 4 of these
operations are multiplies. Generally multiplies are more costly in terms of speed and/or area than additions.
Thus, if we can reduce the number of multiplies at the expense of a few more additions, this can be beneficial.
Note the wordlength growth that can occur (using an 8 bit example below):
8
a 16
8 x
17
8 + Imaginary
b x 16
c 8
16
x
_ 17
8 Real
d 16
x
Developed by:
Top
Alternative Complex Multiplication 3.49
( a + jb ) × ( c + jd ) = ( ac – bd ) + j [ ( a + b ) × ( c + d ) – ac – bd ]
a
+
b
x
c _
+ _
Imaginary
d x
_
Real
x
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved
Top
Notes:
With some algebraic manipulation a complex multiplication can be expressed in terms of 8 operations as
opposed to 6. However, even though this form has 2 more operations than the previous one, there is 1 less
multiplier. We have effectively substituted a multiplier for 3 additions. This procedure offers an alternative
architecture which may be faster in systems where multiplication takes considerably longer than addition.
Note however the implementation cost of the 3 multiply version is not necessarily lower given that one of the
multipliers is a 9 bit multiplier and there are of course 5 adds.
8
a
+
8
b 9
18
9 x
8
c _
16 17
+ _
Imaginary
8 8
d x
8
8 _ 17
16 Real
8 x
Developed by:
Top
Complex Division 3.50
c
x + ÷ Real
d
x x
+
x
August 2007, Version 3.8/21/07 For Academic Use Only. All Rights Reserved