Minimum of 4 SP values in __m128
c, simd, sse
Solution
There is no single instruction/intrinsic but you can do it with two shuffles and two mins:
__m128 _mm_hmin_ps(__m128 v)
{
v = _mm_min_ps(v, _mm_shuffle_ps(v, v, _MM_SHUFFLE(2, 1, 0, 3)));
v = _mm_min_ps(v, _mm_shuffle_ps(v, v, _MM_SHUFFLE(1, 0, 3, 2)));
return v;
}
The output vector will contain the min of all the elements in the input vector, replicated throughout the output vector.
Problem
Suppose to have a `__m128` variable holding 4 SP values, and you want the minimum one, is there any intrinsic function available, or anything other than the naive linear comparison among the values? Right know my solution is the following (suppose the input `__m128` variable is `x`): ``` x = _mm_min_ps(x, (__m128)_mm_srli_si128((__m128i)x, 4)); min = _mm_min_ss(x, (__m128)_mm_srli_si128((__m128i)x, 8))[0]; ``` Which is quite horrible but it's working (btw, is there anything like `_mm_srli_si128` but for the `__m128` type?)