32-bit ALU CSE 675.02: Introduction to Computer Architecture ALU Control 32 A Result 32 32-bit ALU Zero Arithmetic / Logic Unit – ALU Overflow Carry out 32 B Design • Our ALU should be able to perform functions: – logical and function – logical or function Presentation F – arithmetic add function – arithmetic subtract function – arithmetic slt (set-less-then) function Slides by Gojko Babi ć – logical nor function • ALU control lines define a function to be performed on A and B. 07/19/2005 g. babic Presentation F 2 Functioning of 32-bit ALU Designing 32-bit ALU: Beginning 1. Let us start with and function = 0 � and Operation ALU Control ALU Control lines 2. Let us now add or function = 1 � or 4 Ainvert Binvert Operation Function a0 0 0 00 32 and A 0 Result0 b0 Result 0 0 01 or 32 32-bit 1 ALU 0 0 10 Zero add Overflow 0 1 10 subtract Carry out a1 Result1 32 0 B b1 0 1 11 slt 1 1 1 00 nor a2 • Result lines provide result of the chosen function applied to values of Result2 0 b2 A and B 1 • Since this ALU operates on 32-bit operands, it is called 32-bit ALU • Zero output indicates if all Result lines have value 0 • Overflow indicates a sign integer overflow of add and subtract functions; for unsigned integers, this overflow indicator does not provide any useful a31 Result31 0 information b31 • Carry out indicates carry out and unsigned integer overflow 1 g. babic Presentation F 3 g. babic 4
Designing 32-bit ALU: Principles Designing Adder • 32-bit adder is built out of 32 1-bit adders • Number of functions = 0 � and Operation = 1 � or are performed inter- CarryIn nally, but only one a0 1-bit Adder Truth Table result is chosen for and 0 Result0 1-bit Adder b0 the output of ALU a or 1 Input Output Sum a b Carry Sum Carry a1 and Result1 0 In Out b Figure B.5.2 b1 • 32-bit ALU is built or 0 0 0 0 0 1 out of 32 identical 0 0 1 1 0 CarryOut 1-bit ALU’s a2 and Result2 0 CarryIn 0 1 0 1 0 b2 or 1 0 1 1 0 1 From the truth a 1 0 0 1 0 table and after minimization, we 1 0 1 0 1 can have this 1 1 0 0 1 design for CarryOut a31 and b Result31 1 1 1 1 1 0 b31 or Figure B.5.5 1 CarryOut g. babic 5 g. babic Presentation F 6 32-bit Adder 32-bit ALU With 3 Functions CarryIn =0 Operation “0” 1-bit ALU Operation a0 CarryIn a0 Cin Result0 CarryIn sum0 ALU0 + b0 b0 CarryOut Cout a This is a ripple carry adder. 0 a1 CarryIn Cin Result1 a1 ALU1 sum1 + b1 1 Result Operation = 00 � and CarryOut b1 Cout The key to speeding up addition = 01 � or is determining carry out in the = 10 � add 2 a2 CarryIn b Result2 Cin higher order bits sooner. a2 ALU2 sum2 b2 + Result: Carry look-ahead adder . CarryOut b2 Cout CarryOut Figure B.5.6 Cin a31 a31 CarryIn sum31 + Result31 ALU31 Figure B.5.7 b31 b31 Cout + carry out CarryOut Carry out g. babic Presentation F 7 g. babic Presentation F 8
32-bit Subtractor 32-bit Adder / Subtractor “1” “0” binvert “0” A – B = A + (–B) Cin a0 Result0 + Cin a0 Result0 + b0 0 = A + B + 1 Cout b0 Cout 1 Cin a1 Result1 Cin + a1 Result1 + b1 Cout b1 0 Cout 1 Cin a2 Binvert = 0 � addition Result2 + a2 Cin Result2 + = 1 � subtraction b2 Cout b2 0 Cout 1 Cin a31 Result31 + Cin a31 Result31 + b31 Cout b31 0 Cout CarryOut 1 CarryOut 0 g. babic Presentation F 9 g. babic 10 1 2’s Complement Overflow 32-bit ALU With 4 Functions 1-bit ALU Binvert Operation 1-bit ALU for the most significant bit Binvert Operation CarryIn a0 CarryIn B in v e r t O p e r a t i o n 2’s complement overflow happens: b0 ALU0 Result0 a C a r r y I n 0 • if sum of two positive numbers CarryOut results in a negative number 1 a Result 0 • if sum of two negative numbers a1 CarryIn b 0 2 results in a positive number b1 ALU1 Result1 1 1 CarryOut Figure B.5.8 R e s u lt + b 0 2 CarryOut a2 CarryIn 1 b2 ALU2 Result2 Control lines L e s s 3 CarryOut Binvert Operation Function Carry Out (1 line) (2 lines) O v e r f lo w CarryIn 0 00 O v e r f l o w and d e t e c t i o n 0 01 or a31 CarryIn Result31 b31 ALU31 0 10 add Other 1-bit ALUs, i.e. non-most significant bit ALUs, are not affected. 1 10 subtract 0 Carry Out g. babic Presentation F 11 g. babic Presentation F 12 1
32-bit ALU With 4 Functions and Overflow Set Less Than (slt) Function Binvert Operation • slt function is defined as: a0 CarryIn 000 … 001 if A < B, i.e. if A – B < 0 b0 Result0 ALU0 A slt B = CarryOut 000 … 000 if A ≥ B, i.e. if A – B ≥ 0 Control lines a1 CarryIn • Thus each 1-bit ALU should have an additional input (called Binvert Operation Function b1 ALU1 Result1 (1 line) (2 lines) CarryOut “Less”), that will provide results for slt function. This input has 0 00 and value 0 for all but 1-bit ALU for the least significant bit. 0 01 or a2 CarryIn b2 ALU2 Result2 0 10 add • For the least significant bit Less value should be sign of A – B CarryOut 1 10 subtract CarryIn a31 CarryIn Result31 b31 ALU31 Overflow Missing: slt & nor functions and Zero output Carry Out g. babic Presentation F g. babic Presentation F 14 Add correction for CarryOut 32-bit ALU With 5 Functions 32-bit ALU with 5 Functions and Zero Binvert Operation Binvert Operation Binvert CarryIn Bnegate Operation a0 CarryIn a 1-bit ALU for non- 0 b0 ALU0 Result0 a0 CarryIn most significant Less Result0 b0 ALU0 1 CarryOut bits Less CarryOut Result Control lines b 0 2 a1 CarryIn 1 b1 ALU1 Result1 a1 CarryIn Function Binvert Operation Result1 b1 0 Less ALU1 Less 3 (1 line) (2 lines) 0 Less CarryOut Zero CarryOut 0 00 and CarryOut 1-bit ALU for the Binvert Operation most significant a2 CarryIn 0 01 CarryIn or a2 CarryIn Result2 b2 ALU2 Result2 bits b2 ALU2 0 Less 0 10 add 0 Less a CarryOut 0 CarryOut 1 10 subtract 1 1 11 slt Result CarryIn + b 0 2 Result31 1 a31 CarryIn a31 Result31 CarryIn b31 ALU31 Set Less 3 Set b31 ALU31 0 Less Overflow 0 Less Overflow Set Carry Out Carry Out Overflow Overflow Carry Out detection Add correction for CarryOut g. babic Presentation F Operation = 3 and Binvert =1 for slt function Add correction for CarryOut
32-bit ALU with 6 Functions 32-bit ALU Elaboration A nor B = A and B • We have now accounted for all but one of the arithmetic and Binver t logic functions for the core MIPS instruction set. 32-bit ALU with 6 functions omits support for shift instructions. • It would be possible to widen 1-bit ALU multiplexer to include 1-bit shift left and/or 1-bit shift right. • Hardware designers created the circuit called a barrel shifter, which can shift from 1 to 31 bits in no more time than it takes to add two 32-bit numbers. Thus, shifting is normally Figure B.5.10 (Top) done outside the ALU. Function Ainvert Binvert Operation • We now consider integer multiplication (but not division). 0 0 00 and 0 0 01 or 0 0 10 add Carry Out 0 1 10 subtract Add correction for CarryOut 0 1 11 slt 1 1 00 nor Figure B.5.12 g. babic 17 g. babic Presentation F 18 + Carry Out + Binvert Multiplication Multiplication : Example • Multiplication is more complicated than addition: • The multiplication can be done with intermediate additions. – accomplished via shifting and addition • The same example: • More time and more area required multiplicand 10001 multiplier × 10011 • Let's look at 3 versions based on elementary school intermediate product 0000000000 algorithm add since multiplier bit=1 10001 • Example of unsigned multiplication: intermediate product 0000010001 5-bit multiplicand 10001 2 = 17 10 shift multiplicand and add since multiplier bit=1 10001 5-bit multiplier × 10011 2 = 19 10 intermediate product 0000110011 10001 shift multiplicand and no addition since multiplier bit=0 10001 shift multiplicand and no addition since multiplier bit=0 00000 shift multiplicand and add multiplier since bit=1 10001 00000 final result 0101000011 10001 . 101000011 2 = 323 10 • But, this algorithm is very impractical to implement in hardware g. babic Presentation F 19 g. babic Presentation F 20
Recommend
More recommend