25_2 - Code Optimization 1 Outline...

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

View Full Document Right Arrow Icon
1 Code Optimization
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Outline Machine-Independent Optimization Code motion Memory optimization Suggested reading 5.3 ~ 5.6
Background image of page 2
3 Motivation Constant factors matter too! easily see 10:1 performance range depending on how code is written must optimize at multiple levels algorithm, data representations, procedures, and loops
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Motivation Must understand system to optimize performance how programs are compiled and executed how to measure program performance and identify bottlenecks how to improve performance without destroying code modularity and  generality
Background image of page 4
5 Vector ADT typedef struct { int len ; data_t *data ; } vec_rec, *vec_ptr ;   typedef int data_t ; length data 0 1 2 length–1
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Procedures vec_ptr new_vec(int len) Create vector of specified length data_t *get_vec_start(vec_ptr v) Return pointer to start of vector data
Background image of page 6
7 Procedures int get_vec_element( vec_ptr v, int index, int *dest ) Retrieve vector element, store at *dest Return 0 if out of bounds, 1 if successful Similar to array implementations in Pascal, Java E.g., always do bounds checking
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Vector ADT vec_ptr new_vec(int len) { /* allocate header structure */ vec_ptr result = (vec_ptr) malloc(sizeof(vec_rec)) ; if ( !result ) return NULL ; result->len = len ;
Background image of page 8
Vector ADT /* allocate array */ if ( len > 0 ) { data_t *data = (data_t *)calloc(len, sizeof(data_t)) ; if ( !data ) {
Background image of page 9

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

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

Page1 / 32

25_2 - Code Optimization 1 Outline...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online