Quizzes & Puzzles7 mins ago
Computer Architecture - C Language
When the program is recompiled with optimisation (the –O3 compiler
switch) the programmer discovers that the sumLoop () function runs
faster and that the execution time of a sum = sum + increment;
statement drops to 1 nanosecond in the optimised code from the
original measurement of 5 nanoseconds in the non-optimised version
of the program. Give an explanation of the optimisations that are likely
to have been made by the compiler in order to achieve this fivefold
improvement in performance and compare and contrast these
optimisations with the original assembly code in the above listing.
(5 marks)
switch) the programmer discovers that the sumLoop () function runs
faster and that the execution time of a sum = sum + increment;
statement drops to 1 nanosecond in the optimised code from the
original measurement of 5 nanoseconds in the non-optimised version
of the program. Give an explanation of the optimisations that are likely
to have been made by the compiler in order to achieve this fivefold
improvement in performance and compare and contrast these
optimisations with the original assembly code in the above listing.
(5 marks)
Answers
Best Answer
No best answer has yet been selected by Joe111. Once a best answer has been selected, it will be shown here.
For more on marking an answer as the "Best Answer", please visit our FAQ.just incase you really wanted to know rojash here the first part of the question.
Consider the following function that forms part of a C program that has been written to measure the execution time of a simple arithmetic statement like sum = sum + increment;
long sumLoop(long increment, long iterations)
{
long i, sum=0;
for (i=0 ; i < iterations ; i++) {
sum = sum + increment;
}
return (sum);
}
The following (numbered) lines of IA-32 (in GAS format) assembly language corresponding to the above function have been generated when the C program was compiled without optimisation:
10 sumLoop:
11 pushl %ebp
12 movl %esp, %ebp
13 subl $8, %esp
14 movl $0, -8(%ebp)
15 movl $0, -4(%ebp)
16 .L7:
17 movl -4(%ebp), %eax
18 cmpl 12(%ebp), %eax
19 jl .L10
20 jmp .L8
21 .L10:
22 movl 8(%ebp), %eax
23 leal -8(%ebp), %edx
24 addl %eax, (%edx)
25 leal -4(%ebp), %eax
26 incl (%eax)
27 jmp .L7
28 .L8:
29 movl -8(%ebp), %eax
30 leave
31 ret
Where appropriate please refer to these corresponding line number(s) in your answers to the following questions:
Consider the following function that forms part of a C program that has been written to measure the execution time of a simple arithmetic statement like sum = sum + increment;
long sumLoop(long increment, long iterations)
{
long i, sum=0;
for (i=0 ; i < iterations ; i++) {
sum = sum + increment;
}
return (sum);
}
The following (numbered) lines of IA-32 (in GAS format) assembly language corresponding to the above function have been generated when the C program was compiled without optimisation:
10 sumLoop:
11 pushl %ebp
12 movl %esp, %ebp
13 subl $8, %esp
14 movl $0, -8(%ebp)
15 movl $0, -4(%ebp)
16 .L7:
17 movl -4(%ebp), %eax
18 cmpl 12(%ebp), %eax
19 jl .L10
20 jmp .L8
21 .L10:
22 movl 8(%ebp), %eax
23 leal -8(%ebp), %edx
24 addl %eax, (%edx)
25 leal -4(%ebp), %eax
26 incl (%eax)
27 jmp .L7
28 .L8:
29 movl -8(%ebp), %eax
30 leave
31 ret
Where appropriate please refer to these corresponding line number(s) in your answers to the following questions:
Related Questions
Sorry, we can't find any related questions. Try using the search bar at the top of the page to search for some keywords, or choose a topic and submit your own question.