Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me understand how the algorithm works for this machine code. Here is the unanswered problem on Chegg and it is also typed below:

Please help me understand how the algorithm works for this machine code.

Here is the unanswered problem on Chegg and it is also typed below: https://www.chegg.com/homework-help/Computer-Systems-3rd-edition-chapter-3-problem-59HWP-solution-9780134092669

Problem 3.59 (no code required): The following code computes the 128-bit product of two 64-bit signed values x and y and stores the result in memory:

1 typedef __int128 int128_t;

2

3 void store_prod(int128_t *dest, int64_t x, int64_t y) {

4 *dest = x * (int128_t) y;

5 }

GCC generates the following assembly code implementing the computation:

1 store_prod:

2 movq %rdx, %rax

3 cqto

4 movq %rsi, %rcx

5 sarq $63, %rcx

6 imulq %rax, %rcx

7 imulq %rsi, %rdx

8 addq %rdx, %rcx

9 mulq %rsi

10 addq %rcx, %rdx

11 movq %rax, (%rdi)

12 movq %rdx, 8(%rdi)

13 ret Note: xh == xh

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 = 2^64 . xh + xl and y = 2^64 . yh + yl, where xh, xl, yh, and yl are 64- bit values. Similarly, the 128-bit product can be written as p = 2^64 . ph + 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 yl .

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions

Question

=+15. Did you create a campaign that would create buzz?

Answered: 1 week ago

Question

LO1 Understand risk management and identify its components.

Answered: 1 week ago