Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CS 140 Lecture 14 Standard Combinational Modules Professor CK Cheng CSE Dept. UC San Diego Some slides from Harris and Harris.

Similar presentations


Presentation on theme: "1 CS 140 Lecture 14 Standard Combinational Modules Professor CK Cheng CSE Dept. UC San Diego Some slides from Harris and Harris."— Presentation transcript:

1 1 CS 140 Lecture 14 Standard Combinational Modules Professor CK Cheng CSE Dept. UC San Diego Some slides from Harris and Harris

2 2 Part III. Standard Modules A.Interconnect B.Operators. Adders Multiplier Adders1. Representation of numbers 2. Full Adder 3. Half Adder 4. Ripple-Carry Adder 5. Carry Look Ahead Adder 6. Prefix Adder ALU Multiplier Division

3 Operators Specification: Data Representations Arithmetic: Algorithms Logic: Synthesis Layout: Placement and Routing 3

4 4 1. Representation 2’s Complement -x: 2 n -x 1’s Complement -x: 2 n -x-1

5 5 1. Representation Id2’s comp. 1’s comp. 0015 1514 -21413 -31312 -41211 -51110 -6109 -798 -88 2’s Complement -x: 2 n -x e.g. 16-x 1’s Complement -x: 2 n -x-1 e.g. 16-x-1

6 6 1. Representation Id-Binarysign mag2’s comp1’s comp 00000100000001111 0001100111111110 -20010101011101101 -30011101111011100 -401001100 1011 -50101110110111010 -60110111010101001 -70111111110011000 -81000

7 7 Representation 1’s Complement For a negative number, we take the positive number and complement every bit. 2’s Complement For a negative number, we do 1s complement and plus one. (b n-1, b n-2, …, b 0 ): -b n-1 2 n-1 + sum i<n-1 b i 2 i

8 8 Representation 2’s Complement x+y x-y: x+2 n -y= 2 n +x-y -x+y: 2 n -x+y -x-y: 2 n -x+2 n -y = 2 n +2 n -x-y -(-x)=2 n -(2 n -x)=x 1’s Complement x+y x-y: x+2 n -y-1= 2 n -1+x-y -x+y: 2 n -x-1+y=2 n -1-x+y -x-y: 2 n -x-1+2 n -y-1 = 2 n -1+2 n -x-y-1 -(-x)=2 n -(2 n -x-1) -1=x

9 9 2 + 3 = 5 0 0 1 0 + 0 0 1 1 0 1 0 1 2 - 3 = -1 (2’s) 0 0 0 0 1 0 + 1 1 0 1 1 1 1 1 2 - 3 = -1 (1’s) 0 0 1 0 + 1 1 0 0 1 1 1 0 Examples -2 - 3 = -5 (2’s) 1 1 0 0 1 1 1 0 + 1 1 0 1 1 0 1 1 -2 - 3 = -5 (1’s) 1 1 0 0 1 1 0 1 + 1 1 0 0 1 0 0 1 1 1 0 1 0 3 + 5 = 8 0 1 1 1 0 0 1 1 + 0 1 0 1 1 0 0 0 C 4 C 3 Check for overflow (2’s) -3 + -5 = -8 1 1 1 1 0 1 + 1 0 1 1 1 0 0 0 C 4 C 3

10 10 Addition: 2’s Complement Overflow In 2’s complement: overflow = c n xor c n-1 Exercise: 1.Demonstrate the overflow with more examples. 2.Prove the condition.

11 11 Adder MUX Sum minus bb’ a C out overflow C4C4 C3C3 C in Addition and Subtraction using 2’s Complement

12 12 1-Bit Adders

13 13 a b C out S um 0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 0 S um = ab’ + a’b = a + b C out = ab C out S um abab HA a b S um C out Half Adder

14 14 Full Adder Composed of Half Adders HA a b c in x sum c out OR sum c out sum y z

15 15 Full Adder Composed of Half Adders HA a b c in x sum c out sum c out sum y z Idabc in xyzc out s um 000000000 100100001 201001001 301101110 410001001 510101110 611010010 711110011 Idxzc out 0000 1011 2101 311-

16 16 Adder Several types of carry propagate adders (CPAs) are: –Ripple-carry adders (slow) –Carry-lookahead adders (fast) –Prefix adders (faster) Carry-lookahead and prefix adders are faster for large adders but require more hardware. Symbol

17 17 Chain 1-bit adders together Carry ripples through entire chain Disadvantage: slow Ripple-Carry Adder

18 18 The delay of an N-bit ripple-carry adder is: t ripple = Nt FA where t FA is the delay of a full adder Ripple-Carry Adder Delay

19 19 Compress the logic levels of C out Some definitions: –Generate (G i ) and propagate (P i ) signals for each column: A column will generate a carry out if A i AND B i are both 1. G i = A i B i A column will propagate a carry in to the carry out if A i OR B i is 1. P i = A i + B i The carry out of a column (C i ) is: C i+1 = A i B i + (A i + B i )C i = G i + P i C i Carry-Lookahead Adder

20 20 Carry Look Ahead Adder C 1 = a 0 b 0 + (a 0 +b 0 )c 0 = g 0 + p 0 c 0 C 2 = a 1 b 1 + (a 1 +b 1 )c 1 = g 1 + p 1 c 1 = g 1 + p 1 g 0 + p 1 p 0 c 0 C 3 = a 2 b 2 + (a 2 +b 2 )c 2 = g 2 + p 2 c 2 = g 2 + p 2 g 1 + p 2 p 1 g 0 + p 2 p 1 p 0 c 0 C 4 = a 3 b 3 + (a 3 +b 3 )c 3 = g 3 + p 3 c 3 = g 3 + p 3 g 2 + p 3 p 2 g 1 + p 3 p 2 p 1 g 0 + p 3 p 2 p 1 p 0 c 0 q i = a i b i p i = a i + b i a 3 b 3 g3g3 p 3 a 2 b 2 g2g2 p 2 a 1 b 1 g1g1 p 1 a 0 b 0 g0g0 p 0 c1c1 c2c2 c3c3 c4c4 c0c0

21 21 Step 1: compute generate (G) and propagate (P) signals for columns (single bits) Step 2: compute G and P for k-bit blocks Step 3: C in propagates through each k-bit propagate/generate block Carry-Lookahead Addition

22 22 32-bit CLA with 4-bit blocks

23 23 Delay of an N-bit carry-lookahead adder with k-bit blocks: t CLA = t pg + t pg_block + (N/k – 1)t AND_OR + kt FA where –t pg : delay of the column generate and propagate gates –t pg_block :delay of the block generate and propagate gates –t AND_OR :delay from C in to C out of the final AND/OR gate in the k-bit CLA block An N-bit carry-lookahead adder is generally much faster than a ripple-carry adder for N > 16 Carry-Lookahead Adder Delay

24 24 Prefix Adder Computes the carry in (C i-1 ) for each of the columns as fast as possible and then computes the sum: S i = (A i  B i )  C i Computes G and P for 1-bit, then 2-bit blocks, then 4-bit blocks, then 8-bit blocks, etc. until the carry in (generate signal) is known for each column Has log 2 N stages

25 25 Prefix Adder A carry in is produced by being either generated in a column or propagated from a previous column. Define column -1 to hold C in, so G -1 = C in, P -1 = 0 Then, the carry in to col. i = the carry out of col. i-1: C i-1 = G i-1:-1 G i-1:-1 is the generate signal spanning columns i-1 to -1. There will be a carry out of column i-1 (C i-1 ) if the block spanning columns i-1 through -1 generates a carry. Thus, we rewrite the sum equation:S i = (A i  B i )  G i-1:-1 Goal: Compute G 0:-1, G 1:-1, G 2:-1, G 3:-1, G 4:-1, G 5:-1, … (These are called the prefixes)

26 26 Prefix Adder The generate and propagate signals for a block spanning bits i:j are: G i:j = G i:k  P i:k G k-1:j P i:j = P i:k P k-1:j In words, these prefixes describe that: –A block will generate a carry if the upper part (i:k) generates a carry or if the upper part propagates a carry generated in the lower part (k-1:j) –A block will propagate a carry if both the upper and lower parts propagate the carry.

27 27 Prefix Adder Schematic

28 28 The delay of an N-bit prefix adder is: t PA = t pg + log 2 N(t pg_prefix ) + t XOR where –t pg is the delay of the column generate and propagate gates (AND or OR gate) –t pg_prefix is the delay of the black prefix cell (AND-OR gate) Prefix Adder Delay

29 29 Compare the delay of 32-bit ripple-carry, carry- lookahead, and prefix adders. The carry-lookahead adder has 4-bit blocks. Assume that each two-input gate delay is 100 ps and the full adder delay is 300 ps. Adder Delay Comparisons

30 30 Compare the delay of 32-bit ripple-carry, carry- lookahead, and prefix adders. The carry-lookahead adder has 4-bit blocks. Assume that each two-input gate delay is 100 ps and the full adder delay is 300 ps. t ripple = Nt FA = 32(300 ps) = 9.6 ns t CLA = t pg + t pg_block + (N/k – 1)t AND_OR + kt FA = [100 + 600 + (7)200 + 4(300)] ps = 3.3 ns t PA = t pg + log 2 N(t pg_prefix ) + t XOR = [100 + log 2 32(200) + 100] ps = 1.2 ns Adder Delay Comparisons

31 31 Comparator: Equality

32 32 Comparator: Less Than For unsigned numbers

33 33 Arithmetic Logic Unit (ALU) F 2:0 Function 000A & B 001A | B 010A + B 011not used 100A & ~B 101A | ~B 110A - B 111SLT

34 34 ALU Design F 2:0 Function 000A & B 001A | B 010A + B 011not used 100A & ~B 101A | ~B 110A - B 111SLT

35 35 Set Less Than (SLT) Example Configure a 32-bit ALU for the set if less than (SLT) operation. Suppose A = 25 and B = 32.

36 36 Set Less Than (SLT) Example Configure a 32-bit ALU for the set if less than (SLT) operation. Suppose A = 25 and B = 32. –A is less than B, so we expect Y to be the 32-bit representation of 1 (0x00000001). –For SLT, F 2:0 = 111. –F 2 = 1 configures the adder unit as a subtracter. So 25 - 32 = -7. –The two’s complement representation of -7 has a 1 in the most significant bit, so S 31 = 1. –With F 1:0 = 11, the final multiplexer selects Y = S 31 (zero extended) = 0x00000001.

37 37 Shifters Logical shifter: shifts value to left or right and fills empty spaces with 0’s –Ex: 11001 >> 2 = 00110 –Ex: 11001 << 2 = 00100 Arithmetic shifter: same as logical shifter, but on right shift, fills empty spaces with the old most significant bit (msb). –Ex: 11001 >>> 2 = 11110 –Ex: 11001 <<< 2 = 00100 Rotator: rotates bits in a circle, such that bits shifted off one end are shifted into the other end –Ex: 11001 ROR 2 = 01110 –Ex: 11001 ROL 2 = 00111

38 38 Shifter Design

39 Shifter Can be implemented with a mux s d yiyi En 1 0 3 2 1 0 x i+1 x i-1 xixi s d xnxn x0x0 x -1 x n-1 y n -1 y0y0 En s / n l / r y i = x i-1 if En = 1, s = 1, and d = L = x i+1 if En = 1, s = 1, and d = R = x i if En = 1, s = 0 = 0 if En = 0

40 Barrel Shifter O or 1 shift O or 2 shift O or 4 shift x s0s0 s1s1 s2s2 y 0 1 shift

41 41 Shifters as Multipliers and Dividers A left shift by N bits multiplies a number by 2 N –Ex: 00001 << 2 = 00100 (1 × 2 2 = 4) –Ex: 11101 << 2 = 10100 (-3 × 2 2 = -12) The arithmetic right shift by N divides a number by 2 N –Ex: 01000 >>> 2 = 00010 (8 ÷ 2 2 = 2) –Ex: 10000 >>> 2 = 11100 (-16 ÷ 2 2 = -4)

42 42 Multipliers Steps of multiplication for both decimal and binary numbers: –Partial products are formed by multiplying a single digit of the multiplier with the entire multiplicand –Shifted partial products are summed to form the result

43 43 4 x 4 Multiplier

44 44 Division Algorithm Q = A/B R: remainder D: difference R = A for i = N-1 to 0 D = R - B if D < 0 then Q i = 0, R’ = R // R < B else Q i = 1, R’ = D // R  B R = 2R’

45 45 4 x 4 Divider


Download ppt "1 CS 140 Lecture 14 Standard Combinational Modules Professor CK Cheng CSE Dept. UC San Diego Some slides from Harris and Harris."

Similar presentations


Ads by Google