Optimizations of log2 for ivec4
This commit is contained in:
@@ -887,12 +887,6 @@ namespace sign
|
||||
Error += Data[i].Return == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i)
|
||||
{
|
||||
glm::int32 Result = sign_sub(Data[i].Value);
|
||||
Error += Data[i].Return == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,11 @@
|
||||
// File : test/gtc/integer.cpp
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define GLM_FORCE_INLINE
|
||||
#include <glm/gtc/integer.hpp>
|
||||
#include <glm/gtc/type_precision.hpp>
|
||||
#include <glm/gtc/vec1.hpp>
|
||||
#include <glm/gtx/type_aligned.hpp>
|
||||
#include <glm/vector_relational.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
@@ -48,6 +50,126 @@ namespace log2_
|
||||
int perf()
|
||||
{
|
||||
int Error = 0;
|
||||
std::size_t const Count(100000000);
|
||||
|
||||
{
|
||||
std::vector<int> Result;
|
||||
Result.resize(Count);
|
||||
|
||||
std::clock_t Begin = clock();
|
||||
|
||||
for(std::size_t i = 0; i < Count; ++i)
|
||||
Result[i] = glm::log2(static_cast<int>(i));
|
||||
|
||||
std::clock_t End = clock();
|
||||
|
||||
printf("glm::log2<int>: %d clocks\n", End - Begin);
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<glm::ivec4> Result;
|
||||
Result.resize(Count);
|
||||
|
||||
std::clock_t Begin = clock();
|
||||
|
||||
for(std::size_t i = 0; i < Count; ++i)
|
||||
Result[i] = glm::log2(glm::ivec4(i));
|
||||
|
||||
std::clock_t End = clock();
|
||||
|
||||
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))
|
||||
{
|
||||
std::vector<glm::ivec4> Result;
|
||||
Result.resize(Count);
|
||||
|
||||
std::clock_t Begin = clock();
|
||||
|
||||
for(std::size_t i = 0; i < Count; ++i)
|
||||
{
|
||||
glm::tvec4<unsigned long, glm::defaultp> Tmp(glm::uninitialize);
|
||||
_BitScanReverse(&Tmp.x, i);
|
||||
_BitScanReverse(&Tmp.y, i);
|
||||
_BitScanReverse(&Tmp.z, i);
|
||||
_BitScanReverse(&Tmp.w, i);
|
||||
Result[i] = glm::ivec4(Tmp);
|
||||
}
|
||||
|
||||
std::clock_t End = clock();
|
||||
|
||||
printf("glm::log2<ivec4> inlined: %d clocks\n", End - Begin);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
std::vector<glm::tvec4<unsigned long, glm::defaultp> > Result;
|
||||
Result.resize(Count);
|
||||
|
||||
std::clock_t Begin = clock();
|
||||
|
||||
for(std::size_t i = 0; i < Count; ++i)
|
||||
{
|
||||
_BitScanReverse(&Result[i].x, i);
|
||||
_BitScanReverse(&Result[i].y, i);
|
||||
_BitScanReverse(&Result[i].z, i);
|
||||
_BitScanReverse(&Result[i].w, i);
|
||||
}
|
||||
|
||||
std::clock_t End = clock();
|
||||
|
||||
printf("glm::log2<ivec4> inlined no cast: %d clocks\n", End - Begin);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
std::vector<glm::ivec4> Result;
|
||||
Result.resize(Count);
|
||||
|
||||
std::clock_t Begin = clock();
|
||||
|
||||
for(std::size_t i = 0; i < Count; ++i)
|
||||
{
|
||||
_BitScanReverse(reinterpret_cast<unsigned long*>(&Result[i].x), i);
|
||||
_BitScanReverse(reinterpret_cast<unsigned long*>(&Result[i].y), i);
|
||||
_BitScanReverse(reinterpret_cast<unsigned long*>(&Result[i].z), i);
|
||||
_BitScanReverse(reinterpret_cast<unsigned long*>(&Result[i].w), i);
|
||||
}
|
||||
|
||||
std::clock_t End = clock();
|
||||
|
||||
printf("glm::log2<ivec4> reinterpret: %d clocks\n", End - Begin);
|
||||
}
|
||||
# endif//GLM_ARCH != GLM_ARCH_PURE
|
||||
|
||||
{
|
||||
std::vector<float> Result;
|
||||
Result.resize(Count);
|
||||
|
||||
std::clock_t Begin = clock();
|
||||
|
||||
for(std::size_t i = 0; i < Count; ++i)
|
||||
Result[i] = glm::log2(static_cast<float>(i));
|
||||
|
||||
std::clock_t End = clock();
|
||||
|
||||
printf("glm::log2<float>: %d clocks\n", End - Begin);
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<glm::vec4> Result;
|
||||
Result.resize(Count);
|
||||
|
||||
std::clock_t Begin = clock();
|
||||
|
||||
for(std::size_t i = 0; i < Count; ++i)
|
||||
Result[i] = glm::log2(glm::vec4(i));
|
||||
|
||||
std::clock_t End = clock();
|
||||
|
||||
printf("glm::log2<vec4>: %d clocks\n", End - Begin);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user