DOC PREVIEW
CMU CS 15213 - lecture

This preview shows page 1-2-3-23-24-25-26-46-47-48 out of 48 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 48 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Carnegie Mellon Introduction to Computer Systems 15 213 18 243 spring 2009 9th Lecture Feb 10th Instructors Gregory Kesden and Markus P schel Carnegie Mellon Last Time rax Return value r8 Argument 5 rbx Callee saved r9 Argument 6 rcx Argument 4 r10 Callee saved rdx Argument 3 r11 Used for linking rsi Argument 2 r12 C Callee saved rdi Argument 1 r13 Callee saved rsp Stack pointer r14 Callee saved rbp Callee saved r15 Callee saved Carnegie Mellon Last Time Procedures x86 64 Optimizations No base frame pointer Passing arguments to functions through registers if possible Sometimes Writing into the red zone below stack pointer rtn Ptr 8 unused 16 loc 1 24 loc 0 Sometimes Function call using jmp instead of call Reason Performance use stack as little as possible while obeying rules e g caller callee save registers rsp Carnegie Mellon Last Time Arrays int val 5 1 x Nested int pgh 4 5 Multi level int univ 3 5 x 4 2 x 8 1 x 12 3 x 16 x 20 Carnegie Mellon Dynamic Nested Arrays Strength Can create matrix of any size Programming Must do index computation explicitly Performance Accessing single element costly Must do multiplication int new var matrix int n return int calloc sizeof int n n int var ele int a int i int j int n return a i n j movl 12 ebp eax movl 8 ebp edx imull 20 ebp eax addl 16 ebp eax movl edx eax 4 eax i a n i n i j Mem a 4 i n j Carnegie Mellon Dynamic Array Multiplication Per iteration Multiplies 3 2 for subscripts 1 for data Adds 4 2 for array indexing 1 for loop index 1 for data Compute element i k of variable matrix product int var prod ele int a int b int i int k int n int j int result 0 for j 0 j n j result a i n j b j n k return result a b x i th row j th column Carnegie Mellon Optimizing Dynamic Array Multiplication Optimizations int j int result 0 for j 0 j n j result a i n j b j n k return result Performed when set optimization level to O2 Code Motion Expression i n can be computed outside loop Strength Reduction 4 adds 1 mult int j int result 0 int iTn i n int jTnPk k for j 0 j n j result a iTn j b jTnPk jTnPk n return result Incrementing j has effect of incrementing j n k by n 4 adds 3 mults Operations count 4 adds 1 mult Carnegie Mellon Today Structures Alignment Unions Floating point Carnegie Mellon Structures struct rec int i int a 3 int p Memory Layout i a 0 4 p 16 20 Concept Contiguously allocated region of memory Refer to members within structure by names Members may be of different types Accessing Structure Member void set i struct rec r int val r i val IA32 Assembly eax val edx r movl eax edx Mem r val Carnegie Mellon Generating Pointer to Structure Member struct rec int i int a 3 int p r r 4 4 idx i a 0 4 p 16 20 int find a struct rec r int idx return r a idx What does it do ecx idx edx r leal 0 ecx 4 eax Will 4 idx disappear leal 4 eax edx eax r 4 idx 4 blackboard Carnegie Mellon Generating Pointer to Structure Member struct rec int i int a 3 int p Generating Pointer to Array Element Offset of each structure member determined at compile time r r 4 4 idx i a 0 4 p 16 20 int find a struct rec r int idx return r a idx ecx idx edx r leal 0 ecx 4 eax 4 idx leal 4 eax edx eax r 4 idx 4 Carnegie Mellon Structure Referencing Cont C Code struct rec int i int a 3 int p i a 0 i a void set p struct rec r r p r a r i What does it do edx r movl edx ecx leal 0 ecx 4 eax leal 4 edx eax eax movl eax 16 edx 4 p 16 20 0 4 Element i r i 4 r i r 4 4 r i Update r p 16 20 Carnegie Mellon Today Structures Alignment Unions Floating point Carnegie Mellon Alignment Aligned Data Primitive data type requires K bytes Address must be multiple of K Required on some machines advised on IA32 treated differently by IA32 Linux x86 64 Linux and Windows Motivation for Aligning Data Memory accessed by aligned chunks of 4 or 8 bytes system dependent Inefficient to load or store datum that spans quad word boundaries Virtual memory very tricky when datum spans 2 pages Compiler Inserts gaps in structure to ensure correct alignment of fields Carnegie Mellon Specific Cases of Alignment IA32 1 byte char no restrictions on address 2 bytes short lowest 1 bit of address must be 02 4 bytes int float char lowest 2 bits of address must be 002 8 bytes double Windows and most other OS s instruction sets lowest 3 bits of address must be 0002 Linux lowest 2 bits of address must be 002 i e treated the same as a 4 byte primitive data type 12 bytes long double Windows Linux lowest 2 bits of address must be 002 i e treated the same as a 4 byte primitive data type Carnegie Mellon Specific Cases of Alignment x86 64 1 byte char no restrictions on address 2 bytes short lowest 1 bit of address must be 02 4 bytes int float lowest 2 bits of address must be 002 8 bytes double char Windows Linux lowest 3 bits of address must be 0002 16 bytes long double Linux lowest 3 bits of address must be 0002 i e treated the same as a 8 byte primitive data type Carnegie Mellon Satisfying Alignment with Structures Within structure struct S1 char c int i 2 double v p Must satisfy element s alignment requirement Overall structure placement Each structure has alignment requirement K K Largest alignment of any element Initial address structure length must be multiples of K Example under Windows or x86 64 K 8 due to double element c p 0 i 0 3 bytes p 4 i 1 p 8 Multiple of 4 Multiple of 8 v 4 bytes p 16 p 24 Multiple of 8 Multiple of 8 Carnegie Mellon Different Alignment Conventions struct S1 char c int i 2 double v p x86 64 or IA32 Windows K 8 due to double element c p 0 3 bytes i 0 p 4 i 1 v 4 bytes p 8 p 16 p 24 IA32 Linux K 4 double treated like a 4 byte data type c p 0 3 bytes p 4 i 0 i 1 p 8 v p 12 p 20 Carnegie Mellon Saving Space Put large data types first struct S1 char c int i 2 double v p struct S2 …


View Full Document

CMU CS 15213 - lecture

Documents in this Course
lecture

lecture

14 pages

lecture

lecture

46 pages

Caches

Caches

9 pages

lecture

lecture

39 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

56 pages

lecture

lecture

11 pages

lecture

lecture

9 pages

Lecture

Lecture

36 pages

Lecture

Lecture

37 pages

Exam

Exam

16 pages

Lecture

Lecture

10 pages

Lecture

Lecture

43 pages

Lecture

Lecture

8 pages

Lecture

Lecture

8 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

37 pages

Lecture

Lecture

6 pages

Lecture

Lecture

40 pages

coding

coding

2 pages

Exam

Exam

17 pages

Exam

Exam

14 pages

Lecture

Lecture

29 pages

Lecture

Lecture

34 pages

Exam

Exam

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

lecture

lecture

46 pages

Lecture

Lecture

33 pages

Lecture

Lecture

57 pages

Lecture

Lecture

32 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

11 pages

Lecture

Lecture

6 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

18 pages

Exam

Exam

10 pages

Lecture

Lecture

45 pages

Lecture

Lecture

37 pages

Exam

Exam

24 pages

class09

class09

21 pages

class22

class22

37 pages

class20

class20

30 pages

class27

class27

33 pages

class25

class25

21 pages

class04

class04

31 pages

Lecture

Lecture

59 pages

class01a

class01a

14 pages

class12

class12

45 pages

class29

class29

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

6 pages

class03

class03

34 pages

lecture

lecture

42 pages

Lecture

Lecture

40 pages

Lecture

Lecture

47 pages

Exam

Exam

19 pages

R06-B

R06-B

25 pages

class17

class17

37 pages

class25

class25

31 pages

Lecture

Lecture

15 pages

final-f06

final-f06

17 pages

Lecture

Lecture

9 pages

lecture

lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

22 pages

class11

class11

45 pages

lecture

lecture

50 pages

Linking

Linking

37 pages

Lecture

Lecture

64 pages

Integers

Integers

40 pages

Exam

Exam

11 pages

Lecture

Lecture

37 pages

Lecture

Lecture

44 pages

Lecture

Lecture

37 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

45 pages

Final

Final

25 pages

lecture

lecture

9 pages

Lecture

Lecture

30 pages

Lecture

Lecture

16 pages

Final

Final

17 pages

Lecture

Lecture

8 pages

Exam

Exam

11 pages

Lecture

Lecture

47 pages

Lecture

Lecture

9 pages

lecture

lecture

39 pages

Exam

Exam

11 pages

lecture

lecture

41 pages

lecture

lecture

37 pages

Lecture

Lecture

59 pages

Lecture

Lecture

45 pages

Exam 1

Exam 1

18 pages

Lecture

Lecture

41 pages

Lecture

Lecture

32 pages

Lecture

Lecture

30 pages

Lecture

Lecture

9 pages

Lecture

Lecture

9 pages

Lecture

Lecture

15 pages

Lecture

Lecture

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

4 pages

Lecture

Lecture

46 pages

Lecture

Lecture

8 pages

Lecture

Lecture

65 pages

Lecture

Lecture

38 pages

Lecture

Lecture

35 pages

Lecture

Lecture

8 pages

Lecture

Lecture

34 pages

Lecture

Lecture

8 pages

Exam

Exam

13 pages

Lecture

Lecture

43 pages

Lecture

Lecture

9 pages

Lecture

Lecture

12 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

43 pages

Lecture

Lecture

7 pages

Lecture

Lecture

45 pages

Lecture

Lecture

24 pages

Lecture

Lecture

47 pages

Lecture

Lecture

12 pages

Lecture

Lecture

20 pages

Lecture

Lecture

9 pages

Exam

Exam

11 pages

Lecture

Lecture

52 pages

Lecture

Lecture

20 pages

Exam

Exam

11 pages

Lecture

Lecture

35 pages

Lecture

Lecture

47 pages

Lecture

Lecture

18 pages

Lecture

Lecture

30 pages

Lecture

Lecture

59 pages

Lecture

Lecture

37 pages

Lecture

Lecture

22 pages

Lecture

Lecture

35 pages

Exam

Exam

23 pages

Lecture

Lecture

9 pages

Lecture

Lecture

22 pages

class12

class12

32 pages

Lecture

Lecture

8 pages

Lecture

Lecture

39 pages

Lecture

Lecture

44 pages

Lecture

Lecture

38 pages

Lecture

Lecture

69 pages

Lecture

Lecture

41 pages

Lecture

Lecture

12 pages

Lecture

Lecture

52 pages

Lecture

Lecture

59 pages

Lecture

Lecture

39 pages

Lecture

Lecture

83 pages

Lecture

Lecture

59 pages

class01b

class01b

17 pages

Exam

Exam

21 pages

class07

class07

47 pages

Lecture

Lecture

11 pages

Odyssey

Odyssey

18 pages

multicore

multicore

66 pages

Lecture

Lecture

6 pages

lecture

lecture

41 pages

lecture

lecture

55 pages

lecture

lecture

52 pages

lecture

lecture

33 pages

lecture

lecture

46 pages

lecture

lecture

55 pages

lecture

lecture

17 pages

lecture

lecture

49 pages

Exam

Exam

17 pages

lecture

lecture

56 pages

Exam 2

Exam 2

16 pages

Exam 2

Exam 2

16 pages

Notes

Notes

37 pages

Lecture

Lecture

40 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Exam

Exam

13 pages

Lecture

Lecture

32 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

29 pages

Lecture

Lecture

59 pages

Lecture

Lecture

41 pages

Lecture

Lecture

50 pages

Exam

Exam

17 pages

Lecture

Lecture

29 pages

Lecture

Lecture

44 pages

Lecture

Lecture

41 pages

Lecture

Lecture

52 pages

Lecture

Lecture

40 pages

Lecture

Lecture

33 pages

lecture

lecture

10 pages

Lecture

Lecture

27 pages

Lecture

Lecture

29 pages

Lecture

Lecture

39 pages

Lecture

Lecture

9 pages

Lecture

Lecture

29 pages

Lecture

Lecture

8 pages

Lecture

Lecture

43 pages

Lecture

Lecture

43 pages

Lecture

Lecture

75 pages

Lecture

Lecture

55 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lecture

Lecture

35 pages

lecture

lecture

36 pages

Exam

Exam

33 pages

lecture

lecture

56 pages

lecture

lecture

64 pages

lecture

lecture

8 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

36 pages

lecture

lecture

56 pages

lecture

lecture

75 pages

lecture

lecture

36 pages

Lecture

Lecture

50 pages

Lecture

Lecture

45 pages

Lecture

Lecture

13 pages

Exam

Exam

23 pages

Lecture

Lecture

10 pages

Lecture

Lecture

48 pages

Lecture

Lecture

83 pages

lecture

lecture

57 pages

Lecture

Lecture

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

33 pages

lecture

lecture

54 pages

Lecture

Lecture

30 pages

Exam

Exam

13 pages

Lecture

Lecture

36 pages

Lecture

Lecture

40 pages

Exam

Exam

17 pages

Lecture

Lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

44 pages

Lecture

Lecture

34 pages

Lecture

Lecture

24 pages

Lecture

Lecture

29 pages

class12

class12

43 pages

lecture

lecture

43 pages

class22

class22

22 pages

R06-B

R06-B

25 pages

class01b

class01b

19 pages

lecture

lecture

29 pages

lab1

lab1

8 pages

Caches

Caches

36 pages

lecture

lecture

55 pages

Lecture,

Lecture,

37 pages

Integers

Integers

40 pages

Linking

Linking

38 pages

lecture

lecture

45 pages

Lecture

Lecture

61 pages

Linking

Linking

33 pages

lecture

lecture

40 pages

lecture

lecture

40 pages

Lecture

Lecture

32 pages

lecture

lecture

44 pages

Exam

Exam

11 pages

Lecture

Lecture

31 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

40 pages

Exam

Exam

12 pages

Lecture

Lecture

42 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

Lecture

Lecture

13 pages

Lecture

Lecture

35 pages

Lecture

Lecture

20 pages

Final

Final

19 pages

Lecture

Lecture

33 pages

Lecture

Lecture

50 pages

Lecture

Lecture

33 pages

Lecture

Lecture

27 pages

Lecture

Lecture

6 pages

Exam

Exam

15 pages

Lecture

Lecture

24 pages

Lecture

Lecture

23 pages

Lecture

Lecture

43 pages

Lecture

Lecture

32 pages

Lecture

Lecture

52 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

15 pages

lecture

lecture

21 pages

Lecture

Lecture

58 pages

Lecture

Lecture

49 pages

Lecture

Lecture

36 pages

Lecture

Lecture

11 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

33 pages

Exam

Exam

15 pages

Lecture

Lecture

35 pages

Lecture

Lecture

10 pages

Lecture

Lecture

25 pages

Lecture

Lecture

31 pages

Lecture

Lecture

24 pages

Lecture

Lecture

34 pages

Lecture

Lecture

50 pages

lecture

lecture

35 pages

Lecture

Lecture

11 pages

Lecture

Lecture

39 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

exam1-f05

exam1-f05

11 pages

Lecture

Lecture

4 pages

Lecture

Lecture

17 pages

Exam

Exam

17 pages

malloc()

malloc()

12 pages

Lecture

Lecture

57 pages

Lecture

Lecture

30 pages

Lecture

Lecture

30 pages

Lecture

Lecture

47 pages

Lecture

Lecture

33 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lectures

Lectures

33 pages

Lecture

Lecture

36 pages

lecture

lecture

33 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Load more
Download lecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view lecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view lecture and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?