Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
4d27cab1
Commit
4d27cab1
authored
Dec 08, 2004
by
joreland@mysql.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ndb - Fix arbitrary sized bitfields
parent
9a937a3b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
39 deletions
+52
-39
ndb/src/common/util/Bitmask.cpp
ndb/src/common/util/Bitmask.cpp
+52
-39
No files found.
ndb/src/common/util/Bitmask.cpp
View file @
4d27cab1
...
...
@@ -11,7 +11,7 @@ void print(const Uint32 src[], Uint32 len, Uint32 pos = 0)
printf
(
"1"
);
else
printf
(
"0"
);
if
((
i
&
7
)
==
7
)
if
((
i
&
31
)
==
31
)
printf
(
" "
);
}
}
...
...
@@ -19,42 +19,46 @@ void print(const Uint32 src[], Uint32 len, Uint32 pos = 0)
#ifndef __TEST_BITMASK__
void
BitmaskImpl
::
getFieldImpl
(
const
Uint32
src
[],
unsigned
shift
,
unsigned
len
,
Uint32
dst
[])
unsigned
shift
L
,
unsigned
len
,
Uint32
dst
[])
{
assert
(
shift
<
32
);
if
(
len
<=
(
32
-
shift
))
{
*
dst
++
|=
((
*
src
)
&
((
1
<<
len
)
-
1
))
<<
shift
;
}
else
assert
(
shiftL
<
32
);
unsigned
shiftR
=
32
-
shiftL
;
while
(
len
>=
32
)
{
abort
();
while
(
len
>
32
)
{
*
dst
++
|=
(
*
src
)
<<
shift
;
*
dst
=
(
*
src
++
)
>>
(
32
-
shift
);
len
-=
32
;
}
*
dst
++
|=
(
*
src
)
<<
shiftL
;
*
dst
=
shiftL
?
(
*
src
)
>>
shiftR
:
0
;
src
++
;
len
-=
32
;
}
*
dst
++
|=
(
*
src
)
<<
shiftL
;
*
dst
=
shiftL
?
((
*
src
)
>>
shiftR
)
&
((
1
<<
len
)
-
1
)
:
0
;
}
void
BitmaskImpl
::
setFieldImpl
(
Uint32
dst
[],
unsigned
shift
,
unsigned
len
,
const
Uint32
src
[])
unsigned
shift
L
,
unsigned
len
,
const
Uint32
src
[])
{
assert
(
shift
<
32
);
/**
*
* abcd ef00
* 00ab cdef
*/
assert
(
shiftL
<
32
);
unsigned
shiftR
=
32
-
shiftL
;
Uint32
mask
;
if
(
len
<
(
32
-
shift
))
{
mask
=
(
1
<<
len
)
-
1
;
*
dst
=
(
*
dst
&
~
mask
)
|
(((
*
src
++
)
>>
shift
)
&
mask
);
}
else
while
(
len
>=
32
)
{
abort
();
*
dst
=
(
*
src
++
)
>>
shiftL
;
*
dst
++
|=
shiftL
?
(
*
src
)
<<
shiftR
:
0
;
len
-=
32
;
}
Uint32
mask
=
((
1
<<
len
)
-
1
);
*
dst
=
(
*
dst
&
~
mask
);
*
dst
|=
((
*
src
++
)
>>
shiftL
)
&
mask
;
*
dst
|=
shiftL
?
((
*
src
)
<<
shiftR
)
&
mask
:
0
;
}
#else
...
...
@@ -86,6 +90,19 @@ static void require(bool b)
if
(
!
b
)
abort
();
}
static
bool
cmp
(
const
Uint32
b1
[],
const
Uint32
b2
[],
Uint32
len
)
{
Uint32
sz32
=
(
len
+
31
)
>>
5
;
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
if
(
BitmaskImpl
::
get
(
sz32
,
b1
,
i
)
^
BitmaskImpl
::
get
(
sz32
,
b2
,
i
))
return
false
;
}
return
true
;
}
static
int
val_pos
=
0
;
static
int
val
[]
=
{
384
,
241
,
32
,
1
,
1
,
1
,
1
,
0
,
0
,
0
,
0
,
1
,
1
,
1
,
1
,
0
,
0
,
0
,
0
,
...
...
@@ -128,21 +145,21 @@ void simple(int pos, int size)
memset
(
src
,
0x0
,
sz
);
memset
(
dst
,
0x0
,
sz
);
memset
(
mask
,
0x
0
,
sz
);
memset
(
mask
,
0x
FF
,
sz
);
rand
(
src
,
size
);
BitmaskImpl
::
setField
(
sz32
,
mask
,
pos
,
size
,
src
);
BitmaskImpl
::
getField
(
sz32
,
mask
,
pos
,
size
,
dst
);
printf
(
"src: "
);
print
(
src
,
size
);
printf
(
"
\n
"
);
printf
(
"msk: "
);
print
(
mask
,
s
ize
,
pos
);
printf
(
"
\n
"
);
printf
(
"msk: "
);
print
(
mask
,
s
z32
<<
5
);
printf
(
"
\n
"
);
printf
(
"dst: "
);
print
(
dst
,
size
);
printf
(
"
\n
"
);
require
(
memcmp
(
src
,
dst
,
sz
)
==
0
);
require
(
cmp
(
src
,
dst
,
size
)
);
};
static
void
do_test
(
int
bitmask_size
)
{
#if 0
simple(rand() % 33, (rand() %
31
)+1);
simple(rand() % 33, (rand() %
63
)+1);
#else
Vector
<
Alloc
>
alloc_list
;
bitmask_size
=
(
bitmask_size
+
31
)
&
~
31
;
...
...
@@ -186,10 +203,9 @@ do_test(int bitmask_size)
{
printf
(
"freeing [ %d %d ]"
,
min
,
max
);
printf
(
"- mask: "
);
for
(
size_t
k
=
0
;
k
<
(((
max
-
min
)
+
31
)
>>
5
);
k
++
)
printf
(
"%.8x "
,
tmp
.
getBase
()[
k
]);
printf
(
"save: "
);
print
(
tmp
.
getBase
(),
max
-
min
);
printf
(
" save: "
);
size_t
k
;
Alloc
&
a
=
alloc_list
[
j
];
for
(
k
=
0
;
k
<
a
.
data
.
size
();
k
++
)
...
...
@@ -197,7 +213,7 @@ do_test(int bitmask_size)
printf
(
"
\n
"
);
}
int
bytes
=
(
max
-
min
+
7
)
>>
3
;
if
(
memcmp
(
tmp
.
getBase
(),
alloc_list
[
j
].
data
.
getBase
(),
bytes
)
!=
0
)
if
(
!
cmp
(
tmp
.
getBase
(),
alloc_list
[
j
].
data
.
getBase
(),
max
-
min
)
)
{
abort
();
}
...
...
@@ -221,7 +237,6 @@ do_test(int bitmask_size)
Uint32
sz
=
(
lrand
()
%
free
);
sz
=
sz
?
sz
:
1
;
sz
=
(
sz
>
31
)
?
31
:
sz
;
Alloc
a
;
a
.
pos
=
pos
;
a
.
size
=
sz
;
...
...
@@ -237,9 +252,7 @@ do_test(int bitmask_size)
if
(
DEBUG
)
{
printf
(
"- mask: "
);
size_t
k
;
for
(
k
=
0
;
k
<
a
.
data
.
size
();
k
++
)
printf
(
"%.8x "
,
a
.
data
[
k
]);
print
(
a
.
data
.
getBase
(),
sz
);
printf
(
"
\n
"
);
}
BitmaskImpl
::
setField
(
sz32
,
test_mask
.
getBase
(),
pos
,
sz
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment