Skip to content

Instantly share code, notes, and snippets.

@kaityo256
Created May 1, 2015 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kaityo256/3b5601438ccf8d511cb9 to your computer and use it in GitHub Desktop.
Save kaityo256/3b5601438ccf8d511cb9 to your computer and use it in GitHub Desktop.
//----------------------------------------------------------------------
#include <stdio.h>
#include <emmintrin.h>
#include <immintrin.h>
//----------------------------------------------------------------------
void
printm256(__m256d r){
double *a = (double*)(&r);
printf("%f %f %f %f\n",a[0],a[1],a[2],a[3]);
}
//----------------------------------------------------------------------
void
print4bit(int i){
while(i>0){
printf("%d",i%1);
i = i << 1;
}
printf("\n");
}
//----------------------------------------------------------------------
int
main(void){
printf("Pack\n");
__m256d r = _mm256_set_pd(1.0,2.0,3.0,4.0);
__m256d r2 = _mm256_set_pd(-1.0,-2.0,-3.0,-4.0);
printm256(r2);
printf("Broadcast\n");
double a = 1.0;
printm256(_mm256_broadcast_sd(&a));
printf("Shuffle\n");
for(int i=0;i<16;i++){
printm256(_mm256_shuffle_pd(r,r2,i));
}
}
//----------------------------------------------------------------------
/* Result
$ icpc m256.cc
$ ./a.out
Pack
-4.000000 -3.000000 -2.000000 -1.000000
Broadcast
1.000000 1.000000 1.000000 1.000000
Shuffle
4.000000 -4.000000 2.000000 -2.000000
3.000000 -4.000000 2.000000 -2.000000
4.000000 -3.000000 2.000000 -2.000000
3.000000 -3.000000 2.000000 -2.000000
4.000000 -4.000000 1.000000 -2.000000
3.000000 -4.000000 1.000000 -2.000000
4.000000 -3.000000 1.000000 -2.000000
3.000000 -3.000000 1.000000 -2.000000
4.000000 -4.000000 2.000000 -1.000000
3.000000 -4.000000 2.000000 -1.000000
4.000000 -3.000000 2.000000 -1.000000
3.000000 -3.000000 2.000000 -1.000000
4.000000 -4.000000 1.000000 -1.000000
3.000000 -4.000000 1.000000 -1.000000
4.000000 -3.000000 1.000000 -1.000000
3.000000 -3.000000 1.000000 -1.000000
*/
//----------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment