Skip to content

Commit

Permalink
Lab vectorization 2
Browse files Browse the repository at this point in the history
  • Loading branch information
simveit committed Dec 19, 2024
1 parent c86b55b commit b5514b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions labs/core_bound/vectorization_2/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

uint16_t checksum(const Blob &blob) {
uint16_t acc = 0;
for (auto value : blob) {
Carry carry = {};
for (int i = 0; i < blob.size(); i++) {
uint16_t value = blob[i];
acc += value;
acc += acc < value; // add carry
carry[i] = acc < value; // save carry
}
for (int i = 0; i < blob.size(); i++) {
acc += carry[i];
}
return acc;
}
1 change: 1 addition & 0 deletions labs/core_bound/vectorization_2/solution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
constexpr std::size_t N = 64 * 1024;

using Blob = std::array<uint16_t, N>;
using Carry = std::array<uint16_t, N>;

void init(Blob &blob);
uint16_t checksum(const Blob &blob);

0 comments on commit b5514b8

Please sign in to comment.