Browse Source

Promoted bitfieldRotate[Right|left] and bitfieldFill[zero|one]

Christophe Riccio 11 years ago
parent
commit
69274e740c
4 changed files with 81 additions and 65 deletions
  1. 49 7
      glm/gtc/bitfield.hpp
  2. 32 8
      glm/gtc/bitfield.inl
  3. 0 16
      glm/gtx/bit.hpp
  4. 0 34
      glm/gtx/bit.inl

+ 49 - 7
glm/gtc/bitfield.hpp

@@ -55,21 +55,63 @@ namespace glm
 	/// @{
 
 	/// Build a mask of 'count' bits
+	///
 	/// @see gtc_bitfield
 	GLM_FUNC_DECL int mask(int Bits);
-
+	
+	/// Build a mask of 'count' bits
+	///
+	/// @see gtc_bitfield
 	template <precision P, template <typename, precision> class vecType>
 	GLM_FUNC_DECL vecType<int, P> mask(vecType<int, P> const & v);
 
-	/// Rotate all bits to the right.
+	/// Rotate all bits to the right. All the bits dropped in the right side are inserted back on the left side.
+	///
+	/// @see gtc_bitfield
+	template <typename genIUType>
+	GLM_FUNC_DECL genIUType bitfieldRotateRight(genIUType In, int Shift);
+
+	/// Rotate all bits to the right. All the bits dropped in the right side are inserted back on the left side.
+	///
+	/// @see gtc_bitfield
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_DECL vecType<T, P> bitfieldRotateRight(vecType<T, P> const & In, int Shift);
+
+	/// Rotate all bits to the left. All the bits dropped in the left side are inserted back on the right side.
+	///
+	/// @see gtc_bitfield
+	template <typename genIUType>
+	GLM_FUNC_DECL genIUType bitfieldRotateLeft(genIUType In, int Shift);
+
+	/// Rotate all bits to the left. All the bits dropped in the left side are inserted back on the right side.
+	///
+	/// @see gtc_bitfield
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_DECL vecType<T, P> bitfieldRotateLeft(vecType<T, P> const & In, int Shift);
+
+	/// Set to 1 a range of bits.
+	///
+	/// @see gtc_bitfield
+	template <typename genIUType>
+	GLM_FUNC_DECL genIUType bitfieldFillOne(genIUType Value, int FirstBit, int BitCount);
+
+	/// Set to 1 a range of bits.
+	///
+	/// @see gtc_bitfield
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_DECL vecType<T, P> bitfieldFillOne(vecType<T, P> const & Value, int FirstBit, int BitCount);
+
+	/// Set to 0 a range of bits.
+	///
 	/// @see gtc_bitfield
-	template <typename genType>
-	GLM_FUNC_DECL genType bitRotateRight(genType In, int Shift);
+	template <typename genIUType>
+	GLM_FUNC_DECL genIUType bitfieldFillZero(genIUType Value, int FirstBit, int BitCount);
 
-	/// Rotate all bits to the left.
+	/// Set to 0 a range of bits.
+	///
 	/// @see gtc_bitfield
-	template <typename genType>
-	GLM_FUNC_DECL genType bitRotateLeft(genType In, int Shift);
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_DECL vecType<T, P> bitfieldFillZero(vecType<T, P> const & Value, int FirstBit, int BitCount);
 
 	/// Interleaves the bits of x and y.
 	/// The first bit is the first bit of x followed by the first bit of y.

+ 32 - 8
glm/gtc/bitfield.inl

@@ -257,41 +257,65 @@ namespace detail
 	}
 
 	template <typename genIType>
-	GLM_FUNC_QUALIFIER genIType bitRotateRight(genIType In, int Shift)
+	GLM_FUNC_QUALIFIER genIType bitfieldRotateRight(genIType In, int Shift)
 	{
-		GLM_STATIC_ASSERT(std::numeric_limits<genIType>::is_integer, "'bitRotateRight' only accept integer values");
+		GLM_STATIC_ASSERT(std::numeric_limits<genIType>::is_integer, "'bitfieldRotateRight' only accept integer values");
 
 		int const BitSize = static_cast<genIType>(sizeof(genIType) * 8);
 		return (In << static_cast<genIType>(Shift)) | (In >> static_cast<genIType>(BitSize - Shift));
 	}
 
 	template <typename T, precision P, template <typename, precision> class vecType>
-	GLM_FUNC_QUALIFIER vecType<T, P> bitRotateRight(vecType<T, P> const & In, int Shift)
+	GLM_FUNC_QUALIFIER vecType<T, P> bitfieldRotateRight(vecType<T, P> const & In, int Shift)
 	{
-		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitRotateRight' only accept integer values");
+		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitfieldRotateRight' only accept integer values");
 
 		int const BitSize = static_cast<int>(sizeof(T) * 8);
 		return (In << static_cast<T>(Shift)) | (In >> static_cast<T>(BitSize - Shift));
 	}
 
 	template <typename genIType>
-	GLM_FUNC_QUALIFIER genIType bitRotateLeft(genIType In, int Shift)
+	GLM_FUNC_QUALIFIER genIType bitfieldRotateLeft(genIType In, int Shift)
 	{
-		GLM_STATIC_ASSERT(std::numeric_limits<genIType>::is_integer, "'bitRotateLeft' only accept integer values");
+		GLM_STATIC_ASSERT(std::numeric_limits<genIType>::is_integer, "'bitfieldRotateLeft' only accept integer values");
 
 		int const BitSize = static_cast<genIType>(sizeof(genIType) * 8);
 		return (In >> static_cast<genIType>(Shift)) | (In << static_cast<genIType>(BitSize - Shift));
 	}
 
 	template <typename T, precision P, template <typename, precision> class vecType>
-	GLM_FUNC_QUALIFIER vecType<T, P> bitRotateLeft(vecType<T, P> const & In, int Shift)
+	GLM_FUNC_QUALIFIER vecType<T, P> bitfieldRotateLeft(vecType<T, P> const & In, int Shift)
 	{
-		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitRotateLeft' only accept integer values");
+		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitfieldRotateLeft' only accept integer values");
 
 		int const BitSize = static_cast<int>(sizeof(T) * 8);
 		return (In >> static_cast<T>(Shift)) | (In << static_cast<T>(BitSize - Shift));
 	}
 
+	template <typename genIUType>
+	GLM_FUNC_QUALIFIER genIUType bitfieldFillOne(genIUType Value, int FirstBit, int BitCount)
+	{
+		return Value | static_cast<genIUType>(mask(BitCount) << FirstBit);
+	}
+
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_QUALIFIER vecType<T, P> bitfieldFillOne(vecType<T, P> const & Value, int FirstBit, int BitCount)
+	{
+		return Value | static_cast<T>(mask(BitCount) << FirstBit);
+	}
+
+	template <typename genIUType>
+	GLM_FUNC_QUALIFIER genIUType bitfieldFillZero(genIUType Value, int FirstBit, int BitCount)
+	{
+		return Value & static_cast<genIUType>(~(mask(BitCount) << FirstBit));
+	}
+
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_QUALIFIER vecType<T, P> bitfieldFillZero(vecType<T, P> const & Value, int FirstBit, int BitCount)
+	{
+		return Value & static_cast<T>(~(mask(BitCount) << FirstBit));
+	}
+
 	GLM_FUNC_QUALIFIER int16 bitfieldInterleave(int8 x, int8 y)
 	{
 		union sign8

+ 0 - 16
glm/gtx/bit.hpp

@@ -76,22 +76,6 @@ namespace glm
 	template <typename genType> 
 	GLM_FUNC_DECL genType powerOfTwoNearest(genType const & value);
 
-	//! Set to 1 a range of bits.
-	/// @see gtx_bit
-	template <typename genIUType>
-	GLM_FUNC_DECL genIUType fillBitfieldWithOne(
-		genIUType const & Value,
-		int const & FromBit, 
-		int const & ToBit);
-
-	//! Set to 0 a range of bits.
-	/// @see gtx_bit
-	template <typename genIUType>
-	GLM_FUNC_DECL genIUType fillBitfieldWithZero(
-		genIUType const & Value,
-		int const & FromBit, 
-		int const & ToBit);
-
 	/// @}
 } //namespace glm
 

+ 0 - 34
glm/gtx/bit.inl

@@ -152,38 +152,4 @@ namespace glm
 	}
 
 	VECTORIZE_VEC(powerOfTwoNearest)
-
-	template <typename genIUType>
-	GLM_FUNC_QUALIFIER genIUType fillBitfieldWithOne
-	(
-		genIUType const & Value,
-		int const & FromBit, 
-		int const & ToBit
-	)
-	{
-		assert(FromBit <= ToBit);
-		assert(ToBit <= sizeof(genIUType) * std::size_t(8));
-
-		genIUType Result = Value;
-		for(signed i = 0; i <= ToBit; ++i)
-			Result |= (1 << i);
-		return Result;
-	}
-
-	template <typename genIUType>
-	GLM_FUNC_QUALIFIER genIUType fillBitfieldWithZero
-	(
-		genIUType const & Value,
-		int const & FromBit, 
-		int const & ToBit
-	)
-	{
-		assert(FromBit <= ToBit);
-		assert(ToBit <= sizeof(genIUType) * std::size_t(8));
-
-		genIUType Result = Value;
-		for(signed i = 0; i <= ToBit; ++i)
-			Result &= ~(1 << i);
-		return Result;
-	}
 }//namespace glm