20.04.2013 Views

Spring 2011 CSCI 565 - Compiler Design

Spring 2011 CSCI 565 - Compiler Design

Spring 2011 CSCI 565 - Compiler Design

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Pedro Diniz<br />

pedro@isi.edu<br />

<strong>CSCI</strong> <strong>565</strong> - <strong>Compiler</strong> <strong>Design</strong><br />

Computing an Array Address<br />

A[ i ]<br />

• baseA + ( i – low ) x sizeof(baseType(A))<br />

• In general: base(A) + ( i – low ) x sizeof(baseType(A))<br />

<strong>Spring</strong> <strong>2011</strong><br />

What about A[i1 ,i2 ] ?<br />

This stuff looks expensive!<br />

Lots of implicit +, -, x ops<br />

Row-major order, two dimensions<br />

baseA + (( i1 – low1 ) x (high2 – low2 + 1) + i2 – low2 ) x sizeof(baseType(A))<br />

Column-major order, two dimensions<br />

baseA + (( i 2 – low 2 ) x (high 1 – low 1 + 1) + i 1 – low 1 ) x sizeof(baseType(A))<br />

Indirection vectors, two dimensions<br />

*(A[i 1 ])[i 2 ] — where A[i 1 ] is, itself, a 1-d array reference

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!