Added EXT_vector_integer test

This commit is contained in:
Christophe 2019-07-12 15:44:17 +02:00
parent 27b622e968
commit 3288df2f89
2 changed files with 220 additions and 71 deletions

View File

@ -6,7 +6,7 @@ namespace glm
GLM_FUNC_QUALIFIER vec<L, bool, Q> isPowerOfTwo(vec<L, T, Q> const& Value)
{
vec<L, T, Q> const Result(abs(Value));
return equal(Result & (Result - 1), vec<L, T, Q>(0));
return equal(Result & (Result - vec<L, T, Q>(1)), vec<L, T, Q>(0));
}
template<length_t L, typename T, qualifier Q>

View File

@ -14,6 +14,7 @@ namespace isPowerOfTwo
bool Return;
};
template <glm::length_t L>
int test_int16()
{
type<glm::int16> const Data[] =
@ -30,13 +31,14 @@ namespace isPowerOfTwo
for (std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::int16>); i < n; ++i)
{
bool Result = glm::isPowerOfTwo(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
glm::vec<L, bool> const Result = glm::isPowerOfTwo(glm::vec<L, glm::int16>(Data[i].Value));
Error += glm::vec<L, bool>(Data[i].Return) == Result ? 0 : 1;
}
return Error;
}
template <glm::length_t L>
int test_uint16()
{
type<glm::uint16> const Data[] =
@ -53,13 +55,14 @@ namespace isPowerOfTwo
for (std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::uint16>); i < n; ++i)
{
bool Result = glm::isPowerOfTwo(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
glm::vec<L, bool> const Result = glm::isPowerOfTwo(glm::vec<L, glm::uint16>(Data[i].Value));
Error += glm::vec<L, bool>(Data[i].Return) == Result ? 0 : 1;
}
return Error;
}
template <glm::length_t L>
int test_int32()
{
type<int> const Data[] =
@ -76,13 +79,14 @@ namespace isPowerOfTwo
for (std::size_t i = 0, n = sizeof(Data) / sizeof(type<int>); i < n; ++i)
{
bool Result = glm::isPowerOfTwo(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
glm::vec<L, bool> const Result = glm::isPowerOfTwo(glm::vec<L, glm::int32>(Data[i].Value));
Error += glm::vec<L, bool>(Data[i].Return) == Result ? 0 : 1;
}
return Error;
}
template <glm::length_t L>
int test_uint32()
{
type<glm::uint> const Data[] =
@ -99,8 +103,8 @@ namespace isPowerOfTwo
for (std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::uint>); i < n; ++i)
{
bool Result = glm::isPowerOfTwo(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
glm::vec<L, bool> const Result = glm::isPowerOfTwo(glm::vec<L, glm::uint32>(Data[i].Value));
Error += glm::vec<L, bool>(Data[i].Return) == Result ? 0 : 1;
}
return Error;
@ -110,10 +114,25 @@ namespace isPowerOfTwo
{
int Error = 0;
Error += test_int16();
Error += test_uint16();
Error += test_int32();
Error += test_uint32();
Error += test_int16<1>();
Error += test_int16<2>();
Error += test_int16<3>();
Error += test_int16<4>();
Error += test_uint16<1>();
Error += test_uint16<2>();
Error += test_uint16<3>();
Error += test_uint16<4>();
Error += test_int32<1>();
Error += test_int32<2>();
Error += test_int32<3>();
Error += test_int32<4>();
Error += test_uint32<1>();
Error += test_uint32<2>();
Error += test_uint32<3>();
Error += test_uint32<4>();
return Error;
}
@ -121,22 +140,22 @@ namespace isPowerOfTwo
namespace prevPowerOfTwo
{
template <typename T>
template <glm::length_t L, typename T>
int run()
{
int Error = 0;
T const A = glm::prevPowerOfTwo(static_cast<T>(7));
Error += A == static_cast<T>(4) ? 0 : 1;
glm::vec<L, T> const A = glm::prevPowerOfTwo(glm::vec<L, T>(7));
Error += A == glm::vec<L, T>(4) ? 0 : 1;
T const B = glm::prevPowerOfTwo(static_cast<T>(15));
Error += B == static_cast<T>(8) ? 0 : 1;
glm::vec<L, T> const B = glm::prevPowerOfTwo(glm::vec<L, T>(15));
Error += B == glm::vec<L, T>(8) ? 0 : 1;
T const C = glm::prevPowerOfTwo(static_cast<T>(31));
Error += C == static_cast<T>(16) ? 0 : 1;
glm::vec<L, T> const C = glm::prevPowerOfTwo(glm::vec<L, T>(31));
Error += C == glm::vec<L, T>(16) ? 0 : 1;
T const D = glm::prevPowerOfTwo(static_cast<T>(32));
Error += D == static_cast<T>(32) ? 0 : 1;
glm::vec<L, T> const D = glm::prevPowerOfTwo(glm::vec<L, T>(32));
Error += D == glm::vec<L, T>(32) ? 0 : 1;
return Error;
}
@ -145,15 +164,45 @@ namespace prevPowerOfTwo
{
int Error = 0;
Error += run<glm::int8>();
Error += run<glm::int16>();
Error += run<glm::int32>();
Error += run<glm::int64>();
Error += run<1, glm::int8>();
Error += run<2, glm::int8>();
Error += run<3, glm::int8>();
Error += run<4, glm::int8>();
Error += run<glm::uint8>();
Error += run<glm::uint16>();
Error += run<glm::uint32>();
Error += run<glm::uint64>();
Error += run<1, glm::int16>();
Error += run<2, glm::int16>();
Error += run<3, glm::int16>();
Error += run<4, glm::int16>();
Error += run<1, glm::int32>();
Error += run<2, glm::int32>();
Error += run<3, glm::int32>();
Error += run<4, glm::int32>();
Error += run<1, glm::int64>();
Error += run<2, glm::int64>();
Error += run<3, glm::int64>();
Error += run<4, glm::int64>();
Error += run<1, glm::uint8>();
Error += run<2, glm::uint8>();
Error += run<3, glm::uint8>();
Error += run<4, glm::uint8>();
Error += run<1, glm::uint16>();
Error += run<2, glm::uint16>();
Error += run<3, glm::uint16>();
Error += run<4, glm::uint16>();
Error += run<1, glm::uint32>();
Error += run<2, glm::uint32>();
Error += run<3, glm::uint32>();
Error += run<4, glm::uint32>();
Error += run<1, glm::uint64>();
Error += run<2, glm::uint64>();
Error += run<3, glm::uint64>();
Error += run<4, glm::uint64>();
return Error;
}
@ -161,22 +210,22 @@ namespace prevPowerOfTwo
namespace nextPowerOfTwo
{
template <typename T>
template <glm::length_t L, typename T>
int run()
{
int Error = 0;
T const A = glm::nextPowerOfTwo(static_cast<T>(7));
Error += A == static_cast<T>(8) ? 0 : 1;
glm::vec<L, T> const A = glm::nextPowerOfTwo(glm::vec<L, T>(7));
Error += A == glm::vec<L, T>(8) ? 0 : 1;
T const B = glm::nextPowerOfTwo(static_cast<T>(15));
Error += B == static_cast<T>(16) ? 0 : 1;
glm::vec<L, T> const B = glm::nextPowerOfTwo(glm::vec<L, T>(15));
Error += B == glm::vec<L, T>(16) ? 0 : 1;
T const C = glm::nextPowerOfTwo(static_cast<T>(31));
Error += C == static_cast<T>(32) ? 0 : 1;
glm::vec<L, T> const C = glm::nextPowerOfTwo(glm::vec<L, T>(31));
Error += C == glm::vec<L, T>(32) ? 0 : 1;
T const D = glm::nextPowerOfTwo(static_cast<T>(32));
Error += D == static_cast<T>(32) ? 0 : 1;
glm::vec<L, T> const D = glm::nextPowerOfTwo(glm::vec<L, T>(32));
Error += D == glm::vec<L, T>(32) ? 0 : 1;
return Error;
}
@ -185,15 +234,45 @@ namespace nextPowerOfTwo
{
int Error = 0;
Error += run<glm::int8>();
Error += run<glm::int16>();
Error += run<glm::int32>();
Error += run<glm::int64>();
Error += run<1, glm::int8>();
Error += run<2, glm::int8>();
Error += run<3, glm::int8>();
Error += run<4, glm::int8>();
Error += run<glm::uint8>();
Error += run<glm::uint16>();
Error += run<glm::uint32>();
Error += run<glm::uint64>();
Error += run<1, glm::int16>();
Error += run<2, glm::int16>();
Error += run<3, glm::int16>();
Error += run<4, glm::int16>();
Error += run<1, glm::int32>();
Error += run<2, glm::int32>();
Error += run<3, glm::int32>();
Error += run<4, glm::int32>();
Error += run<1, glm::int64>();
Error += run<2, glm::int64>();
Error += run<3, glm::int64>();
Error += run<4, glm::int64>();
Error += run<1, glm::uint8>();
Error += run<2, glm::uint8>();
Error += run<3, glm::uint8>();
Error += run<4, glm::uint8>();
Error += run<1, glm::uint16>();
Error += run<2, glm::uint16>();
Error += run<3, glm::uint16>();
Error += run<4, glm::uint16>();
Error += run<1, glm::uint32>();
Error += run<2, glm::uint32>();
Error += run<3, glm::uint32>();
Error += run<4, glm::uint32>();
Error += run<1, glm::uint64>();
Error += run<2, glm::uint64>();
Error += run<3, glm::uint64>();
Error += run<4, glm::uint64>();
return Error;
}
@ -209,7 +288,7 @@ namespace prevMultiple
genIUType Return;
};
template <typename T>
template <glm::length_t L, typename T>
int run()
{
type<T> const Data[] =
@ -222,8 +301,11 @@ namespace prevMultiple
for (std::size_t i = 0, n = sizeof(Data) / sizeof(type<T>); i < n; ++i)
{
glm::vec<4, T> const Result = glm::prevMultiple(glm::vec<4, T>(Data[i].Source), Data[i].Multiple);
Error += glm::vec<4, T>(Data[i].Return) == Result ? 0 : 1;
glm::vec<L, T> const Result0 = glm::prevMultiple(glm::vec<L, T>(Data[i].Source), Data[i].Multiple);
Error += glm::vec<L, T>(Data[i].Return) == Result0 ? 0 : 1;
glm::vec<L, T> const Result1 = glm::prevMultiple(glm::vec<L, T>(Data[i].Source), glm::vec<L, T>(Data[i].Multiple));
Error += glm::vec<L, T>(Data[i].Return) == Result1 ? 0 : 1;
}
return Error;
@ -233,15 +315,45 @@ namespace prevMultiple
{
int Error = 0;
Error += run<glm::int8>();
Error += run<glm::int16>();
Error += run<glm::int32>();
Error += run<glm::int64>();
Error += run<1, glm::int8>();
Error += run<2, glm::int8>();
Error += run<3, glm::int8>();
Error += run<4, glm::int8>();
Error += run<glm::uint8>();
Error += run<glm::uint16>();
Error += run<glm::uint32>();
Error += run<glm::uint64>();
Error += run<1, glm::int16>();
Error += run<2, glm::int16>();
Error += run<3, glm::int16>();
Error += run<4, glm::int16>();
Error += run<1, glm::int32>();
Error += run<2, glm::int32>();
Error += run<3, glm::int32>();
Error += run<4, glm::int32>();
Error += run<1, glm::int64>();
Error += run<2, glm::int64>();
Error += run<3, glm::int64>();
Error += run<4, glm::int64>();
Error += run<1, glm::uint8>();
Error += run<2, glm::uint8>();
Error += run<3, glm::uint8>();
Error += run<4, glm::uint8>();
Error += run<1, glm::uint16>();
Error += run<2, glm::uint16>();
Error += run<3, glm::uint16>();
Error += run<4, glm::uint16>();
Error += run<1, glm::uint32>();
Error += run<2, glm::uint32>();
Error += run<3, glm::uint32>();
Error += run<4, glm::uint32>();
Error += run<1, glm::uint64>();
Error += run<2, glm::uint64>();
Error += run<3, glm::uint64>();
Error += run<4, glm::uint64>();
return Error;
}
@ -257,21 +369,28 @@ namespace nextMultiple
genIUType Return;
};
template <typename T>
template <glm::length_t L, typename T>
int run()
{
type<T> const Data[] =
{
{ 8, 3, 6 },
{ 7, 7, 7 }
{ 3, 4, 4 },
{ 6, 3, 6 },
{ 5, 3, 6 },
{ 7, 7, 7 },
{ 0, 1, 0 },
{ 8, 3, 9 }
};
int Error = 0;
for (std::size_t i = 0, n = sizeof(Data) / sizeof(type<T>); i < n; ++i)
{
glm::vec<4, T> const Result = glm::nextMultiple(glm::vec<4, T>(Data[i].Source), Data[i].Multiple);
Error += glm::vec<4, T>(Data[i].Return) == Result ? 0 : 1;
glm::vec<L, T> const Result0 = glm::nextMultiple(glm::vec<L, T>(Data[i].Source), glm::vec<L, T>(Data[i].Multiple));
Error += glm::vec<L, T>(Data[i].Return) == Result0 ? 0 : 1;
glm::vec<L, T> const Result1 = glm::nextMultiple(glm::vec<L, T>(Data[i].Source), Data[i].Multiple);
Error += glm::vec<L, T>(Data[i].Return) == Result1 ? 0 : 1;
}
return Error;
@ -281,15 +400,45 @@ namespace nextMultiple
{
int Error = 0;
Error += run<glm::int8>();
Error += run<glm::int16>();
Error += run<glm::int32>();
Error += run<glm::int64>();
Error += run<1, glm::int8>();
Error += run<2, glm::int8>();
Error += run<3, glm::int8>();
Error += run<4, glm::int8>();
Error += run<glm::uint8>();
Error += run<glm::uint16>();
Error += run<glm::uint32>();
Error += run<glm::uint64>();
Error += run<1, glm::int16>();
Error += run<2, glm::int16>();
Error += run<3, glm::int16>();
Error += run<4, glm::int16>();
Error += run<1, glm::int32>();
Error += run<2, glm::int32>();
Error += run<3, glm::int32>();
Error += run<4, glm::int32>();
Error += run<1, glm::int64>();
Error += run<2, glm::int64>();
Error += run<3, glm::int64>();
Error += run<4, glm::int64>();
Error += run<1, glm::uint8>();
Error += run<2, glm::uint8>();
Error += run<3, glm::uint8>();
Error += run<4, glm::uint8>();
Error += run<1, glm::uint16>();
Error += run<2, glm::uint16>();
Error += run<3, glm::uint16>();
Error += run<4, glm::uint16>();
Error += run<1, glm::uint32>();
Error += run<2, glm::uint32>();
Error += run<3, glm::uint32>();
Error += run<4, glm::uint32>();
Error += run<1, glm::uint64>();
Error += run<2, glm::uint64>();
Error += run<3, glm::uint64>();
Error += run<4, glm::uint64>();
return Error;
}