Computer Organization and Design Arithmetic & Logic Circuits Montek Singh Nov 2, 2015 Lecture 11.

Slides:



Advertisements
Similar presentations
ECE2030 Introduction to Computer Engineering Lecture 13: Building Blocks for Combinational Logic (4) Shifters, Multipliers Prof. Hsien-Hsin Sean Lee School.
Advertisements

Arithmetic for Computers
L10 – Transistors Logic Math 1 Comp 411 – Spring /22/07 Arithmetic Circuits Didn’t I learn how to do addition in the second grade?
Comparator.
EE1A2 Microprocessor Systems & Digital Logic Part I Digital Electronic System Design Dr. T. Collins.
Arithmetic Functions and Circuits
Mohamed Younis CMCS 411, Computer Architecture 1 CMCS Computer Architecture Lecture 7 Arithmetic Logic Unit February 19,
DPSD This PPT Credits to : Ms. Elakya - AP / ECE.
Computer Organization and Design Arithmetic & Logic Circuits Henry Fuchs Slides adapted from Montek Singh, who adapted them from Leonard McMillan and from.
Henry Hexmoor1 Chapter 5 Arithmetic Functions Arithmetic functions –Operate on binary vectors –Use the same subfunction in each bit position Can design.
1 CS 140 Lecture 14 Standard Combinational Modules Professor CK Cheng CSE Dept. UC San Diego Some slides from Harris and Harris.
Arithmetic II CPSC 321 E. J. Kim. Today’s Menu Arithmetic-Logic Units Logic Design Revisited Faster Addition Multiplication (if time permits)
Chapter 6 Arithmetic. Addition Carry in Carry out
L9 – Arithmetic Circuits 1 Comp 411 – Fall /14/09 Arithmetic Circuits Didn’t I learn how to do addition in the second grade?
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
Design of Arithmetic Circuits – Adders, Subtractors, BCD adders
Chapter 5 Arithmetic Logic Functions. Page 2 This Chapter..  We will be looking at multi-valued arithmetic and logic functions  Bitwise AND, OR, EXOR,
Charles Kime & Thomas Kaminski © 2008 Pearson Education, Inc. (Hyperlinks are active in View Show mode) Chapter 4 – Arithmetic Functions Logic and Computer.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Logic Circuits I.
Basic Arithmetic (adding and subtracting)
Digital Arithmetic and Arithmetic Circuits
IKI a-Combinatorial Components Bobby Nazief Semester-I The materials on these slides are adopted from those in CS231’s Lecture Notes.
Chapter 4 – Arithmetic Functions and HDLs Logic and Computer Design Fundamentals.
Chapter 6-1 ALU, Adder and Subtractor
CSE 241 Computer Organization Lecture # 9 Ch. 4 Computer Arithmetic Dr. Tamer Samy Gaafar Dept. of Computer & Systems Engineering.
Basic Arithmetic (adding and subtracting)
Advanced VLSI Design Unit 05: Datapath Units. Slide 2 Outline  Adders  Comparators  Shifters  Multi-input Adders  Multipliers.
1 Arithmetic Logic Unit ALU. 2 The Bus Concept 3 CPU Building Blocks  Registers (IR, PC, ACC)  Control Unit (CU)  Arithmetic Logic Unit (ALU)
July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 1 Part III The Arithmetic/Logic Unit.
Lecture 4 Chap 5 Types Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
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.
Ch3b- 2 EE/CS/CPE Computer Organization  Seattle Pacific University There is logic to it andRd, Rs, RtRd
1 Arithmetic I Instructor: Mozafar Bag-Mohammadi Ilam University.
COMP541 Arithmetic Circuits
Combinational Circuits
Topics covered: Arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
COMP541 Arithmetic Circuits
CS 151: Digital Design Chapter 4: Arithmetic Functions and Circuits
CPEN Digital System Design
Addition, Subtraction, Logic Operations and ALU Design
Registers and Binary Arithmetic Prof. Sirer CS 316 Cornell University.
ECE/CS 552: Arithmetic I Instructor:Mikko H Lipasti Fall 2010 University of Wisconsin-Madison Lecture notes partially based on set created by Mark Hill.
Addition and multiplication Arithmetic is the most basic thing you can do with a computer, but it’s not as easy as you might expect! These next few lectures.
ECE DIGITAL LOGIC LECTURE 15: COMBINATIONAL CIRCUITS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2015, 10/20/2015.
MicroProcessors Lec. 4 Dr. Tamer Samy Gaafar. Course Web Page —
EE204 L03-ALUHina Anwar Khan EE204 Computer Architecture Lecture 03- ALU.
President UniversityErwin SitompulDigital Systems 7/1 Lecture 7 Digital Systems Dr.-Ing. Erwin Sitompul President University
ETE 204 – Digital Electronics Combinational Logic Design Single-bit and Multiple-bit Adder Circuits [Lecture: 9] Instructor: Sajib Roy Lecturer, ETE,ULAB.
Addition and multiplication1 Arithmetic is the most basic thing you can do with a computer, but it’s not as easy as you might expect! These next few lectures.
Combinational Circuits
COMP541 Datapaths I Montek Singh Mar 28, 2012.
Addition and multiplication
Digital Systems Section 8 Multiplexers. Digital Systems Section 8 Multiplexers.
Computer Organization and Design Arithmetic & Logic Circuits
ECE/CS 552: Arithmetic and Logic
Computer Organization and Design Arithmetic & Logic Circuits
Computer Organization and Design Arithmetic & Logic Circuits
Arithmetic Circuits Didn’t I learn how
King Fahd University of Petroleum and Minerals
Computer Organization and Design Arithmetic & Logic Circuits
Digital Systems Section 12 Binary Adders. Digital Systems Section 12 Binary Adders.
Addition and multiplication
Instructor: Mozafar Bag-Mohammadi University of Ilam
Addition and multiplication
ECE 352 Digital System Fundamentals
Combinational Circuits
Computer Organization and Design Arithmetic Circuits
Arithmetic and Logic Circuits
Presentation transcript:

Computer Organization and Design Arithmetic & Logic Circuits Montek Singh Nov 2, 2015 Lecture 11

Topics  Arithmetic Circuits adder adder subtractor subtractor  Logic Circuits  Arithmetic & Logic Unit (ALU) … putting it all together … putting it all together

Review: 2’s Complement  8-bit 2’s complement example: = – = – 42  Beauty of 2’s complement representation: same binary addition procedure will work for adding both signed and unsigned numbers same binary addition procedure will work for adding both signed and unsigned numbers  as long as the leftmost carry out is properly handled/ignored  Insert a “binary” point to represent fractions too: = – = – … 2 N-2 -2 N-1 …… N bits “sign bit”“binary” point Range: – 2 N-1 to 2 N-1 – 1

Binary Addition  Example of binary addition “by hand”:  Let’s design a circuit to do it! Start by building a block that adds one column: Start by building a block that adds one column:  called a “full adder” (FA) Then cascade them to add two numbers of any size… Then cascade them to add two numbers of any size… A: 1101 B: Carries from previous column Adding two N-bit numbers produces an (N+1)-bit result A B CO CI S FA A3 B3 A2 B2 A1 B1 A0 B0 S4 S3 S2 S1 S0 A B CO CI S FA A B CO CI S FA A B CO CI S FA A B CO CI S FA 4-bit adder

Binary Addition  Extend to arbitrary # of bits n bits: cascade n full adders n bits: cascade n full adders Called “Ripple-Carry Adder” Called “Ripple-Carry Adder”  carries ripple through from right to left  longest chain of carries has length n –how long does it take to add the numbers 0 and 1? –how long does it take to add the numbers -1 and 1? A n-1 B n-1 A 2 B 2 A 1 B 1 A 0 B 0 S n S n-1 S 2 S 1 S 0 A B CO CI S FA A B CO CI S FA A B CO CI S FA A B CO CI S FA

Designing a Full Adder (1-bit adder)  Follow the step-by-step method 1. Start with a truth table: 2. Write down eqns for the “1” outputs: 3. Simplifying a bit (seems hard, but experienced designers are good at this art!)

For Those Who Prefer Logic Diagrams  A little tricky, but only 5 gates/bit! CiCi A B S CoCo “Sum” Logic “Carry” Logic

Subtraction: A-B = A + (-B)  Subtract B from A = add 2’s complement of B to A In 2’s complement: –B = ~B + 1 In 2’s complement: –B = ~B + 1 Let’s build an arithmetic unit that does both add and sub Let’s build an arithmetic unit that does both add and sub  operation selected by control input: But what about the “+1”? A B CO CI S FA A B CO CI S FA A B CO CI S FA A B CO CI S FA A3 A2 A1 A0 S4 S3 S0 S1 S0 B3 B2 B1 B0 Subtract ~ = bit-wise complement B0B0 B B1B1 B

Condition Codes  One often wants 4 other bits of information from an arith unit: Z (zero): result is = 0 Z (zero): result is = 0  big NOR gate N (negative): result is < 0 N (negative): result is < 0  S N-1 C (carry): indicates that most significant position produced a carry, e.g., “1 + (-1)” C (carry): indicates that most significant position produced a carry, e.g., “1 + (-1)”  Carry from last FA V (overflow): indicates answer doesn’t fit V (overflow): indicates answer doesn’t fit  precisely: To compare A and B, perform A–B and use condition codes: Signed comparison: EQ == Z NE != ~Z LT < N  V LE <= Z+(N  V) GE >= ~(N  V) GT > ~(Z+(N  V)) Unsigned comparison: EQ == Z NE != ~Z LTU < ~C LEU = C GTU > ~(~C+Z) To compare A and B, perform A–B and use condition codes: Signed comparison: EQ == Z NE != ~Z LT < N  V LE <= Z+(N  V) GE >= ~(N  V) GT > ~(Z+(N  V)) Unsigned comparison: EQ == Z NE != ~Z LTU < ~C LEU = C GTU > ~(~C+Z) -or-

Condition Codes  Subtraction is useful also for comparing numbers  To compare A and B: First compute A – B First compute A – B Then check the flags Z, N, C, V Then check the flags Z, N, C, V  Examples: LTU (less than for unsigned numbers) LTU (less than for unsigned numbers)  A < B is given by ~C LT (less than for signed numbers) LT (less than for signed numbers)  A < B is given by N  V Others in table Others in table To compare A and B, perform A–B and use condition codes: Signed comparison: EQ == Z NE != ~Z LT < N  V LE <= Z+(N  V) GE >= ~(N  V) GT > ~(Z+(N  V)) Unsigned comparison: EQ == Z NE != ~Z LTU < ~C LEU = C GTU > ~(~C+Z) To compare A and B, perform A–B and use condition codes: Signed comparison: EQ == Z NE != ~Z LT < N  V LE <= Z+(N  V) GE >= ~(N  V) GT > ~(Z+(N  V)) Unsigned comparison: EQ == Z NE != ~Z LTU < ~C LEU = C GTU > ~(~C+Z)

Latency of Ripple-Carry Adder Worse-case path: carry propagation from LSB to MSB, e.g., when adding 11…111 to 00…001. t PD = (t PD,XOR +t PD,AND + t PD,OR ) +(N-2)*(t PD,OR + t PD,AND ) + t PD,XOR   (N) CI to CO CI N-1 to S N-1  (N) is read “order N” and tells us that the latency of our adder grows in proportion to the number of bits in the operands. A B CO CI S FA A B CO CI S FA A B CO CI S FA A n-1 B n-1 A n-2 B n-2 A 2 B 2 A 1 B 1 A 0 B 0 S n-1 S n-2 S 2 S 1 S 0 A B CO CI S FA A B CO CI S FA C … CI A B S CO A,B to CO (T PD = max propagation delay or latency of the entire adder)

Can we add faster?  Yes, there are many sophisticated designs that are faster… Carry-Lookahead Adders (CLA) Carry-Lookahead Adders (CLA) Carry-Skip Adders Carry-Skip Adders Carry-Select Adders Carry-Select Adders  See textbook for details

Adder Summary  Adding is not only common, but it is also tends to be one of the most time-critical of operations As a result, a wide range of adder architectures have been developed that allow a designer to tradeoff complexity (in terms of the number of gates) for performance. As a result, a wide range of adder architectures have been developed that allow a designer to tradeoff complexity (in terms of the number of gates) for performance. Ripple Carry Carry Skip Carry Select Carry Lookahead Smaller / SlowerBigger / Faster Add AB S Add/Sub AB S sub At this point we’ll define a high-level functional unit for an adder, and specify the details of the implementation as necessary.

Shifting and Logical Operations

Shifting Logic  Shifting is useful for logic operations applied to groups of bits applied to groups of bits used for alignment used for alignment  Shifting also used for “short cut” arithmetic operations shift left logical (sll) shift left logical (sll)  X << 1 is the same as 2*X (unless result overflows) shift right logical (srl) shift right logical (srl)  X >> 1 is the same as X/2 for unsigned numbers shift right arithmetic (sra) shift right arithmetic (sra)  like a right shift, but maintains the sign bit  makes the sign bit “sticky”  X >>> 1 is the same as X/2 for 2’s-compl. numbers

Shifting Logic  Examples: X = = X = = Left Shift: shifts in a 0 from the right end Left Shift: shifts in a 0 from the right end  (X << 1) = = Right Shift: shifts in a 0 from the left end Right Shift: shifts in a 0 from the left end  (X >> 1) = = Signed or “Arithmetic” Right Shift: maintains the sign bit Signed or “Arithmetic” Right Shift: maintains the sign bit  -X = = 2’s complement of X =  ( >>> 1) = ( >>> 1) = =

Shifting Logic: Other shift amounts  Circuit for shifting left by 1 if SLL1 is true if SLL1 is true  shifts the input X: R  X << 1 if SLL1 is false if SLL1 is false  does not shift X: R  X  Other shift amounts shift left by 2 shift left by 2  rewire the multiplexors so each X i feeds into R i+2 similarly: shift left by 4, etc. similarly: shift left by 4, etc. also: srl and sra have similar circuitry also: srl and sra have similar circuitry  srl: each X i feeds into a lower numbered R j  sra: sign bit stays the same R7R6R5R4R3R2R1R0R7R6R5R4R3R2R1R0 X7X6X5X4X3X2X1X0X7X6X5X4X3X2X1X0 “0”“0” SLL1

Shifting Logic: Other shift amounts  Circuit for shifting left by any amount make blocks for SLL1, SLL2, SLL4, SLL8, SLL16 make blocks for SLL1, SLL2, SLL4, SLL8, SLL16 then, any arbitrary shift amount can be made by combining these shifts then, any arbitrary shift amount can be made by combining these shifts example: SLL 13 = SLL ( ) example: SLL 13 = SLL ( ) shift left by 16 SLL16 shift left by 8 SLL8 shift left by 4 SLL4 shift left by 2 SLL2 shift left by 1 SLL = in binary! shift amount

Boolean Operations  It will also be useful to perform logical operations on groups of bits. Which ones? ANDing is useful for “masking” off groups of bits. ANDing is useful for “masking” off groups of bits.  ex & = (mask selects last 4 bits) ANDing is also useful for “clearing” groups of bits. ANDing is also useful for “clearing” groups of bits.  ex & = (0’s clear first 4 bits) ORing is useful for “setting” groups of bits. ORing is useful for “setting” groups of bits.  ex | = (1’s set last 4 bits) XORing is useful for “complementing” groups of bits. XORing is useful for “complementing” groups of bits.  ex ^ = (1’s invert last 4 bits) NORing is useful for.. uhm… NORing is useful for.. uhm…  ex # = (0’s invert, 1’s clear)

Boolean Unit  It is simple to build up a Boolean unit using primitive gates and a mux to select the function. Since there is no interconnection between bits, this unit can be simply replicated at each position. Since there is no interconnection between bits, this unit can be simply replicated at each position. The cost is about 7 gates per bit. One for each primitive function, and approx 3 for the 4-input mux. The cost is about 7 gates per bit. One for each primitive function, and approx 3 for the 4-input mux.  This is a straightforward, but not too elegant of a design. AiAi BiBi QiQi Bool This logic block is repeated for each bit (i.e. 32 times) 2

 Combine add/sub, shift and Boolean units Bool 2-bit used for shifter flavor also A shift amount that B is shifted Flags N,V,C AB Result Bidirectional Shifter Boolean Add/Sub Sub Bool Shft Math 1 0 Z Flag Sub Bool Shft Math OP 0 XX 0 1 A+B 1 XX 0 1 A-B X B >A X B>>>A X A & B X A | B X A ^ B X A | B 5-bit ALUFN An ALU, at last (without comparisons)

 With support for comparisons (LT and LTU) LTU = ~C and LT = N  V LTU = ~C and LT = N  V Sub Bool Shft Math OP 0 XX 0 1 A+B 1 XX 0 1 A-B 1 X0 1 1 A LT B 1 X1 1 1 A LTU B X B >A X B>>>A X A & B X A | B X A ^ B X A | B 5-bit ALUFN AB Result Bidirectional Shifter Boolean Add/Sub Sub Bool Shft Math 1 0 Z Flag Flags N,V,C Bool <? A Complete ALU

Next  Circuits for Multiplication Multiplication Division Division Floating-Point Operations Floating-Point Operations