{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
1 Array
Background image of page 1

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

View Full Document Right Arrow Icon
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 }
Background image of page 2
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:
Background image of page 3

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

View Full Document Right Arrow Icon
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:
Background image of page 4
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]
Background image of page 5

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

View Full Document Right Arrow Icon
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
Background image of page 6
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  
Background image of page 7

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

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

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

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}