hw2_sol_rev1

# hw2_sol_rev1 - EE108B Winter 2003-2004 Handout#20 EE108b...

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

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

View Full Document
EE108B Winter 2003-2004 Handout #20 0x84: b 0x2c 0x88: move sp, s8 0x8c: lw fp, 20(sp) 0x90: addiu sp, sp, 24 0x94: jr ra a. (5 points) Assign a mark for each point below. Please identify the optimizations used by the compiler to transform the code from the unoptimized version into the optimized one and point out where they are applied. Solution: Copy propagation (1 point): Instructions 0x40, 0x54 and 0x7c are removed. Arithmetic identity/Algebraic simplification (1 point): Since (i+1)*4 == (i*4)+4, instructions 0x40 and 0x4c, and 0x54 and 0x60 that computes the new A[i] and B[i], are transformed to 0x34 and 0x20 respectively. Leaf routine optimization (1point): It is a leaf routine and there is no need to save and restore fp and gp. There is also no need to store i and c on the stack since they are only used locally. As a result no stack space need to be allocated. Thus instructions 0xc–0x18, 0x24, 0x3c, 0x50, 0x68, 0x74, 0x80 and 0x88-0x90 in the unoptimized code are removed, and 0x28-0x2c are reduced to instruction 0x10 in the optimized version. Loop invariant code Motion (1 point) : Since the arrays A and B are in static memory, instructions 0x48 and 0x5c that load the base address of A and B are moved above the loop (instructions 0x14- 0x18 in the optimized code) to reduce the number of dynamic instructions. Loop inversion (1 point): Since the lower and upper bound of the for loop are constants, the loop can be transformed into a while loop that has a lower loop overhead. Thus, instructions 0x30-0x38 and 0x84 are transformed to 0x30 and 0x38 in the optimized version. Note: The exact terms are not important, as long as the description of the
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 12

hw2_sol_rev1 - EE108B Winter 2003-2004 Handout#20 EE108b...

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

View Full Document
Ask a homework question - tutors are online