Skip to content

Commit

Permalink
simd: show aligned store in avx_broadcast.cpp
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bevenius <[email protected]>
  • Loading branch information
danbev committed Jun 15, 2024
1 parent 688b286 commit 8fd0ef1
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion fundamentals/simd/src/avx_broadcast.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
#include <immintrin.h>
#include <iostream>

bool isAligned32(void* ptr) {
return (uintptr_t) ptr % 32 == 0;
}

int main() {
double vb = 3.0;
printf("is vb aliged: %s\n", isAligned32(&vb) ? "true" : "false");

__m256d broadcasted = _mm256_broadcast_sd(&vb);

double result[4];
// store unaligned
_mm256_storeu_pd(result, broadcasted);
printf("Result: [%f, %f, %f, %f]\n", result[0], result[1], result[2], result[3]);
printf("Unaligned Result: [%f, %f, %f, %f]\n", result[0], result[1], result[2], result[3]);

alignas(32) double vb2 = 3.0;
printf("Is vb2 aliged: %s\n", isAligned32(&vb2) ? "true" : "false");
__m256d broadcasted2 = _mm256_broadcast_sd(&vb2);
alignas(32) double result2[4];
// store aligned
_mm256_store_pd(result2, broadcasted);
printf("Aligned Result: [%f, %f, %f, %f]\n", result2[0], result2[1], result2[2], result2[3]);

return 0;
}

0 comments on commit 8fd0ef1

Please sign in to comment.