07/19/2005 Arithmetic / Logic Unit – ALU Design Presentation F CSE 675.02: Introduction to Computer Architecture Slides by Gojko Babić.

Slides:



Advertisements
Similar presentations
Mohamed Younis CMCS 411, Computer Architecture 1 CMCS Computer Architecture Lecture 7 Arithmetic Logic Unit February 19,
Advertisements

1 CONSTRUCTING AN ARITHMETIC LOGIC UNIT CHAPTER 4: PART II.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
Chapter 3 Arithmetic for Computers. Multiplication More complicated than addition accomplished via shifting and addition More time and more area Let's.
Arithmetic II CPSC 321 E. J. Kim. Today’s Menu Arithmetic-Logic Units Logic Design Revisited Faster Addition Multiplication (if time permits)
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
1 Chapter 4: Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture Assembly Language and.
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
Chapter Four Arithmetic and Logic Unit
Arithmetic-Logic Units CPSC 321 Computer Architecture Andreas Klappenecker.
1 ECE369 Chapter 3. 2 ECE369 Multiplication More complicated than addition –Accomplished via shifting and addition More time and more area.
1  1998 Morgan Kaufmann Publishers Chapter Four Arithmetic for Computers.
COE 308: Computer Architecture (T041) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (Appendix A, Computer Architecture: A Quantitative Approach,
Chapter 3 Arithmetic for Computers. Arithmetic Where we've been: Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's.
Simple Data Type Representation and conversion of numbers
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
Computer Arithmetic Nizamettin AYDIN
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
Computer Architecture Lecture 3: Logical circuits, computer arithmetics Piotr Bilski.
Computing Systems Basic arithmetic for computers.
ECE232: Hardware Organization and Design
Number Systems and Arithmetic or Computers go to elementary school Reading – Peer Instruction Lecture Materials for Computer Architecture by Dr.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
1 EGRE 426 Fall 08 Chapter Three. 2 Arithmetic What's up ahead: –Implementing the Architecture 32 operation result a b ALU.
1  1998 Morgan Kaufmann Publishers Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture.
Computing Systems Designing a basic ALU.
Conversion to Larger Number of Bits Ex: Immediate Field (signed 16 bit) to 32 bit Positive numbers have implied 0’s to the left. So, put 16 bit number.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
1 Lecture 6 BOOLEAN ALGEBRA and GATES Building a 32 bit processor PH 3: B.1-B.5.
CDA 3101 Fall 2013 Introduction to Computer Organization The Arithmetic Logic Unit (ALU) and MIPS ALU Support 20 September 2013.
Lecture 18: Hardware for Arithmetic Today’s topic –Intro to Boolean functions (Continued) –Designing an ALU 1.
Computer Arithmetic See Stallings Chapter 9 Sep 10, 2009
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
1  2004 Morgan Kaufmann Publishers Performance is specific to a particular program/s –Total execution time is a consistent summary of performance For.
1 ELEN 033 Lecture 4 Chapter 4 of Text (COD2E) Chapters 3 and 4 of Goodman and Miller book.
Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture Arithmetic: Part II.
1  2004 Morgan Kaufmann Publishers Lets Build a Processor Almost ready to move into chapter 5 and start building a processor First, let’s review Boolean.
Computer Architecture Lecture Notes Spring 2005 Dr. Michael P. Frank Competency Area 4: Computer Arithmetic.
순천향대학교 정보기술공학부 이 상 정 1 3. Arithmetic for Computers.
Prof. Hsien-Hsin Sean Lee
Arithmetic-Logic Units. Logic Gates AND gate OR gate NOT gate.
1 Arithmetic Where we've been: –Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's up ahead: –Implementing the Architecture.
Computer Arthmetic Chapter Four P&H. Data Representation Why do we not encode numbers as strings of ASCII digits inside computers? What is overflow when.
9/23/2004Comp 120 Fall September Chapter 4 – Arithmetic and its implementation Assignments 5,6 and 7 posted to the class web page.
EE204 L03-ALUHina Anwar Khan EE204 Computer Architecture Lecture 03- ALU.
By Wannarat Computer System Design Lecture 3 Wannarat Suntiamorntut.
1 CPTR 220 Computer Organization Computer Architecture Assembly Programming.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
William Stallings Computer Organization and Architecture 8th Edition
Computer System Design Lecture 3
Computer Arthmetic Chapter Four P&H.
William Stallings Computer Organization and Architecture 7th Edition
Arithmetic Where we've been:
Arithmetic Logical Unit
How to represent real numbers
Computer Arithmetic Multiplication, Floating Point
ECEG-3202 Computer Architecture and Organization
Presentation transcript:

07/19/2005 Arithmetic / Logic Unit – ALU Design Presentation F CSE : Introduction to Computer Architecture Slides by Gojko Babić

g. babicPresentation F2 ALU Control 32 Result A B 32-bit ALU Our ALU should be able to perform functions: – logical and function – logical or function – arithmetic add function – arithmetic subtract function – arithmetic slt (set-less-then) function – logical nor function ALU control lines define a function to be performed on A and B. 32-bit ALU Zero Overflow Carry out

g. babicPresentation F3 Functioning of 32-bit ALU ALU Control 32 Result A B 32-bit ALU Zero Overflow Carry out ALU Control lines Result lines provide result of the chosen function applied to values of A and B 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 information Carry out indicates carry out and unsigned integer overflow 4 Function AinvertBinvertOperation and0000 or0001 add0010 subtract0110 slt0111 nor1100

g. babic4 Designing 32-bit ALU: Beginning a0 b0 a1 b1 a2 b2 a31 b31 Result0 Result1 Result2 Result31 1.Let us start with and function 2.Let us now add or function Operation = 0  and = 1  or

g. babic5 Designing 32-bit ALU: Principles a0 b0 a1 b1 a2 b2 a31 b31 Result0 Result1 Result2 Result Operation Number of functions are performed inter- nally, but only one result is chosen for the output of ALU 32-bit ALU is built out of 32 identical 1-bit ALU’s and or and or and or and or = 0  and = 1  or

g. babicPresentation F6 Designing Adder abCarry In SumCarry Out bit adder is built out of 32 1-bit adders Input Output Figure B.5.2 Figure B bit Adder Truth Table 1-bit Adder From the truth table and after minimization, we can have this design for CarryOut

g. babicPresentation F7 32-bit Adder a0 b0 a2 b2 a1 b1 a31 b31 sum0 sum31 sum2 sum1 Cout Cin Cout Cin “0” This is a ripple carry adder. The key to speeding up addition is determining carry out in the higher order bits sooner. Result: Carry look-ahead adder. Carry out

g. babicPresentation F8 32-bit ALU With 3 Functions 1-bit ALU CarryOut =0 Operation = 00  and = 01  or = 10  add Figure B.5.6 Figure B carry out

g. babicPresentation F9 32-bit Subtractor “0” a31 b a0 b0 a2 b2 a1 b1 Result0 Result31 Result2 Result1 Cout Cin Cout Cin CarryOut “1” A – B = A + (–B) = A + B + 1

g. babic10 32-bit Adder / Subtractor “0” a31 b a0 b0 a2 b2 a1 b1 Result0 Result31 Result2 Result1 Cout Cin Cout Cin CarryOut binvert Binvert = 0  addition = 1  subtraction 0101

g. babicPresentation F11 32-bit ALU With 4 Functions Function Binvert (1 line) Operation (2 lines) and000 or001 add010 subtract110 Control lines 1-bit ALU 0 2 Result Operation a 1 CarryIn CarryOut 0 1 Binvert b Figure B

g. babicPresentation F12 2’s Complement Overflow 1-bit ALU for the most significant bit Other 1-bit ALUs, i.e. non-most significant bit ALUs, are not affected. 2’s complement overflow happens: if sum of two positive numbers results in a negative number if sum of two negative numbers results in a positive number

g. babicPresentation F 32-bit ALU With 4 Functions and Overflow Function Binvert (1 line) Operation (2 lines) and000 or001 add010 subtract110 Control lines Missing: slt & nor functions and Zero output Add correction for CarryOut

g. babicPresentation F14 slt function is defined as: 000 … 001 if A < B, i.e. if A – B < 0 A slt B = 000 … 000 if A ≥ B, i.e. if A – B ≥ 0 Thus each 1-bit ALU should have an additional input (called “Less”), that will provide results for slt function. This input has value 0 for all but 1-bit ALU for the least significant bit. For the least significant bit Less value should be sign of A – B Set Less Than (slt) Function

0 3 Result Operation a 1 CarryIn CarryOut 0 1 Binvert b 2 Less 32-bit ALU With 5 Functions 1-bit ALU for non- most significant bits Operation = 3 and Binvert =1 for slt function Add correction for CarryOut

g. babicPresentation F 32-bit ALU with 5 Functions and Zero Function Binvert (1 line) Operation (2 lines) and000 or001 add010 subtract110 slt111 Control lines Carry Out Binvert Add correction for CarryOut

g. babic17 32-bit ALU with 6 Functions A nor B = A and B Figure B.5.10 (Top) Carry Out Function AinvertBinvertOperation and0000 or0001 add0010 subtract0110 slt0111 nor1100 Figure B Carry Out + Binvert Binver t Add correction for CarryOut

g. babicPresentation F18 We have now accounted for all but one of the arithmetic and 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 done outside the ALU. We now consider integer multiplication (but not division). 32-bit ALU Elaboration

g. babicPresentation F19 Multiplication is more complicated than addition: –accomplished via shifting and addition More time and more area required Let's look at 3 versions based on elementary school algorithm Example of unsigned multiplication: 5-bit multiplicand = bit multiplier × = = But, this algorithm is very impractical to implement in hardware Multiplication

g. babicPresentation F20 The multiplication can be done with intermediate additions. The same example: multiplicand multiplier × intermediate product add since multiplier bit= intermediate product shift multiplicand and add since multiplier bit= intermediate product shift multiplicand and no addition since multiplier bit=0 shift multiplicand and add multiplier since bit= final result Multiplication : Example

g. babicPresentation F21 Multiplication Hardware: 1 st Version Figure 3.5 Figure 3.6

g. babicPresentation F22 Multiplication Hardware: 2 nd Version

g. babicPresentation F23 Control test Write 32 bits 64 bits Shift right Product Multiplicand 32-bit ALU Done 1. Test Product0 1a. Add multiplicand to the left half of the product and place the result in the left half of the Product register 2. Shift the Product register right 1 bit 32nd repetition? Start Product0 = 0Product0 = 1 No: < 32 repetitions Yes: 32 repetitions Multiplication Hardware: 3 rd Version Figure 3.7

g. babicPresentation F24 A simple algorithm: –Convert to positive integer any of operands (if needed) and remember original signs –Perform multiplication of unsigned numbers using the existing algorithm and hardware –Negate product if original signs disagree This algorithm is not simple to implement in hardware, since it has to: –account in advance about signs, –if needed, convert from negative to positive numbers, –if needed, convert back to negative integer at the end Fast multiplication algorithms. Multiplication of Signed Integers

g. babicPresentation F25 Conversion from real binary to real decimal – = – since: = = and = = = Conversion from real decimal to real binary: = ….. 927/2 = ½  LSB 0.45 × 2 = /2 = ½ 0.9 × 2 = /2 = ½ 0.8 × 2 = /2 = 57 + ½ 0.6 × 2 = /2 = 28 + ½ 0.2 × 2 = /2 = × 2 = /2 = × 2 = 1.6 7/2 = 3 + ½ 0.6 × 2 = 1.2 3/2 = 1 + ½ 0.2 × 2 = 0.4 1/2 = 0 + ½ 0.4 × 2 = 0.8 …… Real Numbers

g. babicPresentation F26 The term floating point number refers to representation of real binary numbers in computers. IEEE 754 standard defines standards for floating point representations Single precision: Floating Point Number Formats s E Fraction Double precision: s E Fraction 31 0 Fraction

g. babicPresentation F27 1. Normalize binary real number i.e. put it into the normalized form: (-1) s × 1.Fraction * 2 Exp = (-1) 1 × * = (-1) 0 × * Load fields of single or double precision format with values from normalized form, but with the adjustment for E field. E = Exp = Exp for single precision E = Exp = Exp for double precision E is called a biased exponent. Converting to Floating Point

g. babicPresentation F28 Find single and double precision of – Normalized form: (-1) 1 × × 2 3 –single precision: E = = |1| | | –double precision E = = |1| | | | | Floating Point: Example 1

g. babicPresentation F29 Find single and double precision of Normalized form: (-1) 0 × * 2 9 –single precision E = = |0| | | truncation |0| | | rounding |0| | | –double precision E = = |0| | | | | … truncation | | rounding | | Floating Point: Example 2

g. babicPresentation F30 Rules for biased exponents in single precision apply only for real exponents in the range [-126,127], thus we can have biased exponents only in the range [1,254]. The number 0.0 is represented as S=0, E=0 and Fraction=0. The infinite number is represented with E=255. There are some additional rules that are outside our scope. Find the largest (non-infinite) real binary number (by magnitude) which can be represented in a single precision. –Floating point overflow Find the smallest (non-zero) real binary number (by magnitude) which can be represented in a single precision. –Floating point underflow Converting to Floating Point: Conclusion

g. babicPresentation F31 Floating Point Addition Figure 3.16

g. babicPresentation F32 Arithmetic Unit for Floating Point Addition Figure 3.17

Conclusion We can build an ALU to support the MIPS instruction set –key idea: use multiplexor to select the output we want –we can efficiently perform subtraction using two’s complement –we can replicate a 1-bit ALU to produce a 32-bit ALU Important points about hardware –all of the gates are always working –the speed of a gate is affected by the number of inputs to the gate –the speed of a circuit is affected by the number of gates in series (on the “critical path” or the “deepest level of logic”) Our primary focus: comprehension, however, –Clever changes to organization can improve performance (similar to using better algorithms in software) –We saw this in multiplication, let’s look at addition now