Created
December 6, 2021 23:08
-
-
Save Const-me/bdcdfc24734f0477e7aab3c2326af562 to your computer and use it in GitHub Desktop.
This file contains 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
__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