


































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
CS203 Advanced Computer Architecture
Typology: Lecture notes
1 / 42
This page cannot be seen from the preview
Don't miss anything!
Instructions 1f
Data int main(){ printf(“Hello, world!\n”); }
Instructions 1f
Data Instruction Fetch Arithmetic Logical Units (ALU) Complex Arithmetic Operations (Mul/div) Branch/ Jump Memory Operations Instruction Decode Program Counter Registers
By loading different programs into memory, your computer can perform different functions
Classic CPU Performance Equation (ET of a program) How many instruction “instances” for the program? How long do we need for each instruction on average? Instructions Program Cycles Instruction × Seconds Cycle × ×
C Code x86 instructions int init_data(int64_t *data, int data_size) { register unsigned int i = 0 ; for(i = 0 ; i < data_size; i++) { s+=data[i]; } return s; } int main(int argc, char **argv) { int *data = malloc(8000000000); init_data(data, 1000000000) return 0; } init_data: .LFB16: endbr testl %esi, %esi jle .L leal -1(%rsi), %ecx xorq %rax, %rax .L3: movslq (%rdi), %rdx addq $4, %rdi addq %rdx, %rax cmpq %rcx, %rdi jne .L .L2: xorlq %rax, %rax ret 1000000000x If data memory access instructions takes 5 cycles, branch 2 cycles, others take only 1 cycle, CPU freq. = 4 GHz ET = ( 5 × 10 9 ) × 2 × 1 4 × 10 9 sec = 2.5 sec CPI
= 20 % × 5 + 20 % × 2 + 60 % × 1 ) = 2 memory inst. → branch inst. →
− 12 Exection Time
IC × % of floating point instructions × 10 − 12 IC × CPI × CT IC is gone!
% of floating point instructions × 10 − 12 CPI × CT
https://www.pollev.com/hungweitseng close in
A. C B. C++ C. Java D. Perl E. Python
Instruction count LOC Ranking C 600k 6 1 C++ 3M 6 2 Java ~145M 8 5 Perl ~12M 4 3 Python ~33M 1 4 GO (Interpreter) ~1200M 1 6 GO (Compiled) ~1.7M 1 Rust ~1.4M 1
A. C B. C++ C. Java D. Perl E. Python
24 CPU
RAX RBX RCX RDX RSP RBP RSI RDI R R R R R R R R RIP FLAGS CS SS DS ES FS GS Memory 64-bit 64-bit 264 Bytes ALU ADD SUB IMUL AND OR XOR JMP JE CALL RET 0x 0x 0x 0x 0x 0x 0x 0x 0xFFFFFFFFFFFFFFC 0xFFFFFFFFFFFFFFC 0xFFFFFFFFFFFFFFD 0xFFFFFFFFFFFFFFD 0xFFFFFFFFFFFFFFE 0xFFFFFFFFFFFFFFE 0xFFFFFFFFFFFFFFF 0xFFFFFFFFFFFFFFF MOV
int A[] = {1,2,3,4,5,6,7,8,9,10,1,2,3, ,5,6,7,8,9,10}; int main() { int i=0, sum=0; for(i = 0; i < 20; i++) { sum += A[i]; } return 0; } memory access logical operations arithmetic operations control flow operations Contents of section .text: 0000 f30f1efa 554889e5 c745f800 000000c 0010 45fc0000 0000c745 f8000000 00eb1e8b 0020 45f84898 488d1485 00000000 488d 0030 0000008b 04020145 fc8345f8 01837df 0040 137edcb8 00000000 5dc main: .LFB0: endbr pushq %rbp movq %rsp, %rbp movl $0, -8(%rbp) movl $0, -4(%rbp) movl $0, -8(%rbp) jmp .L .L3: movl -8(%rbp), %eax cltq leaq 0(,%rax,4), %rdx leaq A(%rip), %rax movl (%rdx,%rax), %eax addl %eax, -4(%rbp) addl $1, -8(%rbp) .L2: cmpl $19, -8(%rbp) jle .L movl $0, %eax popq %rbp ret Contents of section .data: 0000 01000000 02000000 03000000 04000000 0010 05000000 06000000 07000000 08000000 0020 09000000 0a000000 01000000 02000000 0030 03000000 04000000 05000000 06000000 0040 07000000 08000000 09000000 0a
Recap: How my “Java code” becomes a “program” 27
Java Bytecode (.class)
Data
Instructions 07001507 Source Code
Other (.class) 00c2e 00000008 00c2f 00000008 00c2f 00000008 00c 00000008 Data cafebabe 00000033 001d0a 06000f 00100011 0800120a 00130014 07001507 Instructions One Time Cost! Everytime when we run it!
labels Most instructions doesn’t have an argument!