ENCM515 Familiarization Exercise 2 C Coding Practices

Total Page:16

File Type:pdf, Size:1020Kb

ENCM515 Familiarization Exercise 2 C Coding Practices

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 = type of operation). G) Circle and label with a G – The SHARC instruction that sets a floating point register to the value 32.0. (UREG = type of operation). H) Circle and label with a H – A SHARC instruction that accesses a memory location using a POST-MODIFY operation. I) Circle and label with a I – A SHARC instruction that accesses a memory location using a PRE-MODIFY operation. J) Circle and label with a J – A SHARC instruction that DOES NOT access a memory location BUT STILL IS USING a PRE-MODIFY operation. K) Circle and label with a K – A VISUALDSP assembler directive indicating that a value can be used by instructions in files outside of the current file. What is the “value” that can be used outside of this file – in particular by the linker? L) Circle and label with an L – A SHARC instruction that is storing a floating-point value from the register bank to memory. M) Circle and label with an M – The value of MAXSIZE as shown in the assembly code.

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”?

Recommended publications