Answered step by step
Verified Expert Solution
Question
1 Approved Answer
As usual, you have been provided with a file lab 1 0 . h with headers for the functions described, lab 1 0 c .
As usual, you have been provided with a file labh with headers for the functions described, labcc with analogous C implementations, tests.c with reasonably thorough tests of the functions as described.
Dot Product, again
The dot product pairwise product, and sum that we did in Lab makes more sense on floating point values.
In labS write a function dotdouble that calculates the dot product of two arrays, as before but on doubleprecision floating point arrays.
An equivalent dotdoublec has been provided in labcc
Polynomial evaluation, again
We previously wrote a function that evaluated a cubic polynomial on a single x value, using the equivalent of this expression: xxax b c d
This time, we want to apply this operation to an array of double x values, writing the result to another equallysized array. That is for each array element, do the above calculation and put the result in the corresponding position in the "output" array.
In labS write a function mappolydouble with this signature the coefficients will be constant:
void mappolydoubledouble input, double output, uintt length, double a double b double c double d;
Equivalent mappolydoublec and mappolydoublec have been provided, with the two expressions we used in the previous exercise, for comparison.
That, but Single Precision
Maybe singleprecision floating point operations are faster?
In labS write functions dotsingle and mappolysingle that are equivalent to the above but work on singleprecision floating point values float This should be as simple as swapping doubleprecision instructions for their singleprecision equivalents, and changing the element size from to
Some singleprecision instructions that I found useful: movd, addss, mulss.
As before, there are dotsinglec and mappolysinglec in labcc for comparison.
Time It
The provided timing.c provides some timing tests on reasonablysized arrays. Have a look. How does your code compare to what the compiler wrote? Use O to give the compiler its best chance.
Why not x
As mentioned in lecture, we aren't using the x instructions in this course. Why not? It seems like there are a lot of programmerfriendly instructions there loading constants, trigonometry, logarithms, they work on a stack and everybody loves stacks
This function with C signature void sinxdouble input, double output, uintt length calculates the sine of each element of an array of double and fills another equallysized array with the results. You don't need to worry about the details, except that it uses x floating point instructions to do the calculation. You can copy it into your labS
sinx:
mov $rcx
sloop:
cmp rdxrcx
jae sret
fldl rdi, rcx
fsin
fstpl rsi, rcx
inc rcx
jmp sloop
sret:
ret
Create a program sinc and write a C implementation sinstdlib that does the same operation, but using the C standard library's sin function. You will have to include math.h and add lm to your compilinglinking command.
The sin function you're calling isn't using any trig instructions, but is doing something different. Is it faster?
You have not been provided with testing or timing code for this part of the exercise. That is deliberate. Write a main function in your sinc that produces output relevant to testingtiming the implementations ie what you need to convince yourself your code is correct and answer the question below The command to compile it should be like this:
gcc labcc labS sinc lm
Questions
Answer these questions in a text file answers.txt
What was the running time of the dot product implementations? Assembly vs the compiler, and single vs doubleprecision?
Same question, but for the polynomial evaluation? Prediction: the differences should be much more obvious here.
What is the relative running time of the xbased sine calculation vs the C implementation that uses its own implementation of the function
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started