CS 61C Great Ideas in Computer Architecture Machine Structures Instructors Randy H Katz David A Patterson http inst eecs Berkeley edu cs61c fa10 01 14 2019 Spring 2010 Lecture 9 1 New School Machine Structures It s a bit more complicated Software Parallel Requests Assigned to computer e g Search Katz Parallel Threads Assigned to core e g Lookup Ads Hardware Harness Parallelism Achieve High Performance Warehouse Scale Computer Smart Phone Today s Lecture Computer Parallel Instructions 1 instruction one time e g 5 pipelined instructions Parallel Data 1 data item one time e g Add of 4 pairs of words Hardware descriptions Memory Core Cache Input Output Instruction Unit s Core Functional Unit s A0 B0 A1 B1 A2 B2 A3 B3 Main Memory All gates one time 01 14 2019 Core Logic Gates Spring 2010 Lecture 9 3 Levels of Representation Interpretation Today s Lecture High Level Language Program e g C Compiler Assembly Language Program e g MIPS Assembler Machine Language Program MIPS temp v k v k v k 1 v k 1 temp lw lw sw sw t0 0 2 t1 4 2 t1 0 2 t0 4 2 0000 1010 1100 0101 1001 1111 0110 1000 1100 0101 1010 0000 Anything can be represented as a number i e data or instructions 0110 1000 1111 1001 1010 0000 0101 1100 1111 1001 1000 0110 0101 1100 0000 1010 1000 0110 1001 1111 Machine Interpretation Hardware Architecture Description e g block diagrams Architecture Implementation Logic Circuit Description Circuit Schematic Diagrams Spring 2010 Lecture 9 01 14 2019 4 Review Everything is a binary number in a computer Instructions and data stored program concept Assemblers can enhance machine instruction set to help assembly language programmer Translate from text that easy for programmers to understand into code that machine executes efficiently Compilers Assemblers Linkers allow separate translation of modules 01 14 2019 Spring 2010 Lecture 9 5 Agenda Compilers Optimization Interpreters Just InTime Compiler Administrivia Dynamic Linking Technology Trends Revisited Technology Break Components of a Computer 01 14 2019 Spring 2010 Lecture 9 6 What s a Compiler Compiler a program that accepts as input a program text in a certain language and produces as output a program text in another language while preserving the meaning of that text The text must comply with the syntax rules of whichever programming language it is written in A compiler s complexity depends on the syntax of the language and how much abstraction that programming language provides A C compiler is much simpler than C Compiler Compiler executes before compiled program runs 01 14 2019 Spring 2010 Lecture 9 7 Compiled Languages Edit Compile Link Run Editor Source code Compiler Object code Linker Editor Editor 01 14 2019 Source code Source code Compiler Compiler Executable program Object code Object code Spring 2010 Lecture 9 2 8 Compiler Optimization gcc compiler options O1 the compiler tries to reduce code size and execution time without performing any optimizations that take a great deal of compilation time O2 Optimize even more GCC performs nearly all supported optimizations that do not involve a space speed tradeoff As compared to O this option increases both compilation time and the performance of the generated code O3 Optimize yet more All O2 optimizations and also turns on the finline functions 01 14 2019 Spring 2010 Lecture 9 9 What is Typical Benefit of Compiler Optimization What is a typical program For now try a toy program BubbleSort c 01 14 2019 define ARRAY SIZE 20000 int main int iarray ARRAY SIZE x y holder for x 0 x ARRAY SIZE x for y 0 y ARRAY SIZE 1 y if iarray y iarray y 1 holder iarray y 1 iarray y 1 iarray y iarray y holder Lecture 9 Spring 2010 10 Unoptimized MIPS Code L3 lw 2 80016 sp slt 3 2 20000 bne 3 0 L6 j L4 L6 set noreorder nop set reorder sw 0 80020 sp L7 lw 2 80020 sp slt 3 2 19999 bne 3 0 L10 j L5 L10 lw 2 80020 sp move 3 2 sll 2 3 2 addu 3 sp 16 01 14 2019 addu 2 3 2 lw 4 80020 sp addu 3 4 1 move 4 3 sll 3 4 2 addu 4 sp 16 addu 3 4 3 lw 2 0 2 lw 3 0 3 slt 2 3 2 beq 2 0 L9 lw 3 80020 sp addu 2 3 1 move 3 2 sll 2 3 2 addu 3 sp 16 addu 2 3 2 lw 3 0 2 sw 3 80024 sp lw 3 80020 sp addu 2 3 1 move 3 2 sll 2 3 2 addu 3 sp 16 addu 2 3 2 lw 3 80020 sp move 4 3 sll 3 4 2 addu 4 sp 16 addu 3 4 3 lw 4 0 3 sw 4 0 2 lw 2 80020 sp move 3 2 sll 2 3 2 addu 3 sp 16 addu 2 3 2 lw 3 80024 sp sw 3 0 2 Spring 2010 Lecture 9 L11 L9 lw 2 80020 sp addu 3 2 1 sw 3 80020 sp j L7 L8 L5 lw 2 80016 sp addu 3 2 1 sw 3 80016 sp j L3 L4 L2 li 12 65536 ori 12 12 0x38b0 addu 13 12 sp addu sp sp 12 j 31 11 O2 optimized MIPS Code li 13 65536 L6 slt 2 4 3 beq 2 0 L9 sw 3 0 5 sw 4 0 6 ori 13 13 0x3890 addu 13 13 sp sw 28 0 13 L9 move 4 0 move 3 7 addu 8 sp 16 slt 2 3 19999 move 3 0 addu 9 4 1 p2align 3 L10 sll 2 3 2 addu 6 8 2 addu 7 3 1 sll 2 7 2 addu 5 8 2 lw 3 0 6 lw 4 0 5 01 14 2019 bne 2 0 L10 move 4 9 slt 2 4 20000 bne 2 0 L6 li 12 65536 ori 12 12 0x38a0 addu 13 12 sp addu sp sp 12 j 31 Spring 2010 Lecture 9 12 What s an Interpreter It reads and executes source statements executed one at a time No linking No machine code generation so more portable Start executing quicker but run much more slowly than compiled code Performing the actions straight from the text allows better error checking and reporting to be done The interpreter stays around during execution Unlike compiler some work is done after program starts Writing an interpreter is much less work than writing a compiler 01 14 2019 Spring 2010 Lecture 9 13 Interpreted Languages Edit Run Editor 01 14 2019 Source code Interpreter Spring 2010 Lecture 9 2 14 Compiler vs Interpreter Advantages Compilation Faster Execution Single file to execute Compiler can do better diagnosis of syntax and semantic errors since it has more info than an interpreter Interpreter only sees one line at a time Can find syntax errors before run program Compiler can optimize code 01 14 2019 Interpreter Easier to debug program Faster development time Spring 2010 Lecture 9 15 Compiler …
View Full Document
Unlocking...