rsimd

Make SIMD instruction sets easier to use
git clone git://git.meso-star.fr/rsimd.git
Log | Files | Refs | README | LICENSE

math4.h (1650B)


      1 /* Copyright (C) 2014-2019, 2021, 2023, 2025 Vincent Forest (vaplv@free.fr)
      2  *
      3  * The RSIMD library is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published
      5  * by the Free Software Foundation, either version 3 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * The RSIMD library is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with the RSIMD library. If not, see <http://www.gnu.org/licenses/>. */
     15 
     16 #ifndef RSIMD_MATH4_H
     17 #define RSIMD_MATH4_H
     18 
     19 #define RSIMD_WIDTH__ 4
     20 #include "vXf_begin.h"
     21 #include "mathX.h"
     22 #include "vXf_end.h"
     23 
     24 /*******************************************************************************
     25  * Miscellaneous
     26  ******************************************************************************/
     27 static FINLINE v4f_T /* Cartesian (xyz) to spherical (r, theta, phi)*/
     28 v4f_xyz_to_rthetaphi(const v4f_T v)
     29 {
     30   const v4f_T zero = v4f_zero();
     31   const v4f_T len2 = v4f_len2(v);
     32   const v4f_T len3 = v4f_len3(v);
     33   const v4f_T theta = v4f_sel
     34     (v4f_acos(v4f_div(v4f_zzzz(v), len3)), zero, v4f_eq(len3, zero));
     35   const v4f_T tmp_phi = v4f_sel
     36     (v4f_asin(v4f_div(v4f_yyyy(v), len2)), zero, v4f_eq(len2, zero));
     37   const v4f_T phi = v4f_sel
     38     (v4f_sub(v4f_set1((float)PI), tmp_phi),tmp_phi, v4f_ge(v4f_xxxx(v), zero));
     39   return v4f_xyab(v4f_xayb(len3, theta), phi);
     40 }
     41 #endif /* RSIMD_MATH4_H */