1
/* Copyright (C) 2004-2005 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
#include <Bitmask.hpp>
20
BitmaskImpl::getFieldImpl(const Uint32 src[],
21
unsigned shiftL, unsigned len, Uint32 dst[])
23
/* Copy whole words of src to dst, shifting src left
24
* by shiftL. Undefined bits of the last written dst word
29
unsigned shiftR = 32 - shiftL;
30
unsigned undefined = shiftL ? ~0 : 0;
32
/* Merge first word with previously set bits if there's a shift */
33
* dst = shiftL ? * dst : 0;
35
/* Treat the zero-shift case separately to avoid
36
* trampling or reading past the end of src
48
/* Last word has some bits set */
49
Uint32 mask= ((1 << len) -1); // 0000111
50
* dst = (* src) & mask;
53
else // shiftL !=0, need to build each word from two words shifted
57
* dst++ |= (* src) << shiftL;
58
* dst = ((* src++) >> shiftR) & undefined;
62
/* Have space for shiftR more bits in the current dst word
67
/* Fit the remaining bits in the current dst word */
68
* dst |= ((* src) & ((1 << len) - 1)) << shiftL;
72
/* Need to write to two dst words */
73
* dst++ |= ((* src) << shiftL);
74
* dst = ((* src) >> shiftR) & ((1 << (len - shiftR)) - 1) & undefined;
80
BitmaskImpl::setFieldImpl(Uint32 dst[],
81
unsigned shiftL, unsigned len, const Uint32 src[])
89
unsigned shiftR = 32 - shiftL;
90
unsigned undefined = shiftL ? ~0 : 0;
93
* dst = (* src++) >> shiftL;
94
* dst++ |= ((* src) << shiftR) & undefined;
99
Uint32 mask = ((1 << len) -1);
100
* dst = (* dst & ~mask);
103
/* Remaining bits fit in current word */
104
* dst |= ((* src++) >> shiftL) & mask;
108
/* Remaining bits update 2 words */
109
* dst |= ((* src++) >> shiftL);
110
* dst |= ((* src) & ((1 << (len - shiftR)) - 1)) << shiftR ;
114
/* Bitmask testcase code moved from here to
115
* storage/ndb/test/ndbapi/testBitfield.cpp
116
* to get coverage from automated testing