Skip to content

Instantly share code, notes, and snippets.

@Const-me
Created December 6, 2021 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Const-me/bdcdfc24734f0477e7aab3c2326af562 to your computer and use it in GitHub Desktop.
Save Const-me/bdcdfc24734f0477e7aab3c2326af562 to your computer and use it in GitHub Desktop.
__m128i convertMask( __m256d src )
{
// Bit-cast into fp32 vector, the intrinsic compiles into no instructions
const __m256 f32 = _mm256_castpd_ps( src );
// Split into high/low halves; casting is free, vextractf128 is not.
const __m128 low = _mm256_castps256_ps128( f32 );
const __m128 high = _mm256_extractf128_ps( f32, 1 );
// Combine 32-bit values into a single vector with correct order
// _mm_shuffle_ps takes first 2 lanes from the first argument, last 2 lanes fro the second argument.
const __m128 combined = _mm_shuffle_ps( low, high, _MM_SHUFFLE( 2, 0, 2, 0 ) );
// Cast result into int vector
return _mm_castps_si128( combined );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment