Fixed mod function specialization #281 Fixed bitscan detection

This commit is contained in:
Christophe Riccio
2014-11-29 18:47:58 +01:00
parent 9b250cc86f
commit 7e81213fdd
8 changed files with 225 additions and 36 deletions

View File

@@ -162,6 +162,40 @@ namespace modf_
}
}//namespace modf
namespace mod_
{
int test()
{
int Error(0);
{
float A(3.0);
float B(2.0f);
float C = glm::mod(A, B);
Error += glm::abs(C - 1.0f) < 0.00001f ? 0 : 1;
}
{
glm::vec4 A(3.0);
float B(2.0f);
glm::vec4 C = glm::mod(A, B);
Error += glm::all(glm::epsilonEqual(C, glm::vec4(1.0f), 0.00001f)) ? 0 : 1;
}
{
glm::vec4 A(3.0);
glm::vec4 B(2.0f);
glm::vec4 C = glm::mod(A, B);
Error += glm::all(glm::epsilonEqual(C, glm::vec4(1.0f), 0.00001f)) ? 0 : 1;
}
return Error;
}
}//namespace mod_
namespace floatBitsToInt
{
int test()
@@ -1109,6 +1143,7 @@ int main()
Error += sign::test();
Error += floor_::test();
Error += mod_::test();
Error += modf_::test();
Error += floatBitsToInt::test();
Error += floatBitsToUint::test();

View File

@@ -578,6 +578,7 @@ namespace findMSB
genType Return;
};
# if GLM_HAS_BITSCAN_WINDOWS
template <typename genIUType>
GLM_FUNC_QUALIFIER int findMSB_intrinsic(genIUType Value)
{
@@ -590,6 +591,20 @@ namespace findMSB
_BitScanReverse(&Result, Value);
return int(Result);
}
# endif//GLM_HAS_BITSCAN_WINDOWS
# if GLM_ARCH & GLM_ARCH_AVX
template <typename genIUType>
GLM_FUNC_QUALIFIER int findMSB_avx(genIUType Value)
{
GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findMSB' only accept integer values");
if(Value == 0)
return -1;
return int(_tzcnt_u32(Value));
}
# endif
template <typename genIUType>
GLM_FUNC_QUALIFIER int findMSB_095(genIUType Value)
@@ -698,7 +713,7 @@ namespace findMSB
};
int Error(0);
std::size_t const Count(1000000);
std::size_t const Count(10000000);
std::clock_t Timestamps0 = std::clock();
@@ -738,12 +753,14 @@ namespace findMSB
std::clock_t Timestamps4 = std::clock();
for(std::size_t k = 0; k < Count; ++k)
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i)
{
int Result = findMSB_intrinsic(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
# if GLM_HAS_BITSCAN_WINDOWS
for(std::size_t k = 0; k < Count; ++k)
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i)
{
int Result = findMSB_intrinsic(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
# endif//GLM_HAS_BITSCAN_WINDOWS
std::clock_t Timestamps5 = std::clock();
@@ -756,13 +773,31 @@ namespace findMSB
std::clock_t Timestamps6 = std::clock();
# if GLM_ARCH & GLM_ARCH_AVX
for(std::size_t k = 0; k < Count; ++k)
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i)
{
int Result = findMSB_avx(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
# endif
std::clock_t Timestamps7 = std::clock();
std::printf("glm::findMSB: %d clocks\n", static_cast<unsigned int>(Timestamps1 - Timestamps0));
std::printf("findMSB - nlz1: %d clocks\n", static_cast<unsigned int>(Timestamps2 - Timestamps1));
std::printf("findMSB - nlz2: %d clocks\n", static_cast<unsigned int>(Timestamps3 - Timestamps2));
std::printf("findMSB - 0.9.5: %d clocks\n", static_cast<unsigned int>(Timestamps4 - Timestamps3));
std::printf("findMSB - intrinsics: %d clocks\n", static_cast<unsigned int>(Timestamps5 - Timestamps4));
# if GLM_HAS_BITSCAN_WINDOWS
std::printf("findMSB - intrinsics: %d clocks\n", static_cast<unsigned int>(Timestamps5 - Timestamps4));
# endif//GLM_HAS_BITSCAN_WINDOWS
std::printf("findMSB - pop: %d clocks\n", static_cast<unsigned int>(Timestamps6 - Timestamps5));
# if GLM_ARCH & GLM_ARCH_AVX
std::printf("findMSB - avx tzcnt: %d clocks\n", static_cast<unsigned int>(Timestamps7 - Timestamps6));
# endif
return Error;
}
@@ -888,6 +923,8 @@ namespace findMSB
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i)
{
int Result0 = findMSB_intrinsic(Data[i].Value);
//unsigned int A = _lzcnt_u32(Data[i].Value);
//unsigned int B = _tzcnt_u32(Data[i].Value);
Error += Data[i].Return == Result0 ? 0 : 1;
}
@@ -1527,6 +1564,8 @@ int main()
Error += ::bitfieldInsert::test();
Error += ::bitfieldExtract::test();
Error += ::findMSB::perf();
# ifdef GLM_TEST_ENABLE_PERF
Error += ::bitCount::perf();
Error += ::bitfieldReverse::perf();

View File

@@ -30,6 +30,7 @@
///////////////////////////////////////////////////////////////////////////////////
#define GLM_FORCE_INLINE
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/integer.hpp>
#include <glm/gtc/type_precision.hpp>
#include <glm/gtc/vec1.hpp>
@@ -102,7 +103,7 @@ namespace log2_
printf("glm::log2<ivec4>: %d clocks\n", End - Begin);
}
# if(GLM_ARCH != GLM_ARCH_PURE) && (GLM_COMPILER & (GLM_COMPILER_VC | GLM_COMPILER_APPLE_CLANG | GLM_COMPILER_LLVM))
# if GLM_HAS_BITSCAN_WINDOWS
{
std::vector<glm::ivec4> Result;
Result.resize(Count);
@@ -163,7 +164,7 @@ namespace log2_
printf("glm::log2<ivec4> reinterpret: %d clocks\n", End - Begin);
}
# endif//GLM_ARCH != GLM_ARCH_PURE
# endif//GLM_HAS_BITSCAN_WINDOWS
{
std::vector<float> Result;
@@ -197,12 +198,70 @@ namespace log2_
}
}//namespace log2_
namespace mod_
{
int test()
{
int Error(0);
{
float A(3.0);
float B(2.0f);
float C = glm::mod(A, B);
Error += glm::abs(C - 1.0f) < 0.00001f ? 0 : 1;
}
{
glm::vec4 A(3.0);
float B(2.0f);
glm::vec4 C = glm::mod(A, B);
Error += glm::all(glm::epsilonEqual(C, glm::vec4(1.0f), 0.00001f)) ? 0 : 1;
}
{
glm::vec4 A(3.0);
glm::vec4 B(2.0f);
glm::vec4 C = glm::mod(A, B);
Error += glm::all(glm::epsilonEqual(C, glm::vec4(1.0f), 0.00001f)) ? 0 : 1;
}
{
int A(3);
int B(2);
int C = glm::mod(A, B);
Error += C == 1 ? 0 : 1;
}
{
glm::ivec4 A(3);
int B(2);
glm::ivec4 C = glm::mod(A, B);
Error += glm::all(glm::equal(C, glm::ivec4(1))) ? 0 : 1;
}
{
glm::ivec4 A(3);
glm::ivec4 B(2);
glm::ivec4 C = glm::mod(A, B);
Error += glm::all(glm::equal(C, glm::ivec4(1))) ? 0 : 1;
}
return Error;
}
}//namespace mod_
int main()
{
int Error(0);
Error += ::log2_::test();
Error += ::mod_::test();
# ifdef GLM_TEST_ENABLE_PERF
Error += ::log2_::perf();