Question

Suppose I have the following 4 vectors of doubles in Xeon Phi registers:

A-> |a8|a7|a6|a5|a4|a3|a2|a1|
B-> |b8|b7|b6|b5|b4|b3|b2|b1|
C-> |c8|c7|c6|c5|c4|c3|c2|c1|
D-> |d8|d7|d6|d5|d4|d3|d2|d1|

I want to permute them into the following:

A_new ->|d2|d1|c2|c1|b2|b1|a2|a1|
B_new ->|d4|d3|c4|c3|b4|b3|a4|a3|
C_new ->|d6|d5|c6|c5|b6|b5|a6|a5|
D_new ->|d8|d7|c8|c7|b8|b7|a8|a7|

The goal is to get :

O = _mm512_add_pd(_mm512_add_pd(A_new,B_new),_mm512_add_pd(C_new,D_new));

How can I achiever the above with the least number of instructions/cycles?

Was it helpful?

Solution

Answered by Evgueni Petrov in the Intel forums:

__m512i a1 = (__m512i)_mm512_mask_blend_pd(0x33, B, _mm512_swizzle_pd(A, _MM_SWIZ_REG_BADC));
__m512i a0 = (__m512i)_mm512_mask_blend_pd(0xcc, A, _mm512_swizzle_pd(B, _MM_SWIZ_REG_BADC));
__m512i a3 = (__m512i)_mm512_mask_blend_pd(0x33, D, _mm512_swizzle_pd(C, _MM_SWIZ_REG_BADC));
__m512i a2 = (__m512i)_mm512_mask_blend_pd(0xcc, C, _mm512_swizzle_pd(D, _MM_SWIZ_REG_BADC));

__m512d C_new = (__m512d)_mm512_mask_alignr_epi32(a2, 0x00ff, a0, a0, 8);
__m512d A_new = (__m512d)_mm512_mask_alignr_epi32(a0, 0xff00, a2, a2, 8);
__m512d D_new = (__m512d)_mm512_mask_alignr_epi32(a3, 0x00ff, a1, a1, 8);
__m512d B_new = (__m512d)_mm512_mask_alignr_epi32(a1, 0xff00, a3, a3, 8);

As of this writing, the _mm512_mask_blend_pd() intrinsic isn't mentioned in the Intel C++ User Guide but should be corrected soon. It is present in the "zmmintrin.h" header file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top