Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wasm-watermarker
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nagayama15
wasm-watermarker
Commits
6b4e0316
Commit
6b4e0316
authored
Jul 26, 2019
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve computational complexity of the function ordering method
parent
1fd7d8a7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
29 deletions
+14
-29
FunctionOrderingWatermarker.cpp
src/kyut/watermarker/FunctionOrderingWatermarker.cpp
+12
-27
test_FunctionOrderingWatermarker.cpp
test/kyut/watermarker/test_FunctionOrderingWatermarker.cpp
+2
-2
No files found.
src/kyut/watermarker/FunctionOrderingWatermarker.cpp
View file @
6b4e0316
...
@@ -14,26 +14,6 @@ namespace kyut::watermarker {
...
@@ -14,26 +14,6 @@ namespace kyut::watermarker {
constexpr
auto
factorialBitLengthTable
=
std
::
array
<
std
::
size_t
,
21
>
{
constexpr
auto
factorialBitLengthTable
=
std
::
array
<
std
::
size_t
,
21
>
{
0
,
0
,
1
,
2
,
4
,
6
,
9
,
12
,
15
,
18
,
21
,
25
,
28
,
32
,
36
,
40
,
44
,
48
,
52
,
56
,
61
,
0
,
0
,
1
,
2
,
4
,
6
,
9
,
12
,
15
,
18
,
21
,
25
,
28
,
32
,
36
,
40
,
44
,
48
,
52
,
56
,
61
,
};
};
/**
* @brief Move the `element` in [begin, end) to the beginning of the range.
* The order of elements other than `element` is maintained.
*
* @tparam BidirectionalIterator Bidirectional iterator type.
* @param begin Bidirectional iterator to the initial position in a sequence.
* @param end Bidirectional iterator to the final position in a sequence.
* @param element Bidirectional iterator to the element to be moved.
* `element` must be in the range of [begin, end).
*/
template
<
typename
BidirectionalIterator
>
void
moveToFront
(
BidirectionalIterator
begin
,
BidirectionalIterator
end
,
BidirectionalIterator
element
)
{
assert
(
std
::
distance
(
begin
,
element
)
>=
0
);
assert
(
std
::
distance
(
begin
,
element
)
<
std
::
distance
(
begin
,
end
));
auto
tmp
=
std
::
move
(
*
element
);
std
::
move_backward
(
begin
,
element
,
std
::
next
(
element
));
*
begin
=
std
::
move
(
tmp
);
}
}
// namespace
}
// namespace
std
::
size_t
embedFunctionOrdering
(
wasm
::
Module
&
module
,
CircularBitStreamReader
&
stream
,
std
::
size_t
maxChunkSize
)
{
std
::
size_t
embedFunctionOrdering
(
wasm
::
Module
&
module
,
CircularBitStreamReader
&
stream
,
std
::
size_t
maxChunkSize
)
{
...
@@ -69,7 +49,7 @@ namespace kyut::watermarker {
...
@@ -69,7 +49,7 @@ namespace kyut::watermarker {
const
auto
n
=
watermark
%
distance
;
const
auto
n
=
watermark
%
distance
;
watermark
/=
distance
;
watermark
/=
distance
;
moveToFront
(
it
,
chunkEnd
,
it
+
n
);
std
::
swap
(
*
it
,
*
(
it
+
n
)
);
}
}
numBits
+=
numBitsEmbeddedInChunk
;
numBits
+=
numBitsEmbeddedInChunk
;
...
@@ -112,19 +92,24 @@ namespace kyut::watermarker {
...
@@ -112,19 +92,24 @@ namespace kyut::watermarker {
std
::
uint64_t
watermark
=
0
;
std
::
uint64_t
watermark
=
0
;
std
::
uint64_t
base
=
1
;
std
::
uint64_t
base
=
1
;
auto
funcBegin
=
std
::
begin
(
functions
);
const
auto
funcEnd
=
std
::
end
(
functions
);
for
(
auto
it
=
chunkBegin
;
it
!=
chunkEnd
;
++
it
)
{
for
(
auto
it
=
chunkBegin
;
it
!=
chunkEnd
;
++
it
)
{
assert
(
std
::
distance
(
it
,
chunkEnd
)
==
std
::
distance
(
funcBegin
,
funcEnd
));
// Get index of the function `*it`
// Get index of the function `*it`
const
auto
pos
=
std
::
find_if
(
const
auto
pos
=
std
::
find_if
(
funcBegin
,
funcEnd
,
[
it
](
const
auto
&
f
)
{
return
f
==
it
->
get
();
});
std
::
begin
(
functions
),
std
::
end
(
functions
),
[
it
](
const
auto
&
f
)
{
return
f
==
it
->
get
();
});
assert
(
pos
!=
funcEnd
);
assert
(
pos
!=
std
::
end
(
functions
));
const
std
::
size_t
index
=
std
::
distance
(
std
::
begin
(
functions
)
,
pos
);
const
std
::
size_t
index
=
std
::
distance
(
funcBegin
,
pos
);
watermark
+=
index
*
base
;
watermark
+=
index
*
base
;
base
*=
functions
.
size
(
);
base
*=
std
::
distance
(
funcBegin
,
funcEnd
);
// Remove the function found in this step
// Remove the function found in this step
functions
.
erase
(
pos
);
std
::
swap
(
*
funcBegin
,
*
pos
);
++
funcBegin
;
}
}
stream
.
write
(
watermark
,
numBitsEmbeddedInChunk
);
stream
.
write
(
watermark
,
numBitsEmbeddedInChunk
);
...
...
test/kyut/watermarker/test_FunctionOrderingWatermarker.cpp
View file @
6b4e0316
...
@@ -67,8 +67,8 @@ BOOST_AUTO_TEST_CASE(embed_function_ordering) {
...
@@ -67,8 +67,8 @@ BOOST_AUTO_TEST_CASE(embed_function_ordering) {
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
1
]
->
name
,
"g2"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
1
]
->
name
,
"g2"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
2
]
->
name
,
"g3"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
2
]
->
name
,
"g3"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
3
]
->
name
,
"f3"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
3
]
->
name
,
"f3"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
4
]
->
name
,
"f
1
"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
4
]
->
name
,
"f
2
"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
5
]
->
name
,
"f
2
"
);
BOOST_REQUIRE_EQUAL
(
module
.
functions
[
5
]
->
name
,
"f
1
"
);
}
}
// Embed 0b11
// Embed 0b11
...
...
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