How do I convert _m128i to an unsigned int with SSE?

前端 未结 2 2055
野趣味
野趣味 2021-02-10 05:41

I have made a function for posterizing images.

// =(
#define ARGB_COLOR(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))

inline UINT         


        
2条回答
  •  無奈伤痛
    2021-02-10 06:23

    Unfortunately, there's no instruction to do that even in AVX (none that I'm aware of). So you will have to do it manually like are right now.

    However, your current method is very sub-optimal and you're relying on .m128i_u8 which is an MSVC extension. Based on my experience with MSVC, it will use an aligned buffer to access the individual elements. This has a very heavy penalty because of partial-word access.

    Instead of .m128i_u8, use _mm_extract_epi32(). This is in SSE4.1. But you're already relying with SSE4.1 with _mm_cvtepu8_epi32().

    This situation is particularly bad since you're working with 1-byte granularity. If you were working with 2-byte (16-bit integer) granularity instead, there is an efficient solution using shuffle intrinsics.

提交回复
热议问题