Commit 9a71f575 authored by unknown's avatar unknown

ndb - Use BitmaskImpl in TUP (in BitField operations)


ndb/include/util/Bitmask.hpp:
  New methods for working with bit fields of
    arbitrary size
ndb/src/kernel/blocks/dbtup/DbtupRoutines.cpp:
  Use BitmaskImpl at all time (in BitField operations)
parent 6f1c6017
...@@ -131,6 +131,19 @@ public: ...@@ -131,6 +131,19 @@ public:
static void setField(unsigned size, Uint32 data[], static void setField(unsigned size, Uint32 data[],
unsigned pos, unsigned len, Uint32 val); unsigned pos, unsigned len, Uint32 val);
/**
* getField - Get bitfield at given position and length
*/
static void getField(unsigned size, const Uint32 data[],
unsigned pos, unsigned len, Uint32 dst[]);
/**
* setField - Set bitfield at given position and length
*/
static void setField(unsigned size, Uint32 data[],
unsigned pos, unsigned len, const Uint32 src[]);
/** /**
* getText - Return as hex-digits (only for debug routines). * getText - Return as hex-digits (only for debug routines).
*/ */
...@@ -794,4 +807,38 @@ public: ...@@ -794,4 +807,38 @@ public:
Bitmask() { this->clear();} Bitmask() { this->clear();}
}; };
inline void
BitmaskImpl::getField(unsigned size, const Uint32 data[],
unsigned pos, unsigned len, Uint32 dst[])
{
assert(len > 0);
assert(pos + len < (size << 5));
Uint32 word = pos >> 5;
Uint32 offset = pos & 31;
if(offset + len <= 32)
{
dst[0] = (data[word] >> offset) & ((1 << len) - 1);
return;
}
abort();
}
inline void
BitmaskImpl::setField(unsigned size, Uint32 data[],
unsigned pos, unsigned len, const Uint32 src[])
{
assert(len > 0);
assert(pos + len < (size << 5));
Uint32 word = pos >> 5;
Uint32 offset = pos & 31;
if(offset + len <= 32)
{
Uint32 mask = ((1 << len) - 1) << offset;
data[word] = (data[word] & ~mask) | ((src[0] << offset) & mask);
return;
}
abort();
}
#endif #endif
...@@ -1028,22 +1028,22 @@ Dbtup::readBitsNotNULL(Uint32* outBuffer, ...@@ -1028,22 +1028,22 @@ Dbtup::readBitsNotNULL(Uint32* outBuffer,
offsetInTuple += regTabPtr->tupNullIndex; offsetInTuple += regTabPtr->tupNullIndex;
ndbrequire(offsetInTuple < tCheckOffset); ndbrequire(offsetInTuple < tCheckOffset);
Uint32 pos = offsetInTuple << 5 + offsetInWord;
Uint32 indexBuf = tOutBufIndex; Uint32 indexBuf = tOutBufIndex;
Uint32 newIndexBuf = indexBuf + ((bitCount + 31) >> 5); Uint32 newIndexBuf = indexBuf + ((bitCount + 31) >> 5);
Uint32 maxRead = tMaxRead; Uint32 maxRead = tMaxRead;
outBuffer[indexBuf] =
(tTupleHeader[offsetInTuple] >> offsetInWord) & ((1 << bitCount) - 1);
if(offsetInWord + bitCount > 32)
{
ndbrequire(false);
}
if (newIndexBuf <= maxRead) { if (newIndexBuf <= maxRead) {
ljam(); ljam();
ahOut->setDataSize((bitCount + 31) >> 5); ahOut->setDataSize((bitCount + 31) >> 5);
tOutBufIndex = newIndexBuf; tOutBufIndex = newIndexBuf;
BitmaskImpl::getField(regTabPtr->tupNullWords,
tTupleHeader+regTabPtr->tupNullIndex,
pos,
bitCount,
outBuffer+indexBuf);
return true; return true;
} else { } else {
ljam(); ljam();
...@@ -1069,34 +1069,27 @@ Dbtup::readBitsNULLable(Uint32* outBuffer, ...@@ -1069,34 +1069,27 @@ Dbtup::readBitsNULLable(Uint32* outBuffer,
Uint32 indexBuf = tOutBufIndex; Uint32 indexBuf = tOutBufIndex;
Uint32 newIndexBuf = indexBuf + (bitCount + 31) >> 5; Uint32 newIndexBuf = indexBuf + (bitCount + 31) >> 5;
Uint32 maxRead = tMaxRead; Uint32 maxRead = tMaxRead;
Uint32 pos = offsetInWord << 5 + offsetInTuple;
if((tTupleHeader[offsetInTuple] >> offsetInWord) & 1) if(BitmaskImpl::get(regTabPtr->tupNullWords,
tTupleHeader+regTabPtr->tupNullIndex,
pos))
{ {
ljam(); ljam();
ahOut->setNULL(); ahOut->setNULL();
return true; return true;
} }
offsetInWord ++;
if(offsetInWord == 32)
{
ljam();
offsetInWord = 0;
offsetInTuple++;
}
outBuffer[indexBuf] =
(tTupleHeader[offsetInTuple] >> offsetInWord) & ((1 << bitCount) - 1);
if(offsetInWord + bitCount > 32)
{
ndbrequire(false);
}
if (newIndexBuf <= maxRead) { if (newIndexBuf <= maxRead) {
ljam(); ljam();
ahOut->setDataSize((bitCount + 31) >> 5); ahOut->setDataSize((bitCount + 31) >> 5);
tOutBufIndex = newIndexBuf; tOutBufIndex = newIndexBuf;
BitmaskImpl::getField(regTabPtr->tupNullWords,
tTupleHeader+regTabPtr->tupNullIndex,
pos+1,
bitCount,
outBuffer+indexBuf);
return true; return true;
} else { } else {
ljam(); ljam();
...@@ -1123,24 +1116,16 @@ Dbtup::updateBitsNotNULL(Uint32* inBuffer, ...@@ -1123,24 +1116,16 @@ Dbtup::updateBitsNotNULL(Uint32* inBuffer,
ndbrequire((nullFlagOffset < regTabPtr->tupNullWords) && ndbrequire((nullFlagOffset < regTabPtr->tupNullWords) &&
(nullWordOffset < tCheckOffset)); (nullWordOffset < tCheckOffset));
Uint32 nullBits = tTupleHeader[nullWordOffset]; Uint32 nullBits = tTupleHeader[nullWordOffset];
Uint32 pos = (nullFlagOffset << 5) + nullFlagBitOffset;
if (newIndex <= inBufLen) { if (newIndex <= inBufLen) {
Uint32 updateWord = inBuffer[indexBuf + 1];
if (!nullIndicator) { if (!nullIndicator) {
BitmaskImpl::setField(regTabPtr->tupNullWords,
tTupleHeader+regTabPtr->tupNullIndex,
pos,
bitCount,
inBuffer+indexBuf+1);
tInBufIndex = newIndex; tInBufIndex = newIndex;
Uint32 mask = ((1 << bitCount) - 1) << nullFlagBitOffset;
if(nullFlagBitOffset + bitCount <= 32)
{
ljam();
tTupleHeader[nullWordOffset] =
(nullBits & ~mask) |
((updateWord << nullFlagBitOffset) & mask);
return true;
}
else
{
abort();
}
return true; return true;
} else { } else {
ljam(); ljam();
...@@ -1171,41 +1156,29 @@ Dbtup::updateBitsNULLable(Uint32* inBuffer, ...@@ -1171,41 +1156,29 @@ Dbtup::updateBitsNULLable(Uint32* inBuffer,
(nullWordOffset < tCheckOffset)); (nullWordOffset < tCheckOffset));
Uint32 nullBits = tTupleHeader[nullWordOffset]; Uint32 nullBits = tTupleHeader[nullWordOffset];
Uint32 bitCount = AttributeDescriptor::getArraySize(attrDescriptor); Uint32 bitCount = AttributeDescriptor::getArraySize(attrDescriptor);
Uint32 pos = (nullFlagOffset << 5) + nullFlagBitOffset;
if (!nullIndicator) { if (!nullIndicator) {
Uint32 newIndex = indexBuf + 1 + ((bitCount + 31) >> 5); BitmaskImpl::clear(regTabPtr->tupNullWords,
nullBits &= (~(1 << nullFlagBitOffset)); tTupleHeader+regTabPtr->tupNullIndex,
ljam(); pos);
tTupleHeader[nullWordOffset] = nullBits; BitmaskImpl::setField(regTabPtr->tupNullWords,
tTupleHeader+regTabPtr->tupNullIndex,
nullFlagBitOffset++; pos+1,
if(nullFlagBitOffset == 32) bitCount,
{ inBuffer+indexBuf+1);
ljam();
nullFlagBitOffset = 0;
nullWordOffset++;
nullBits = tTupleHeader[nullWordOffset];
}
Uint32 updateWord = inBuffer[indexBuf + 1]; Uint32 newIndex = indexBuf + 1 + ((bitCount + 31) >> 5);
Uint32 mask = ((1 << bitCount) - 1) << nullFlagBitOffset;
tInBufLen = newIndex; tInBufLen = newIndex;
if(nullFlagBitOffset + bitCount <= 32)
{
ljam();
tTupleHeader[nullWordOffset] =
(nullBits & ~mask) |
((updateWord << nullFlagBitOffset) & mask);
return true; return true;
}
abort();
} else { } else {
Uint32 newIndex = tInBufIndex + 1; Uint32 newIndex = tInBufIndex + 1;
if (newIndex <= tInBufLen) { if (newIndex <= tInBufLen) {
nullBits |= (1 << nullFlagBitOffset);
ljam(); ljam();
tTupleHeader[nullWordOffset] = nullBits; BitmaskImpl::set(regTabPtr->tupNullWords,
tTupleHeader+regTabPtr->tupNullIndex,
pos);
tInBufIndex = newIndex; tInBufIndex = newIndex;
return true; return true;
} 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