Interface Documentation
Version: invalid
debruijn.hh
Go to the documentation of this file.
1 /*
2  @@@@@@@@ @@ @@@@@@ @@@@@@@@ @@
3  /@@///// /@@ @@////@@ @@////// /@@
4  /@@ /@@ @@@@@ @@ // /@@ /@@
5  /@@@@@@@ /@@ @@///@@/@@ /@@@@@@@@@/@@
6  /@@//// /@@/@@@@@@@/@@ ////////@@/@@
7  /@@ /@@/@@//// //@@ @@ /@@/@@
8  /@@ @@@//@@@@@@ //@@@@@@ @@@@@@@@ /@@
9  // /// ////// ////// //////// //
10 
11  Copyright (c) 2016, Triad National Security, LLC
12  All rights reserved.
13  */
14 #pragma once
15 
18 #include <cstddef>
19 #include <cstdint>
20 
21 namespace flecsi {
22 namespace util {
23 
24 //----------------------------------------------------------------------------//
37 //----------------------------------------------------------------------------//
38 
40 {
41 
42  // de Bruijn sequence
43  // binary: 0000 0111 0111 1100 1011 0101 0011 0001
44  // hex: 0 7 7 c b 5 3 1
45  static constexpr uint32_t seq_ = 0x077cb531;
46 
47  // Lookup table. Note that this depends on the specific de Bruijn
48  // sequence that is being used.
49  static constexpr uint32_t index_[32] = {0,
50  1,
51  28,
52  2,
53  29,
54  14,
55  24,
56  3,
57  30,
58  22,
59  20,
60  15,
61  25,
62  17,
63  4,
64  8,
65  31,
66  27,
67  13,
68  23,
69  21,
70  19,
71  16,
72  7,
73  26,
74  12,
75  18,
76  6,
77  11,
78  5,
79  10,
80  9};
81 
82 public:
83  //--------------------------------------------------------------------------//
87  //--------------------------------------------------------------------------//
88 
89  static constexpr uint32_t index(const uint32_t b) {
90  // 1. & Two's-complement to isolate the right-most set bit
91  // 2. * Shift and truncate the sequence by the isolated bit index
92  // 3. >> Shift off all but the high log_2(32) bits to get the lookup index
93  // 4. [] return the index from the lookup table
94 #if defined(_MSC_VER)
95 #pragma warning(push)
96 #pragma warning(disable : 4146) // unary minus operator applied to unsigned
97  // type, result still unsigned
98 #endif
99  return index_[(b & -b) * seq_ >> 27];
100 #if defined(_MSC_VER)
101 #pragma warning(pop)
102 #endif
103  } // index
104 
105 }; // debruijn32_t
106 
107 } // namespace util
108 } // namespace flecsi
Definition: debruijn.hh:39
static constexpr uint32_t index(const uint32_t b)
Definition: debruijn.hh:89
Definition: control.hh:31