Question: The following C code sets the diagonal elements of one of our fixed-size arrays to val: When compiled with optimization level -01, GCC generates the

The following C code sets the diagonal elements of one of our fixed-size arrays to val:

/* Set all diagonal elements to val */ void fix_set_diag(fix_matrix A, int val) { } long i; for (i 0; i

When compiled with optimization level -01, GCC generates the following assembly code:

1 fix_set_diag: 2 3 4 5 6 7 8 void A in %rdi, val in %rsi movl $0, %eax fix_set_diag(fix_matrix A, int val)

Create a C code program fix_set_diag_opt that uses optimizations similar to those in the assembly code, in the same style as the code in Figure 3.37(b). Use expressions involving the parameter N rather than integer constants, so that your code will work correctly if N is redefined.

Figure 3.37(b)

(b) Optimized C code 2 3 4 50 6 8 9 10 L= 11 12 13 /* Compute i,k of fixed matrix product */ int

/* Set all diagonal elements to val */ void fix_set_diag(fix_matrix A, int val) { } long i; for (i 0; i < N; i++) A [i] [i] = val;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

This exercise requires that you be able to study compilergenerated assembly code to understand what ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Systems A Programmers Perspective Questions!