{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

12 - Array 1 Optimization 1 int decimal5_opt(int*x 2cfw 3...

This preview shows pages 1–10. Sign up to view the full content.

1 Array

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Optimization 1 int decimal5_opt(int *x) 2 { 3 int val = 0; 4 int *xend = x + 4; 5 6 do { 7 val = (10 * val) + *x; 8 x++; 9 } while (x <= xend); 10 11 return val; 12 }
3 Optimization 1 movl 8(%ebp),%ecx Get base addr of array x 2 xorl %eax,%eax val = 0; 3 leal 16(%ecx),%ebx xend = x+4 (16 bytes = 4 double words) 4 .L12: loop:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Optimization 4 .L12: loop: 5 leal (%eax,%eax,4),%edx Compute 5*val 6 movl (%ecx),%eax Compute *x 7 leal (%eax,%edx,2),%eax Compute *x + 2*(5*val) 8 addl \$4,%ecx x++ 9 cmpl %ebx,%ecx Compare x:xend 10 jbe .L12 if <=, goto loop:
5 Nested Array int   A[4][3] ;  Array A is a two-dimensional array  with four rows and three columns It is referenced as A[0][0] through A[3][2]

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6 Nested Array Element Address A[0][0] x A A[0][1] x A +4 A[0][2] x A +8 A[1][0] x A +12 A[1][1] x A +16 A[1][2] x A +20 A[2][0] x A +24 A[2][1] x A +28 A[2][2] x A +32 A[3][0] x A +36 A[3][1] x A +40 A[3][2] x A +44
7 Nested Array  int   A[4][3] ; Array of array typedef  int row3_t[3] ;  row3_t   A[4] ; Array A contains 4 elements, each requiring 12 bytes to store 3  integers The whole size of array A is 48 bytes Row major ordered in memory

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
8 Nested Array T   D[R][C] ; D[i][j] is at memory address x + L* ( C * i + j ) L is sizeof(T)
9 Access A[i,j]

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}