Line data Source code
1 : ///////////////////////////////////////////////////////////////////////////
2 : // Inastemp - Berenger Bramas MPCDF - 2016
3 : // Under MIT Licence, please you must read the LICENCE file.
4 : ///////////////////////////////////////////////////////////////////////////
5 : #ifndef UTILS_HPP
6 : #define UTILS_HPP
7 :
8 : // for std::size_t
9 : #include <cstdio>
10 :
11 : namespace InaUtils {
12 :
13 : template < class TypeSrc, class TypeDest >
14 : inline TypeDest ConvertBits(TypeSrc src) {
15 : union InaBits {
16 : TypeSrc src;
17 : TypeDest dest;
18 : };
19 : InaBits bits;
20 606 : bits.src = src;
21 42 : return bits.dest;
22 : }
23 :
24 : template <class VecType>
25 : inline VecType FastPow(VecType base, std::size_t power){
26 : VecType res = VecType(1.);
27 :
28 1288 : while(power){
29 784 : if(1 & power){
30 : res *= base;
31 : }
32 868 : base *= base;
33 868 : power >>= 1;
34 : }
35 :
36 : return res;
37 : }
38 :
39 : inline std::size_t FastPowNbMul(std::size_t power){
40 168 : std::size_t nbMul = 0;
41 :
42 532 : while(power){
43 364 : if(1 & power){
44 196 : nbMul += 1;
45 : }
46 364 : nbMul += 1;
47 364 : power >>= 1;
48 : }
49 :
50 : return nbMul;
51 : }
52 :
53 : }
54 :
55 : #endif // UTILS_HPP
|