Computer Architecture: A Constructive Approach Combinational ALU Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.

Slides:



Advertisements
Similar presentations
INSTRUCTION SET ARCHITECTURES
Advertisements

1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
Combinational Circuits in Bluespec
Snick  snack A Working Computer Slides based on work by Bob Woodham and others.
Lec 17 Nov 2 Chapter 4 – CPU design data path design control logic design single-cycle CPU performance limitations of single cycle CPU multi-cycle CPU.
Chapter 10-Arithmetic-logic units
Chapter 4 Processor Technology and Architecture. Chapter goals Describe CPU instruction and execution cycles Explain how primitive CPU instructions are.
The Processor Data Path & Control Chapter 5 Part 1 - Introduction and Single Clock Cycle Design N. Guydosh 2/29/04.
1 CHAPTER 4: PART I ARITHMETIC FOR COMPUTERS. 2 The MIPS ALU We’ll be working with the MIPS instruction set architecture –similar to other architectures.
CS 1308 – Computer Literacy and the Internet. It’s Not Magic  The goal of the next series of lectures is to show you exactly how a computer works. 
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Logic Circuits I.
Computer Architecture: A Constructive Approach Sequential Circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
CS1Q Computer Systems Lecture 9 Simon Gay. Lecture 9CS1Q Computer Systems - Simon Gay2 Addition We want to be able to do arithmetic on computers and therefore.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
HCL and ALU תרגול 10. Overview of Logic Design Fundamental Hardware Requirements – Communication: How to get values from one place to another – Computation.
COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections
Chapter 4 CSF 2009 The processor: Building the datapath.
1 CS232: Computer Architecture II Fall 2011 Intel i7 Quad-core.
Constructive Computer Architecture Combinational circuits-2 Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Lec 15Systems Architecture1 Systems Architecture Lecture 15: A Simple Implementation of MIPS Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Computer Organization CS224 Fall 2012 Lesson 22. The Big Picture  The Five Classic Components of a Computer  Chapter 4 Topic: Processor Design Control.
CDA 3101 Fall 2013 Introduction to Computer Organization The Arithmetic Logic Unit (ALU) and MIPS ALU Support 20 September 2013.
ECE 445 – Computer Organization
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /19/2013 Lecture 17: The Processor - Overview Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
Discussed in class and on Fridays n FSMs (only synchronous, with asynchronous reset) –Moore –Mealy –Rabin-Scott n Generalized register: –With D FFs, –With.
Constructive Computer Architecture Combinational circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
IT253: Computer Organization
CS 1308 – Computer Literacy and the Internet Building the CPU.
1 A single-cycle MIPS processor  An instruction set architecture is an interface that defines the hardware operations which are available to software.
MIPS ALU. Building from the adder to ALU ALU – Arithmetic Logic Unit, does the major calculations in the computer, including – Add – And – Or – Sub –
ALU (Continued) Computer Architecture (Fall 2006).
6.S078 - Computer Architecture: A Constructive Approach Combinational circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute.
Computer Architecture Lecture 9 MIPS ALU and Data Paths Ralph Grishman Oct NYU.
Arithmetic-logic units1 An arithmetic-logic unit, or ALU, performs many different arithmetic and logic operations. The ALU is the “heart” of a processor—you.
Verilog hdl – II.
Constructive Computer Architecture Combinational circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
1 CS232: Computer Architecture II Fall 2010 AMD dual-core Opteron.
Introduction to Verilog. Data Types A wire specifies a combinational signal. – Think of it as an actual wire. A reg (register) holds a value. – A reg.
CPU Overview Computer Organization II 1 February 2009 © McQuain & Ribbens Introduction CPU performance factors – Instruction count n Determined.
Simple ALU How to perform this C language integer operation in the computer C=A+B; ? The arithmetic/logic unit (ALU) of a processor performs integer arithmetic.
Elements of Datapath for the fetch and increment The first element we need: a memory unit to store the instructions of a program and supply instructions.
MIPS ALU. Exercise – Design a selector? I need a circuit that takes two input bits, a and b, and a selector bit s. The function is that if s=0, f=a. if.
Logic Gates Dr.Ahmed Bayoumi Dr.Shady Elmashad. Objectives  Identify the basic gates and describe the behavior of each  Combine basic gates into circuits.
Computer Architecture: A Constructive Approach Combinational circuits Teacher: Yoav Etsion Teaching Assistant: Yuval H. Nacson Taken (with permission)
Multiple Clock Domains (MCD) Arvind with Nirav Dave Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology.
Combinational Circuits
Sequential Circuits - 2 Constructive Computer Architecture Arvind
COMP541 Datapaths I Montek Singh Mar 28, 2012.
Introduction CPU performance factors
Combinational ALU Constructive Computer Architecture Arvind
Morgan Kaufmann Publishers
Combinational circuits-2
Combinational Circuits in Bluespec
Behavioral Modeling in Verilog
Combinational circuits
Computer Organization and Design Arithmetic & Logic Circuits
BSV objects and a tour of known BSV problems
Combinational circuits
Computer Organization and Design Arithmetic & Logic Circuits
Combinational circuits
Chapter 8 Central Processing Unit
Sequential Circuits - 2 Constructive Computer Architecture Arvind
Morgan Kaufmann Publishers The Processor
Unit 10 Arithmetic-logic Units
Combinational Circuits
ECE 352 Digital System Fundamentals
Combinational ALU 6.S078 - Computer Architecture:
Presentation transcript:

Computer Architecture: A Constructive Approach Combinational ALU Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology January 9, 2012L1-1

Computing Devices Then… EDSAC, University of Cambridge, UK, 1949 January 9, 2012 L01-2

Computing Devices Now Dramatic progress in terms of size, speed, cost, reliability January 9, 2012 L01-3

How does a program execute on hardware A C program to add two arrays: The hardware must know, for example, How to add and compare two numbers Must have a place to keep the program and data Must know how to fetch instructions and data Must know how to sequence instructions:  Fetch a[i], Fetch b[i], add, store results in c[i], increment i, … January 9, 2012 L1-4http://csg.csail.mit.edu/SNU void vvadd( int n, int a[], int b[], int c[] ) { int i; for ( i = 0; i < n; i++ ) c[i] = a[i] + b[i]; } Computer Architecture is learning about how programs execute and designing hardware to execute them efficiently

Instruction Set Architecture (ISA) Computer architecture is the discipline of designing and implementing interfaces through which hardware and software interact This interface is often referred to as the Instruction Set Architecture (ISA) Examples: Intel’s IA-32, ARM, ARM-Thumb, PowerPC In this class we will use SMIPS, a subset of MIPS ISA Implementations are deeply affected by the technology issues; we will assume a simple and abstract model of technology based on Silicon January 9, 2012 L1-5http://csg.csail.mit.edu/SNU

Goal of the Intensive Course Learn a constructive approach to studying computer architecture Learn a new method of describing architectures where there is less emphasis on figures/diagrams and more emphasis on executable descriptions Each architecture and each part of it would be defined as executable code in Bluespec By this Friday you will have designed several different computers on which you will be able to execute your C programs January 9, 2012 L1-6http://csg.csail.mit.edu/SNU

In this lecture we will study how to implement simple arithmetic-logic operations we will first look at circuits for component functions such as Add, Shift and then put them together to form an Arithmetic-Logic Unit (ALU) January 9, 2012L1-7

Arithmetic-Logic Unit (ALU) Computers have many important interconnected parts or subsystems: Central Processing Unit Memory system including caches I/O systems ALU resides inside the CPU and carried out all the arithmetic and logical functions Op - Add, Sub,... - And, Or, Xor, Not,... - GT, LT, EQ, Zero,...  Result Comp? A B ALU January 9, 2012 L1-8http://csg.csail.mit.edu/SNU

Full Adder: A one-bit adder function fa(a, b, c_in); s = (a ^ b)^ c_in; c_out = (a & b) | (c_in & (a ^ b)); return {c_out,s}; endfunction Not quite correct – needs type annotations January 9, 2012 L1-9http://csg.csail.mit.edu/SNU

Full Adder: A one-bit adder corrected function Bit#(2) fa(Bit#(1) a, Bit#(1) b, Bit#(1) c_in); Bit#(1) s = (a ^ b)^ c_in; Bit#(1) c_out = (a & b) | (c_in & (a ^ b)); return {c_out,s}; endfunction Bit#(1) a declaration says that a is one bit wide {c_out,s} represents bit concatenation How big is {c_out,s} ? January 9, 2012 L1-10http://csg.csail.mit.edu/SNU

Types Every expression and variable in a Bluespec program has a type; sometimes it is specified explicitly and sometimes it is deduced by the compiler A type is a grouping of values: Integer: 1, 2, 3, … Bool: True, False Bit : 0,1 A pair of Integers: Tuple2#(Integer, Integer) A function fname from Integers to Integers: function Integer fname (Integer arg) Thus we say an expression has a type, belongs to a type January 9, 2012 L1-11http://csg.csail.mit.edu/SNU The type of each expression is unique

Type declaration versus deduction User writes down types of some expressions in a program and the compiler deduces the types of the rest of expressions If the type deduction cannot be performed or the type declarations are inconsistent then the compiler complains function Bit#(2) fa(Bit#(1) a, Bit#(1) b, Bit#(1) c_in); Bit#(1) s = (a ^ b)^ c_in; Bit#(2) c_out = (a & b) | (c_in & (a ^ b)); return {c_out,s}; endfunction type error January 9, 2012 L1-12http://csg.csail.mit.edu/SNU Type checking prevents lots of silly mistakes

2-bit Ripple-Carry Adder function Bit#(3) add(Bit#(2) x, Bit#(2) y, Bit#(1) c0); Bit#(2) s = 0; Bit#(3) c; c[0] = c0; let cs0 = fa(x[0], y[0], c[0]); c[1] = cs0[1]; s[0] = cs0[0]; let cs1 = fa(x[1], y[1], c[1]); c[2] = cs1[1]; s[1] = cs1[0]; return {c[2],s}; endfunction fa x[0] y[0] c[0] s[0] x[1] y[1] c[1] s[1] c[2] January 9, 2012 L1-13http://csg.csail.mit.edu/SNU

“let” syntax January 9, 2012 L1-14http://csg.csail.mit.edu/SNU The “let” syntax: avoids having to write down types explicitly let cs0 = fa(x[0], y[0], c[0]); Bits#(2) cs0 = fa(x[0], y[0], c[0]); The same

Parameterized types: # A type declaration itself can be parameterized – the parameters are indicated by using the syntax ‘#’ For example Bit#(n) represents n bits and can be instantiated by specifying a value of n Bit#(1), Bit#(32), Bit#(8), … January 9, 2012 L1-15http://csg.csail.mit.edu/SNU

An w-bit Ripple-Carry Adder function Bit#(w+1) addN(Bit#(w) x, Bit#(w) y, Bit#(1) c0); Bit#(w) s; Bit#(w+1) c; c[0] = c0; for(Integer i=0; i<w; i=i+1) begin let cs = fa(x[i],y[i],c[i]); c[i+1] = cs[1]; s[i] = cs[0]; end return {c[w],s}; endfunction Not quite correct January 9, 2012 L1-16http://csg.csail.mit.edu/SNU // concrete instances of addN! function Bit#(33) add32(Bit#(32) x, Bit#(32) y, Bit#(1) c0) = addN(x,y,c0); function Bit#(4) add3(Bit#(3) x, Bit#(3) y, Bit#(1) c0) = addN(x,y,c0);

valueOf(w) versus w Each expression has a type and a value and these come from two entirely disjoint worlds n in Bit#(n) resides in the types world Sometimes we need to use values from the types world into actual computation. The function valueOf allows us to do that Thus i<w is not type correct i<valueOf(w) is type correct January 9, 2012 L1-17http://csg.csail.mit.edu/SNU

Tadd#(w,1) versus w+1 Sometimes we need to perform operations in the types world that are very similar to the operations in the value world Examples: Add, Mul, Log We define a few special operators in the types space for such operations Examples: Tadd#(m,n), Tmul#(m,n), … January 9, 2012 L1-18http://csg.csail.mit.edu/SNU

A w-bit Ripple-Carry Adder corrected function Bit#(Tadd#(w,1)) addN(Bit#(w) x, Bit#(w) y, Bit#(1) c0); Bit#(w) s; Bit#(Tadd#(w,1)) c; c[0] = c0; let valw = valueOf(w); for(Integer i=0; i<valw; i=i+1) begin let cs = fa(x[i],y[i],c[i]); c[i+1] = cs[1]; s[i] = cs[0]; end return {c[valw],s}; endfunction January 9, 2012 L1-19http://csg.csail.mit.edu/SNU

Integer versus Int#(32) In mathematics integers are unbounded but in computer systems integers always have a fixed size Bluespec allows us to express both types of integers, though unbounded integers are used only as a programming convenience January 9, 2012 L1-20http://csg.csail.mit.edu/SNU for(Integer i=0; i<valw; i=i+1) begin let cs = fa(x[i],y[i],c[i]); c[i+1] = cs[1]; s[i] = cs[0]; end

Static Elaboration phase When Bluespec program are compiled, first type checking is done and then the compiler gets rid of many different constructs which have no direct hardware meaning, like Integers, loops cs0 = fa(x[0], y[0], c[0]); c[1]=cs0[1]; s[0]=cs0[0]; cs1 = fa(x[1], y[1], c[1]); c[2]=cs1[1]; s[1]=cs1[0]; … csw = fa(x[w-1], y[w-1], c[w-1]); c[w] = csw[1]; s[w-1] = csw[0]; January 9, 2012 L1-21http://csg.csail.mit.edu/SNU for(Integer i=0; i<valw; i=i+1) begin let cs = fa(x[i],y[i],c[i]); c[i+1] = cs[1]; s[i] = cs[0]; end

00 Logical right shift by 2 Fixed size shift operation is cheap in hardware – just wire the circuit appropriately Rotate, sign-extended shifts – all are equally easy January 9, 2012 L1-22http://csg.csail.mit.edu/SNU a b c d 0 0 a b

Conditional operation: shift versus no-shift We need a Mux to select the appropriate wires: if s is one the Mux will select the wires on the left otherwise it would select wires on the right s (s==0)?{a,b,c,d}:{0,0,a,b}; January 9, 2012 L1-23http://csg.csail.mit.edu/SNU 00

Gate-level implementation of a multiplexer January 9, 2012 L1-24http://csg.csail.mit.edu/SNU (s==0)?A:B case {s1,s0} matches 0: return A; 1: return B; 2: return C; 3: return D; endcase AND OR S A B S S0S0 S0S0 S1S1 A 2-way multiplexer A B C D A B A 4-way multiplexer

Logical right shift by n Shift n can be broken down in several steps of fixed-length shifts of 1, 2, 4, … Thus a shift of size 3 can be performed by first doing a shift of length 2 and then a shift of length 1 We need a Mux to select whether we need to shift at all The whole structure can be expressed an a bunch of nested conditional expressions You will write a Blusepec program to produce a variable size shifter in Lab 1 this afternoon January 9, 2012 L1-25http://csg.csail.mit.edu/SNU 00 0 s0 s1

Combinational ALU function Bit#(width) combALU(Bit#(width) a, Bit#(width) b, OP op); case op matches NOT: return ~a; AND: return a&b; OR: return a|b; SHL: return a<<b; SHR: return a>>b; ADD: return addN(a,b); SUB: return a-b; MUL: return combMulN(a,b); endcase endfunction Once we have implemented the primitive operations like addN, >>, the ALU can be implemented simply by introducing a Mux controlled by op to select the appropriate circuit January 9, 2012 L1-26http://csg.csail.mit.edu/SNU Other operations may be needed slightly stylized code

Conditional operations Generate one-bit result which is used for branching Eq (a,b) : (a == b); Neq(a,b) : (a != b); Le(a) : signedLE(a, 0); Lt(a) : signedLT(a, 0); Ge(a) : signedGE(a, 0); Gt(a) : signedGT(a, 0); Straightforward to implement; can be combined with the ALU with an extra bit of output January 9, 2012 L1-27http://csg.csail.mit.edu/SNU

ALU with Conditionals mux add comb MulN a b op January 9, 2012 L1-28http://csg.csail.mit.edu/SNU … Next - Sequential Circuits mux 0 EQ