Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Help please 6. [5pt] Bonus problem The following code computes the 128-bit product of two 64-bit signed values x and y and stores the result
Help please
6. [5pt] Bonus problem The following code computes the 128-bit product of two 64-bit signed values x and y and stores the result in memory: \( \begin{array}{ll}1 & \text { typedef } \\ 2 & \text { int128 int128_t; } \\ 3 & \text { void store_prod(int128_t } * \text { dest, int64_t } x \text {, int64_t y) }\{ \\ 4 & \text { *dest }=x *(\text { int128_t) y; } \\ 5 & \}\end{array} \) Gcc generates the following assembly code implementing the computation: \( \begin{array}{lcl}1 & \text { store_prod: } \\ 2 & \text { movq } & \% r d x, \% r a x \\ 3 & \text { cqto } & \\ 4 & \text { movq } & \% r s i, \% r c x \\ 5 & \text { sarq } & \$ 63, \% r c x \\ 6 & \text { imulq } & \% r a x, \% r c x \\ 7 & \text { imulq } & \% r s i, \% r d x \\ 8 & \text { addq } & \% r d x, \% r c x \\ 9 & \text { mulq } & \% r s i \\ 10 & \text { addq } & \% r c x, \% r d x \\ 11 & \text { movq } & \% r a x,(\% r d i) \\ 12 & \text { movq } & \% r d x, 8(\% r d i) \\ 13 & \text { ret } & \end{array} \) This code uses three multiplications for the multiprecision arithmetic required to implement 128-bit arithmetic on a 64-bit machine. Describe the algorithm used to compute the product, and annotate the assembly code to show how it realizes your algorithm. Hint: When extending arguments of x and y to 128 bits, they can be rewritten as x=264xh+xl and y=264yh+yl, where xh,xl,yh, and yl are 64bit values. Similarly, the 128-bit product can be written as p=264ph+pl, where ph and pl are 64-bit values. Show how the code computes the values of ph and pl in terms of xh,xl,yh, and ylStep 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