Skip to content

Commit

Permalink
Update cpp.md
Browse files Browse the repository at this point in the history
Signed-off-by: Dennis Eichhorn <spl1nes.com@googlemail.com>
  • Loading branch information
spl1nes authored Aug 5, 2024
1 parent 00739a9 commit 79644ad
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions standards/cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,15 @@ Performs 8 additions at the same time:
```c++
void add_arrays(float* a, float* b, float* result, size_t size) {
size_t i = 0;
for (; i < size - (size % 8); i += 8) { // Process 8 elements at a time
for (; i < size - (size % 8); i += 8) {
__m256 va = _mm256_loadu_ps(&a[i]);
__m256 vb = _mm256_loadu_ps(&b[i]);
__m256 vr = _mm256_add_ps(va, vb);
_mm256_storeu_ps(&result[i], vr);
}
for (; i < size; ++i) { // Handle the remainder
// Handle the remainder if size is not dividable by 8
for (; i < size; ++i) {
result[i] = a[i] + b[i];
}
}
Expand Down

0 comments on commit 79644ad

Please sign in to comment.