How to use if condition in intrinsics

I want to compare two floating point variables using intrinsics. If the comparison is correct, do something else. I want to make it normal if .... Is there a way to use the built-in functions?

//normal code
vector<float> v1, v2;
for(int i = 0; i < v1.size(); ++i)
if(v1[i]<v2[i])
{
    //do something
}
else
{
    //do something
)

How to do it using SSE2 or AVX?

0
source share
3 answers

I found a document that is very useful for conditional SIMD instructions. This is the perfect solution for my question. If the condition ... else

Document: http://saluc.engr.uconn.edu/refs/processors/intel/sse_sse2.pdf

0
source

SIMD . , , - -.

. 4 , , :

__m128i match_counts = _mm_setzero_si128();

for (...) {
    __m128  fvec = something;
    __m128i  condition = _mm_castps_si128( _mm_cmplt_ps(fvec, _mm_setzero_ps()) );  // for elements less than zero
    __m128i masked_constant = _mm_and_si128(condition, _mm_set1_epi32(4));
    match_counts = _mm_add_epi32(match_counts, masked_constant);
}

, , . .

, , , 4 . (SIMD , 16 16 , 4 32- ).

+1

, v1[i] < v2[i] , , , ( ), , " " (.. " , " ), , , , .

, (), _mm_movemask_ps, 3 :

  • , false, " -", , .
  • , true, .
  • , . , , ( , 1 FP- ) " (un) " ( , ), , .

3 , , , , " " , "",.

. "" . , , .

, , , - , . , , , , , , , .

, , , (, , , ), . , , , ().

, , , , , IO. , .

+1

All Articles