Skip to content

Instantly share code, notes, and snippets.

@lgolubyev
Created May 23, 2022 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgolubyev/fec32a829598f04ecfca747aacf0b5ac to your computer and use it in GitHub Desktop.
Save lgolubyev/fec32a829598f04ecfca747aacf0b5ac to your computer and use it in GitHub Desktop.
pivate static int SumOdd_BranchFree_Parallel_NoChecks_BetterPorts(int[] array)
{
int counterA = 0;
int counterB = 0;
int counterC = 0;
int counterD = 0;
fixed (int* data = &array[0])
{
var p = (int*)data;
var n = (int*)data;
for (var i = 0; i < array.Length; i += 4)
{
counterA += (n[0] & 1) * p[0];
counterB += (n[1] & 1) * p[1];
counterC += (n[2] & 1) * p[2];
counterD += (n[3] & 1) * p[3];
p += 4;
n += 4;
}
return counterA + counterB + counterC + counterD;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment