CMSC 611: Advanced Computer Architecture

Similar documents
Systems Architecture I

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

Communicating with People (2.8)

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

Levels of Programming. Registers

COMPUTER ORGANIZATION AND DESIGN

ECE 486/586. Computer Architecture. Lecture # 7

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

Chapter 2. Instructions:

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization

Chapter 2A Instructions: Language of the Computer

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro

ECE232: Hardware Organization and Design

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Chapter 2: Instructions:

Architecture II. Computer Systems Laboratory Sungkyunkwan University

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Math 230 Assembly Programming (AKA Computer Organization) Spring MIPS Intro

CS/COE1541: Introduction to Computer Architecture

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

LECTURE 2: INSTRUCTIONS

MIPS Instruction Set Architecture (2)

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

Reduced Instruction Set Computer (RISC)

Instruction Set Architecture. "Speaking with the computer"

ECE369. Chapter 2 ECE369

MIPS (SPIM) Assembler Syntax

COE608: Computer Organization and Architecture

Lecture 4: MIPS Instruction Set

Chapter 3 MIPS Assembly Language. Ó1998 Morgan Kaufmann Publishers 1

All instructions have 3 operands Operand order is fixed (destination first)

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

ECE 30 Introduction to Computer Engineering

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

Lecture 5: Procedure Calls

Computer Architecture. MIPS Instruction Set Architecture

Assembling Programs. .o les (Unix).obj les (Windows/DOS)

Reduced Instruction Set Computer (RISC)

Course Administration

CENG3420 Lecture 03 Review

MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE

CS3350B Computer Architecture Winter 2015

Computer Architecture

CSCE 5610: Computer Architecture

CENG3420 L03: Instruction Set Architecture

Chapter 2. Instructions: Language of the Computer. HW#1: 1.3 all, 1.4 all, 1.6.1, , , , , and Due date: one week.

CS3350B Computer Architecture MIPS Procedures and Compilation

Chapter 3. Instructions:

Solutions for Chapter 2 Exercises

Machine Instructions - II. Hwansoo Han

Instructions: MIPS arithmetic. MIPS arithmetic. Chapter 3 : MIPS Downloaded from:

Part I: Translating & Starting a Program: Compiler, Linker, Assembler, Loader. Lecture 4

CSE 141 Computer Architecture Spring Lecture 3 Instruction Set Architecute. Course Schedule. Announcements

Lecture 5: Procedure Calls

Lec 13: Linking and Memory. Kavita Bala CS 3410, Fall 2008 Computer Science Cornell University. Announcements

CSE Lecture In Class Example Handout

1 5. Addressing Modes COMP2611 Fall 2015 Instruction: Language of the Computer

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

CS 61C: Great Ideas in Computer Architecture Introduction to Assembly Language and RISC-V Instruction Set Architecture

EEC 581 Computer Architecture Lecture 1 Review MIPS

Instructions: Assembly Language

ECE260: Fundamentals of Computer Engineering

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

Chapter 2. Instructions: Language of the Computer

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

Orange Coast College. Business Division. Computer Science Department CS 116- Computer Architecture. The Instructions

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

Review (1/2) IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with. CS61C - Machine Structures

MIPS ISA-II: Procedure Calls & Program Assembly

ECE260: Fundamentals of Computer Engineering

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro

ECE232: Hardware Organization and Design

CSCI341. Lecture 22, MIPS Programming: Directives, Linkers, Loaders, Memory

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

bits 5..0 the sub-function of opcode 0, 32 for the add instruction

Computer Organization MIPS ISA

Two processors sharing an area of memory. P1 writes, then P2 reads Data race if P1 and P2 don t synchronize. Result depends of order of accesses

ECE260: Fundamentals of Computer Engineering. Supporting Procedures in Computer Hardware

CMSC 611: Advanced Computer Architecture

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

Forecast. Instructions (354 Review) Basics. Basics. Instruction set architecture (ISA) is its vocabulary. Instructions are the words of a computer

CSE Lecture In Class Example Handout

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

55:132/22C:160, HPCA Spring 2011

Processor. Han Wang CS3410, Spring 2012 Computer Science Cornell University. See P&H Chapter , 4.1 4

CS 61C: Great Ideas in Computer Architecture More RISC-V Instructions and How to Implement Functions

CS3350B Computer Architecture MIPS Instruction Representation

From Code to Program: CALL Con'nued (Linking, and Loading)

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

Transcription:

CMSC 611: Advanced Computer Architecture Compilers Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted from Hennessy & Patterson / 2003 Elsevier Science

Typical Compilation

Compiling Array Indexing Let's assume that A is an array of word-length integers and that the compiler has associated the variables g, h and i with the registers $s1, $s2 and $s4. Let's assume that the starting address, or base address, of the array is in $s3. The following is a possible compilation of a segment of a C program to MIPS assembly instructions: g = h + A[i]; First convert word-index to byte-index: add $t1, $s4, $s4 # Temp reg $t1 = 2 * i add $t1, $t1, $t1 # Temp reg $t1 = 4 * i To get the address of A[i], we need to add $t1 to the base of A in $s3: add $t1, $t1, $s3 # $t1 = address of A[i] (4 * i + $s3) Now we can use that address to load A[i] into a temporary register: lw $t0, 0($t1) # Temporary register $t0 gets A[i] Finally add A[i] to h and place the sum in g: add $s1, $s2, $t0 # g = h + A[i]

Compiling if-then-else Assuming the five variables f, g, h, i, and j correspond to the five registers $s0 through $s4, what is the compiled MIPS code for the following C if statement: f = g + h i=j i == j? i!j Else: f = g h MIPS: if (i == j) f = g + h; else f = g - h; bne $s3, $s4, Else # go to Else if i! j add $s0, $s1, $s2 # f = g + h (skipped if i! j) Exit: j Exit Else: sub $s0, $s1, $s2 # f = g - h (skipped if i = j) Exit:

Assume that i, j and k correspond to $s3 through $s5, and the base of the array save is in $s6. what is the compiled MIPS code for the following C segment: MIPS: Compiling a while Loop while (save[i] == k) i = i + j; The first step is to load save[i] into a temporary register Loop: add $t1, $s3, $s3 # Temp reg $t1 = 2 * i add $t1, $t1, $t1 # Temp reg $t1 = 4 * i add $t1, $t1, $s6 # $t1 = address of save[i] lw $t0, 0($t1) # Temp reg $t0 = save[i] The next instruction performs the loop test, exiting if save[i]! k bne $t0, $s5, Exit # go to Exit if save[i]! k The next instruction add j to i: add $s3, $s3, $s4 # i = i + j Finally reaching the loop end j Loop # go back to the beginning of loop Exit:

Major Types of Optimization Optimization Name Explanation Frequency High level At or near source level; machine indep. Procedure integration Replace procedure call by procedure body N.M Local Within straight line code Common sub- expression elimination Constant propagation Stack height reduction Global Global common sub expression elimination Copy propagation Code motion Induction variable elimination Machine-dependant Strength reduction Pipeline Scheduling Replace two instances of the same computation by single copy Replace all instances of a variable that is assigned a constant with the constant Rearrange expression tree to minimize resources needed for expression evaluation Across a branch 18% 22% N.M Same as local, but this version crosses branches 13% Replace all instances of a variable A that has been assigned X (i.e., A = X) with X Remove code from a loop that computes same value each iteration of the loop Simplify/eliminate array addressing calculations within loops Depends on machine knowledge Many examples, such as replace multiply by a constant with adds and shifts Reorder instructions to improve pipeline performance 11% 16% 2% N.M N.M.

Program and Compiler Optimization Level Effect of Optimization Measurements taken on MIPS Level 0: non-optimized code Level 1: local optimization Level 2: global optimization, s/w pipelining Level 3: adds procedure integration

Multimedia Instructions Small vector processing targeting multimedia Intel s MMX, PowerPC AltiVec, Sparc VIS, MIPS MDMX N 1/N th -word vectors packed into one register Same operations performed on all N vectors Plus Little additional ALU hardware Utilize under-used hardware resources Minus Extra pack & unpack if data isn t already arranged perfectly Limited vector sizes, difficult to compile for general code Result Mostly used in hand-coded libraries Compare to general vector processing Hide memory latency in vector access Strided processing, gather/scatter addressing

Effect of Compilers on ISA Promote regularity Limit # register formats and variability of operands Orthogonality in operations, registers & addressing Provide primitives, not solutions Common features over specific language features Special-purpose instructions often unusable (except through hand-assembly-coded libraries) Simplify trade-offs among alternatives Simplify the analysis of special features such as cache and pipeline Allow simultaneous activities to promote optimization

C program Compiler Starting a Program Assembly language program Assembler Object files for Unix typically contains: Header: size & position of components Text segment: machine code Data segment: static and dynamic variables Relocation info: identify absolute memory ref. Symbol table: name & location of labels, procedures and variables Debugging info: mapping source to object code, break points, etc. Object: Machine language module Object: Library routine (machine language) Linker - Place code & data modules symbolically in memory -Determine the address of data & instruction labels -Patch both internal & external ref. Executable: Machine language program Loader Memory

Linking Object Files Object file header Name Procedure A Text size 100 hex Data size 20 hex Text segment Address Instruction 0 lw $a0, 0($gp) 4 jal 0 Data segment 0 (X). Relocation Info Address Instruction type Dependency 0 lw X 4 jal B Symbol table Label Address X - B - Object file header Name Procedure B Text size 200 hex Data size 30 hex Text segment Address Instruction 0 lw $a0, 0($gp) 4 jal 0 Data segment 0 (Y). Relocation Info Address Instruction type Dependency 0 lw Y 4 jal A Symbol table Label Address Y - A - Executable file header Text size 300 hex Data size 50 hex Text segment Address Instruction 0040 0000 hex lw $a0, 8000 hex ($gp) 0040 0004 hex jal 40 0100 hex 0040 0100 hex lw $a1, 8020 hex ($gp) 0040 0104 hex jal 40 0000 hex Data segment Address 1000 0000 hex (X) 1000 0020 hex (Y) Assuming the value in $gp is 1000 8000 hex

Loading Executable Program $sp $gp pc 7fff ffff hex 1000 8000 hex Stack Dynamic data Static data 1000 0000 hex Text 0040 0000 hex Reserved 0 To load an executable, the operating system follows these steps: 1. Read the executable file header to determine the size of text and data segments 2. Create an address space large enough for the text and data 3. Copy the instructions and data from the executable file into memory 4. Copy the parameters (if any) to the main program onto the stack 5. Initialize the machine registers and sets the stack pointer to the first free location 6. Jump to a start-up routines that copies the parameters into the argument registers and calls the main routine of the program