Fixed bitfieldInsert and bitfieldExtract

This commit is contained in:
Christophe Riccio 2014-11-12 22:48:15 +01:00
parent debe75a6e1
commit 062ee19ac7
4 changed files with 23 additions and 18 deletions

View File

@ -44,7 +44,7 @@ namespace detail
{ {
GLM_FUNC_QUALIFIER int mask(int Bits) GLM_FUNC_QUALIFIER int mask(int Bits)
{ {
return ~((~0) << Bits); return Bits >= 32 ? 0xffffffff : (static_cast<int>(1) << Bits) - static_cast<int>(1);
} }
}//namespace detail }//namespace detail

View File

@ -866,7 +866,7 @@ namespace sign
{ {
int Error = 0; int Error = 0;
std::size_t const Count = 1000000000; std::size_t const Count = 10000000;
std::vector<glm::int32> Input, Output; std::vector<glm::int32> Input, Output;
Input.resize(Count); Input.resize(Count);
Output.resize(Count); Output.resize(Count);
@ -913,7 +913,7 @@ namespace sign
{ {
int Error = 0; int Error = 0;
std::size_t const Count = 1000000000; std::size_t const Count = 10000000;
std::vector<glm::int32> Input, Output; std::vector<glm::int32> Input, Output;
Input.resize(Count); Input.resize(Count);
Output.resize(Count); Output.resize(Count);
@ -960,7 +960,7 @@ namespace sign
{ {
int Error = 0; int Error = 0;
glm::uint32 const Count = 1000000000; glm::uint32 const Count = 10000000;
std::clock_t Timestamp0 = std::clock(); std::clock_t Timestamp0 = std::clock();
glm::int32 Sum = 0; glm::int32 Sum = 0;

View File

@ -37,11 +37,12 @@ namespace bitfieldInsert
typeU32 const Data32[] = typeU32 const Data32[] =
{ {
{0x00000000, 0xffffffff, 0, 31, 0x7fffffff},
{0x00000000, 0xffffffff, 0, 32, 0xffffffff},
{0x00000000, 0xffffffff, 0, 0, 0x00000000},
{0xff000000, 0x0000ff00, 8, 8, 0xff00ff00}, {0xff000000, 0x0000ff00, 8, 8, 0xff00ff00},
{0xffff0000, 0x0000ffff, 16, 16, 0x00000000}, {0xffff0000, 0x0000ffff, 16, 16, 0x00000000},
{0x0000ffff, 0xffff0000, 16, 16, 0xffffffff}, {0x0000ffff, 0xffff0000, 16, 16, 0xffffffff}
{0x00000000, 0xffffffff, 0, 32, 0xffffffff},
{0x00000000, 0xffffffff, 0, 0, 0x00000000}
}; };
int test() int test()
@ -342,7 +343,7 @@ namespace findMSB
std::clock_t Timestamps1 = std::clock(); std::clock_t Timestamps1 = std::clock();
for(std::size_t k = 0; k < 10000000; ++k) for(std::size_t k = 0; k < 1000000; ++k)
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i) for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i)
{ {
int Result = findMSB_095(Data[i].Value); int Result = findMSB_095(Data[i].Value);
@ -401,7 +402,7 @@ namespace findMSB
std::clock_t Timestamps1 = std::clock(); std::clock_t Timestamps1 = std::clock();
for(std::size_t k = 0; k < 10000000; ++k) for(std::size_t k = 0; k < 1000000; ++k)
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i) for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i)
{ {
int Result = findMSB_nlz1(Data[i].Value); int Result = findMSB_nlz1(Data[i].Value);
@ -536,7 +537,7 @@ namespace findMSB
int Error(0); int Error(0);
Error += perf_950(); Error += perf_950();
Error += perf_ops(); //Error += perf_ops();
return Error; return Error;
} }

View File

@ -106,7 +106,9 @@ namespace mask
{ 0, 0x00000000}, { 0, 0x00000000},
{ 1, 0x00000001}, { 1, 0x00000001},
{ 2, 0x00000003}, { 2, 0x00000003},
{3, 0x00000007} { 3, 0x00000007},
{31, 0x7fffffff},
{32, 0xffffffff}
}; };
int Error(0); int Error(0);
@ -145,7 +147,9 @@ namespace mask
{glm::ivec4( 0), glm::ivec4(0x00000000)}, {glm::ivec4( 0), glm::ivec4(0x00000000)},
{glm::ivec4( 1), glm::ivec4(0x00000001)}, {glm::ivec4( 1), glm::ivec4(0x00000001)},
{glm::ivec4( 2), glm::ivec4(0x00000003)}, {glm::ivec4( 2), glm::ivec4(0x00000003)},
{glm::ivec4(3), glm::ivec4(0x00000007)} {glm::ivec4( 3), glm::ivec4(0x00000007)},
{glm::ivec4(31), glm::ivec4(0x7fffffff)},
{glm::ivec4(32), glm::ivec4(0xffffffff)}
}; };
int Error(0); int Error(0);