Professional Documents
Culture Documents
Lecture # 08
<rehan.hafiz@seecs.edu.pk>
http://lms.nust.edu.pk/
Acknowledgement: Material from the following sources has been consulted/used in these slides: 1. [CIL] Advanced Digital Design with the Verilog HDL, M D. Ciletti 2. [SHO] Digital Design of Signal Processing System by Dr Shoab A Khan 3. [STV] Advanced FPGA Design, Steve Kilts 4. Ercegovacs Book: Digital Arithmetic 2004 5. Dr. Shoab A Khans CASE Lectures on Advanced Digital System Design
Material/Slides from these slides CAN be used with following citing reference: Dr. Rehan Hafiz: Advanced Digital System Design 2010
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Tuesday @ 5:30-6:20 pm, Friday @ 6:30-7:20 pm By appointment/Email VISpro Lab above SEECS Library
1 2 3
3
Introduction Verilog+ Combinational Logic Verilog + Sequential Logic Synthesis in Verilog Micro-Architecture <Micro-Coded-Machines> Optimizing Speed Optimizing Area FIR Implementation CDC Issues Fixed-Point Arithmetic Adders Multipliers CORDIC Algorithmic Transformations for System Design Algorithmic Transformations Project Project
4 5 6 7 8 10 11 12 13 13 14
Outline & Introduction, Initial Assessment of students, Digital design methodology & design flow Combinational Logic Review + Verilog Introduction, Combinational Building Blocks in Verilog Sequential Common Structure in Verilog (LFSR /CRC+ Counters + RAMS), Sequential Logic in Verilog Synthesis of Blocking/Non-Blocking Statements Design Partitioning + RISC Microprocessor + Micro architecture Document Architecting Speed in Digital System Design: [Throughput, Latency, Timing] Architecting Area in Digital System Design: [Area Optimization] FIR Implementations + Pipelining & Parallelism in Non Recursive DFGs Cross-Clock Domain Issues & RESET circuits Arithmetic Operations: Review Fixed Point Representation Adders & Fast Adders Multi-Operand Addition Multiplication , Multiplication by Constants + BOOTH Multipliers CORDIC (sine, cosine, magnitude, division, etc), CORDIC in HW DFG representation of DSP Algorithms, Iteration Bound & Retiming
15
16 17
Lecture Overview
4
Algorithms,
Arithmetic & Numbers 2s Complement Representation Generating Overflow Flag Fixed point / Floating point Qn.m format Truncating/ Rounding
Algorithms in Hardware
5
Primitives
Addition/subtraction
Multi
operand addition Logical and arithmetic shift Multiplication by constant Multiplication Division
Algorithms
Sequenced Composition
of Primitives
Numbers in hardware
6
Negative Number
Representing Numbers
7
Signed Magnitude
8
Designate left-most bit as a sign bit with no arithmetic weight 1-> negative, 0-> positive. Positive and negative zero (0000 vs. 1000) Difficult to add numbers of different sign or subtract numbers of same sign (comparison)
Same sign bits Add and use same sign Different signs Logic to decide add or sub & final sign
N-1 bits are available to represent magnitude Range of N-bit signed-magnitude number is: -(2N-1 1) to (2N-1 1)
[CIL]
Ones Complement
9
Flipped bits as negative number Positive and negative zero (0000 vs. 1000) Subtraction is more complicated than in 2scomp Range of N-bit signedmagnitude number is:
-(2N-1 1) to (2N-1 1)
Twos Complement
10
Example
For N=8, -10 b11110110 For N=5, -10 b10110
Paper & Pencil conversion by scanning from right to left, leaving the first one and flipping all the remaining bits
Twos Complement
12
Arithmetic
+,
-, *, / performed in hardware with a unit that can carry out binary operations of addition and bitwise complement.
Addition: Same hardware as
reduced dynamic range Subtraction: Bitwise complements and addition of one and a number ! Multiplication: Repeated additions Division involves repeated subtraction Negative of a number : Complement & add 1
13
Addition in 2s Complement
Addition/Subtraction in 2s Complement
14
to Normal Binary Addition with (a+(-b)) Rather than subtracting add the negative of the number Example: (-10)-(10)
Negating a number in HW
15
Addition of number similar to unsigned binary addition Flip all the bits & Add ONE
17
Knowing Overflow
Hardware cannot distinguish between signed and unsigned integers YOU are solely responsible for using the correct data type with each instruction Verilog does not provide synthesizable signed representation
Consider
numbers
18
Overflow Examples
19
Overflow Unsigned
Carry
Out of MSB
2s Complement
Carryout
OF
it to the destination OF = (carry out of the MSB) XOR (carry into the MSB)
20
Knowing your 2s Complement Number for Corner Cases (Because of the slightly asymmetric range, negation may lead to overflow! )
21
Corner Cases
22
There is no equal opposite of -2N-1 in N bits 2s complement representation For example, while multiplying two ve numbers like -4 x -4 , we can get 16 and we cant represent this as a 5-bit 2s complement No.
Needs Correction
<Unsigned overflow>
25
bits to left of point have value 1 bits to right of point have value < 1
binary point
29 28 27 26 25 24 23 22 21 20 21 22 23 24 25 26
(512) (256) (128) (64) (32) (16) (8) (4) (2) (1) (0.5) (0.25) (0.0625) (0.015625) (0.125) (0.03125)
0 1 0 0 0 0 1 1 0 1.0 1 1 1 1 0 269.46875
Qn.m Format
28
Qn.m format is a fixed positional number system for representing floating-point numbers Qn.m simply means that N-bit binary number has n bits to the left and m bits to the right of the binary point
In
There is NO Decimal in HW
29
1.
Define the total No. of bits to represent a No. (Lets say 10 bits)
2.
Fix a Decimal some where in the No. -21 20 2-1 2-2 2-3 2-4 2-5 2-6 2-7 2-8 (Lets say after 2 locations) Note that there is no decimal in H/W.
Fractional Bits
n depends upon the range of our required integer m depends upon how much precision we want in the fractional part of our computation.
Q3.13
Example 1 bit for the sign and 2 bits are reserved for the integer part 13 bits are reserved for the fractional part
The algorithm is analyzed for all set of inputs Range of each variable is observed Depending upon the precision required, n and m are specified. For implementation on programmable processors, N=16, or 32 For Application Specific Hardware, an optimal value of N is specified.
32
Speech Samples
AGC
Filter
Q1.17 Format
Q9.12 Format
At every point, we check the ranges Compress
Q3.18 Format
O/p
33
Arithmetic in Q Format
Addition in Q Format
34
Q=QMax(n1,n2) +
Max(m1.m2)
Addition in Q Format
35
If two numbers a and b of Qn1.m1 and Qn2.m2 formats respectively are added, the result is in Qn.m format, where n is larger of n1 and n2 and m is larger of m1 and m2.
Example Implied Decimal
Qn1.m1 = Qn2.m2 = 0
0 0 1 0 1 1 1 0 1 1 0
Q2.2 Q4.4
Qn.m =
0 1 1 1 1 1 1 0
Q4.4
Sign Extension
36
We need to extend the sign bit to its left. Copying the sign bit to its left doesnt change the original value of the number
Addition in Q Format
37
If two numbers a and b of Qn1.m1 and Qn2.m2 formats respectively are added, the result is in Qn.m format, where n is larger of n1 and n2 and m is larger of m1 and m2.
Example Implied Decimal Q2.2 = - 2 + 1 + 0.5 = -0.5 Q4.4 = 1 + 2+ 4 + 0.25 + 0.125 = 7.375
Qn1.m1 = 1 Qn2.m2 = 0
1 1 1 1 0 1 1 1 0 1 1 0
Qn.m =
0 1 1 0 1 1 1 0
Bit Growth
38
Due the demand for increased number of bits effective Width of the words will increase
Multiplication in Q-Format
39
c=axb
Q n1.m1 Q n2.m2
(a) (b)
Q (n1+n2) . (m1+m2) ( c )
Truncation
Simple Truncate An operation similar to floor
Rounding
41
Thanks