1 / 52 איפה אנחנו ולאן ממשיכים?? מבנה מחשבים  Arithmetic Single/multicycle Datapaths IFetchDcdExecMemWB IFetchDcdExecMemWB IFetchDcdExecMemWB IFetchDcdExecMemWB.

Slides:



Advertisements
Similar presentations
Henk Corporaal TUEindhoven 2011
Advertisements

Goal: Write Programs in Assembly
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Lecture 5: MIPS Instruction Set
ISA Issues; Performance Considerations. Testing / System Verilog: ECE385.
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
1 ECE369 ECE369 Chapter 2. 2 ECE369 Instruction Set Architecture A very important abstraction –interface between hardware and low-level software –standardizes.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
ELEN 468 Advanced Logic Design
Systems Architecture Lecture 5: MIPS Instruction Set
Chapter 2 Instructions: Language of the Computer
1 Chapter 3: Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow Very restrictive e.g.,
1 Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow Very restrictive e.g., MIPS Arithmetic.
1 Warning! Unlike the previous lessons, for today's lesson you will have to listen, think and even understand (for the exam, of course). Individuals with.
MIPS Architecture CPSC 321 Computer Architecture Andreas Klappenecker.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
1 הקדמה מה נלמד ? כיצד מחשב בנוי. כיצד לנתח ביצועי מחשב. נושאים המשפיעים על מעבדים חדשים (cache, pipeline ) הספר המלווה Computer Organization & Design.
1 CSE SUNY New Paltz Chapter 3 Machine Language Instructions.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
1 הקדמה מה נלמד ? כיצד מחשב בנוי. כיצד לנתח ביצועי מחשב. נושאים המשפיעים על מעבדים חדשים (cache, pipeline ) הספר המלווה Computer Organization & Design.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
1  1998 Morgan Kaufmann Publishers Chapter 3 Text in blue is by N. Guydosh Updated 1/27/04 Instructions: Language of the Machine.
1 איפה אנחנו ולאן ממשיכים?? מבנה מחשבים  Arithmetic Single/multicycle Datapaths IFetchDcdExecMemWB IFetchDcdExecMemWB IFetchDcdExecMemWB IFetchDcdExecMemWB.
Computer Architecture - The Instruction Set The Course’s Goals  To be interesting and fun. An interested student learns more.  To answer questions that.
1  2004 Morgan Kaufmann Publishers Chapter 2. 2  2004 Morgan Kaufmann Publishers Instructions: Language of the Machine We’ll be working with the MIPS.
ISA-2 CSCE430/830 MIPS: Case Study of Instruction Set Architecture CSCE430/830 Computer Architecture Instructor: Hong Jiang Courtesy of Prof. Yifeng Zhu.
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
순천향대학교 정보기술공학부 이 상 정 1 2. Instructions: Language of the Computer.
1 EGRE 426 Fall 09 Handout Pipeline examples continued from last class.
1 CS/EE 362 Hardware Fundamentals Lecture 10 (Chapter 3: Hennessy and Patterson) Winter Quarter 1998 Chris Myers.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
1  1998 Morgan Kaufmann Publishers Machine Instructions: Language of the Machine Lowest level of programming, control directly the hardware Assembly instructions.
6.S078 - Computer Architecture: A Constructive Approach Introduction to SMIPS Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts.
1 Instruction Set Architecture (ISA) Alexander Titov 10/20/2012.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
1 Copyright 1998 Morgan Kaufmann Publishers, Inc. All rights reserved. MIPS Assembly language In computer programs we have : Data Instructions (Arithmetic.
Computer Architecture (CS 207 D) Instruction Set Architecture ISA.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /08/2013 Lecture 10: MIPS Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL STATE.
Small constants are used quite frequently (50% of operands) e.g., A = A + 5; B = B + 1; C = C - 18; Solutions? Why not? put 'typical constants' in memory.
CHAPTER 6 Instruction Set Architecture 12/7/
 1998 Morgan Kaufmann Publishers MIPS arithmetic All instructions have 3 operands Operand order is fixed (destination first) Example: C code: A = B +
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
EE472 – Spring 2007P. Chiang, with Slide Help from C. Kozyrakis (Stanford) ECE472 Computer Architecture Lecture #3—Oct. 2, 2007 Patrick Chiang TA: Kang-Min.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
Instruction Set Architecture Chapter 3 – P & H. Introduction Instruction set architecture interface between programmer and CPU Good ISA makes program.
1  1998 Morgan Kaufmann Publishers Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow.
Computer Architecture & Operations I
Computer Architecture & Operations I
MIPS Assembly.
MIPS Instruction Set Advantages
Instruction Set Architecture
ELEN 468 Advanced Logic Design
ECE3055 Computer Architecture and Operating Systems MIPS ISA
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Systems Architecture Lecture 5: MIPS Instruction Set
Henk Corporaal TUEindhoven 2010
ECE232: Hardware Organization and Design
September 24 Test 1 review More programming
Systems Architecture I
COMS 361 Computer Organization
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
COMS 361 Computer Organization
Machine Instructions.
Instruction Set Architecture
Presentation transcript:

1 / 52 איפה אנחנו ולאן ממשיכים?? מבנה מחשבים  Arithmetic Single/multicycle Datapaths IFetchDcdExecMemWB IFetchDcdExecMemWB IFetchDcdExecMemWB IFetchDcdExecMemWB PipeliningMemory Systems I/O

2 / 52 מה נלמד ? כיצד מחשב בנוי. כיצד לנתח ביצועי מחשב. נושאים המשפיעים על מעבדים חדשים (cache, pipeline ) הספר: Computer Organization & Design The hardware/software interface, David A. Patterson and John L. Hennessy. Third Edition 2005

3 / 52 שפת מכונה שפת מכונה - הפקודות שהמחשב מכיר. אסמבלי - נוח יותר לקריאה. - הפשטה. - מעבר חד חד ערכי משפת המכונה. שפת C - נוח יותר לתיכנות. - לא מעבר חד חד ערכי. - תלוי קומפיילר ואופטימיזציה - Portable מתי מתכנתים באסמבלי ? דומה יותר לאנגלית רגילה. (אפשר להתאים השפה לעיבוד שהיא אמורה לבצע.) פרודקטיביות גבוהה: במשפט אחד מגדירים הרבה חישובים שהמכונה נדרשת לעשות. והכי חשוב: לא תלוי במחשב !!! דומה לאנגלית רגילה. תלויה במחשב. לכל מחשב פקודות Assembly שונות. לכל מחשב יש רגיסטרים אחרים, פקודות אחרות וכו’. כיום מתכנתים בשפת אסמבלי רק כשמוכרחים: * כאשר הזמן הוא קריטי וצריך לבצע אופטימיזציה “ידנית” של הקוד * כאשר צריך להשתמש בכל המשאבים של המחשב שאי אפשר לנצלם ע”י שפה עילית, כמו למשל, בדיקת overflow או שימוש ב- index register וכו’ * כאשר הזיכרון הוא קריטי וצריך אופטימיזציה של ניהול הזיכרון (בעיקר במחשבים מיוחדים כמו DSPs)

4 / 52

5 / 52 Levels of Representation temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; lw$15, 0($2) lw$16, 4($2),sw$16 0($2) sw$15, 4($2) ALUOP[0:3] <= InstReg[9:11] & MASK שפה עלית : קל לתכנת לא חד ערכי לשפת מכונה תלוי קומפיילר אופטימיזר Portable שפת סף ( אסמבלי Assembly) 1:1 לשפת מכונה יותר קריא מש ' מכונה High Level Language Program Assembly Language Program Machine Language Program Control Signal Specification °°°° Compiler Assembler Machine Interpretation

6 / 52 MIPS Instruction Set Use the MIPS ISA document as the final word on the ISA MIPS ISA document available on Course Web Site.

7 / 52 Instruction Sets: A Thin Interface Instruction Set Architecture I/O systemProcessor Digital Design Circuit Design Datapath & Control Transistors Memory Hardware Compiler Operating System (Mac OS X) Application (iTunes) Software Assembler Syntax: ADD $8 $9 $10Semantics: $8 = $9 + $10 In Hexadecimal: 012A Binary: 6 bits5 bits 6 bits Fieldsize: opcodersrtrdfunctshamt Bitfield: “R-Format”

8 / 52 Instruction Set Architecture יש דמיון רב בין שפות המכונה השונות אנו נלמד את שפת המכונה של מעבד ה- MIPS שפותח בתחילת שנות ה- 80 ( משתמשים בו ב- Silicon Graphics,NEC,Sony ). RISC v. CISC –Reduced Instruction Set Computer - MIPS – Complex Instruction Set Computer המוטו “ פחות זה יותר “ כלומר: סט פקודות קטן יותר, כאשר הפקודות עצמן פשוטות יותר, מאפשר ביצועים טובים יותר. זאת היות והחומרה הדרושה לביצוע הפקודות הנ”ל תהיה פשוטה יותר המהירות תגדל ושטח הסיליקון הדרוש (=המחיר) יצטמצם.

9 / 52 Hardware implements semantics... Instruction Fetch Instruction Decode Operand Fetch Execute Result Store Next Instruction Fetch next inst from memory:012A4020 opcodersrtrdfunctshamt Decode fields to get : ADD $8 $9 $10 “Retrieve” register values: $9 $10 Add $9 to $10 Place this sum in $8 Prepare to fetch instruction that follows the ADD in the program. Syntax: ADD $8 $9 $10Semantics: $8 = $9 + $10

10 / 52 Memory Instructions: LW $1,32($2) Instruction Fetch Instruction Decode Operand Fetch Execute Result Store Next Instruction Fetch the load inst from memory “Retrieve” register value: $2 Compute memory address: 32 + $2 Load memory address contents into: $1 Prepare to fetch instr that follows the LW in the program. Depending on load semantics, new $1 is visible to that instr, or not until the following instr (”delayed loads”). Decode fields to get : LW $1, 32($2) opcodersrtoffset “I-Format”

11 / 52 Branch Instructions: BEQ $1,$2,25 Instruction Fetch Instruction Decode Operand Fetch Execute Result Store Next Instruction Fetch branch inst from memory “Retrieve” register values: $1, $2 Compute if we take branch: $1 == $2 ? Decode fields to get: BEQ $1, $2, 25 opcodersrtoffset “I-Format” ALWAYS prepare to fetch instr that follows the BEQ in the program (”delayed branch”). IF we take branch, the instr we fetch AFTER that instruction is PC PC == “Program Counter”

12 / 52 Why ISA is important? Code size –long instructions may take more time to be fetched –Requires larges memory (important in small devices, e.g., cell phones) Number of instructions (IC) –Reducing IC reduce execution time (assuming same CPI and frequency) Code “simplicity” –Simple HW implementation which leads to higher frequency and lower power –Code optimization can better be applied to “simple code”

13 / 52 The impact of the ISA RISC vs CISC

14 / 52 CISC Processors CISC - Complex Instruction Set Computer The idea: a high level machine language Characteristic –Many instruction types, with many addressing modes –Some of the instructions are complex: Perform complex tasks Require many cycles –ALU operations directly on memory Usually uses limited number of registers –Variable length instructions Common instructions get short codes  save code length Example: x86

15 / 52 CISC Drawbacks Compilers do not take advantage of the complex instructions and the complex indexing methods Implement complex instructions and complex addressing modes  complicate the processor  slow down the simple, common instructions  contradict Amdahl’s law corollary: Make The Common Case Fast Variable length instructions are real pain in the neck: –It is difficult to decode few instructions in parallel As long as instruction is not decoded, its length is unknown  It is unknown where the instruction ends  It is unknown where the next instruction starts –An instruction may not fit into the “right behavior” of the memory hierarchy (will be discussed next lectures) Examples: VAX, x86 (!?!)

16 / 52 RISC Processors RISC - Reduced Instruction Set Computer The idea: simple instructions enable fast hardware Characteristic –A small instruction set, with only a few instructions formats –Simple instructions execute simple tasks require a single cycle (with pipeline) –A few indexing methods –ALU operations on registers only Memory is accessed using Load and Store instructions only. Many orthogonal registers Three address machine: Add dst, src1, src2 –Fixed length instructions Examples: MIPS TM, Sparc TM, Alpha TM, PowerPC TM

17 / 52 RISC Processors (Cont.) Simple architecture  Simple micro-architecture –Simple, small and fast control logic –Simpler to design and validate –Room for on die caches: instruction cache + data cache Parallelize data and instruction access –Shorten time-to-market Using a smart compiler –Better pipeline usage –Better register allocation Existing RISC processor are not “pure” RISC –e.g., support division which takes many cycles

18 / 52 RISC v. CISC I - מספר פקודות בתוכנית T– הזמן לביצוע פקודה RISC: I * T CISC: I * T

19 / 52 So, what is better, RISC or CISC Today CISC architectures (X86) are running as fast as RISC (or even faster) The main reasons are: –Translates CISC instructions into RISC instructions (ucode) –CISC architecture are using “RISC like engine” We will discuss this kind of solutions later on in this course.

20 / 52 כלל תכנון מספר 1: Simplicity favors Regularity פעולות אריתמטיות MIPS addi a,b,100 # a=b+100 add a,b,c # a=b+c 8086 ADD EAX,B # EAX= EAX+B אנו מעדיפים מנגנון פשוט עם פקודות מינימליות כמו R3 = R1 op R2 עלפני מחשב שקל יותר לתכנות עם כמה משתנים שרוצים בפקודה למשל R5 = ( R1 op1 R2) op2 (R3 op3 R4) אבל קשה מאוד לתכנן ולממש אותו.

21 / 52 כלל תכנון מס’ 2: Smaller is faster נאפשר פעולות אריתמטיות רק על רגיסטרים. האופרנדים יכולים להיות רגיסטר או קבוע (אחד). סה”כ יש 32 רגיסטרים. spilling רגיסטר word = 32 bits = 4 bytes קונבנציות $1,$2 … $s0,$s C משתנים של $t1,$t2 … - משתנים זמניים דוגמא: f=(g+h)-(k+j) #$s0=f, $s1=g, $s2=h, $s3=k, $s4=j add $t0,$s1,$s2 add $t1,$s3,$s4 sub $s0, $t0, $t1 הרגיסטרים מסומנים ע”י $. או $31 - $0 או ע”י שמות הקשורים לתפקידיהם בתכנית. יש הסכמה על תפקידי הרגיסטרים הנ”ל בכל התכניות בשפת C למשל. הדוגצא מתארת איך המשפט ( f=(g+h)-(k+j מיוצג ע”י פקודות אסמבלי. הרגיסטרים הם ליבו של הפרוססור. הגישה אליהם מהירה מלזיכרון. נגשים,בוזמנית” ל-3 רגיסטרים: מ-2 קוראים ולשלישי כותבים.. עמ’ 110

22 / 52 Policy of Use Conventions רגיסטרים נוספים הם at = $1 $ השמור לאסמבלר ו- k0, $ k1 = $ 26, $ 27 $ השמורים למערכת ההפעלה

23 / 52 הזיכרון הזיכרון - מערך גדול. כתובת לזיכרון - אינדקס למערך. Byte addressing - האינדקס בבתים. גודל הזיכרון המכסימלי 2 30 words = 2 32 bytes bits of data

24 / 52 פניה לזיכרון פקודות Load and Store טוענים מילה אבל הכתובת בזיכרון היא בבתים - LW lw $s1,100($s2) # $s1=Memory[$s2+100] sw $s1,100($s2) # Memory[$s2+100]=$s1 דוגמא נוספת: save - מערך של Word muli $9,$19,4 # Temporary reg $9:=i*4 lw $8,save($9) # Temporary reg $8:=save[i] מקום במערך = offset מצביע למערך = base register מקום במערך = offset

25 / 52 קריאה של byte ישנם גם פקודות כמו (lb (load byte ו- (sb(store byte שימושי לקריאת char: גודל byte ב - ASCII American Standard Code For Information Interchange ב- Unicode - גודל char הוא 2 בתים.

26 / 52 ASCII

27 / 52 גישה לזיכרון דוגמא: A מערך של words כתובת A ב- s3 $ h נמצא ב-s2 $ C code: A[2] = h + A[2]; MIPS code: lw $t0, 8($s3) # $t0=$s3[8] add $t0, $s2,$t0 # $t0=$s2+$t0 sw $t0, 8($s3) # $s3[8]=$t bits of data A A[0] A[1] INTEL = Little endian A[2] MIPS = Big endian

28 / 52 הפקודות ב- MIPS בגודל זהה של 32 ביט. ב פקודות בגודל משתנה מ-1 עד ל-17 בתים. :דוגמא add $s1,$s2,$s3 # $s1=$17,$s2=$18, $s3=$19 פורמט הפקודה מסוג R-type op rs rt rdshamtfunct op - opecoders - register source rt- register source no 2rd - register destination funct - function shamt - shift amount שפת המכונה

29 / 52 צמצום מספר סוגי הפקודות השונים. דמיון בין הפקודות. Example: lw $s1, 32($s2) # $s1 =$17, $s2= op rs rt 16 bit number כלל תכנון מס’ 3 : תכנון טוב דורש לעיתים פשרות op rs rt rdshamtfunct op rs rt 16 bit address op 26 bit address RIJRIJ

30 / 52 התוכנית נשמרת בזיכרון בדיוק כמו נתונים ביצוע תוכנית רגיסטר מיוחד PC - Program Counter שומר את כתובת הפקודה. קוראים מילה שלמה מהזיכרון. מקדמים את ה - PC. ProcessorMemory memory for data, programs, compilers, editors, etc. התוכנית בזיכרון

31 / 52 Jump - קפיצה “אבסולוטית” ללא תנאים j label Branch - קפיצה יחסית מותנת bne $1,$2,label# $1!=$2 go to label Example: if (i!=j) beq $s4, $s5, Lab1 h=i+j;add $s3, $s4, $s5 else j Lab2 h=i-j;Lab1:sub $s3, $s4, $s5 Lab2:... Branch vs Jump ($s3=h $s4 =i $s5=j )

32 / 52 Instructions: bne $t4,$t5,Label Next instruction is at Label if $t4!= $t5 beq $t4,$t5,Label Next instruction is at Label if $t4 = $t5 j Label Next instruction is at Label Formats: מכאן branch - קפיצה יחסית בגבולות 16^2 מילים. הנחה: רוב ה- branches יהיו קפיצות לוקאליות. Beq $s1,$s2,25 # if ($s1 ==$s2) go to PC *4 op rs rt 16 bit address op 26 bit address IJIJ Addresses in Branches and Jumps

33 / 52 דוגמא לקידוד

34 / 52 כלל שחשוב לזכור :מקודדים MIPS באסמבלי של כתובת code במילים כתובת data בבתים ניגש לזיכרון הוא מבקש את הכתובת בבתים MIPS כאשר מעבד

35 / 52 Slt- set less then if $s1 < $s2 then $t0 = 1 slt $t0, $s1, $s2 else $t0 = 0 ניתן לבנות את blt: Blt –branch less then blt $s0,$s1, Less slt $at,$s0,$s1 # $t0 gets 1 if $s0<$s1 bne $at,$zero, Less # go to Less if $t0 != 0 blt היא Pseudo instruction Assembler uses $at (= $1) for pseudo instructions Branch-if-less-than?

36 / 52 דוגמאות נוספות ל- Pseudo instruction bne $8,$21,far_adrs שקול ל - beq $8,$21,nxt j far_adrs nxt: move $t1,$s4 add $t1,$s4,$zero שקול ל -

37 / 52 כלל תכנון מס’ 4 : בנה את המקרה השכיח - מהיר הרבה פעולות ארתמטיות מתבצעות עם קבועים קטנים. קבועים גדולים $t0= addi $29, $29, lui $t0, # $t0=2^16*( ) 2 ori $t0,$t0, # $t0=$t0|| $to= … לכן הוקצו פקודות מיוחדות לחיבור חיסור והשוואה של קבועים קטנים: addi, slti, andi, ori, xori נחשב ב-2 פקודות, כלומר לאט יותר, אבל נדרשת רק פקודה אחת נוספת: lui

38 / 52 לסיכום

39 / 52 תרגיל שאלה 1: לפניך קוד הכתוב ב-C, ושני תרגומים שלו לשפת האסמבלי של MIPS: while (save[i]!=k) do i=i+j ; save:array [ ] of word $19 מתפקד כ i ו $20 כ-j ו-$21 כ-k. תרגום ראשון: Loop: muli $9,$19,4 # Temporary reg $9:=i*4 lw $8,save($9) # Temporary reg $8:=save[i] beq $8,$21,Exit # Goto Exit if save[i] = k add $19,$19,$20 # i:=i+j j Loop # Goto Loop Exit:

40 / 52 המשך תרגיל תרגום שני: muli $9,$19,4# Temporary reg $9:=i*4 lw $8,save($9)# Temporary reg $8:=save[i] beq $8,$21,Exit# Goto Exit if save[i] = k Loop: add $19,$19,$20# i:=i+j muli $9,$19,4# Temporary reg $9:=i*4 lw $8,save($9)# Temporary reg $8:=save[i] bnq $8,$21,Loop# Goto Loop if save[i]!=k Exit: שאלה: בהנחה שהלולאה מתבצעת 10 פעמים, מה מספר הפקודות שמתבצעות בכל אחד מהתרגומים?

41 / 52 Compiler A.asm B.asm compiler A.obj B.obj linker C.lib (c.obj) P.exe loader Memory

42 / 52 תהליך הקומפילציה

43 / 52 דוגמא B.asm compiler A.obj B.obj s:.word 3,4 j k lw $1,s ($2) k: add $1,$2,$3 m:.word 2 sw 7, m($3) A.asm 3 4 j 2 lw $1,0($2) add $1,$2,$3 2 sw $7,0($3) sw $7,0($3) j 3 lw $1,4($2) add $1,$2,$3 linker P.exe

44 / 52 קובץ Object ב- Unix Object file header text segment data segment relocation information symbol table debugging information

45 / 52 מבנה הזיכרון במחשב MIPS

46 / 52

47 / 52 Preprocessing Macro: Code: After preprocessing

48 / 52

49 / 52

50 / 52 Calling procedure:

51 / 52 Sub1: Callee procedure:

52 / 52 Single Cycle