mirror of
https://github.com/g-truc/glm.git
synced 2024-12-01 20:24:38 +00:00
Added Z-order experiments
This commit is contained in:
parent
ff64d51a1c
commit
96adec5f5e
@ -628,9 +628,9 @@ namespace bitfieldInterleave5
|
|||||||
GLM_FUNC_QUALIFIER glm::uint16 bitfieldInterleave_u8vec2(glm::uint8 x, glm::uint8 y)
|
GLM_FUNC_QUALIFIER glm::uint16 bitfieldInterleave_u8vec2(glm::uint8 x, glm::uint8 y)
|
||||||
{
|
{
|
||||||
glm::uint32 Result = (glm::uint32(y) << 16) | glm::uint32(x);
|
glm::uint32 Result = (glm::uint32(y) << 16) | glm::uint32(x);
|
||||||
Result = ((Result << 4) | Result) & glm::uint32(0x0F0F0F0F);
|
Result = ((Result << 4) | Result) & 0x0F0F0F0F;
|
||||||
Result = ((Result << 2) | Result) & glm::uint32(0x33333333);
|
Result = ((Result << 2) | Result) & 0x33333333;
|
||||||
Result = ((Result << 1) | Result) & glm::uint32(0x55555555);
|
Result = ((Result << 1) | Result) & 0x55555555;
|
||||||
return static_cast<glm::uint16>((Result & 0x0000FFFF) | (Result >> 15));
|
return static_cast<glm::uint16>((Result & 0x0000FFFF) | (Result >> 15));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,28 +638,34 @@ namespace bitfieldInterleave5
|
|||||||
{
|
{
|
||||||
glm::uint32 Result(InterleavedBitfield);
|
glm::uint32 Result(InterleavedBitfield);
|
||||||
Result = ((Result << 15) | Result) & 0x55555555;
|
Result = ((Result << 15) | Result) & 0x55555555;
|
||||||
Result = ((Result >> 1) | Result) & glm::uint32(0x33333333);
|
Result = ((Result >> 1) | Result) & 0x33333333;
|
||||||
Result = ((Result >> 2) | Result) & glm::uint32(0x0F0F0F0F);
|
Result = ((Result >> 2) | Result) & 0x0F0F0F0F;
|
||||||
Result = ((Result >> 4) | Result) & glm::uint32(0x00FF00FF);
|
Result = ((Result >> 4) | Result) & 0x00FF00FF;
|
||||||
return glm::u8vec2(Result & 0x0000FFFF, Result >> 16);
|
return glm::u8vec2(Result & 0x0000FFFF, Result >> 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER glm::uint32 bitfieldInterleave_u8vec4(glm::uint8 x, glm::uint8 y, glm::uint8 z, glm::uint8 w)
|
GLM_FUNC_QUALIFIER glm::uint32 bitfieldInterleave_u8vec4(glm::uint8 x, glm::uint8 y, glm::uint8 z, glm::uint8 w)
|
||||||
{
|
{
|
||||||
glm::uint64 Result = (glm::uint64(w) << 48) | (glm::uint64(z) << 32) | (glm::uint64(y) << 16) | glm::uint64(x);
|
glm::uint64 Result = (glm::uint64(w) << 48) | (glm::uint64(z) << 32) | (glm::uint64(y) << 16) | glm::uint64(x);
|
||||||
Result = ((Result << 4) | Result) & 0x0F0F0F0F0F0F0F0Full;
|
Result = ((Result << 12) | Result) & 0x000F000F000F000Full;
|
||||||
Result = ((Result << 2) | Result) & 0x3333333333333333ull;
|
Result = ((Result << 6) | Result) & 0x0303030303030303ull;
|
||||||
Result = ((Result << 1) | Result) & 0x5555555555555555ull;
|
Result = ((Result << 3) | Result) & 0x1111111111111111ull;
|
||||||
return static_cast<glm::uint32>((Result & 0x0000FFFF) | (Result >> 15));
|
|
||||||
|
const glm::uint32 a = static_cast<glm::uint32>((Result & 0x000000000000FFFF) >> ( 0 - 0));
|
||||||
|
const glm::uint32 b = static_cast<glm::uint32>((Result & 0x00000000FFFF0000) >> (16 - 3));
|
||||||
|
const glm::uint32 c = static_cast<glm::uint32>((Result & 0x0000FFFF00000000) >> (32 - 6));
|
||||||
|
const glm::uint32 d = static_cast<glm::uint32>((Result & 0xFFFF000000000000) >> (48 - 12));
|
||||||
|
|
||||||
|
return a | b | c | d;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER glm::u8vec4 bitfieldDeinterleave_u8vec4(glm::uint32 InterleavedBitfield)
|
GLM_FUNC_QUALIFIER glm::u8vec4 bitfieldDeinterleave_u8vec4(glm::uint32 InterleavedBitfield)
|
||||||
{
|
{
|
||||||
glm::uint64 Result(InterleavedBitfield);
|
glm::uint64 Result(InterleavedBitfield);
|
||||||
Result = ((Result << 15) | Result) & 0x5555555555555555ull;
|
Result = ((Result << 15) | Result) & 0x9249249249249249ull;
|
||||||
Result = ((Result >> 1) | Result) & 0x3333333333333333ull;
|
Result = ((Result >> 1) | Result) & 0x30C30C30C30C30C3ull;
|
||||||
Result = ((Result >> 2) | Result) & 0x0F0F0F0F0F0F0F0Full;
|
Result = ((Result >> 2) | Result) & 0xF00F00F00F00F00Full;
|
||||||
Result = ((Result >> 4) | Result) & 0x00FF00FF00FF00FFull;
|
Result = ((Result >> 4) | Result) & 0x00FF0000FF0000FFull;
|
||||||
return glm::u8vec4(
|
return glm::u8vec4(
|
||||||
(Result >> 0) & 0x000000000000FFFFull,
|
(Result >> 0) & 0x000000000000FFFFull,
|
||||||
(Result >> 16) & 0x00000000FFFF0000ull,
|
(Result >> 16) & 0x00000000FFFF0000ull,
|
||||||
@ -707,10 +713,24 @@ namespace bitfieldInterleave5
|
|||||||
for(glm::size_t j = 0; j < 256; ++j)
|
for(glm::size_t j = 0; j < 256; ++j)
|
||||||
for(glm::size_t i = 0; i < 256; ++i)
|
for(glm::size_t i = 0; i < 256; ++i)
|
||||||
{
|
{
|
||||||
glm::uint32 A = bitfieldInterleave_u16vec2(glm::uint16(i), glm::uint16(j));
|
glm::uint32 A = bitfieldInterleave_u8vec4(glm::uint8(i), glm::uint8(j), glm::uint8(i), glm::uint8(j));
|
||||||
glm::u8vec2 C = bitfieldDeinterleave_u8vec2(A);
|
glm::uint32 B = glm::bitfieldInterleave(glm::uint8(i), glm::uint8(j), glm::uint8(i), glm::uint8(j));
|
||||||
|
Error += A == B ? 0 : 1;
|
||||||
|
/*
|
||||||
|
glm::u8vec4 C = bitfieldDeinterleave_u8vec4(A);
|
||||||
Error += C.x == glm::uint8(i) ? 0 : 1;
|
Error += C.x == glm::uint8(i) ? 0 : 1;
|
||||||
Error += C.y == glm::uint8(j) ? 0 : 1;
|
Error += C.y == glm::uint8(j) ? 0 : 1;
|
||||||
|
Error += C.z == glm::uint8(i) ? 0 : 1;
|
||||||
|
Error += C.w == glm::uint8(j) ? 0 : 1;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
for(glm::size_t j = 0; j < 256; ++j)
|
||||||
|
for(glm::size_t i = 0; i < 256; ++i)
|
||||||
|
{
|
||||||
|
glm::uint32 A = bitfieldInterleave_u16vec2(glm::uint16(i), glm::uint16(j));
|
||||||
|
glm::uint32 B = glm::bitfieldInterleave(glm::uint16(i), glm::uint16(j));
|
||||||
|
Error += A == B ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Error;
|
return Error;
|
||||||
@ -729,7 +749,7 @@ namespace bitfieldInterleave5
|
|||||||
|
|
||||||
const std::clock_t EndTime = std::clock();
|
const std::clock_t EndTime = std::clock();
|
||||||
|
|
||||||
std::printf("glm::bitfieldInterleave Time %d clocks\n", static_cast<unsigned int>(EndTime - BeginTime));
|
std::printf("glm::bitfieldInterleave<u8vec2> Time %d clocks\n", static_cast<unsigned int>(EndTime - BeginTime));
|
||||||
|
|
||||||
return Error;
|
return Error;
|
||||||
}
|
}
|
||||||
@ -752,6 +772,60 @@ namespace bitfieldInterleave5
|
|||||||
return Error;
|
return Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int perf_old_u8vec4(std::vector<glm::uint32>& Result)
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
const std::clock_t BeginTime = std::clock();
|
||||||
|
|
||||||
|
for(glm::size_t k = 0; k < 10000; ++k)
|
||||||
|
for(glm::size_t j = 0; j < 256; ++j)
|
||||||
|
for(glm::size_t i = 0; i < 256; ++i)
|
||||||
|
Error += Result[j * 256 + i] == glm::bitfieldInterleave(glm::uint8(i), glm::uint8(j), glm::uint8(i), glm::uint8(j)) ? 0 : 1;
|
||||||
|
|
||||||
|
const std::clock_t EndTime = std::clock();
|
||||||
|
|
||||||
|
std::printf("glm::bitfieldInterleave<u8vec4> Time %d clocks\n", static_cast<unsigned int>(EndTime - BeginTime));
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int perf_new_u8vec4(std::vector<glm::uint32>& Result)
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
const std::clock_t BeginTime = std::clock();
|
||||||
|
|
||||||
|
for(glm::size_t k = 0; k < 10000; ++k)
|
||||||
|
for(glm::size_t j = 0; j < 256; ++j)
|
||||||
|
for(glm::size_t i = 0; i < 256; ++i)
|
||||||
|
Error += Result[j * 256 + i] == bitfieldInterleave_u8vec4(glm::uint8(i), glm::uint8(j), glm::uint8(i), glm::uint8(j)) ? 0 : 1;
|
||||||
|
|
||||||
|
const std::clock_t EndTime = std::clock();
|
||||||
|
|
||||||
|
std::printf("bitfieldInterleave_u8vec4 Time %d clocks\n", static_cast<unsigned int>(EndTime - BeginTime));
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int perf_old_u16vec2(std::vector<glm::uint32>& Result)
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
const std::clock_t BeginTime = std::clock();
|
||||||
|
|
||||||
|
for(glm::size_t k = 0; k < 10000; ++k)
|
||||||
|
for(glm::size_t j = 0; j < 256; ++j)
|
||||||
|
for(glm::size_t i = 0; i < 256; ++i)
|
||||||
|
Error += Result[j * 256 + i] == glm::bitfieldInterleave(glm::uint16(i), glm::uint16(j)) ? 0 : 1;
|
||||||
|
|
||||||
|
const std::clock_t EndTime = std::clock();
|
||||||
|
|
||||||
|
std::printf("glm::bitfieldInterleave<u16vec2> Time %d clocks\n", static_cast<unsigned int>(EndTime - BeginTime));
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
int perf_new_u16vec2(std::vector<glm::uint32>& Result)
|
int perf_new_u16vec2(std::vector<glm::uint32>& Result)
|
||||||
{
|
{
|
||||||
int Error = 0;
|
int Error = 0;
|
||||||
@ -784,11 +858,20 @@ namespace bitfieldInterleave5
|
|||||||
Error += perf_old_u8vec2(Result_u8vec2);
|
Error += perf_old_u8vec2(Result_u8vec2);
|
||||||
Error += perf_new_u8vec2(Result_u8vec2);
|
Error += perf_new_u8vec2(Result_u8vec2);
|
||||||
|
|
||||||
|
std::vector<glm::uint32> Result_u8vec4(256 * 256, 0);
|
||||||
|
for(glm::size_t j = 0; j < 256; ++j)
|
||||||
|
for(glm::size_t i = 0; i < 256; ++i)
|
||||||
|
Result_u8vec4[j * 256 + i] = glm::bitfieldInterleave(glm::uint8(i), glm::uint8(j), glm::uint8(i), glm::uint8(j));
|
||||||
|
|
||||||
|
Error += perf_old_u8vec4(Result_u8vec4);
|
||||||
|
Error += perf_new_u8vec4(Result_u8vec4);
|
||||||
|
|
||||||
std::vector<glm::uint32> Result_u16vec2(256 * 256, 0);
|
std::vector<glm::uint32> Result_u16vec2(256 * 256, 0);
|
||||||
for(glm::size_t j = 0; j < 256; ++j)
|
for(glm::size_t j = 0; j < 256; ++j)
|
||||||
for(glm::size_t i = 0; i < 256; ++i)
|
for(glm::size_t i = 0; i < 256; ++i)
|
||||||
Result_u16vec2[j * 256 + i] = glm::bitfieldInterleave(glm::uint16(i), glm::uint16(j));
|
Result_u16vec2[j * 256 + i] = glm::bitfieldInterleave(glm::uint16(i), glm::uint16(j));
|
||||||
|
|
||||||
|
Error += perf_old_u16vec2(Result_u16vec2);
|
||||||
Error += perf_new_u16vec2(Result_u16vec2);
|
Error += perf_new_u16vec2(Result_u16vec2);
|
||||||
|
|
||||||
std::printf("bitfieldInterleave perf: %d Errors\n", Error);
|
std::printf("bitfieldInterleave perf: %d Errors\n", Error);
|
||||||
|
Loading…
Reference in New Issue
Block a user