Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "1 / 52 איפה אנחנו ולאן ממשיכים?? מבנה מחשבים  Arithmetic Single/multicycle Datapaths IFetchDcdExecMemWB IFetchDcdExecMemWB IFetchDcdExecMemWB IFetchDcdExecMemWB."— Presentation transcript:

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

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

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

4 4 / 52

5 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) 0000 1001 1100 0110 1010 1111 0101 1000 1010 1111 0101 1000 0000 1001 1100 0110 1100 0110 1010 1111 0101 1000 0000 1001 0101 1000 0000 1001 1100 0110 1010 1111 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 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 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: 012A4020 00000001001 0101001000 00000 100000Binary: 6 bits5 bits 6 bits Fieldsize: opcodersrtrdfunctshamt Bitfield: “R-Format”

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

9 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 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 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 + 4 + 100. PC == “Program Counter”

12 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 13 / 52 The impact of the ISA RISC vs CISC

14 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 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 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 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 18 / 52 RISC v. CISC I - מספר פקודות בתוכנית T– הזמן לביצוע פקודה RISC: I * T CISC: I * T

19 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 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 21 / 52 כלל תכנון מס’ 2: Smaller is faster נאפשר פעולות אריתמטיות רק על רגיסטרים. האופרנדים יכולים להיות רגיסטר או קבוע (אחד). סה”כ יש 32 רגיסטרים. spilling רגיסטר word = 32 bits = 4 bytes קונבנציות $1,$2 … $s0,$s1... - 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 22 / 52 Policy of Use Conventions רגיסטרים נוספים הם at = $1 $ השמור לאסמבלר ו- k0, $ k1 = $ 26, $ 27 $ השמורים למערכת ההפעלה

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

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

26 26 / 52 ASCII

27 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]=$t0 0 4 8 12 16 32 bits of data A A[0] A[1] INTEL = Little endian A[2] MIPS = Big endian 013 0123 2

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

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

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

31 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 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 +25*4 op rs rt 16 bit address op 26 bit address IJIJ Addresses in Branches and Jumps

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

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

35 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 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 37 / 52 כלל תכנון מס’ 4 : בנה את המקרה השכיח - מהיר הרבה פעולות ארתמטיות מתבצעות עם קבועים קטנים. קבועים גדולים $t0=101010101010101011111111111111111 addi $29, $29, 4 1010101010101010 00000000000000001111111111111111 10101010101010101111111111111111 0000000000000000 lui $t0,1010101010101010 # $t0=2^16*(101010101010101010) 2 ori $t0,$t0, 1111111111111111 # $t0=$t0||1010101010101010 $to=10101010101010101111111111111… לכן הוקצו פקודות מיוחדות לחיבור חיסור והשוואה של קבועים קטנים: addi, slti, andi, ori, xori נחשב ב-2 פקודות, כלומר לאט יותר, אבל נדרשת רק פקודה אחת נוספת: lui

38 38 / 52 לסיכום

39 39 / 52 תרגיל שאלה 1: לפניך קוד הכתוב ב-C, ושני תרגומים שלו לשפת האסמבלי של MIPS: while (save[i]!=k) do i=i+j ; save:array [ 0..100] 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 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 41 / 52 Compiler A.asm B.asm compiler A.obj B.obj linker C.lib (c.obj) P.exe loader Memory

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

43 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) 2 3 4 sw $7,0($3) j 3 lw $1,4($2) add $1,$2,$3 linker P.exe

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

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

46 46 / 52

47 47 / 52 Preprocessing Macro: Code: After preprocessing

48 48 / 52

49 49 / 52

50 50 / 52 Calling procedure:

51 51 / 52 Sub1: Callee procedure:

52 52 / 52 Single Cycle


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

Similar presentations


Ads by Google