C ++ SSE过滤器实现 [英] C++ SSE filter implementation

查看:210
本文介绍了C ++ SSE过滤器实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用SSE做4像素操作。
在将图像数据加载到__m128时出现问题。
我的图像数据是一个char缓冲区。
让我说我的图像是1024 x1024。
我的过滤器是16x16。

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 16x16.

__m128 IMG_VALUES, FIL_VALUES, NEW_VALUES;
//ok:
IMG_VALUES=_mm_load_ps(&pInput[0]);
//hang below:
IMG_VALUES=_mm_load_ps(&pInput[1]);

我不知道如何处理索引1,2,3 ...谢谢。

I dont know how to handle index 1,2,3... thanks.

推荐答案

如果你真的需要使用浮点数,而不是整数/固定点,那么你将需要加载你的8位数据,解压缩到32位(需要两个操作:8位到16位,然后16位到32位),然后转换为浮点数。这是可怕的低效率,但你应该看看这样做与例如。 16位固定点操作。

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.

请注意,对于每个16像素加载,您将有4个4 x浮点块处理,即您的16×8位像素的向量

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.

所需的内在函数摘要:

_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

这篇关于C ++ SSE过滤器实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆