Computer Architecture ECE 361 Lecture 6: ALU Design
Computer Architecture ECE 361 Lecture 6: ALU Design
Computer Architecture ECE 361 Lecture 6: ALU Design
ECE 361
Lecture 6: ALU Design
361 ALU.1
Review: ALU Design
A 32 B 32
signed-arith
and cin xor co
a31 b31 a0 b0 4
ALU31 ALU0
M
co cin co cin
s31 s0
C/L to
produce
select,
comp,
Ovflw 32
S c-in
361 ALU.2
Review: Elements of the Design
Process
° Divide and Conquer (e.g., ALU)
• Formulate a solution in terms of simpler components.
• Design each of the components (subproblems)
361 ALU.3
Outline of Today’s
Lecture
° Multiply
361 ALU.4
MIPS arithmetic
° instructions
Instruction Example Meaning Comments
° add add $1,$2,$3 $1 = $2 + $3 3 operands; exception possible
° subtract sub $1,$2,$3 $1 = $2 – $3 3 operands; exception possible
° add immediate addi $1,$2,100 $1 = $2 + 100 + constant; exception possible
° add unsigned addu $1,$2,$3 $1 = $2 + $3 3 operands; no exceptions
° subtract unsigned subu $1,$2,$3 $1 = $2 – $3 3 operands; no exceptions
° add imm. unsign. addiu $1,$2,100 $1 = $2 + 100 + constant;
no exceptions
° multiply mult $2,$3 Hi, Lo = $2 x $3 64-bit signed product
° multiply unsigned multu$2,$3 Hi, Lo = $2 x $3 64-bit unsigned product
° divide div $2,$3 Lo = $2 ÷ $3, Lo = quotient, Hi = remainder
° Hi = $2 mod $3
° divide unsigned divu $2,$3 Lo = $2 ÷ $3, Unsigned quotient & remainder
° Hi = $2 mod $3
° Move from Hi mfhi $1 $1 = Hi Used to get copy of Hi
° Move from Lo mflo $1 $1 = Lo Used to get copy of Lo
361 ALU.5
MIPS logical
instructions
Instruction Example Meaning Comment
and and $1,$2,$3 $1 = $2 & $3 3 reg. operands; Logical AND
or or $1,$2,$3 $1 = $2 | $3 3 reg. operands; Logical OR
xor xor $1,$2,$3 $1 = $2 $3 3 reg. operands; Logical XOR
nor nor $1,$2,$3 $1 = ~($2 |$3) 3 reg. operands; Logical NOR
and immediate andi $1,$2,10 $1 = $2 & 10 Logical AND reg, constant
or immediate ori $1,$2,10 $1 = $2 | 10 Logical OR reg, constant
xor immediate xori $1, $2,10 $1 = ~$2 &~10 Logical XOR reg, constant
shift left logical sll $1,$2,10 $1 = $2 << 10 Shift left by constant
shift right logical srl $1,$2,10 $1 = $2 >> 10 Shift right by constant
shift right arithm. sra $1,$2,10 $1 = $2 >> 10 Shift right (sign extend)
shift left logical sllv $1,$2,$3 $1 = $2 << $3 Shift left by variable
shift right logical srlv $1,$2, $3 $1 = $2 >> $3 Shift right by variable
shift right arithm. srav $1,$2, $3 $1 = $2 >> $3 Shift right arith. by variable
361 ALU.6
Additional MIPS ALU
requirements
361 ALU.7
Add XOR to
ALU
Mux
Result
1-bit
Full
B Adder
CarryOut
361 ALU.8
Shifters
Three different kinds:
left right
msb lsb msb lsb
Note: these are single bit shifts. A given instruction might request
0 to 32 bits to be shifted!
361 ALU.9
Administrative
Matters
361 ALU.10
MULTIPLY
(unsigned)
° Paper and pencil example (unsigned):
Multiplicand 1000
Multiplier 1001
1000
0000
0000
1000
Product 01001000
361 ALU.11
Unsigned Combinational
Multiplier 0 0 0 0
A3 A2 A1 A0
B0
A3 A2 A1 A0
B1
A3 A2 A1 A0
B2
A3 A2 A1 A0
B3
P7 P6 P5 P4 P3 P2 P1 P0
° Stage i accumulates A * 2 i if Bi == 1
361 ALU.12
How does it
work? 0 0 0 0 0 0 0
A3 A2 A1 A0
B0
A3 A2 A1 A0
B1
A3 A2 A1 A0
B2
A3 A2 A1 A0
B3
P7 P6 P5 P4 P3 P2 P1 P0
361 ALU.13
Unisigned shift-add multiplier (version
1)
Shift Left
Multiplicand
64 bits
Write
Product Control
64 bits
361 ALU.14
Multiply Algorithm Version Start
1
Multiplier0 = 1 1. Test Multiplier0 = 0
Multiplier0
361 ALU.16
MULTIPLY HARDWARE Version 2
Multiplicand
32 bits
Multiplier Shift Right
32-bit ALU 32 bits
Shift Right
Product Control
64 bits Write
361 ALU.17
Multiply Algorithm Version Start
2
Multiplier Multiplicand Product
0011 0010 0000 0000
Multiplier0 = 1 1. Test Multiplier0 = 0
Multiplier0
A3 A2 A1 A0
B0
A3 A2 A1 A0
B1
A3 A2 A1 A0
B2
A3 A2 A1 A0
B3
P7 P6 P5 P4 P3 P2 P1 P0
° Multiplicand stay’s still and product moves right
361 ALU.19
Observations on Multiply Version
2
361 ALU.21
MULTIPLY HARDWARE Version 3
Multiplicand
32 bits
32-bit ALU
Shift Right
Product (Multiplier) Control
64 bits Write
361 ALU.22
Multiply Algorithm Version Start
3
Multiplicand Product
0010 0000 0011
Product0 = 1 1. Test Product0 = 0
Product0
361 ALU.24
Motivation for Booth’s
° Algorithm
Example 2 x 6 = 0010 x 0110:
0010
x 0110
+ 0000 shift (0 in multiplier)
+ 0010 add (1 in multiplier)
+ 0100 add (1 in multiplier)
+ 0000 shift (0 in multiplier)
00001100
° ALU with add or subtract gets same result in more than one way:
6 = – 2 + 8 , or
0110 = – 0010+ 1000
0010
x 0110
+ 0000 shift (0 in multiplier)
– 0010 sub (first 1 in multiplier)
+ 0000 shift (middle of string of 1s)
+ 0010 add (prior step had last 1)
00001100
361 ALU.25
Booth’s Algorithm
Insight
middle of run
end of run beginning of run
0 1 1 1 1 0
Current Bit Bit to the Right Explanation Example
Originally for Speed since shift faster than add for his machine
361 ALU.27
Booths Example (2 x
-3)
Operation Multiplicand Product next?
361 ALU.28
Booth’s
Algorithm
2.As in the previous algorithm, shift the Product register right (arith) 1 bit.
361 ALU.29
MIPS logical
instructions
° Instruction Example Meaning Comment
° and and $1,$2,$3 $1 = $2 & $3 3 reg. operands; Logical AND
° or or $1,$2,$3 $1 = $2 | $3 3 reg. operands; Logical OR
° xor xor $1,$2,$3 $1 = $2 $3 3 reg. operands; Logical XOR
° nor nor $1,$2,$3 $1 = ~($2 |$3) 3 reg. operands; Logical NOR
° and immediate andi $1,$2,10 $1 = $2 & 10 Logical AND reg, constant
° or immediate ori $1,$2,10 $1 = $2 | 10 Logical OR reg, constant
° xor immediate xori $1, $2,10 $1 = ~$2 &~10 Logical XOR reg, constant
° shift left logical sll $1,$2,10 $1 = $2 << 10 Shift left by constant
° shift right logical srl $1,$2,10 $1 = $2 >> 10 Shift right by constant
° shift right arithm. sra $1,$2,10 $1 = $2 >> 10 Shift right (sign extend)
° shift left logical sllv $1,$2,$3 $1 = $2 << $3 Shift left by variable
° shift right logical srlv $1,$2, $3 $1 = $2 >> $3 Shift right by variable
° shift right arithm. srav $1,$2, $3 $1 = $2 >> $3 Shift right arith. by variable
361 ALU.30
Shifters
Two kinds:
Note: these are single bit shifts. A given instruction might request
0 to 32 bits to be shifted!
361 ALU.31
Combinational Shifter from
MUXes
Basic Building Block A B
sel 1 0
D
8-bit right shifter
A7 A6 A5 A4 A3 A2 A1 A0 S2 S1 S0
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
R7 R6 R5 R4 R3 R2 R1 R0
S0
(0,1)
S1
(0, 2)
S2
(0, 4)
S3
(0, 8)
361 ALU.33
Summary
° There are algorithms that calculate many bits of multiply per cycle
(see exercises 4.36 to 4.39 )
361 ALU.34