| 472 | { |
| 473 | const float fPi = 3.141592653589793f, fOneOverPi = 0.3183098861837907f; |
| 474 | CPPSPMD_DECL(const uint8_t, s_table0[16]) = { 128 + 0, 128 + 2, 128 + -2, 128 + 4, 128 + 0, 128 + 2, 128 + -2, 128 + 4, 128 + 0, 128 + 2, 128 + -2, 128 + 4, 128 + 0, 128 + 2, 128 + -2, 128 + 4 }; |
| 475 | |
| 476 | vint table = init_lookup4(s_table0); // a load |
| 477 | vint sgn = cast_vfloat_to_vint(x) & 0x80000000; |
| 478 | |
| 479 | store_all(x, abs(x)); |
| 480 | vfloat orig_x = x; |
| 481 | |
| 482 | vfloat q = x * fOneOverPi; |
| 483 | store_all(x, q - floor(q)); |
| 484 | |
| 485 | vfloat x4 = x * 4.0f; |
| 486 | vint octant = (vint)(x4); |
| 487 | |
| 488 | vfloat x0 = spmd_ternaryf((octant & 1) != 0, -x4, x4); |
| 489 | |
| 490 | vint k = table_lookup4_8(octant, table) & 0xFF; // a shuffle |
| 491 | |
| 492 | vfloat bias = (vfloat)k + -128.0f; |
| 493 | vfloat y = x0 + bias; |
| 494 | |
| 495 | vfloat z = tan82(y); |
| 496 | |
| 497 | vfloat r; |
| 498 | |
| 499 | vbool octant_one_or_two = (octant == 1) || (octant == 2); |
| 500 | |
| 501 | // SPMD optimization - skip costly divide if we can |
| 502 | if (spmd_any(octant_one_or_two)) |
| 503 | { |
| 504 | const float fDivThresh = .4371e-7f; |
| 505 | vfloat one_over_z = 1.0f / spmd_ternaryf(abs(z) > fDivThresh, z, spmd_ternaryf(z < 0.0f, -fDivThresh, fDivThresh)); |
| 506 | |
| 507 | vfloat b = spmd_ternaryf(octant_one_or_two, one_over_z, z); |
| 508 | store_all(r, spmd_ternaryf((octant & 2) != 0, -b, b)); |
| 509 | } |
| 510 | else |
| 511 | { |
| 512 | store_all(r, spmd_ternaryf(octant == 0, z, -z)); |
| 513 | } |
| 514 | |
| 515 | // Small angle approximation, to decrease the max rel error near Pi. |
| 516 | SPMD_SIF(x >= (1.0f - .0003125f*4.0f)) |
| 517 | { |
| 518 | store(r, vfnma(floor(q) + 1.0f, fPi, orig_x)); |
| 519 | } |
| 520 | SPMD_SENDIF |
| 521 | |
| 522 | return cast_vint_to_vfloat(cast_vfloat_to_vint(r) ^ sgn); |
| 523 | } |
| 524 | |
| 525 | inline void spmd_kernel::seed_rand(rand_context& x, vint seed) |
| 526 | { |
nothing calls this directly
no test coverage detected