In float
, it seems pretty easy to floor()
and than int()
, such as:
float z = floor(LOG2EF * x + 0.5f);
const int32_t n = int32_t(z);
become:
__m128 z = _mm_add_ps(_mm_mul_ps(log2ef, x), half);
__m128 t = _mm_cvtepi32_ps(_mm_cvttps_epi32(z));
z = _mm_sub_ps(t, _mm_and_ps(_mm_cmplt_ps(z, t), one));
__m128i n = _mm_cvtps_epi32(z);
But how would you achieve this in double
using only SSE2?
This is the double version I'd like to convert:
double z = floor(LOG2E * x + 0.5);
const int32_t n = int32_t(z);