A library for working with phylogenetic and population genetic data.
v0.32.0
utils/bits/operators.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_BITS_OPERATORS_H_
2 #define GENESIS_UTILS_BITS_OPERATORS_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2024 Lucas Czech
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@sund.ku.dk>
23  University of Copenhagen, Globe Institute, Section for GeoGenetics
24  Oster Voldgade 5-7, 1350 Copenhagen K, Denmark
25 */
26 
34 #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
35 
37 
38 #include <cstdint>
39 #include <immintrin.h> // _pext_u64
40 
41 #ifdef __BMI2__
42 # define GENSIS_HAS_COMPILETIME_BMI2 1
43 #else
44 # define GENSIS_HAS_COMPILETIME_BMI2 0
45 #endif
46 
47 namespace genesis {
48 namespace utils {
49 
50 // ================================================================================================
51 // Bit Extract
52 // ================================================================================================
53 
65 template <typename Integral>
66 inline constexpr Integral extract_bits( Integral source, Integral mask )
67 {
68  Integral res = 0;
69  Integral bb = 1;
70  do {
71  Integral lsb = mask & -mask;
72  mask &= ~lsb;
73  bool isset = source & lsb;
74  res |= isset ? bb : 0;
75  bb += bb;
76  } while (mask);
77 
78  return res;
79 }
80 
81 inline uint64_t bit_extract( uint64_t source, uint64_t mask )
82 {
83  return _pext_u64( source, mask );
84 
85  // static const bool has_pext_support = info_get_hardware().HW_BMI2;
86  // if( GENSIS_HAS_COMPILETIME_BMI2 && has_pext_support ) {
87  // return _pext_u64( source, mask );
88  // } else {
89  //
90  // }
91 }
92 
93 // ================================================================================================
94 // Pop Count
95 // ================================================================================================
96 
97 template< class T >
98 inline constexpr size_t pop_count( T x )
99 {
100  (void) x;
101  // https://en.cppreference.com/w/cpp/numeric/popcount
102  // https://en.cppreference.com/w/cpp/header/bit
103  return 0;
104 }
105 
106 } // namespace utils
107 } // namespace genesis
108 
109 #endif // ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
110 #endif // include guard
info.hpp
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42