/* * Tested with: * gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) * * With and without OMP, this works just fine with no special options: * $ gcc test2.c -o test2 && ./test2 alpha bravo charlie * 0x7fffb15cfee0 ./test2 * 0x7fffb15cfee0 alpha * 0x7fffb15cfee0 bravo * 0x7fffb15cfee0 charlie * * Using "-mavx2 -DUSE_VTYPE" works fine too. * */ #include #include #ifdef _OPENMP #include #endif #if USE_VTYPE && __AVX2__ #include #endif /* * I had to place this in a separate function to avoid having the unaligned * branch optimized away (even using -O0), since gcc is totally convinced it * simply can't be unaligned! */ void out(char *pt) { if ((size_t)pt & 31) printf("%s unaligned!\n", pt); else puts(pt); } /* * Exact same stuff as in test.c, but put in a separate function. I'm not * sure it actually ends up inlined, but anyhow it still works fine. */ static inline void func(int argc, char **argv, int i) { #if USE_VTYPE && __AVX2__ __m256i _pt[1024 / sizeof(__m256i)]; char *pt = (void*)_pt; #else __attribute__ ((aligned(32))) char pt[1024]; #endif sprintf(pt, "%p ", pt); strcat(pt, argv[i]); out(pt); } int main(int argc, char **argv) { int i; #ifdef _OPENMP #pragma omp parallel for #endif for (i = 0; i < argc; i++) { func(argc, argv, i); } return 0; }