Last active
March 14, 2021 19:52
-
-
Save LucianoPAlmeida/9e052d288239a8da23813cffd3ec5772 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// The vectorizer can determine the best vector width, but let's consider vectorize_width(4) | |
#pragma clang loop vectorize(enable) vectorize_width(4) | |
int addScalar(int *x, int n, int s) { | |
for (int i = 0; i < n/4/*vector_width*/; ++i) | |
// The pseudo code bellow would be performed as a single SIMD vector instruction. | |
x[i] += s; | |
x[i + 1] += s; | |
x[i + 2] += s; | |
x[i + 3] += s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment