Skip to content

Instantly share code, notes, and snippets.

@xigh
Created May 19, 2020 07:22
Show Gist options
  • Save xigh/d147be7f766fb1d291ec9ff3238dc068 to your computer and use it in GitHub Desktop.
Save xigh/d147be7f766fb1d291ec9ff3238dc068 to your computer and use it in GitHub Desktop.
#include <immintrin.h>
#include <inttypes.h>
#include <stdio.h>
char * sprint_m256(__m256 v) {
static char tmp[256];
snprintf(tmp, sizeof tmp, "[%8.2f, %8.2f, %8.2f, %8.2f, %8.2f, %8.2f, %8.2f, %8.2f]",
v[7], v[6], v[5], v[4], v[3], v[2], v[1], v[0]);
return tmp;
}
char * sprint_m128(__m128 v) {
static char tmp[256];
snprintf(tmp, sizeof tmp, "[%8.2f, %8.2f, %8.2f, %8.2f]",
v[3], v[2], v[1], v[0]);
return tmp;
}
int main(int argc, char **argv) {
__m256 a = _mm256_set_ps(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 0.0f, 0.0f, 0.0f);
printf("a= %s\n", sprint_m256(a));
__m256 b = _mm256_set_ps(6.0f, 7.0f, 8.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
printf("b= %s\n", sprint_m256(b));
printf("\n");
__m128 h = _mm256_extractf128_ps(b, 1);
__m128 z = _mm_set1_ps(0.0f);
__m256 t = _mm256_setr_m128(h, z);
printf("t= %s\n", sprint_m256(t));
t = _mm256_permute_ps(t, 0b00111001);
printf("t= %s {after permute}\n", sprint_m256(t));
__m256 c = _mm256_blend_ps(a, t, 0b00000111);
printf("c= %s\n", sprint_m256(c));
return 0;
}
@xigh
Copy link
Author

xigh commented May 19, 2020

With this code, I get :

a= [ 1.00, 2.00, 3.00, 4.00, 5.00, 0.00, 0.00, 0.00]
b= [ 6.00, 7.00, 8.00, 0.00, 0.00, 0.00, 0.00, 0.00]

t= [ 0.00, 0.00, 0.00, 0.00, 6.00, 7.00, 8.00, 0.00]
t= [ 0.00, 0.00, 0.00, 0.00, 0.00, 6.00, 7.00, 8.00] {after permute}
c= [ 1.00, 2.00, 3.00, 4.00, 5.00, 6.00, 7.00, 8.00]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment