ECE2030 Introduction To Computer Engineering Lecture 13: Building Blocks For Combinational Logic (4) Shifters, Multipliers
ECE2030 Introduction To Computer Engineering Lecture 13: Building Blocks For Combinational Logic (4) Shifters, Multipliers
Basic Shifting
Shift directions
Left (multiply by 2)
Right (divide by 2)
Take floor value if the result is not an integer
Floor value of X (or X ) is the greatest
integer number less than or equal to X, E.g.
5/2 = 2
-3/2 = -2
Shift types
Logical (or unsigned)
Arithmetic (or signed)
Logical Shift
Shift Left
MSB: Shifted out
LSB: Shifted in with a 0
Examples:
(11001011 << 1) = 10010110
(11001011 << 3) = 01011000
Shift right
MSB: Shifted in with a 0
LSB: Shifted out
Examples: (Some ISA use triple > for logical right
shift)
(11001011 >>> 1) = 01100101
(11001011 >>> 3) = 00011001
Arithmetic Shift
Shift left
MSB: Shifted out, however, be aware of
overflow/underflow
LSB: Shifted in with a 0
Examples:
(1100 << 1) = 1000
(1100 << 3) = 0000 (Incorrect!) Underflow
Shift right
MSB: Retain sign bit
LSB: Shifted out
Examples:
(1100 >> 1) = 1110 (Retain sign bit)
(1100 >> 3) = 1111 ( -4/8 = -1 ) Floor value of -0.5
1111 1101
1111 1011
1111 0110
1011 1111 (= -65) Arithmetic shift left by 1 (i.e. x2)
0111 1110 (= +126 -130) Underflow !
Overflow/Underflow
A3
S/NS
S1
L/R
S0
D3
A2
D2
A1
D1
A0
S1
S0
D3
D2
D1
D0
A3
A2
A1
A0
A3
A2
A1
A2
A1
A0
D0
D3 S1A 3 S1S0 A 2
D 2 S1A 2 S1 S0 A 3 S1S0 A1
D1 S1A1 S1 S0 A 2 S1S0 A 0
D 0 S1A 0 S1 S0 A1
A3
A2
00 01 10 11
s1
s0 4-to-1 Mux
D3
S1
S0
S1
S0
D3
D2
D1
D0
A3
A2
A1
A0
Right Shift
A3
A2
A1
Left Shift
A2
A1
A0
A1
00 01 10 11
s1
s0 4-to-1 Mux
D2
A0
00 01 10 11
s1
s0 4-to-1 Mux
D1
00 01 10 11
s1
s0 4-to-1 Mux
D0
A3
A2
00 01 10 11
s1
s0 4-to-1 Mux
D3
S1
S0
S1
S0
D3
D2
D1
D0
A3
A2
A1
A0
Right Shift
A3
A3
A2
A1
Left Shift
A2
A1
A0
A1
00 01 10 11
s1
s0 4-to-1 Mux
D2
A0
00 01 10 11
s1
s0 4-to-1 Mux
D1
00 01 10 11
s1
s0 4-to-1 Mux
D0
Overflow/
Underflow
A3
A2
00 01 10 11
s1
s0 4-to-1 Mux
D3
S1
S0
S1
S0
D3
D2
D1
D0
A3
A2
A1
A0
Right Shift
A3
A3
A2
A1
Left Shift
A2
A1
A0
A1
00 01 10 11
s1
s0 4-to-1 Mux
D2
A0
00 01 10 11
s1
s0 4-to-1 Mux
D1
00 01 10 11
s1
s0 4-to-1 Mux
D0
Overflow
Underflow Detection
A3
A2
00 01 10 11
s1
s0 4-to-1 Mux
D3
S1
S0
Overflow/
Underflow
S1
S0
D3
D2
D1
D0
A3
A2
A1
A0
Right Shift
A3
A3
A2
A1
Left Shift
A2
A1
A0
A1
00 01 10 11
s1
s0 4-to-1 Mux
D2
A0
00 01 10 11
s1
s0 4-to-1 Mux
D1
00 01 10 11
s1
s0 4-to-1 Mux
D0
Rotator
A3
D3
S0
S0
D3
D2
D1
D0
A3
A2
A1
A0
A0
A3
A2
A1
A1
A0
A3
A2
A2
A1
A0
A3
A2
00 01 10 11
s1
s0 4-to-1 Mux
S1
S1
A1
00 01 10 11
s1
s0 4-to-1 Mux
D2
A0
00 01 10 11
s1
s0 4-to-1 Mux
D1
00 01 10 11
s1
s0 4-to-1 Mux
D0
Barrel Shifter
Right Shift
Left Shift
S2
S1
S0
D3
D2
D1
D0
A3
A2
A1
A0
A3
A3
A2
A1
A3
A3
A3
A2
A3
A3
A3
A3
A3
A2
A1
A0
A2
A1
A0
A1
A0
A0
A3
00 01 10 11
s1
s0 4-to-1 Mux
2-to-1 Mux
S0
S2
0
1
S1
D3
S2
S1
S0
D
3
D
2
D
1
D
0
A3
A2
A1
A0
A3
A3
A2
A1
A3
A3
A3
A2
A3
A3
A3
A3
A3
A2
A1
A0
A2
A1
A0
A1
A0
A0
s0
s1 4-to-1 Mux
00 01 10 11
A3 A2 A1 A0
Replicate and change wiring of the two 4-to-1 Muxes for D2, D1 and
Input Number
16
S3
23 Shifter
16
S2
22 Shifter
16
S1
21 Shifter
16
S0
Left/Right
20 Shifter
16
Output Number
S=0
(No Shift)
S=1
S=2
S=3
A3
D3
S=1
A2 A2
D2
S=2
A1
D1
S=3
A0
D0
S=0
(No Shift)
S=1
S=2
S=3
= A3
D2
= A3
D1
= A2
D0
= A1
S=1
A2
S=2
A1
S=3
A0
S=0
(No Shift)
S=1
S=2
S=3
b1 a1
b1 a0 b0 a1 b0 a0
2-bit by 2-bit
x
a1
a0
b1
b0
a1 b0
a1 b1
a1 b1
carry out
a0 b1
a1 b0 a0 b1
c H.A.
a0 b0
c H.A.
p2
p1
a0 b0
carry
p3
p0
a2 b2
b2
b1
b0
a 2 b0
a1 b0
a0 b0
a 2 b1
a1 b1
a 0 b1
a1 b 2
a0 b 2
b1 a2
b1 a1 b0 a2 b1 a0 b0 a1 b0 a0
0
s
b2 a2
c
co F.A. ci
ss
co F.A. ci
ss
b2 a1
c
b2 a0
c
s
s
p5
co F.A. ci
cs
co F.A. ci
cs
p4
p3
co F.A. ci
cs
p2
co F.A. ci
p1
p0
a3 b0
a2 b0
a2 b1
a1 b0
a1 b1
a0 b1
a0 b0
a0 b0
a3 b2
a3 b3
a2 b2
a1 b2
a0 b2
a2 b3
a1 b3
a0 b3
b0 a0
A
Cout
Cin
Sum
Full Adder
P7
P6
P5
P4
P3
P2
P1
P0
Propagation Delay
a3 b0
a3 b3
P7
a2 b0
a1 b0
a3 b1
a2 b1
a1 b1
a0 b1
4+
3+
2+
a3 b2
a2 b2
a1 b2
a0 b2
6+
5+
4+
a2 b3
a1 b3
a0 b3
7+
6+
P6
P5
P4
P3
a0 b0
4x4
Delay = 8 adders
8x8
Delay = 20 adders
P2
P1
P0
Carry-Save Multiplier
a3 b0
a2 b0
a2 b1
a2 b2
a3 b3
P7
a1 b1
a3 b1
a1 b2
a0 b2
a3 b2
a1 b3
a0 b3
a2 b3
P6
P5
P4
a1 b0
a0 b1
a0 b0
0
P3
P2
P1
P0
a2 b0
a2 b1
1+
a2 b2
P7
1+
a1 b2
a0 b2
2+
2+
a3 b2
a1 b3
a0 b3
3+
3+
5+
4+
P6
P5
P4
a3 b3
a1 b1
a3 b1
a2 b3
a1 b0
a0 b1
1+
a0 b0
4x4
Delay
= 6 adders
8x8
Delay
= 14 adders
0
P3
P2
P1
P0
0011 (+3)
1110 (-2)
-------------------0 0110
00 11
-------------------01 0010
110 1
-------------------1010 (-6)