Skip to content

Instantly share code, notes, and snippets.

@LucianoPAlmeida
Last active March 14, 2021 19:52
Show Gist options
  • Save LucianoPAlmeida/9e052d288239a8da23813cffd3ec5772 to your computer and use it in GitHub Desktop.
Save LucianoPAlmeida/9e052d288239a8da23813cffd3ec5772 to your computer and use it in GitHub Desktop.
// 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