os/kernelhwsrv/userlibandfileserver/fileserver/fs_utils/filesystem_utils.inl
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/fs_utils/filesystem_utils.inl	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,239 @@
     1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// 
    1.18 +
    1.19 +/**
    1.20 +    @file
    1.21 +    @internalTechnology
    1.22 +*/
    1.23 +
    1.24 +#if !defined(__FILESYSTEM_UTILS_INL__)
    1.25 +#define __FILESYSTEM_UTILS_INL__
    1.26 +
    1.27 +
    1.28 +//-----------------------------------------------------------------------------
    1.29 +/** @return 2^aVal */
    1.30 +inline TUint32 Pow2(TUint32 aVal)
    1.31 +    {
    1.32 +    ASSERT(aVal<32);
    1.33 +    return 1 << aVal;
    1.34 +    }
    1.35 +
    1.36 +//-----------------------------------------------------------------------------
    1.37 +/** @return TUint32 value equals 2^aVal */
    1.38 +inline TUint32 Pow2_32(TUint32 aVal)
    1.39 +    {
    1.40 +    ASSERT(aVal < 32);
    1.41 +    return 1 << aVal;
    1.42 +    }
    1.43 +
    1.44 +//-----------------------------------------------------------------------------
    1.45 +/** @return TUint64 value equals 2^aVal */
    1.46 +inline TUint64 Pow2_64(TUint32 aVal)
    1.47 +    {
    1.48 +    ASSERT(aVal < 64);
    1.49 +    return ((TUint64)1) << aVal;
    1.50 +    }
    1.51 +
    1.52 +//-----------------------------------------------------------------------------
    1.53 +/**
    1.54 +    Indicates if a number passed in is a power of two
    1.55 +    @return ETrue if aVal is a power of 2 
    1.56 +*/
    1.57 +inline TBool IsPowerOf2(TUint32 aVal)
    1.58 +    {
    1.59 +    if (aVal==0)
    1.60 +        return EFalse;
    1.61 +
    1.62 +    return !(aVal & (aVal-1));
    1.63 +    }
    1.64 +
    1.65 +//-----------------------------------------------------------------------------
    1.66 +/**
    1.67 +    Indicates if a number passed in is a power of two
    1.68 +    @return ETrue if aVal is a power of 2 
    1.69 +*/
    1.70 +inline TBool IsPowerOf2_64(TUint64 aVal)
    1.71 +    {
    1.72 +    if (aVal==0)
    1.73 +        return EFalse;
    1.74 +
    1.75 +    return !(aVal & (aVal-1));
    1.76 +
    1.77 +    }
    1.78 +
    1.79 +//-----------------------------------------------------------------------------
    1.80 +
    1.81 +/**
    1.82 +    rounds down the given value to 2^aGranularityLog2
    1.83 +    @param  aVal                input value to round down
    1.84 +    @param  aGranularityLog2    Log2(granularity)
    1.85 +    @return rounded - down value
    1.86 +*/
    1.87 +inline TUint32 RoundDown(TUint32 aVal, TUint32 aGranularityLog2)
    1.88 +{
    1.89 +    ASSERT(aGranularityLog2 < 32);
    1.90 +    return (aVal >> aGranularityLog2) << aGranularityLog2;
    1.91 +}
    1.92 +
    1.93 +//-----------------------------------------------------------------------------
    1.94 +/**  
    1.95 +    Rounds up aVal to the 2^aGranularityLog2 
    1.96 +    For example: RoundUp(0x08, 2) == 0x08; RoundUp(0x08, 3) == 0x08; RoundUp(0x08, 4) == 0x10; RoundUp(0x19, 4) == 0x20
    1.97 +    
    1.98 +    @return rounded-up value
    1.99 +*/
   1.100 +inline TUint32 RoundUp(TUint32 aVal, TUint32 aGranularityLog2)
   1.101 +    {
   1.102 +    ASSERT(aGranularityLog2 < 32);
   1.103 +                                         
   1.104 +    if( (aVal & ((1<<aGranularityLog2)-1)) == 0)
   1.105 +        return aVal;    
   1.106 +
   1.107 +    aVal >>= aGranularityLog2;
   1.108 +    aVal++;
   1.109 +    aVal <<= aGranularityLog2;
   1.110 +
   1.111 +    return aVal;
   1.112 +    }
   1.113 +
   1.114 +//-----------------------------------------------------------------------------
   1.115 +
   1.116 +/**
   1.117 +    @return Boolean exclusive OR between a1 and a2
   1.118 +    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"
   1.119 +    E.g: BoolXor(0x17, 0x4a) == EFalse;
   1.120 +*/
   1.121 +TBool BoolXOR(TBool a1, TBool a2)
   1.122 +    {
   1.123 +    if(!a1 && !a2)        
   1.124 +        return EFalse;
   1.125 +    else if(a1 && a2)
   1.126 +        return EFalse;
   1.127 +    else
   1.128 +        return ETrue;
   1.129 +    }
   1.130 +
   1.131 +//-----------------------------------------------------------------------------
   1.132 +
   1.133 +/**
   1.134 +    Calculates the log2 of a number
   1.135 +    This is the explicitly inlined version. Extensive using it may result in a code bloat.
   1.136 +
   1.137 +    @param aNum Number to calulate the log two of
   1.138 +    @return The log two of the number passed in
   1.139 +*/
   1.140 +inline TUint32 Log2_inline(TUint32 aVal)
   1.141 +    {
   1.142 +    __ASSERT_COMPILE(sizeof(TUint32) == 4);
   1.143 +    ASSERT(aVal);
   1.144 +
   1.145 +    TUint32 bitPos=31;
   1.146 +
   1.147 +    if(!(aVal >> 16)) {bitPos-=16; aVal<<=16;}
   1.148 +    if(!(aVal >> 24)) {bitPos-=8;  aVal<<=8 ;}
   1.149 +    if(!(aVal >> 28)) {bitPos-=4;  aVal<<=4 ;}
   1.150 +    if(!(aVal >> 30)) {bitPos-=2;  aVal<<=2 ;}
   1.151 +    if(!(aVal >> 31)) {bitPos-=1;}
   1.152 +    
   1.153 +    return bitPos;
   1.154 +    }
   1.155 +
   1.156 +
   1.157 +//-----------------------------------------------------------------------------
   1.158 +/**
   1.159 +    Calculates number of '1' bits in the aVal
   1.160 +    This is the explicitly inlined version. Extensive using it may result in a code bloat.
   1.161 +
   1.162 +    @param aVal some value
   1.163 +    @return number of '1' bits in the aVal
   1.164 +*/
   1.165 +inline TUint32 Count1Bits_inline(TUint32 aVal)
   1.166 +    {
   1.167 +    if(!aVal)
   1.168 +        return 0;
   1.169 +
   1.170 +    if(aVal == 0xFFFFFFFF)
   1.171 +        return 32;
   1.172 +
   1.173 +    aVal = aVal - ((aVal >> 1) & 0x55555555);
   1.174 +    aVal = (aVal & 0x33333333) + ((aVal >> 2) & 0x33333333);
   1.175 +    aVal = (aVal + (aVal >> 4)) & 0x0f0f0f0f;
   1.176 +    aVal = aVal + (aVal >> 8);
   1.177 +    aVal = aVal + (aVal >> 16);
   1.178 +
   1.179 +    return aVal & 0x3f;
   1.180 +    }
   1.181 +
   1.182 +
   1.183 +
   1.184 +
   1.185 +//-----------------------------------------------------------------------------
   1.186 +
   1.187 +/** clear all bits */
   1.188 +void T32Bits::Clear()
   1.189 +    {
   1.190 +    iData = 0;
   1.191 +    }
   1.192 +
   1.193 +/** @return non-0 if at least one of 32 bits is set to '1' */
   1.194 +TBool T32Bits::HasBitsSet() const 
   1.195 +    {
   1.196 +    return iData;
   1.197 +    } 
   1.198 +
   1.199 +/** sets bit number "aIndex" to '1' */
   1.200 +void T32Bits::SetBit(TUint32 aIndex)
   1.201 +    {
   1.202 +    ASSERT(aIndex < 32);
   1.203 +    iData |= (1<<aIndex);
   1.204 +    }
   1.205 +
   1.206 +/** 
   1.207 +    Get value of the bit number "aIndex". 
   1.208 +    @return 0 if the bit aIndex is '0' non-zero otherwise
   1.209 +*/
   1.210 +TBool T32Bits::operator[](TUint32 aIndex) const
   1.211 +    {
   1.212 +    ASSERT(aIndex < 32);
   1.213 +    return (iData & (1<<aIndex));
   1.214 +    }
   1.215 +
   1.216 +
   1.217 +
   1.218 +
   1.219 +
   1.220 +
   1.221 +
   1.222 +
   1.223 +
   1.224 +
   1.225 +#endif //__FILESYSTEM_UTILS_INL__
   1.226 +
   1.227 +
   1.228 +
   1.229 +
   1.230 +
   1.231 +
   1.232 +
   1.233 +
   1.234 +
   1.235 +
   1.236 +
   1.237 +
   1.238 +
   1.239 +
   1.240 +
   1.241 +
   1.242 +