(svn r19019) -Codechange: use HasExactlyOneBit() and HasAtMostOneBit() instead of CountBits() where possible

This commit is contained in:
smatz
2010-02-05 17:05:58 +00:00
parent 1d6bfd2a6c
commit 6c1ab1a2fa
8 changed files with 35 additions and 11 deletions

View File

@@ -254,6 +254,30 @@ static inline uint CountBits(T value)
return num;
}
/**
* Test whether \a value has exactly 1 bit set
*
* @param value the value to test.
* @return does \a value have exactly 1 bit set?
*/
template <typename T>
static FORCEINLINE bool HasExactlyOneBit(T value)
{
return value != 0 && (value & (value - 1)) == 0;
}
/**
* Test whether \a value has at most 1 bit set
*
* @param value the value to test.
* @return does \a value have at most 1 bit set?
*/
template <typename T>
static FORCEINLINE bool HasAtMostOneBit(T value)
{
return (value & (value - 1)) == 0;
}
/**
* ROtate x Left by n
*