Question: #include typedef word_t word_t; word_t src[8], dst[8]; /* $begin ncopy */ /* * ncopy - copy src to dst, returning number of positive ints *
#include
typedef word_t word_t;
word_t src[8], dst[8];
/* $begin ncopy */ /* * ncopy - copy src to dst, returning number of positive ints * contained in src array. */ word_t ncopy(word_t *src, word_t *dst, word_t len) { word_t count = 0; word_t val;
while (len > 0) { val = *src++; *dst++ = val; if (val > 0) count++; len--; } return count; } /* $end ncopy */
int main() { word_t i, count;
for (i=0; i<8; i++) src[i]= i+1; count = ncopy(src, dst, 8); printf ("count=%d ", count); exit(0); }
How would i translate the above code into y-86 using the template below.
################################################################## # ncopy.ys - Copy a src block of len words to dst. # Return the number of positive words (>0) contained in src. # ################################################################## # Do not modify this portion # Function prologue. # %rdi = src, %rsi = dst, %rdx = len ncopy:
################################################################## # You can modify this portion # Loop header xorq %rax,%rax # count = 0; andq %rdx,%rdx # len <= 0? jle Done # if so, goto Done:
Loop: mrmovq (%rdi), %r10 # read val from src... rmmovq %r10, (%rsi) # ...and store it to dst andq %r10, %r10 # val <= 0? jle Npos # if so, goto Npos: irmovq $1, %r10 addq %r10, %rax # count++
Npos: irmovq $1, %r10 subq %r10, %rdx # len-- irmovq $8, %r10 addq %r10, %rdi # src++ addq %r10, %rsi # dst++ andq %rdx,%rdx # len > 0? jg Loop # if so, goto Loop: ################################################################## # Do not modify the following section of code # Function epilogue. Done: ret ################################################################## # Keep the following label at the end of your function End: #/* $end ncopy-ys */
Your task in Part C is to modify ncopy.ys with the goal of making ncopy.ys run as fast as possible.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
