Skip to content

Instantly share code, notes, and snippets.

@hyunsik
Created April 3, 2013 18:44
Show Gist options
  • Save hyunsik/5304001 to your computer and use it in GitHub Desktop.
Save hyunsik/5304001 to your computer and use it in GitHub Desktop.
sum_unrolled.c
int sum_unrolled( int n, int *a )
{
int sum = 0;
/* do the body of the work in a faster unrolled loop */
for( int i = 0; i < n/4*4; i += 4 )
{
sum += a[i+0];
sum += a[i+1];
sum += a[i+2];
sum += a[i+3];
}
/* handle the small tail in a usual way */
for( int i = n/4*4; i < n; i++ )
sum += a[i];
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment