Update contrib.
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 #if !defined(__FILESYSTEM_UTILS_INL__)
22 #define __FILESYSTEM_UTILS_INL__
25 //-----------------------------------------------------------------------------
27 inline TUint32 Pow2(TUint32 aVal)
33 //-----------------------------------------------------------------------------
34 /** @return TUint32 value equals 2^aVal */
35 inline TUint32 Pow2_32(TUint32 aVal)
41 //-----------------------------------------------------------------------------
42 /** @return TUint64 value equals 2^aVal */
43 inline TUint64 Pow2_64(TUint32 aVal)
46 return ((TUint64)1) << aVal;
49 //-----------------------------------------------------------------------------
51 Indicates if a number passed in is a power of two
52 @return ETrue if aVal is a power of 2
54 inline TBool IsPowerOf2(TUint32 aVal)
59 return !(aVal & (aVal-1));
62 //-----------------------------------------------------------------------------
64 Indicates if a number passed in is a power of two
65 @return ETrue if aVal is a power of 2
67 inline TBool IsPowerOf2_64(TUint64 aVal)
72 return !(aVal & (aVal-1));
76 //-----------------------------------------------------------------------------
79 rounds down the given value to 2^aGranularityLog2
80 @param aVal input value to round down
81 @param aGranularityLog2 Log2(granularity)
82 @return rounded - down value
84 inline TUint32 RoundDown(TUint32 aVal, TUint32 aGranularityLog2)
86 ASSERT(aGranularityLog2 < 32);
87 return (aVal >> aGranularityLog2) << aGranularityLog2;
90 //-----------------------------------------------------------------------------
92 Rounds up aVal to the 2^aGranularityLog2
93 For example: RoundUp(0x08, 2) == 0x08; RoundUp(0x08, 3) == 0x08; RoundUp(0x08, 4) == 0x10; RoundUp(0x19, 4) == 0x20
95 @return rounded-up value
97 inline TUint32 RoundUp(TUint32 aVal, TUint32 aGranularityLog2)
99 ASSERT(aGranularityLog2 < 32);
101 if( (aVal & ((1<<aGranularityLog2)-1)) == 0)
104 aVal >>= aGranularityLog2;
106 aVal <<= aGranularityLog2;
111 //-----------------------------------------------------------------------------
114 @return Boolean exclusive OR between a1 and a2
115 This function should be used on C-style TBool, which is, actually TInt type; Its '0' value means "False" and _any_ non-zero means "True"
116 E.g: BoolXor(0x17, 0x4a) == EFalse;
118 TBool BoolXOR(TBool a1, TBool a2)
128 //-----------------------------------------------------------------------------
131 Calculates the log2 of a number
132 This is the explicitly inlined version. Extensive using it may result in a code bloat.
134 @param aNum Number to calulate the log two of
135 @return The log two of the number passed in
137 inline TUint32 Log2_inline(TUint32 aVal)
139 __ASSERT_COMPILE(sizeof(TUint32) == 4);
144 if(!(aVal >> 16)) {bitPos-=16; aVal<<=16;}
145 if(!(aVal >> 24)) {bitPos-=8; aVal<<=8 ;}
146 if(!(aVal >> 28)) {bitPos-=4; aVal<<=4 ;}
147 if(!(aVal >> 30)) {bitPos-=2; aVal<<=2 ;}
148 if(!(aVal >> 31)) {bitPos-=1;}
154 //-----------------------------------------------------------------------------
156 Calculates number of '1' bits in the aVal
157 This is the explicitly inlined version. Extensive using it may result in a code bloat.
159 @param aVal some value
160 @return number of '1' bits in the aVal
162 inline TUint32 Count1Bits_inline(TUint32 aVal)
167 if(aVal == 0xFFFFFFFF)
170 aVal = aVal - ((aVal >> 1) & 0x55555555);
171 aVal = (aVal & 0x33333333) + ((aVal >> 2) & 0x33333333);
172 aVal = (aVal + (aVal >> 4)) & 0x0f0f0f0f;
173 aVal = aVal + (aVal >> 8);
174 aVal = aVal + (aVal >> 16);
182 //-----------------------------------------------------------------------------
184 /** clear all bits */
185 void T32Bits::Clear()
190 /** @return non-0 if at least one of 32 bits is set to '1' */
191 TBool T32Bits::HasBitsSet() const
196 /** sets bit number "aIndex" to '1' */
197 void T32Bits::SetBit(TUint32 aIndex)
200 iData |= (1<<aIndex);
204 Get value of the bit number "aIndex".
205 @return 0 if the bit aIndex is '0' non-zero otherwise
207 TBool T32Bits::operator[](TUint32 aIndex) const
210 return (iData & (1<<aIndex));
222 #endif //__FILESYSTEM_UTILS_INL__