Search code examples
cassemblyx86sse

Getting max value in a __m128i vector with SSE?


I have just started using SSE and I am confused how to get the maximum integer value (max) of a __m128i. For instance:

__m128i t = _mm_setr_ps(0,1,2,3);
// max(t) = 3;

Searching around led me to MAXPS instruction but I can't seem to find how to use that with "xmmintrin.h".

Also, is there any documentation for "xmmintrin.h" that you would recommend, rather than looking into the header file itself?


Solution

  • If you find yourself needing to do horizontal operations on vectors, especially if it's inside an inner loop, then it's usually a sign that you are approaching your SIMD implementation in the wrong way. SIMD likes to operate element-wise on vectors - "vertically" if you like, not horizontally.

    As for documentation, there is a very useful reference on intel.com which contains all the opcodes and intrinsics for everything from MMX through the various flavours of SSE all the way up to AVX and AVX-512.