cppspmd_math_declares.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Do not include this header directly.
  2. // This header defines shared struct spmd_kernel helpers.
  3. //
  4. // Copyright 2020-2021 Binomial LLC
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License");
  7. // you may not use this file except in compliance with the License.
  8. // You may obtain a copy of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS,
  14. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. // See the License for the specific language governing permissions and
  16. // limitations under the License.
  17. // See cppspmd_math.h for detailed error statistics.
  18. CPPSPMD_FORCE_INLINE void reduce_expb(vfloat& arg, vfloat& two_int_a, vint& adjustment);
  19. CPPSPMD_FORCE_INLINE vfloat tan56(vfloat x);
  20. CPPSPMD_FORCE_INLINE vfloat tan82(vfloat x);
  21. inline vfloat log2_est(vfloat v);
  22. inline vfloat log_est(vfloat v);
  23. inline vfloat exp2_est(vfloat arg);
  24. inline vfloat exp_est(vfloat arg);
  25. inline vfloat pow_est(vfloat arg1, vfloat arg2);
  26. CPPSPMD_FORCE_INLINE vfloat recip_est1(const vfloat& q);
  27. CPPSPMD_FORCE_INLINE vfloat recip_est1_pn(const vfloat& q);
  28. inline vfloat mod_angles(vfloat a);
  29. inline vfloat sincos_est_a(vfloat a, bool sin_flag);
  30. CPPSPMD_FORCE_INLINE vfloat sin_est_a(vfloat a) { return sincos_est_a(a, true); }
  31. CPPSPMD_FORCE_INLINE vfloat cos_est_a(vfloat a) { return sincos_est_a(a, false); }
  32. inline vfloat sin_est(vfloat a);
  33. inline vfloat cos_est(vfloat a);
  34. // Don't call with values <= 0.
  35. CPPSPMD_FORCE_INLINE vfloat rsqrt_est1(vfloat x0);
  36. // Don't call with values <= 0.
  37. CPPSPMD_FORCE_INLINE vfloat rsqrt_est2(vfloat x0);
  38. CPPSPMD_FORCE_INLINE vfloat atan2_est(vfloat y, vfloat x);
  39. CPPSPMD_FORCE_INLINE vfloat atan_est(vfloat x) { return atan2_est(x, vfloat(1.0f)); }
  40. // Don't call this for angles close to 90/270!
  41. inline vfloat tan_est(vfloat x);
  42. // https://burtleburtle.net/bob/rand/smallprng.html
  43. struct rand_context { vint a, b, c, d; };
  44. inline void seed_rand(rand_context& x, vint seed);
  45. // Returns 32-bit unsigned random numbers.
  46. inline vint get_randu(rand_context& x);
  47. // Returns random numbers between [low, high), or low if low >= high
  48. inline vint get_randi(rand_context& x, vint low, vint high);
  49. // Returns random numbers between [low, high), or low if low >= high
  50. inline vfloat get_randf(rand_context& x, vfloat low, vfloat high);
  51. CPPSPMD_FORCE_INLINE void init_reverse_bits(vint& tab1, vint& tab2);
  52. CPPSPMD_FORCE_INLINE vint reverse_bits(vint k, vint tab1, vint tab2);
  53. CPPSPMD_FORCE_INLINE vint count_leading_zeros(vint x);
  54. CPPSPMD_FORCE_INLINE vint count_leading_zeros_alt(vint x);
  55. CPPSPMD_FORCE_INLINE vint count_trailing_zeros(vint x);
  56. CPPSPMD_FORCE_INLINE vint count_set_bits(vint x);
  57. void print_vint(vint v);
  58. void print_vbool(vbool v);
  59. void print_vint_hex(vint v);
  60. void print_active_lanes(const char *pPrefix);
  61. void print_vfloat(vfloat v);