mirror of
https://github.com/g-truc/glm.git
synced 2024-11-26 10:14:35 +00:00
More integer vectorization
This commit is contained in:
parent
0274cb6e58
commit
72a2f49834
@ -123,8 +123,8 @@ namespace glm
|
|||||||
template <typename T, precision P, template <typename, precision> class vecType>
|
template <typename T, precision P, template <typename, precision> class vecType>
|
||||||
GLM_FUNC_DECL vecType<T, P> bitfieldExtract(
|
GLM_FUNC_DECL vecType<T, P> bitfieldExtract(
|
||||||
vecType<T, P> const & Value,
|
vecType<T, P> const & Value,
|
||||||
int const & Offset,
|
int Offset,
|
||||||
int const & Bits);
|
int Bits);
|
||||||
|
|
||||||
/// Returns the insertion the bits least-significant bits of insert into base.
|
/// 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(
|
GLM_FUNC_DECL vecType<T, P> bitfieldInsert(
|
||||||
vecType<T, P> const & Base,
|
vecType<T, P> const & Base,
|
||||||
vecType<T, P> const & Insert,
|
vecType<T, P> const & Insert,
|
||||||
int const & Offset,
|
int Offset,
|
||||||
int const & Bits);
|
int Bits);
|
||||||
|
|
||||||
/// Returns the reversal of the bits of value.
|
/// 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,
|
/// The bit numbered n of the result will be taken from bit (bits - 1) - n of value,
|
||||||
|
@ -135,7 +135,7 @@ namespace glm
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, precision P, template <typename, precision> class vecType>
|
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");
|
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitfieldExtract' only accept integer inputs");
|
||||||
|
|
||||||
@ -153,78 +153,30 @@ namespace glm
|
|||||||
|
|
||||||
// bitfieldInsert
|
// bitfieldInsert
|
||||||
template <typename genIUType>
|
template <typename genIUType>
|
||||||
GLM_FUNC_QUALIFIER genIUType bitfieldInsert
|
GLM_FUNC_QUALIFIER genIUType bitfieldInsert(genIUType const & Base, genIUType const & Insert, int Offset, int Bits)
|
||||||
(
|
|
||||||
genIUType const & Base,
|
|
||||||
genIUType const & Insert,
|
|
||||||
int const & Offset,
|
|
||||||
int const & Bits
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'bitfieldInsert' only accept integer values");
|
return bitfieldInsert(tvec1<genIUType>(Base), tvec1<genIUType>(Insert), Offset, Bits).x;
|
||||||
assert(Offset + Bits <= sizeof(genIUType));
|
}
|
||||||
|
|
||||||
|
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)
|
if(Bits == 0)
|
||||||
return Base;
|
return Base;
|
||||||
|
|
||||||
genIUType Mask = 0;
|
vecType<T, P> Mask(0);
|
||||||
for(int Bit = Offset; Bit < Offset + Bits; ++Bit)
|
for(int Bit = Offset; Bit < Offset + Bits; ++Bit)
|
||||||
Mask |= (1 << Bit);
|
Mask |= (static_cast<int>(1) << Bit);
|
||||||
|
|
||||||
return (Base & ~Mask) | (Insert & Mask);
|
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
|
// bitfieldReverse
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER T bitfieldReverse(T v)
|
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;
|
return bitfieldReverse(tvec1<T>(v)).x;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,8 +201,6 @@ namespace glm
|
|||||||
template <typename genIUType>
|
template <typename genIUType>
|
||||||
GLM_FUNC_QUALIFIER int bitCount(genIUType x)
|
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;
|
return bitCount(tvec1<genIUType>(x)).x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,53 @@ enum result
|
|||||||
STATIC_ASSERT
|
STATIC_ASSERT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace bitfieldInsert
|
||||||
|
{
|
||||||
|
template <typename genType, typename sizeType>
|
||||||
|
struct type
|
||||||
|
{
|
||||||
|
genType Base;
|
||||||
|
genType Insert;
|
||||||
|
sizeType Offset;
|
||||||
|
sizeType Bits;
|
||||||
|
genType Return;
|
||||||
|
result Result;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef type<glm::uint, glm::uint> typeU32;
|
||||||
|
|
||||||
|
typeU32 const Data32[] =
|
||||||
|
{
|
||||||
|
{0xffffffff, 8,24, 0xffffff00, SUCCESS},
|
||||||
|
};
|
||||||
|
|
||||||
|
int test()
|
||||||
|
{
|
||||||
|
glm::uint count = sizeof(Data32) / sizeof(typeU32);
|
||||||
|
|
||||||
|
for(glm::uint i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
glm::uint Return = glm::bitfieldInsert(
|
||||||
|
Data32[i].Base,
|
||||||
|
Data32[i].Insert,
|
||||||
|
Data32[i].Offset,
|
||||||
|
Data32[i].Bits);
|
||||||
|
|
||||||
|
bool Compare = Data32[i].Return == Return;
|
||||||
|
|
||||||
|
if(Data32[i].Result == SUCCESS && Compare)
|
||||||
|
continue;
|
||||||
|
else if(Data32[i].Result == FAIL && !Compare)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::cout << "glm::bitfieldInsert test fail on test " << i << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}//bitfieldInsert
|
||||||
|
|
||||||
namespace bitfieldExtract
|
namespace bitfieldExtract
|
||||||
{
|
{
|
||||||
template <typename genType, typename sizeType>
|
template <typename genType, typename sizeType>
|
||||||
@ -480,6 +527,7 @@ int main()
|
|||||||
Error += ::imulExtended::test();
|
Error += ::imulExtended::test();
|
||||||
Error += ::uaddCarry::test();
|
Error += ::uaddCarry::test();
|
||||||
Error += ::usubBorrow::test();
|
Error += ::usubBorrow::test();
|
||||||
|
Error += ::bitfieldInsert::test();
|
||||||
Error += ::bitfieldExtract::test();
|
Error += ::bitfieldExtract::test();
|
||||||
Error += ::bitfieldReverse::test();
|
Error += ::bitfieldReverse::test();
|
||||||
Error += ::findMSB::test();
|
Error += ::findMSB::test();
|
||||||
|
Loading…
Reference in New Issue
Block a user