Guest User

Untitled

a guest
Oct 29th, 2015
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. void BallsManager::process()
  2. {
  3.         static const float min_x = 0.0f;
  4.         static const float max_x = 640.0f;
  5.         static const float min_y = 0.0f;
  6.         static const float max_y = 480.0f;
  7.  
  8.         __m128 mtwo = _mm_set_ps1(-2.0f);
  9.         __m128 one  = _mm_set_ps1(1.0f);
  10.  
  11.         __m128 vminx = _mm_load_ps1(&min_x);
  12.         __m128 vmaxx = _mm_load_ps1(&max_x);
  13.  
  14.         __m128 vminy = _mm_load_ps1(&min_y);
  15.         __m128 vmaxy = _mm_load_ps1(&max_y);
  16.  
  17. #pragma omp parallel for
  18.         for (size_t i = 0; i < m_count; i += 4) {
  19.                 __m128 mask;
  20.                 __m128 vx = _mm_load_ps(&x[i]);
  21.                 __m128 vdirx = _mm_load_ps(&dir_x[i]);
  22.  
  23.                 __m128 vy = _mm_load_ps(&y[i]);
  24.                 __m128 vdiry = _mm_load_ps(&dir_y[i]);
  25.  
  26.                 mask = _mm_or_ps(_mm_cmple_ps(vx, vminx), _mm_cmpge_ps(vx, vmaxx));
  27.                 vdirx = _mm_mul_ps(_mm_add_ps(_mm_and_ps(mask, mtwo), one), vdirx);
  28.                 vx = _mm_add_ps(vx, vdirx);
  29.  
  30.                 mask = _mm_or_ps(_mm_cmple_ps(vy, vminy), _mm_cmpge_ps(vy, vmaxy));
  31.                 vdiry = _mm_mul_ps(_mm_add_ps(_mm_and_ps(mask, mtwo), one), vdiry);
  32.                 vy = _mm_add_ps(vy, vdiry);
  33.  
  34.                 _mm_store_ps(&dir_x[i], vdirx);
  35.                 _mm_store_ps(&x[i], vx);
  36.  
  37.                 _mm_store_ps(&dir_y[i], vdiry);
  38.                 _mm_store_ps(&y[i], vy);
  39.         }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment