How can I use SIMD to accelerate XOR two blocks of memory?

后端 未结 3 1214
心在旅途
心在旅途 2021-01-12 14:09

I want to XOR two blocks of memory as quickly as possible, How can I use SIMD to accelerate it?

My original code is below:

void region_xor_w64(   uns         


        
3条回答
  •  一生所求
    2021-01-12 14:33

    As the size of the region is passed by value why wouldn't the code be:

    void region_xor_w64(unsigned char *r1, unsigned char *r2, unsigned int i)
    {
        while (i--)
            r2[i] = r1[i] ^ r2[i];
    }
    

    or even:

    void region_xor_w64(unsigned char *r1, unsigned char *r2, unsigned int i)
    {
        while (i--)
            r2[i] ^= r1[i];
    }
    

    If there's a preference towards going forwards ('up memory') and for using pointers, then:

    void region_xor_w64(unsigned char *r1, unsigned char *r2, unsigned int i)
    {
        while (i--)
            *r2++ ^= *r1++;
    }
    

提交回复
热议问题