Question: plz solve this proble TT The library function memset has the following prototype void enemset (void es int c, size_t n) This function fills n


plz solve this proble TT
The library function memset has the following prototype void enemset (void es int c, size_t n) This function fills n bytes of the memory area starting at s with copies of the loworder byte of C. For example, itcan be used to zero out a region of memory by giving argument 0 for C, but other values are possible. The following is a straightforward implementation of memset 1 Basic implementation of memset 2 void *basic memset (void *s int c, size t n) Size t cnt 0; unsigned char schar s while (cnt n) schar++ (unsigned char C; ent return 10 11 Implement a more efficient version of the function by using a word of data type unsigned long to pack eight copies of c, and then step through the region using word-level writes. You might find it helpful to do additional loop unrolling as well. On our reference machine, we were able to reduce the CPE from 1.00 for the straightforward implementation t 0.127. That is, the program is able to write 8 bytes every clock cycle. Here are some additional guidelines. To ensure portability, let K denote the value of sizeof (unsigned long) for the machine on which you run your program You may not call any library functions. Your code should work for arbitrary values of n, including when it is not a multiple of K. You can do this in a manner similar to the way we finish the last few iterations with loop unrolling You should write your code so that it will compile and run correctly on any machine regardless of the value of K. Make use of the operation sizeof to do this On some machines, unaligned writes can be much slower than aligned ones. (On some non- x86 machines, they can even cause segmentation faults.) Write your code so that it starts with byte-level writes until the destination address is a multiple of K, then do word-level writes, and
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
