Intel® ISA Extensions
Use hardware-based isolation and memory encryption to provide more code protection in your solutions.
1094 Discussions

how do i use if-else statement in sse2 intrinsics

Smart_Lubobya
Beginner
245 Views

original codes

if(y < 0)

block[j+8] = (short)(-( (((-y) * n[_q]) + _f) >> _a ));

else

block[j+8] = (short)( ((y * n[_q]) + _f) >> _a );

my attempt
if(y < 0) //error C2676: binary '<' : '__m128i' does not define this operator or a conversion to a type acceptable

{
tmp1= _mm_mulhi_epi16(_mm_sub_epi16(_mm_setzero_si128(), y), n[_q]);//error C2676: binary '[' : '__m128i' does not define this operator.
tmp2 =_mm_add_epi16(tmp1,_f);
tmp3=_mm_srli_epi32(tmp2, _a);
block[j+8] =_mm_sub_epi16(_mm_setzero_si128(), tmp3);
}
else

{
tmp4= _mm_mulhi_epi16( y, n[_q]);
tmp5 =_mm_add_epi16(tmp4,_f);
block[j+8]=_mm_srli_epi32(tmp5, _a);
}
note: >> shift right
* multiplication
how can i sort out these errors (see commented error)or is there a better way of writting these original codes
0 Kudos
1 Reply
bronxzv
New Contributor II
245 Views
you can't use if-else with SSE2 intrisics (though you can with regular C++ code and using the auto-vectorizer)

with the intrinsics you have to use mask operations like this(Int128 is a wrapper class for __m128i) :

friend Int128 Select (const Int128 &mask, const Int128 &a, const Int128 &b)
{return _mm_or_si128(_mm_and_si128(mask.m,a.m),_mm_andnot_si128(mask.m,b.m));}

NB masks are computed with _mm_cmplt_epi16 and the like

now your use case looks like no more than |y| so you should find a simplified solution, though AFAIK abs(x) is easier to vectorize with packed floats (single andps/andpd to clear the sign bits) than packed ints
0 Kudos
Reply