ATLAS Offline Software
LWHistBitUtils.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Header file for class LWHistBitUtils //
9 // //
10 // Description: Helper for various bit-operations. //
11 // //
12 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
13 // Initial version: April 2009 //
14 // //
16 
17 #ifndef LWHISTBITUTILS_H
18 #define LWHISTBITUTILS_H
19 
20 #include <cassert>
21 #include <stdint.h>
22 #include <cstring>
23 
25 public:
26 
27  template <class T> static T countSetBits(T data);
28  template <class T> static T countSetBitsBefore(T data, T ibit);
29  template <class T> static bool bitIsSet(T data, T ibit) { return data & (0x1<<ibit); }
30  template <class T> static void setBit(T& data, T ibit) { data |= (0x1<<ibit); }
31 
32  template <uint8_t sizeofT> static uint8_t totalSummedOffsetInStages(uint32_t stagepattern );
33 
34  //Get positions of first and last set bits (1..32) (assumes i!=0):
35  static uint32_t posMSB(uint32_t i);//position of most significant bit
36  static uint32_t posLSB(uint32_t i);//position of least significant bit
37  //8 bit versions:
40 
41  //Fast version of std::max<int>(0,x):
42  // This relies on implementation and undefined behavior.
43  // On x86_64, the naive way of writing this will anyway compile to a conditional
44  // move, so this is likely no faster. In any case, the only place this is used
45  // is from within a nest of other conditionals, so i really doubt that this
46  // will make any difference at all. So go back to the simple
47  // way of writing this.
48  //static int minZero(int x) { assert(int(x-(x&x>>(sizeof(int)*8-1)))==std::max<int>(0,x)); return x-(x&x>>(sizeof(int)*8-1)); }
49  static int minZero(int x) { return std::max<int>(0, x); }
50 
51 private:
52  template <uint8_t sizeofT> static uint8_t stageOffset8Bits(uint32_t stagepattern);
53 
56 };
57 
58 #include "LWHistBitUtils.icc"
59 
60 #endif
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:575
LWHistBitUtils::countSetBits
static T countSetBits(T data)
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
LWHistBitUtils::posLSB
static uint32_t posLSB(uint32_t i)
x
#define x
LWHistBitUtils::posLSB
static uint8_t posLSB(uint8_t i)
LWHistBitUtils::posMSB
static uint8_t posMSB(uint8_t i)
LWHistBitUtils::totalSummedOffsetInStages
static uint8_t totalSummedOffsetInStages(uint32_t stagepattern)
LWHistBitUtils::setBit
static void setBit(T &data, T ibit)
Definition: LWHistBitUtils.h:30
LWHistBitUtils::countSetBitsBefore
static T countSetBitsBefore(T data, T ibit)
lumiFormat.i
int i
Definition: lumiFormat.py:92
LWHistBitUtils
Definition: LWHistBitUtils.h:24
LWHistBitUtils::LWHistBitUtils
LWHistBitUtils()
Definition: LWHistBitUtils.h:54
LWHistBitUtils::~LWHistBitUtils
~LWHistBitUtils()
Definition: LWHistBitUtils.h:55
LWHistBitUtils::posMSB
static uint32_t posMSB(uint32_t i)
LWHistBitUtils::minZero
static int minZero(int x)
Definition: LWHistBitUtils.h:49
LWHistBitUtils.icc
LWHistBitUtils::bitIsSet
static bool bitIsSet(T data, T ibit)
Definition: LWHistBitUtils.h:29
LWHistBitUtils::stageOffset8Bits
static uint8_t stageOffset8Bits(uint32_t stagepattern)
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35