Project
Loading...
Searching...
No Matches
bitOps.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#ifndef MATHUTILS_INCLUDE_MATHUTILS_DETAIL_BITOPS_H_
17#define MATHUTILS_INCLUDE_MATHUTILS_DETAIL_BITOPS_H_
18
19#ifndef GPUCA_GPUCODE_DEVICE
20#include <cstdint>
21#endif
22
23namespace o2
24{
25namespace math_utils
26{
27namespace detail
28{
29// fast bit count
30inline int numberOfBitsSet(uint32_t x)
31{
32 // count number of non-0 bits in 32bit word
33 x = x - ((x >> 1) & 0x55555555);
34 x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
35 return (((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
36}
37
38// recursive creation of bitmask
39template <typename T>
40constexpr uint32_t bit2Mask(T v)
41{
42 return 0x1 << v;
43}
44
45template <typename T, typename... Args>
46constexpr uint32_t bit2Mask(T first, Args... args)
47{
48 return (0x1 << first) | bit2Mask(args...);
49}
50
51} // namespace detail
52} // namespace math_utils
53} // namespace o2
54
55#endif /* MATHUTILS_INCLUDE_MATHUTILS_DETAIL_BITOPS_H_ */
GLint GLenum GLint x
Definition glcorearb.h:403
const GLdouble * v
Definition glcorearb.h:832
int numberOfBitsSet(uint32_t x)
Definition bitOps.h:30
constexpr uint32_t bit2Mask(T v)
Definition bitOps.h:40
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...