Question: Using C Language I've begun a C function that intends to bitwise xor two memory buffers together and write the result to a third buffer

Using C Language

I've begun a C function that intends to bitwise xor two memory buffers together and write the result to a third buffer (ie, the i-th byte of output is the bitwise xor of the i-th bytes of the two inputs). Finish the function using SSE to accellerate the process. If the buffer is not a multiple of 16 bytes long, you will need to complete the xoring in a second loop that xors one byte at a time. Use SSE instrinsics for all SSE loads, stores, and manipulations.

Pseudo code BELOW

while(size is greater than 16)

load sc1 with SSE function to x

load sc2 with SSE function to y

xor x and y with xor SSE function and store into res variable

Use SSE store function to store res into dst

adjust the pointer for dst, sc1, sc2 by 16 bytes

subtract 16 from the sz

after loop xor the remaining bytes from sc1 and sc2 and store them into dst

Using C Language I've begun a C function that intends to bitwise

1 #include 2 #include 3 4 /* Bitwise xors sz bytes of memory beginning at src1 and src2 */ 5 /* writing the results to memory beginning at dst. */ 6- void xor_sse(void *dst, void *srci, void *srca, int sz) { 7 uint8_t *d (uint8_t *)dst; // d has same address as dst 8 uint8_t *s1 (uint8_t *)src1; // s1 has same address as src1 9 uint8_t *s2 (uint8_t *)src2; // s2 has same address as srca 10 11 // Write loop that uses SSE as far as possible 12 13 // Write loop that finishes any leftover without SSE 14 } 15 1 #include 2 #include 3 4 /* Bitwise xors sz bytes of memory beginning at src1 and src2 */ 5 /* writing the results to memory beginning at dst. */ 6- void xor_sse(void *dst, void *srci, void *srca, int sz) { 7 uint8_t *d (uint8_t *)dst; // d has same address as dst 8 uint8_t *s1 (uint8_t *)src1; // s1 has same address as src1 9 uint8_t *s2 (uint8_t *)src2; // s2 has same address as srca 10 11 // Write loop that uses SSE as far as possible 12 13 // Write loop that finishes any leftover without SSE 14 } 15

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!