Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
benchmark
Project
Overview
Details
Activity
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
Chen Yisong
benchmark
Commits
74e82e82
Commit
74e82e82
authored
May 25, 2016
by
Albert Pretorius
Committed by
Albert Pretorius
May 26, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Force DoNotOptimize operand to memory for both gcc and clang
parent
a38f022b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
6 deletions
+45
-6
AUTHORS
AUTHORS
+1
-0
CONTRIBUTORS
CONTRIBUTORS
+1
-0
benchmark_api.h
include/benchmark/benchmark_api.h
+4
-6
CMakeLists.txt
test/CMakeLists.txt
+3
-0
donotoptimize_test.cc
test/donotoptimize_test.cc
+36
-0
No files found.
AUTHORS
View file @
74e82e82
...
...
@@ -8,6 +8,7 @@
#
# Please keep the list sorted.
Albert Pretorius <pretoalb@gmail.com>
Arne Beer <arne@twobeer.de>
Christopher Seymour <chris.j.seymour@hotmail.com>
David Coeurjolly <david.coeurjolly@liris.cnrs.fr>
...
...
CONTRIBUTORS
View file @
74e82e82
...
...
@@ -22,6 +22,7 @@
#
# Please keep the list sorted.
Albert Pretorius <pretoalb@gmail.com>
Arne Beer <arne@twobeer.de>
Billy Robert O'Neal III <billy.oneal@gmail.com> <bion@microsoft.com>
Chris Kennelly <ckennelly@google.com> <ckennelly@ckennelly.com>
...
...
include/benchmark/benchmark_api.h
View file @
74e82e82
...
...
@@ -210,20 +210,18 @@ Benchmark* RegisterBenchmarkInternal(Benchmark*);
// expression from being optimized away by the compiler. This function is
// intented to add little to no overhead.
// See: http://stackoverflow.com/questions/28287064
#if defined(__
clang__) && defined(__
GNUC__)
#if defined(__GNUC__)
// TODO(ericwf): Clang has a bug where it tries to always use a register
// even if value must be stored in memory. This causes codegen to fail.
// To work around this we remove the "r" modifier so the operand is always
// loaded into memory.
// GCC also has a bug where it complains about inconsistent operand constraints
// when "+rm" is used for a type larger than can fit in a register or two.
// For now force the operand to memory for both GCC and Clang.
template
<
class
Tp
>
inline
BENCHMARK_ALWAYS_INLINE
void
DoNotOptimize
(
Tp
const
&
value
)
{
asm
volatile
(
""
:
"+m"
(
const_cast
<
Tp
&>
(
value
)));
}
#elif defined(__GNUC__)
template
<
class
Tp
>
inline
BENCHMARK_ALWAYS_INLINE
void
DoNotOptimize
(
Tp
const
&
value
)
{
asm
volatile
(
""
:
"+rm"
(
const_cast
<
Tp
&>
(
value
)));
}
#else
template
<
class
Tp
>
inline
BENCHMARK_ALWAYS_INLINE
void
DoNotOptimize
(
Tp
const
&
value
)
{
...
...
test/CMakeLists.txt
View file @
74e82e82
...
...
@@ -39,6 +39,9 @@ add_test(diagnostics_test diagnostics_test --benchmark_min_time=0.01)
compile_benchmark_test
(
skip_with_error_test
)
add_test
(
skip_with_error_test skip_with_error_test --benchmark_min_time=0.01
)
compile_benchmark_test
(
donotoptimize_test
)
add_test
(
donotoptimize_test donotoptimize_test --benchmark_min_time=0.01
)
compile_benchmark_test
(
fixture_test
)
add_test
(
fixture_test fixture_test --benchmark_min_time=0.01
)
...
...
test/donotoptimize_test.cc
0 → 100644
View file @
74e82e82
#include "benchmark/benchmark.h"
#include <cstdint>
namespace
{
#if defined(__GNUC__)
std
::
uint64_t
double_up
(
const
std
::
uint64_t
x
)
__attribute__
((
const
));
#endif
std
::
uint64_t
double_up
(
const
std
::
uint64_t
x
)
{
return
x
*
2
;
}
}
int
main
(
int
,
char
*
[])
{
// this test verifies compilation of DoNotOptimize() for some types
char
buffer8
[
8
];
benchmark
::
DoNotOptimize
(
buffer8
);
char
buffer20
[
20
];
benchmark
::
DoNotOptimize
(
buffer20
);
char
buffer1024
[
1024
];
benchmark
::
DoNotOptimize
(
buffer1024
);
benchmark
::
DoNotOptimize
(
&
buffer1024
[
0
]);
int
x
=
123
;
benchmark
::
DoNotOptimize
(
x
);
benchmark
::
DoNotOptimize
(
&
x
);
benchmark
::
DoNotOptimize
(
x
+=
42
);
benchmark
::
DoNotOptimize
(
double_up
(
x
));
return
0
;
}
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