No need to compute valBit until mask bit is 1.

llvm-svn: 210084
This commit is contained in:
Rui Ueyama 2014-06-03 07:39:32 +00:00
parent 6c3bbf4271
commit 9ef8a9c94b
1 changed files with 6 additions and 6 deletions

View File

@ -21,10 +21,10 @@ template <typename T> T gatherBits(T val, T mask) {
T result = 0;
size_t off = 0;
for (size_t bit = 0; bit != sizeof(T) * 8; ++bit) {
const bool valBit = (val >> bit) & 1;
const bool maskBit = (mask >> bit) & 1;
for (size_t bit = 0; bit < sizeof(T) * 8; ++bit) {
bool maskBit = (mask >> bit) & 1;
if (maskBit) {
bool valBit = (val >> bit) & 1;
result |= static_cast<T>(valBit) << off;
++off;
}
@ -41,10 +41,10 @@ template <typename T> T scatterBits(T val, T mask) {
T result = 0;
size_t off = 0;
for (size_t bit = 0; bit != sizeof(T) * 8; ++bit) {
const bool valBit = (val >> off) & 1;
const bool maskBit = (mask >> bit) & 1;
for (size_t bit = 0; bit < sizeof(T) * 8; ++bit) {
bool maskBit = (mask >> bit) & 1;
if (maskBit) {
bool valBit = (val >> off) & 1;
result |= static_cast<T>(valBit) << bit;
++off;
}