RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
BitMask.hpp
Go to the documentation of this file.
1 
11 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
12 // Copyright (c) Lawrence Livermore National Security, LLC and other
13 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
14 // files for dates and other details. No copyright assignment is required
15 // to contribute to RAJA.
16 //
17 // SPDX-License-Identifier: (BSD-3-Clause)
18 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
19 
20 #ifndef RAJA_util_BitMask_HPP
21 #define RAJA_util_BitMask_HPP
22 
23 #include "RAJA/config.hpp"
24 
25 namespace RAJA
26 {
27 
28 template<camp::idx_t N>
29 struct LogBase2
30 {
31  static constexpr camp::idx_t value = LogBase2<(N >> 1)>::value + 1;
32  static constexpr bool is_exact = ((1 << value) == N);
33 };
34 
35 template<>
36 struct LogBase2<0>
37 {
38  static constexpr camp::idx_t value = -1;
39  static constexpr bool is_exact = true;
40 };
41 
54 template<int Width, int Shift>
55 struct BitMask
56 {
57  static constexpr int shift = Shift;
58  static constexpr int width = Width;
59  static constexpr int max_input_size = 1 << (Shift + Width);
60  static constexpr int max_masked_size = 1 << Width;
61  static constexpr int max_shifted_size = 1 << Shift;
62 
63  template<typename T>
64  RAJA_HOST_DEVICE static constexpr T maskValue(T input)
65  {
66  return ((input >> (static_cast<T>(Shift))) &
67  static_cast<T>((1 << (Width)) - 1));
68  }
69 
70  template<typename T>
71  RAJA_HOST_DEVICE static constexpr T getOuter(T input)
72  {
73  return ((input >> (static_cast<T>(Shift))) >> Width);
74  }
75 
76  template<typename T>
77  RAJA_HOST_DEVICE static constexpr T maskOuter(T input)
78  {
79  return (input & (static_cast<T>(-1) << (Width + Shift)));
80  }
81 };
82 
83 } // namespace RAJA
84 
85 #endif // RAJA_util_BitMask_HPP
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
Definition: AlignedRangeIndexSetBuilders.cpp:35
Definition: BitMask.hpp:56
static constexpr int max_shifted_size
Definition: BitMask.hpp:61
static constexpr int max_input_size
Definition: BitMask.hpp:59
static constexpr int shift
Definition: BitMask.hpp:57
static constexpr int width
Definition: BitMask.hpp:58
static constexpr int max_masked_size
Definition: BitMask.hpp:60
static constexpr RAJA_HOST_DEVICE T getOuter(T input)
Definition: BitMask.hpp:71
static constexpr RAJA_HOST_DEVICE T maskOuter(T input)
Definition: BitMask.hpp:77
static constexpr RAJA_HOST_DEVICE T maskValue(T input)
Definition: BitMask.hpp:64
Definition: BitMask.hpp:30
static constexpr camp::idx_t value
Definition: BitMask.hpp:31
static constexpr bool is_exact
Definition: BitMask.hpp:32