SSE version for modf

I have the following working implementation modfusing the built-in SSE functions, but it seems pretty wasteful to convert in __m128iand out to a process when I need a result like __m128.

__m128 integer = _mm_cvtepi32_ps(_mm_cvttps_epi32(value));
__m128 fraction = _mm_sub_ps(value, integer);

Is there an instruction to truncate without type conversion or any kind of magic hack?

+4
source share
1 answer

With SSE4.1, you can use the instructions and : roundpsroundpd

//  Single Precision
__m128 integer = _mm_round_ps(value,_MM_FROUND_TRUNC);
__m128 fraction = _mm_sub_ps(value,integer);

//  Double Precision
__m128d integer = _mm_round_pd(value,_MM_FROUND_TRUNC);
__m128d fraction = _mm_sub_pd(value,integer);

This will separate the integer and fractional parts, keeping the sign for both of them.

Similarly for AVX:

//  Single Precision
__m256 integer = _mm256_round_ps(value,_MM_FROUND_TRUNC);
__m256 fraction = _mm256_sub_ps(value,integer);

//  Double Precision
__m256d integer = _mm256_round_pd(value,_MM_FROUND_TRUNC);
__m256d fraction = _mm256_sub_pd(value,integer);

XOP, ( _mm256_frcz_pd ).

SSE4.1, "+/- ". ( )

+4

All Articles