ENCM515 Familiarization Exercise 2 C Coding Practices
Total Page:16
File Type:pdf, Size:1020Kb
ENCM515 -- Familiarization Exercise 2 – “C” coding practices
Q1 The following code was passed through the VisualDSP++ “C++ compiler” using the “-S” option (stop after compiling) to produce an assembly language file – look inside directory “DEBUG” for the file
The resulting code was
If your surname starts with A – M -- CIRCLE THE FIRST line of code that satisfies the question. If your surname starts with N – Z -- CIRCLE THE LAST line of code that satisfies the question.
A) Circle and label with an A -- the marker that indicates the END of a SHARC instruction B) Circle and label with a B -- the marker that separates two PARALLEL OPERATING SHARC instructions. C) Circle and label with a C – A SHARC instruction where the architecture has been customized to work with the “C/C++” languages D) Circle and label with a D – A SHARC instruction where there are two or more operations that are TRULY working in parallel. E) Circle and label with an E – A SHARC instruction line where the unobservant would THINK that there are two or more operations working in parallel (Peculiarity of the SHARC syntax.) F) Circle and label with an F – A SHARC instruction that sets an index register to a 32-bit constant. (UREG =
Q4. Take the following “C” code routines and pass through the VisualDSP++ compiler to produce an assembly language file. Then complete the table below using the assembly code information 15 marks Written using indexing mode in “C” UsingCopies()UsingCopies()UsingIndex) UsingIndex() (Unoptimized)(Optimized) (Unoptimized)(Optimized) Number of instructions “inside the loop”. “Parallel” count as 1 including software loop control operations. Number of instructions “placing values on the “C” stack” Number of “dm” operations per each time around the loop Number of “pm” operations per each time round the loop Total number of times that the loop is executed
Total number of “dm” operations performed during the function execution. Total number of “pm” operations performed during the function execution. Number of times that the division 9.0/5.0 is calculated during “RUN-TIME” (execution of the code) The “theoretical” best time for executing the total loop if “all possible optimisation could be found”. This is “theoretical” best time is calculated as Loop overhead + the maximum of the following Number of multiplications Number of additions/subtractions Number of shifts Number of dm operations Number of pm operations
Why is it the “maximum” rather than the “sum”? Rewrite the code using an “autoincrementing” mode of indexing (See Familiarization exercise 1). Complete the table below Written using “auto-incrementing” mode in “C” UsingCopies()UsingCopies()UsingIndex) UsingIndex() (Unoptimized)(Optimized) (Unoptimized)(Optimized) Number of instructions “inside the loop”. “Parallel” count as 1 including software loop control operations. Number of instructions “placing values on the “C” stack” Number of “dm” operations per each time around the loop Number of “pm” operations per each time round the loop Total number of times that the loop is executed
Total number of “dm” operations performed during the function execution. Total number of “pm” operations performed during the function execution. Number of times that the division 9.0/5.0 is calculated during “RUN-TIME” (execution of the code) The “theoretical” best time for executing the total loop if “all possible optimisation could be found”. This is “theoretical” best time is calculated as Loop overhead + the maximum of the following Number of multiplications Number of additions/subtractions Number of shifts Number of dm operations Number of pm operations
Why is it the “maximum” rather than the “sum”?