Arc tangent function of two variables in SSE version 2 Algorithm Explanation: The function atan2() is evaluated by first calling atan(), which yields the arc tangent in [-pi/2, pi/2] radians, and then adjusting the result based on the signs of the arguments to return the arc tangent in the range [-pi,pi]. Considering the quadrants defined as: Quadrant 1 : positive y, positive x Quadrant 2 : pos
| 496 | // quadrants 4 and 1, respectively. The results from these quadrants need to be |
| 497 | // adjusted. |
| 498 | inline __m128 sseAtan2(const __m128 y, const __m128 x) |
| 499 | { |
| 500 | __m128 res = sseAtan(_mm_div_ps(y, x)); |
| 501 | |
| 502 | // Fix for x=0 and y=0 |
| 503 | __m128 zero_mask = _mm_or_ps(_mm_cmpneq_ps(x, EZERO), _mm_cmpneq_ps(y, EZERO)); |
| 504 | res = _mm_and_ps(res, zero_mask); |
| 505 | |
| 506 | // Adjust quadrants 2 and 3 based on the sign of the arguments |
| 507 | __m128 neg_x = isNegativeSpecial(x); |
| 508 | __m128 sign_y = _mm_and_ps(y, ESIGN_MASK); |
| 509 | |
| 510 | return _mm_add_ps(res, _mm_and_ps(_mm_or_ps(sign_y, E_PI), neg_x)); |
| 511 | } |
| 512 | |
| 513 | // Scalar version of sseAtan2 |
| 514 | inline float sseAtan2(const float y, const float x) |