Optimizations of log2 for ivec4

This commit is contained in:
Christophe Riccio
2014-11-24 01:56:36 +01:00
parent 117634c7ea
commit e8fbcf76dd
5 changed files with 171 additions and 40 deletions

View File

@@ -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;
}