Created
April 3, 2013 18:44
-
-
Save hyunsik/5304001 to your computer and use it in GitHub Desktop.
sum_unrolled.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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