Added bitfieldDeinterleave with tests

This commit is contained in:
Christophe Riccio
2018-06-01 18:01:35 +02:00
parent f5572344f5
commit b4981e56fa
5 changed files with 205 additions and 8 deletions

View File

@@ -289,6 +289,62 @@ namespace min_
return Error;
}
int min_tern(int a, int b)
{
return a < b ? a : b;
}
int min_int(int x, int y)
{
return y ^ ((x ^ y) & -(x < y));
}
static int perf(int Count)
{
std::vector<int> A(Count);
std::vector<int> B(Count);
std::size_t const InternalCount = 200000;
for(std::size_t i = 0; i < Count; ++i)
{
A[i] = glm::linearRand(-1000, 1000);
B[i] = glm::linearRand(-1000, 1000);
}
int Error = 0;
glm::int32 SumA = 0;
{
std::clock_t Timestamp0 = std::clock();
for (std::size_t j = 0; j < InternalCount; ++j)
for (std::size_t i = 0; i < Count; ++i)
SumA += min_tern(A[i], B[i]);
std::clock_t Timestamp1 = std::clock();
std::printf("min_tern Time %d clocks\n", static_cast<unsigned int>(Timestamp1 - Timestamp0));
}
glm::int32 SumB = 0;
{
std::clock_t Timestamp0 = std::clock();
for (std::size_t j = 0; j < InternalCount; ++j)
for (std::size_t i = 0; i < Count; ++i)
SumB += min_int(A[i], B[i]);
std::clock_t Timestamp1 = std::clock();
std::printf("min_int Time %d clocks\n", static_cast<unsigned int>(Timestamp1 - Timestamp0));
}
Error += SumA == SumB ? 0 : 1;
return Error;
}
}//namespace min_
namespace max_
@@ -1262,6 +1318,8 @@ int main()
# endif
Error += sign::perf(Samples);
Error += min_::perf(Samples);
return Error;
}

View File

@@ -493,19 +493,29 @@ namespace bitfieldInterleave
for(glm::uint8 y = 0; y < 127; ++y)
for(glm::uint8 x = 0; x < 127; ++x)
{
glm::uint64 A(glm::bitfieldInterleave(glm::uint8(x), glm::uint8(y)));
glm::uint64 B(glm::bitfieldInterleave(glm::uint16(x), glm::uint16(y)));
glm::uint64 C(glm::bitfieldInterleave(glm::uint32(x), glm::uint32(y)));
glm::uint64 A(glm::bitfieldInterleave(glm::u8vec2(x, y)));
glm::uint64 B(glm::bitfieldInterleave(glm::u16vec2(x, y)));
glm::uint64 C(glm::bitfieldInterleave(glm::u32vec2(x, y)));
Error += A == B ? 0 : 1;
Error += A == C ? 0 : 1;
glm::int64 D(glm::bitfieldInterleave(glm::int8(x), glm::int8(y)));
glm::int64 E(glm::bitfieldInterleave(glm::int16(x), glm::int16(y)));
glm::int64 F(glm::bitfieldInterleave(glm::int32(x), glm::int32(y)));
glm::u32vec2 const& D = glm::bitfieldDeinterleave(C);
Error += D.x == x ? 0 : 1;
Error += D.y == y ? 0 : 1;
}
}
Error += D == E ? 0 : 1;
Error += D == F ? 0 : 1;
{
for(glm::uint8 y = 0; y < 127; ++y)
for(glm::uint8 x = 0; x < 127; ++x)
{
glm::int64 A(glm::bitfieldInterleave(glm::int8(x), glm::int8(y)));
glm::int64 B(glm::bitfieldInterleave(glm::int16(x), glm::int16(y)));
glm::int64 C(glm::bitfieldInterleave(glm::int32(x), glm::int32(y)));
Error += A == B ? 0 : 1;
Error += A == C ? 0 : 1;
}
}
@@ -888,6 +898,7 @@ namespace bitfieldInterleave5
int main()
{
int Error = 0;
/* Tests for a faster and to reserve bitfieldInterleave
Error += ::bitfieldInterleave5::test();
Error += ::bitfieldInterleave5::perf();