Path: blob/master/thirdparty/basis_universal/encoder/cppspmd_math_declares.h
9903 views
// Do not include this header directly.1// This header defines shared struct spmd_kernel helpers.2//3// Copyright 2020-2024 Binomial LLC4//5// Licensed under the Apache License, Version 2.0 (the "License");6// you may not use this file except in compliance with the License.7// You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing, software12// distributed under the License is distributed on an "AS IS" BASIS,13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14// See the License for the specific language governing permissions and15// limitations under the License.1617// See cppspmd_math.h for detailed error statistics.1819CPPSPMD_FORCE_INLINE void reduce_expb(vfloat& arg, vfloat& two_int_a, vint& adjustment);20CPPSPMD_FORCE_INLINE vfloat tan56(vfloat x);21CPPSPMD_FORCE_INLINE vfloat tan82(vfloat x);2223inline vfloat log2_est(vfloat v);2425inline vfloat log_est(vfloat v);2627inline vfloat exp2_est(vfloat arg);2829inline vfloat exp_est(vfloat arg);3031inline vfloat pow_est(vfloat arg1, vfloat arg2);3233CPPSPMD_FORCE_INLINE vfloat recip_est1(const vfloat& q);34CPPSPMD_FORCE_INLINE vfloat recip_est1_pn(const vfloat& q);3536inline vfloat mod_angles(vfloat a);3738inline vfloat sincos_est_a(vfloat a, bool sin_flag);39CPPSPMD_FORCE_INLINE vfloat sin_est_a(vfloat a) { return sincos_est_a(a, true); }40CPPSPMD_FORCE_INLINE vfloat cos_est_a(vfloat a) { return sincos_est_a(a, false); }4142inline vfloat sin_est(vfloat a);4344inline vfloat cos_est(vfloat a);4546// Don't call with values <= 0.47CPPSPMD_FORCE_INLINE vfloat rsqrt_est1(vfloat x0);4849// Don't call with values <= 0.50CPPSPMD_FORCE_INLINE vfloat rsqrt_est2(vfloat x0);5152CPPSPMD_FORCE_INLINE vfloat atan2_est(vfloat y, vfloat x);5354CPPSPMD_FORCE_INLINE vfloat atan_est(vfloat x) { return atan2_est(x, vfloat(1.0f)); }5556// Don't call this for angles close to 90/270!57inline vfloat tan_est(vfloat x);5859// https://burtleburtle.net/bob/rand/smallprng.html60struct rand_context { vint a, b, c, d; };6162inline void seed_rand(rand_context& x, vint seed);6364// Returns 32-bit unsigned random numbers.65inline vint get_randu(rand_context& x);6667// Returns random numbers between [low, high), or low if low >= high68inline vint get_randi(rand_context& x, vint low, vint high);6970// Returns random numbers between [low, high), or low if low >= high71inline vfloat get_randf(rand_context& x, vfloat low, vfloat high);7273CPPSPMD_FORCE_INLINE void init_reverse_bits(vint& tab1, vint& tab2);74CPPSPMD_FORCE_INLINE vint reverse_bits(vint k, vint tab1, vint tab2);7576CPPSPMD_FORCE_INLINE vint count_leading_zeros(vint x);77CPPSPMD_FORCE_INLINE vint count_leading_zeros_alt(vint x);7879CPPSPMD_FORCE_INLINE vint count_trailing_zeros(vint x);8081CPPSPMD_FORCE_INLINE vint count_set_bits(vint x);8283void print_vint(vint v);84void print_vbool(vbool v);85void print_vint_hex(vint v);86void print_active_lanes(const char *pPrefix);87void print_vfloat(vfloat v);88899091