#define MIN_MAX_SSE2( A, B ) \
{ \
const __m128i max = _mm_max_epi16( A, B ); \
const __m128i min = _mm_min_epi16( B, A ); \
A = min; \
B = max; \
}
SSE2未対応CPU用にMMX版もあります。
#define MIN_MAX_MMX( A, B ) \
{ \
const __m64 mask = _mm_cmpgt_pi16( A, B ); \
const __m64 max = _mm_or_si64( _mm_andnot_si64( mask, B ), _mm_and_si64( mask, A ) ); \
const __m64 min = _mm_or_si64( _mm_andnot_si64( mask, A ), _mm_and_si64( mask, B ) ); \
A = min; \
B = max; \
}
#define MIN_MAX_MMX( A, B ) \
{ \
const __m64 t = _mm_and_si64( _mm_xor_si64( A, B ), _mm_cmpgt_pi16( A, B ) ); \
A = _mm_xor_si64( t, A ); \
B = _mm_xor_si64( t, B ); \
}