File diff r18781:e1de9a06f7cd → r18782:6453522c2154
src/core/bitmath_func.hpp
Show inline comments
 
@@ -26,13 +26,13 @@
 
 * @param x The value to read some bits.
 
 * @param s The startposition to read some bits.
 
 * @param n The number of bits to read.
 
 * @return The selected bits, aligned to a LSB.
 
 */
 
template <typename T>
 
static FORCEINLINE uint GB(const T x, const uint8 s, const uint8 n)
 
static inline uint GB(const T x, const uint8 s, const uint8 n)
 
{
 
	return (x >> s) & (((T)1U << n) - 1);
 
}
 

	
 
/**
 
 * Set \a n bits in \a x starting at bit \a s to \a d
 
@@ -50,13 +50,13 @@ static FORCEINLINE uint GB(const T x, co
 
 * @param s The startposition for the new bits
 
 * @param n The size/window for the new bits
 
 * @param d The actually new bits to save in the defined position.
 
 * @return The new value of \a x
 
 */
 
template <typename T, typename U>
 
static FORCEINLINE T SB(T &x, const uint8 s, const uint8 n, const U d)
 
static inline T SB(T &x, const uint8 s, const uint8 n, const U d)
 
{
 
	x &= (T)(~((((T)1U << n) - 1) << s));
 
	x |= (T)(d << s);
 
	return x;
 
}
 

	
 
@@ -73,13 +73,13 @@ static FORCEINLINE T SB(T &x, const uint
 
 * @param s The startposition of the addition
 
 * @param n The size/window for the addition
 
 * @param i The value to add at the given startposition in the given window.
 
 * @return The new value of x
 
 */
 
template <typename T, typename U>
 
static FORCEINLINE T AB(T &x, const uint8 s, const uint8 n, const U i)
 
static inline T AB(T &x, const uint8 s, const uint8 n, const U i)
 
{
 
	const T mask = ((((T)1U << n) - 1) << s);
 
	x = (T)((x & ~mask) | ((x + (i << s)) & mask));
 
	return x;
 
}
 

	
 
@@ -92,13 +92,13 @@ static FORCEINLINE T AB(T &x, const uint
 
 *
 
 * @param x The value to check
 
 * @param y The position of the bit to check, started from the LSB
 
 * @return True if the bit is set, false else.
 
 */
 
template <typename T>
 
static FORCEINLINE bool HasBit(const T x, const uint8 y)
 
static inline bool HasBit(const T x, const uint8 y)
 
{
 
	return (x & ((T)1U << y)) != 0;
 
}
 

	
 
/**
 
 * Set a bit in a variable.
 
@@ -109,13 +109,13 @@ static FORCEINLINE bool HasBit(const T x
 
 *
 
 * @param x The variable to set a bit
 
 * @param y The bit position to set
 
 * @return The new value of the old value with the bit set
 
 */
 
template <typename T>
 
static FORCEINLINE T SetBit(T &x, const uint8 y)
 
static inline T SetBit(T &x, const uint8 y)
 
{
 
	return x = (T)(x | ((T)1U << y));
 
}
 

	
 
/**
 
 * Sets several bits in a variable.
 
@@ -138,13 +138,13 @@ static FORCEINLINE T SetBit(T &x, const 
 
 *
 
 * @param x The variable to clear the bit
 
 * @param y The bit position to clear
 
 * @return The new value of the old value with the bit cleared
 
 */
 
template <typename T>
 
static FORCEINLINE T ClrBit(T &x, const uint8 y)
 
static inline T ClrBit(T &x, const uint8 y)
 
{
 
	return x = (T)(x & ~((T)1U << y));
 
}
 

	
 
/**
 
 * Clears several bits in a variable.
 
@@ -167,13 +167,13 @@ static FORCEINLINE T ClrBit(T &x, const 
 
 *
 
 * @param x The varliable to toggle the bit
 
 * @param y The bit position to toggle
 
 * @return The new value of the old value with the bit toggled
 
 */
 
template <typename T>
 
static FORCEINLINE T ToggleBit(T &x, const uint8 y)
 
static inline T ToggleBit(T &x, const uint8 y)
 
{
 
	return x = (T)(x ^ ((T)1U << y));
 
}
 

	
 

	
 
/** Lookup table to check which bit is set in a 6 bit variable */
 
@@ -202,13 +202,13 @@ extern const uint8 _ffb_64[64];
 
 * be also zero to check the bits at 0x3F00.
 
 *
 
 * @param value The value to check the first bits
 
 * @return The position of the first bit which is set
 
 * @see FIND_FIRST_BIT
 
 */
 
static FORCEINLINE uint8 FindFirstBit2x64(const int value)
 
static inline uint8 FindFirstBit2x64(const int value)
 
{
 
	if ((value & 0xFF) == 0) {
 
		return FIND_FIRST_BIT((value >> 8) & 0x3F) + 8;
 
	} else {
 
		return FIND_FIRST_BIT(value & 0x3F);
 
	}
 
@@ -225,13 +225,13 @@ uint8 FindLastBit(uint64 x);
 
 * So, 110100 returns 110000, 000001 returns 000000, etc.
 
 *
 
 * @param value The value to clear the first bit
 
 * @return The new value with the first bit cleared
 
 */
 
template <typename T>
 
static FORCEINLINE T KillFirstBit(T value)
 
static inline T KillFirstBit(T value)
 
{
 
	return value &= (T)(value - 1);
 
}
 

	
 
/**
 
 * Counts the number of set bits in a variable.
 
@@ -260,25 +260,25 @@ static inline uint CountBits(T value)
 
 * 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)
 
static inline 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)
 
static inline bool HasAtMostOneBit(T value)
 
{
 
	return (value & (value - 1)) == 0;
 
}
 

	
 
/**
 
 * ROtate x Left by n
 
@@ -286,13 +286,13 @@ static FORCEINLINE bool HasAtMostOneBit(
 
 * @note Assumes a byte has 8 bits
 
 * @param x The value which we want to rotate
 
 * @param n The number how many we waht to rotate
 
 * @return A bit rotated number
 
 */
 
template <typename T>
 
static FORCEINLINE T ROL(const T x, const uint8 n)
 
static inline T ROL(const T x, const uint8 n)
 
{
 
	return (T)(x << n | x >> (sizeof(x) * 8 - n));
 
}
 

	
 
/**
 
 * ROtate x Right by n
 
@@ -300,13 +300,13 @@ static FORCEINLINE T ROL(const T x, cons
 
 * @note Assumes a byte has 8 bits
 
 * @param x The value which we want to rotate
 
 * @param n The number how many we waht to rotate
 
 * @return A bit rotated number
 
 */
 
template <typename T>
 
static FORCEINLINE T ROR(const T x, const uint8 n)
 
static inline T ROR(const T x, const uint8 n)
 
{
 
	return (T)(x >> n | x << (sizeof(x) * 8 - n));
 
}
 

	
 
/**
 
 * Do an operation for each set bit in a value.
 
@@ -362,13 +362,13 @@ static FORCEINLINE T ROR(const T x, cons
 
#else
 
	/**
 
	 * Perform a 32 bits endianness bitswap on x.
 
	 * @param x the variable to bitswap
 
	 * @return the bitswapped value.
 
	 */
 
	static FORCEINLINE uint32 BSWAP32(uint32 x)
 
	static inline uint32 BSWAP32(uint32 x)
 
	{
 
#if !defined(__ICC) && defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4)  && __GNUC_MINOR__ >= 3))
 
		/* GCC >= 4.3 provides a builtin, resulting in faster code */
 
		return (uint32)__builtin_bswap32((int32)x);
 
#else
 
		return ((x >> 24) & 0xFF) | ((x >> 8) & 0xFF00) | ((x << 8) & 0xFF0000) | ((x << 24) & 0xFF000000);
 
@@ -377,13 +377,13 @@ static FORCEINLINE T ROR(const T x, cons
 

	
 
	/**
 
	 * Perform a 16 bits endianness bitswap on x.
 
	 * @param x the variable to bitswap
 
	 * @return the bitswapped value.
 
	 */
 
	static FORCEINLINE uint16 BSWAP16(uint16 x)
 
	static inline uint16 BSWAP16(uint16 x)
 
	{
 
		return (x >> 8) | (x << 8);
 
	}
 
#endif /* __APPLE__ */
 

	
 
#endif /* BITMATH_FUNC_HPP */