μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
bits.cpp
Go to the documentation of this file.
1/*
2---------------------------------------------------------------------------
3
4 This file is part of uHAL.
5
6 uHAL is a hardware access library and programming framework
7 originally developed for upgrades of the Level-1 trigger of the CMS
8 experiment at CERN.
9
10 uHAL is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 uHAL is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22
23
24 Andrew Rose, Imperial College, London
25 email: awr01 <AT> imperial.ac.uk
26
27 Marc Magrans de Abril, CERN
28 email: marc.magrans.de.abril <AT> cern.ch
29
30 Tom Williams, Rutherford Appleton Laboratory, Oxfordshire
31 email: tom.williams <AT> cern.ch
32
33---------------------------------------------------------------------------
34*/
35
37
38
39
40namespace uhal
41{
42 namespace utilities
43 {
44 unsigned int TrailingRightBits ( uint32_t aValue )
45 {
46 // unsigned int lReturn = sizeof ( aValue ) * 8; // lReturn will be the number of zero bits on the right
47 unsigned int lReturn = sizeof ( aValue ) << 3; // lReturn will be the number of zero bits on the right
48 aValue &= -signed ( aValue );
49
50 if ( aValue )
51 {
52 lReturn--;
53 }
54
55 if ( aValue & 0x0000FFFF )
56 {
57 lReturn -= 16;
58 }
59
60 if ( aValue & 0x00FF00FF )
61 {
62 lReturn -= 8;
63 }
64
65 if ( aValue & 0x0F0F0F0F )
66 {
67 lReturn -= 4;
68 }
69
70 if ( aValue & 0x33333333 )
71 {
72 lReturn -= 2;
73 }
74
75 if ( aValue & 0x55555555 )
76 {
77 lReturn -= 1;
78 }
79
80 return lReturn;
81 }
82 }
83}
unsigned int TrailingRightBits(uint32_t aValue)
Helper function to calculate the number of zero-bits at the righthand end of a 32-bit number.
Definition: bits.cpp:44