field_utils.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2020-2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020-2021 Nikita Kaskov <nbering@nil.foundation>
4 //
5 // MIT License
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 //---------------------------------------------------------------------------//
25 
26 #ifndef CRYPTO3_ALGEBRA_FIELD_UTILS_HPP
27 #define CRYPTO3_ALGEBRA_FIELD_UTILS_HPP
28 
29 #include <type_traits>
30 #include <complex>
31 
32 #include <boost/math/constants/constants.hpp>
34 
35 namespace nil {
36  namespace crypto3 {
37  namespace math {
38  namespace detail {
39 
40  using namespace nil::crypto3::algebra;
41 
42  std::size_t bitreverse(std::size_t n, const std::size_t l) {
43  std::size_t r = 0;
44  for (std::size_t k = 0; k < l; ++k) {
45  r = (r << 1) | (n & 1);
46  n >>= 1;
47  }
48  return r;
49  }
50 
51  constexpr std::size_t power_of_two(std::size_t n) {
52  n--;
53  n |= n >> 1;
54  n |= n >> 2;
55  n |= n >> 4;
56  n |= n >> 8;
57  n |= n >> 16;
58  n++;
59 
60  return n;
61  }
62 
63  template<typename FieldType>
64  typename FieldType::value_type coset_shift() {
65  return
67  .squared();
68  }
69 
70  } // namespace detail
71  } // namespace fft
72  } // namespace crypto3
73 } // namespace nil
74 
75 #endif // CRYPTO3_FIELD_UTILS_HPP
Definition: pair.hpp:33
FieldType::value_type coset_shift()
Definition: field_utils.hpp:64
std::size_t bitreverse(std::size_t n, const std::size_t l)
Definition: field_utils.hpp:42
constexpr std::size_t power_of_two(std::size_t n)
Definition: field_utils.hpp:51
Definition: pair.hpp:31
Definition: fields/params.hpp:58