SSE/AVX/AVX2汇编技巧

处理除法分支,其它类似的分支也可通过mask去除

	static const __m128 zero128_ps = _mm_setzero_ps();
	/*
	if(y!=0)
		return x/y;
	else 
		return z;
	*/
	inline __m128 div128_ps(__m128 x, __m128 y, __m128 z)
	{
		__m128 mask = _mm_cmpneq_ps(y, zero128_ps);
		__m128 xy = _mm_div_ps(x, y);
		xy=_mm_or_ps(_mm_and_ps(mask, xy), _mm_andnot_ps(mask,z));
		return xy;
	}
	/*
	if(y!=0)
		return x/y;
	else 
		return 0;
	*/
	inline __m128 div128_ps(__m128 x, __m128 y)
	{
		__m128 mask = _mm_cmpneq_ps(y, zero128_ps);
		__m128 xy = _mm_div_ps(x, y);
		xy =_mm_and_ps(mask, xy);
		return xy;
	}

你可能感兴趣的:(SSE/AVX/AVX2汇编技巧)