More integer vectorization

This commit is contained in:
Christophe Riccio
2014-10-24 02:46:59 +02:00
parent 0274cb6e58
commit 72a2f49834
3 changed files with 63 additions and 65 deletions

View File

@@ -123,8 +123,8 @@ namespace glm
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> bitfieldExtract(
vecType<T, P> const & Value,
int const & Offset,
int const & Bits);
int Offset,
int Bits);
/// Returns the insertion the bits least-significant bits of insert into base.
///
@@ -144,8 +144,8 @@ namespace glm
GLM_FUNC_DECL vecType<T, P> bitfieldInsert(
vecType<T, P> const & Base,
vecType<T, P> const & Insert,
int const & Offset,
int const & Bits);
int Offset,
int Bits);
/// Returns the reversal of the bits of value.
/// The bit numbered n of the result will be taken from bit (bits - 1) - n of value,

View File

@@ -135,7 +135,7 @@ namespace glm
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> bitfieldExtract(vecType<T, P> const & Value, int const & Offset, int const & Bits)
GLM_FUNC_QUALIFIER vecType<T, P> bitfieldExtract(vecType<T, P> const & Value, int Offset, int Bits)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitfieldExtract' only accept integer inputs");
@@ -153,78 +153,30 @@ namespace glm
// bitfieldInsert
template <typename genIUType>
GLM_FUNC_QUALIFIER genIUType bitfieldInsert
(
genIUType const & Base,
genIUType const & Insert,
int const & Offset,
int const & Bits
)
GLM_FUNC_QUALIFIER genIUType bitfieldInsert(genIUType const & Base, genIUType const & Insert, int Offset, int Bits)
{
GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'bitfieldInsert' only accept integer values");
assert(Offset + Bits <= sizeof(genIUType));
return bitfieldInsert(tvec1<genIUType>(Base), tvec1<genIUType>(Insert), Offset, Bits).x;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> bitfieldInsert(vecType<T, P> const & Base, vecType<T, P> const & Insert, int Offset, int Bits)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitfieldInsert' only accept integer values");
if(Bits == 0)
return Base;
genIUType Mask = 0;
vecType<T, P> Mask(0);
for(int Bit = Offset; Bit < Offset + Bits; ++Bit)
Mask |= (1 << Bit);
Mask |= (static_cast<int>(1) << Bit);
return (Base & ~Mask) | (Insert & Mask);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P> bitfieldInsert
(
tvec2<T, P> const & Base,
tvec2<T, P> const & Insert,
int const & Offset,
int const & Bits
)
{
return tvec2<T, P>(
bitfieldInsert(Base[0], Insert[0], Offset, Bits),
bitfieldInsert(Base[1], Insert[1], Offset, Bits));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> bitfieldInsert
(
tvec3<T, P> const & Base,
tvec3<T, P> const & Insert,
int const & Offset,
int const & Bits
)
{
return tvec3<T, P>(
bitfieldInsert(Base[0], Insert[0], Offset, Bits),
bitfieldInsert(Base[1], Insert[1], Offset, Bits),
bitfieldInsert(Base[2], Insert[2], Offset, Bits));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> bitfieldInsert
(
tvec4<T, P> const & Base,
tvec4<T, P> const & Insert,
int const & Offset,
int const & Bits
)
{
return tvec4<T, P>(
bitfieldInsert(Base[0], Insert[0], Offset, Bits),
bitfieldInsert(Base[1], Insert[1], Offset, Bits),
bitfieldInsert(Base[2], Insert[2], Offset, Bits),
bitfieldInsert(Base[3], Insert[3], Offset, Bits));
}
// bitfieldReverse
template <typename T>
GLM_FUNC_QUALIFIER T bitfieldReverse(T v)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitfieldReverse' only accept integer values");
return bitfieldReverse(tvec1<T>(v)).x;
}
@@ -249,8 +201,6 @@ namespace glm
template <typename genIUType>
GLM_FUNC_QUALIFIER int bitCount(genIUType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'bitCount' only accept integer values");
return bitCount(tvec1<genIUType>(x)).x;
}