如何比较 __m128 类型? [英] How to compare __m128 types?
问题描述
__m128 a;
__m128 b;
如何编码a != b
?
使用什么:_mm_cmpneq_ps
或 _mm_cmpneq_ss
?
如何处理结果?
找不到足够的文档.
推荐答案
您可能应该使用 _mm_cmpneq_ps
.但是,SIMD 代码与标量代码的比较解释略有不同.你想测试 any 对应的元素不相等吗?还是所有对应的元素不相等?
You should probably use _mm_cmpneq_ps
. However the interpretation of comparisons is a little different with SIMD code than with scalar code. Do you want to test for any corresponding element not being equal ? Or all corresponding elements not being equal ?
要测试 _mm_cmpneq_ps
的 4 个比较的结果,您可以使用 _mm_movemask_epi8
.
To test the results of the 4 comparisons from _mm_cmpneq_ps
you can use _mm_movemask_epi8
.
请注意,比较浮点值是否相等或不等通常不是一个好主意,除非在非常特殊的情况下.
__m128i vcmp = (__m128i)_mm_cmpneq_ps(a, b); // compare a, b for inequality
uint16_t test = _mm_movemask_epi8(vcmp); // extract results of comparison
if (test == 0xffff)
// *all* elements not equal
else if (test != 0)
// *some* elements not equal
else
// no elements not equal, i.e. all elements equal
对于文档,您需要来自英特尔的这两卷:
For documentation you want these two volumes from Intel:
英特尔® 64 和 IA-32 架构软件开发人员手册第 2A 卷:指令集参考,A-M
英特尔® 64 和 IA-32 架构软件开发人员手册第 2B 卷:指令集参考,N-Z
这篇关于如何比较 __m128 类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!