Last active
August 29, 2015 14:13
-
-
Save reinsteam/160d24a581883e1da2ce to your computer and use it in GitHub Desktop.
AoS => SoA transformation for 3-component vectors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*---------------------------------------------------------------------------------------------------------------------- | |
input : srcStream => four 3-component vectors : x0y0z0 x1y1z1 x2y2z2 x3y3z3 | |
output : dstStream => three 4-component vectors : x0x1x2x3 y0y1y2y3 z0z1z2z3 | |
----------------------------------------------------------------------------------------------------------------------*/ | |
void AoS2SoA(float * __restrict dstStream, float const * __restrict srcStream) | |
{ | |
__m128 x1_y1_z1_x2 = _mm_load_ps(srcStream + 0); | |
__m128 y2_z2_x3_y3 = _mm_load_ps(srcStream + 4); | |
__m128 z3_x4_y4_z4 = _mm_load_ps(srcStream + 8); | |
__m128 y1_z1_y2_z2 = _mm_shuffle_ps(x1_y1_z1_x2, y2_z2_x3_y3, _MM_SHUFFLE(1, 0, 2, 1)); | |
__m128 x3_y3_x4_y4 = _mm_shuffle_ps(y2_z2_x3_y3, z3_x4_y4_z4, _MM_SHUFFLE(2, 1, 3, 2)); | |
__m128 x1_x2_x3_x4 = _mm_shuffle_ps(x1_y1_z1_x2, x3_y3_x4_y4, _MM_SHUFFLE(2, 0, 3, 0)); | |
__m128 z1_z2_z3_z4 = _mm_shuffle_ps(y1_z1_y2_z2, z3_x4_y4_z4, _MM_SHUFFLE(3, 0, 3, 1)); | |
__m128 y1_y2_y3_y4 = _mm_shuffle_ps(y1_z1_y2_z2, x3_y3_x4_y4, _MM_SHUFFLE(3, 1, 2, 0)); | |
_mm_store_ps(dstStream + 0, x1_x2_x3_x4); | |
_mm_store_ps(dstStream + 4, y1_y2_y3_y4); | |
_mm_store_ps(dstStream + 8, z1_z2_z3_z4); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment