How to count character occurrences using SIMD

后端 未结 3 820
耶瑟儿~
耶瑟儿~ 2020-12-21 13:04

I am given a array of lowercase characters (up to 1.5Gb) and a character c. And I want to find how many occurrences are of the character c using AVX instructions.

         


        
3条回答
  •  遥遥无期
    2020-12-21 13:31

    If you don't insist on using only SIMD instructions, you can make use
    of the VPMOVMSKB instruction in combination with the POPCNT instruction. The former combines the highest bits of each byte into a 32-bit integer mask and the latter counts the 1 bits in this integer (=the count of char matches).

    int couter=0;
    for(i=0; i

    I haven't tested this solution, but you should get the gist.

提交回复
热议问题