Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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