我想使用'_mm_cmpgt_epi8'来获取比较值。 [英] I want to use the '_mm_cmpgt_epi8' to get the comparison value.

查看:413
本文介绍了我想使用'_mm_cmpgt_epi8'来获取比较值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我按以下顺序进行。



1.定义了一个, b,c,如下所示。

Hi all.

I proceeded in the following order.

1. Defined a,b,c, as following.

__m128i a = _mm_set_epi8(136,135,134,133,132,131,130,129,128,127,126,125,124,123,122,121);
__m128i b = _mm_set1_epi8(125);
__m128i c = _mm_setzero_si128();



2.使用'_mm_cmpgt_epi8'获取'c'。


2. Use the '_mm_cmpgt_epi8' to get the 'c'.

c = _mm_cmpgt_epi8(a, b);



所以我期待这个结果。

255,255,255,255,255,255,255,255,255,255,255,0,0, 0,0,0



但我得到了这个结果。

0,0,0,0,0,0, 0,0,0, 255,255,0,0,0,0,0



所以我得出以下结论:

1.如果'a'的值从0到127,则输出正常比较值。

2.如果'a'的值大于128,则值始终为输出为0.



出现什么问题?



我要比较0到255之间的值。



有解决方案吗?



我尝试了什么:



我通过将'a'的值更改为0到255来获得结果。


So I expected this result.
255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0

But I got this result.
0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0

So I got the following conclusions.
1. If the value of 'a' is from 0 to 127, the normal comparison value is output.
2. If the value of 'a' is greater than 128, the value is always output to 0.

What kind of problem?

I want to compare the value 0 to 255.

Is there a solution?

What I have tried:

I had obtained the result by changing the value of 'a' to 0 to 255.

推荐答案

从内在的描述:

From the description of the intrinsic:
Quote:

比较a中16个带符号的8位整数和b中16个带符号的8位整数大于。

Compares the 16 signed 8-bit integers in a and the 16 signed 8-bit integers in b for greater than.



比较签名的 8位值。因此,所有值> = 128都是负的(记住减去256)。例如,值136被视为-119,显然小于125.



此SO线程提供了比较无符号值的解决方案: c ++ - SSE2内在函数 - 比较无符号整数 - 堆栈溢出 [ ^ ]


It compares signed 8-bit values. So all values >= 128 are negative (subtract 256 in mind). For example the value 136 is treated as -119 which is obviously less than 125.

This SO thread provides a solution for comparing unsigned values: c++ - SSE2 intrinsics - comparing unsigned integers - Stack Overflow[^]


这篇关于我想使用'_mm_cmpgt_epi8'来获取比较值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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