stream/include/nil/crypto3/detail/unbounded_shift.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation>
3 //
4 // MIT License
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //---------------------------------------------------------------------------//
24 
25 #ifndef CRYPTO3_DETAIL_UNBOUNDED_SHIFT_HPP
26 #define CRYPTO3_DETAIL_UNBOUNDED_SHIFT_HPP
27 
28 #include <boost/assert.hpp>
29 
30 namespace nil {
31  namespace crypto3 {
32  namespace detail {
33 
34  template<int N, typename T>
35  struct unbounded_shifter {
36  static T shl(T x) {
37  return unbounded_shifter<N - 1, T>::shl(T(x << 1));
38  }
39 
40  static T shr(T x) {
41  return unbounded_shifter<N - 1, T>::shr(T(x >> 1));
42  }
43  };
44 
45  template<typename T>
46  struct unbounded_shifter<0, T> {
47  static T shl(T x) {
48  return x;
49  }
50 
51  static T shr(T x) {
52  return x;
53  }
54  };
55 
56  template<int N, typename T>
57  T unbounded_shl(T x) {
59  }
60 
61  template<int N, typename T>
62  T unbounded_shr(T x) {
64  }
65 
66  template<int N, typename T>
67  T low_bits(T x) {
68  T highmask = unbounded_shl<N, T>(~T());
69  return T(x & ~highmask);
70  }
71 
72  } // namespace detail
73  } // namespace crypto3
74 } // namespace nil
75 
76 #endif // CRYPTO3_BLOCK_DETAIL_UNBOUNDED_SHIFT_HPP
T unbounded_shr(T x)
Definition: algebra/include/nil/crypto3/detail/unbounded_shift.hpp:64
T low_bits(T x)
Definition: algebra/include/nil/crypto3/detail/unbounded_shift.hpp:79
T unbounded_shl(T x)
Definition: algebra/include/nil/crypto3/detail/unbounded_shift.hpp:59
Definition: pair.hpp:31
static T shl(T x)
Definition: stream/include/nil/crypto3/detail/unbounded_shift.hpp:47
static T shr(T x)
Definition: stream/include/nil/crypto3/detail/unbounded_shift.hpp:51
static T shr(T x)
Definition: stream/include/nil/crypto3/detail/unbounded_shift.hpp:40
static T shl(T x)
Definition: stream/include/nil/crypto3/detail/unbounded_shift.hpp:36