Commit 3605cead authored by joreland@mysql.com's avatar joreland@mysql.com

ndb - bit field

  micro optimization
parent b883f8fd
...@@ -24,16 +24,16 @@ BitmaskImpl::getFieldImpl(const Uint32 src[], ...@@ -24,16 +24,16 @@ BitmaskImpl::getFieldImpl(const Uint32 src[],
assert(shiftL < 32); assert(shiftL < 32);
unsigned shiftR = 32 - shiftL; unsigned shiftR = 32 - shiftL;
unsigned undefined = shiftL ? ~0 : 0;
while(len >= 32) while(len >= 32)
{ {
* dst++ |= (* src) << shiftL; * dst++ |= (* src) << shiftL;
* dst = shiftL ? (* src) >> shiftR : 0; * dst = ((* src++) >> shiftR) & undefined;
src++;
len -= 32; len -= 32;
} }
* dst++ |= (* src) << shiftL; * dst++ |= (* src) << shiftL;
* dst = shiftL ? ((* src) >> shiftR) & ((1 << len) - 1) : 0; * dst = ((* src) >> shiftR) & ((1 << len) - 1) & undefined;
} }
void void
...@@ -47,18 +47,18 @@ BitmaskImpl::setFieldImpl(Uint32 dst[], ...@@ -47,18 +47,18 @@ BitmaskImpl::setFieldImpl(Uint32 dst[],
*/ */
assert(shiftL < 32); assert(shiftL < 32);
unsigned shiftR = 32 - shiftL; unsigned shiftR = 32 - shiftL;
unsigned undefined = shiftL ? ~0 : 0;
while(len >= 32) while(len >= 32)
{ {
* dst = (* src++) >> shiftL; * dst = (* src++) >> shiftL;
* dst++ |= shiftL ? (* src) << shiftR : 0; * dst++ |= ((* src) << shiftR) & undefined;
len -= 32; len -= 32;
} }
Uint32 mask = ((1 << len) -1); Uint32 mask = ((1 << len) -1);
* dst = (* dst & ~mask); * dst = (* dst & ~mask);
* dst |= ((* src++) >> shiftL) & mask; * dst |= ((* src++) >> shiftL) & mask;
* dst |= shiftL ? ((* src) << shiftR) & mask : 0; * dst |= ((* src) << shiftR) & mask & undefined;
} }
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment