The compiler places directives in the assembly code

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: The registers values are: %edx holds cnt, %ebx holds Aptr, %ecx holds nTjPk, and %esi holds result. 152 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS code/asm/array.c 1 2 3 4 5 6 7 8 9 10 11 12 13 typedef int *var_matrix; /* Compute i,k of variable matrix product */ int var_prod_ele(var_matrix A, var_matrix B, int i, int k, int n) { int j; int result = 0; for (j = 0; j < n; j++) result += A[i*n + j] * B[j*n + k]; return result; } code/asm/array.c (a) Original C code code/asm/array.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 /* Compute i,k of variable matrix product */ int var_prod_ele_opt(var_matrix A, var_matrix B, int i, int k, int n) { int *Aptr = &A[i*n]; int nTjPk = n; int cnt = n; int result = 0; if (n <= 0) return result; do { result += (*Aptr) * B[nTjPk]; Aptr += 1; nTjPk += n; cnt--; } while (cnt); return result; } code/asm/array.c (b) Optimized C code Figure 3.24: Original and Optimized Code to Compute Element of Matrix Product for Variable Length Arrays. The compiler performs these optimizations automatically. 3.9. HETEROGENEOUS DATA STRUCTURES 1 2 3 4 5 6 7 8 9 153 loop: .L37: movl 12(%ebp),%eax movl (%ebx),%edi addl $4,%ebx imull (%eax,%ecx,4),%edi addl %edi,%esi addl 24(%ebp),%ecx decl %...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online