C++ SSE filter implementation

后端 未结 1 1345
悲&欢浪女
悲&欢浪女 2021-01-24 12:23

I tried to use SSE to do 4 pixels operation. I have problem in loading the image data to __m128. My image data is a char buffer. Let say my image is 1024 x1024. My filter is 16x

1条回答
  •  时光说笑
    2021-01-24 12:35

    If you really need to do this with floating point rather then integer/fixed point then you will need to load your 8 bit data, unpack to 32 bits (requires two operations: 8 bit to 16 bit, then 16 bit to 32 bit), then convert to float. This is horribly inefficient though, and you should look at doing this with e.g. 16 bit fixed point operations.

    Note that for each 16 pixel load you will then have 4 blocks of 4 x float to process, i.e. your vectors of 16 x 8 bit pixels will become 4 x vectors of 4 x floats.

    Summary of required intrinsics:

    _mm_load_si128(...)       // load 16 x 8 bit values
    
    _mm_unpacklo_epi8(...)    // unpack 8 bit -> 16 bit
    _mm_unpackhi_epi8(...)
    
    _mm_unpacklo_epi16(...)   // unpack 16 bit -> 32 bit
    _mm_unpackhi_epi16(...)
    
    _mm_cvtepi32_ps(...)      // convert 32 bit int -> float
    

    0 讨论(0)
提交回复
热议问题