I have an array pointer int * counters
in which there are some counters of all letters of the alphabet. There is a char * array
with random letters and I have to count all the occurences of all letters in the array using AVX,AVX2 vectors. I am using __256i
of 8-bit vectors, so 32 characters at a time and I want to update the counters based on the 32 characters I have at each iteration in the vector.
The problem is that we cannot know which letters there are at the iteration, so the only way I could think of is update the counters serial based on the characters, that is:
for (int j = 0; j < 32; j++) {
counters[array[j]-'a']++;
}
So, if it is possible, how could I change this for loop with SIMD executions so that I update more counters at a time and not updating them serial?
Is there any instruction like gather
that instead of getting data from memory, storing it in different locations in it?
I am sorry if what I am asking isn't that clear, so please ask to elaborate
Thank you in advance.