有序/无序比较是什么意思? [英] What does ordered / unordered comparison mean?
本文介绍了有序/无序比较是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
看上证所运营商
CMPORDPS - ordered compare packed singles
CMPUNORDPS - unordered compare packed singles
有序和无序是什么意思?我在x86指令集中寻找了等效指令,但它似乎只有无序(FUCOM).
What do ordered and unordered mean? I looked for equivalent instructions in the x86 instruction set, and it only seems to have unordered (FUCOM).
推荐答案
有序比较检查两个操作数是否都不为NaN
.相反,无序比较检查两个操作数是否为NaN
.
An ordered comparison checks if neither operand is NaN
. Conversely, an unordered comparison checks if either operand is a NaN
.
此页面提供了更多有关此的信息:
This page gives some more information on this:
- http://csapp.cs.cmu.edu/public/waside/waside-sse.pdf (section 5)
这里的想法是与NaN
的比较是不确定的. (无法确定结果).因此,有序/无序比较会检查情况是否如此.
The idea here is that comparisons with NaN
are indeterminate. (can't decide the result) So an ordered/unordered comparison checks if this is (or isn't) the case.
double a = 0.;
double b = 0.;
__m128d x = _mm_set1_pd(a / b); // NaN
__m128d y = _mm_set1_pd(1.0); // 1.0
__m128d z = _mm_set1_pd(1.0); // 1.0
__m128d c0 = _mm_cmpord_pd(x,y); // NaN vs. 1.0
__m128d c1 = _mm_cmpunord_pd(x,y); // NaN vs. 1.0
__m128d c2 = _mm_cmpord_pd(y,z); // 1.0 vs. 1.0
__m128d c3 = _mm_cmpunord_pd(y,z); // 1.0 vs. 1.0
__m128d c4 = _mm_cmpord_pd(x,x); // NaN vs. NaN
__m128d c5 = _mm_cmpunord_pd(x,x); // NaN vs. NaN
cout << _mm_castpd_si128(c0).m128i_i64[0] << endl;
cout << _mm_castpd_si128(c1).m128i_i64[0] << endl;
cout << _mm_castpd_si128(c2).m128i_i64[0] << endl;
cout << _mm_castpd_si128(c3).m128i_i64[0] << endl;
cout << _mm_castpd_si128(c4).m128i_i64[0] << endl;
cout << _mm_castpd_si128(c5).m128i_i64[0] << endl;
结果:
0
-1
-1
0
0
-1
-
NaN
和1.0
的有序比较得到false
. -
NaN
和1.0
的无序比较给出true
. - 有序比较给出
true
. - 无序比较给出
false
. -
NaN
和Nan
的有序比较得到false
. -
NaN
和NaN
的无序比较给出true
. - Ordered comparison of
NaN
and1.0
givesfalse
. - Unordered comparison of
NaN
and1.0
givestrue
. - Ordered comparison of
1.0
and1.0
givestrue
. - Unordered comparison of
1.0
and1.0
givesfalse
. - Ordered comparison of
NaN
andNan
givesfalse
. - Unordered comparison of
NaN
andNaN
givestrue
.
1.0
的1.0
的
这篇关于有序/无序比较是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文