Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void BallsManager::process()
- {
- static const float min_x = 0.0f;
- static const float max_x = 640.0f;
- static const float min_y = 0.0f;
- static const float max_y = 480.0f;
- __m128 mtwo = _mm_set_ps1(-2.0f);
- __m128 one = _mm_set_ps1(1.0f);
- __m128 vminx = _mm_load_ps1(&min_x);
- __m128 vmaxx = _mm_load_ps1(&max_x);
- __m128 vminy = _mm_load_ps1(&min_y);
- __m128 vmaxy = _mm_load_ps1(&max_y);
- #pragma omp parallel for
- for (size_t i = 0; i < m_count; i += 4) {
- __m128 mask;
- __m128 vx = _mm_load_ps(&x[i]);
- __m128 vdirx = _mm_load_ps(&dir_x[i]);
- __m128 vy = _mm_load_ps(&y[i]);
- __m128 vdiry = _mm_load_ps(&dir_y[i]);
- mask = _mm_or_ps(_mm_cmple_ps(vx, vminx), _mm_cmpge_ps(vx, vmaxx));
- vdirx = _mm_mul_ps(_mm_add_ps(_mm_and_ps(mask, mtwo), one), vdirx);
- vx = _mm_add_ps(vx, vdirx);
- mask = _mm_or_ps(_mm_cmple_ps(vy, vminy), _mm_cmpge_ps(vy, vmaxy));
- vdiry = _mm_mul_ps(_mm_add_ps(_mm_and_ps(mask, mtwo), one), vdiry);
- vy = _mm_add_ps(vy, vdiry);
- _mm_store_ps(&dir_x[i], vdirx);
- _mm_store_ps(&x[i], vx);
- _mm_store_ps(&dir_y[i], vdiry);
- _mm_store_ps(&y[i], vy);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment