Getting max value in a __m128i vector with SSE?

后端 未结 4 2103
Happy的楠姐
Happy的楠姐 2020-11-30 12:21

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 =         


        
4条回答
  •  一整个雨季
    2020-11-30 12:57

    According to this page, there is no horizontal max, and you need to test the elements vertically:

    movhlps xmm1,xmm0         ; Move top two floats to lower part of xmm1
    maxps   xmm0,xmm1         ; Get maximum of the two sets of floats
    pshufd  xmm1,xmm0,$55     ; Move second float to lower part of xmm1
    maxps   xmm0,xmm1         ; Get minimum of the two remaining floats
    

    Conversely, getting the minimum:

    movhlps xmm1,xmm0
    minps   xmm0,xmm1
    pshufd  xmm1,xmm0,$55
    minps   xmm0,xmm1
    

提交回复
热议问题