我找到了一种方法来比较两个__m128d变量之间的上半部分。 所以我查找了https://software.intel.com/sites/landingpage/IntrinsicsGuide/相对内在函数。
但我只能找到一些内在函数来比较两个变量之间的下半部分,例如_mm_comieq_sd
。
我很奇怪为什么没有关于比较上半部分的内在函数,更重要的是,如何比较两个__m128d变量之间的上半部分?
更新
代码就像
j0 = jprev0;
j1 = jprev1;
t_0 = p_i_x - pj_x_0;
t_1 = p_i_x - pj_x_1;
r2_0 = t_0 * t_0;
r2_1 = t_1 * t_1;
t_0 = p_i_y - pj_y_0;
t_1 = p_i_y - pj_y_1;
r2_0 += t_0 * t_0;
r2_1 += t_1 * t_1;
t_0 = p_i_z - pj_z_0;
t_1 = p_i_z - pj_z_1;
r2_0 += t_0 * t_0;
r2_1 += t_1 * t_1;
#if NAMD_ComputeNonbonded_SortAtoms != 0 && ( 0 PAIR ( + 1 ) )
sortEntry0 = sortValues + g;
sortEntry1 = sortValues + g + 1;
jprev0 = sortEntry0->index;
jprev1 = sortEntry1->index;
#else
jprev0 = glist[g ];
jprev1 = glist[g+1];
#endif
pj_x_0 = p_1[jprev0].position.x;
pj_x_1 = p_1[jprev1].position.x;
pj_y_0 = p_1[jprev0].position.y;
pj_y_1 = p_1[jprev1].position.y;
pj_z_0 = p_1[jprev0].position.z;
pj_z_1 = p_1[jprev1].position.z;
// want to use sse to compare those
bool test0 = ( r2_0 < groupplcutoff2 );
bool test1 = ( r2_1 < groupplcutoff2 );
//removing ifs benefits on many architectures
//as the extra stores will only warm the cache up
goodglist [ hu ] = j0;
goodglist [ hu + test0 ] = j1;
hu += test0 + test1;
我正在尝试用SSE重写它。
答案 0 :(得分:0)
你问在比较下半部分之后如何比较上半部分。
SIMD方式做比较是使用压缩比较指令,如__m128d _mm_cmplt_pd (__m128d a, __m128d b)
,它产生一个掩码作为输出,而不是设置标志。 AVX有一个改进的vcmppd / vcmpps
,它有更多的比较运算符选择,你作为第3个arg传递。 _mm_cmp_pd (__m128d a, __m128d b, const int imm8)
。
const __m128d groupplcutoff2_vec = _mm_broadcastsd_pd(groupplcutoff2);
// should emit SSE3 movddup like _mm_movedup_pd() would.
__m128d r2 = ...;
// bool test0 = ( r2_0 < groupplcutoff2 );
// bool test1 = ( r2_1 < groupplcutoff2 );
__m128d ltvec = _mm_cmplt_pd(r2, groupplcutoff2_vec);
int ltmask = _mm_movemask_pd(ltvec);
bool test0 = ltmask & 1;
// bool test1 = ltmask & 2;
// assuming j is double. I'm not sure from your code, it might be int.
// and you're right, doing both stores unconditionally is prob. fastest, if your code isn't heavy on stores.
// goodglist [ hu ] = j0;
_mm_store_sd (goodglist [ hu ], j);
// goodglist [ hu + test0 ] = j1;
_mm_storeh_pd(goodglist [ hu + test0 ], j);
// don't try to use non-AVX _mm_maskmoveu_si128, it's like movnt. And doesn't do exactly what this needs, anyway, without shuffling j and ltvec.
// hu += test0 + test1;
hu += _popcnt32(ltmask); // Nehalem or later. Check the popcnt CPUID flag
popcnt技巧与AVX一样有效(4个双打打包在ymm寄存器中)。打包比较 - &gt; movemask和使用位操作是一个很有用的技巧。