Math from: http://developer.download.nvidia.com/cg/atan2.html TODO: Needs more validation, parameter checking.
| 392 | // Math from: http://developer.download.nvidia.com/cg/atan2.html |
| 393 | // TODO: Needs more validation, parameter checking. |
| 394 | CPPSPMD_FORCE_INLINE vfloat spmd_kernel::atan2_est(vfloat y, vfloat x) |
| 395 | { |
| 396 | vfloat t1 = abs(y); |
| 397 | vfloat t3 = abs(x); |
| 398 | |
| 399 | vfloat t0 = max(t3, t1); |
| 400 | store_all(t1, min(t3, t1)); |
| 401 | |
| 402 | store_all(t3, t1 / t0); |
| 403 | |
| 404 | vfloat t4 = t3 * t3; |
| 405 | store_all(t0, vfma(-0.013480470f, t4, 0.057477314f)); |
| 406 | store_all(t0, vfms(t0, t4, 0.121239071f)); |
| 407 | store_all(t0, vfma(t0, t4, 0.195635925f)); |
| 408 | store_all(t0, vfms(t0, t4, 0.332994597f)); |
| 409 | store_all(t0, vfma(t0, t4, 0.999995630f)); |
| 410 | store_all(t3, t0 * t3); |
| 411 | |
| 412 | store_all(t3, spmd_ternaryf(abs(y) > abs(x), vfloat(1.570796327f) - t3, t3)); |
| 413 | |
| 414 | store_all(t3, spmd_ternaryf(x < 0.0f, vfloat(3.141592654f) - t3, t3)); |
| 415 | store_all(t3, spmd_ternaryf(y < 0.0f, -t3, t3)); |
| 416 | |
| 417 | return t3; |
| 418 | } |
| 419 | |
| 420 | /* |
| 421 | clang 9.0.0 for win /fp:precise release |