cb66c5d68e
bazel / bazel.ubuntu-latest (push) Failing after 1s
build-and-test-perfcounters / ubuntu-latest.Debug (push) Failing after 0s
build-and-test-perfcounters / ubuntu-latest.Release (push) Failing after 1s
doxygen / Build HTML documentation (push) Failing after 1s
python + Bazel pre-commit checks / pre-commit (push) Failing after 1s
sanitizer / tsan.Debug (push) Failing after 1s
sanitizer / ubsan.Debug (push) Failing after 0s
sanitizer / ubsan.RelWithDebInfo (push) Failing after 1s
build-and-test-min-cmake / ubuntu-latest.min-cmake (push) Failing after 1s
clang-format-lint / check-clang-format (push) Failing after 1s
sanitizer / asan.Debug (push) Failing after 1s
sanitizer / msan.RelWithDebInfo (push) Failing after 1s
clang-tidy / run-clang-tidy (push) Failing after 1s
sanitizer / msan.Debug (push) Failing after 1s
sanitizer / asan.RelWithDebInfo (push) Failing after 0s
sanitizer / tsan.RelWithDebInfo (push) Failing after 0s
test-bindings / Test Rust bindings on ubuntu-latest (push) Failing after 0s
test-bindings / Test Python 3.10 bindings on ubuntu-latest (push) Failing after 0s
test-bindings / Test Python 3.11 bindings on ubuntu-latest (push) Failing after 0s
test-bindings / Test Python 3.12 bindings on ubuntu-latest (push) Failing after 1s
test-bindings / Test Python 3.13 bindings on ubuntu-latest (push) Failing after 0s
build-and-test / macos-latest.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.shared.clang++ (push) Has been cancelled
bazel / bazel.macos-latest (push) Has been cancelled
bazel / bazel.windows-latest (push) Has been cancelled
build-and-test-min-cmake / macos-latest.min-cmake (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Debug.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.shared.g++ (push) Has been cancelled
build-and-test / macos-latest.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.static.g++ (push) Has been cancelled
build-and-test / macos-latest.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.shared.clang++ (push) Has been cancelled
build-and-test / macos-latest.Release.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Debug.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Release.static.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.static.g++ (push) Has been cancelled
build-and-test / windows-2025.Debug.static.VS-18-2025 (push) Has been cancelled
build-and-test / windows-2022.Release.shared.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2022.Release.static.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2025.Release.shared.VS-18-2025 (push) Has been cancelled
build-and-test / windows-2025.Release.static.VS-18-2025 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.UCRT64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.UCRT64 (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.static.g++ (push) Has been cancelled
build-and-test / windows-2022.Debug.shared.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2022.Debug.static.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2025.Debug.shared.VS-18-2025 (push) Has been cancelled
build-and-test / windows-latest.Release.static.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Release.static.UCRT64 (push) Has been cancelled
test-bindings / Test Python 3.10 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.11 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.12 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.13 bindings on macos-latest (push) Has been cancelled
build-and-test / windows-latest.Release.shared.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Release.shared.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Release.shared.UCRT64 (push) Has been cancelled
build-and-test / windows-latest.Release.static.CLANG64 (push) Has been cancelled
test-bindings / Test Python 3.12 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.13 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.10 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.11 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Rust bindings on macos-latest (push) Has been cancelled
test-bindings / Test Rust bindings on windows-latest (push) Has been cancelled
153 lines
4.8 KiB
C++
153 lines
4.8 KiB
C++
// Copyright 2015 Google Inc. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#ifndef BENCHMARK_UTILS_H_
|
|
#define BENCHMARK_UTILS_H_
|
|
|
|
#include <atomic>
|
|
#include <type_traits>
|
|
#include <utility>
|
|
|
|
#include "benchmark/export.h"
|
|
#include "benchmark/macros.h"
|
|
|
|
namespace benchmark {
|
|
|
|
namespace internal {
|
|
BENCHMARK_EXPORT void UseCharPointer(char const volatile*);
|
|
}
|
|
|
|
#if (!defined(__GNUC__) && !defined(__clang__)) || defined(__pnacl__) || \
|
|
defined(__EMSCRIPTEN__)
|
|
#define BENCHMARK_HAS_NO_INLINE_ASSEMBLY
|
|
#endif
|
|
|
|
inline BENCHMARK_ALWAYS_INLINE void ClobberMemory() {
|
|
std::atomic_signal_fence(std::memory_order_acq_rel);
|
|
}
|
|
|
|
#define BENCHMARK_DONOTOPTIMIZE_CONST_REF_DEPRECATED_MSG \
|
|
"DoNotOptimize(T const&) can permit undesired compiler optimizations. " \
|
|
"Pass a non-const lvalue instead; if the argument is an expression result, " \
|
|
"store it in a local variable first."
|
|
|
|
#ifndef BENCHMARK_HAS_NO_INLINE_ASSEMBLY
|
|
#if !defined(__GNUC__) || defined(__llvm__) || defined(__INTEL_COMPILER)
|
|
template <class Tp>
|
|
BENCHMARK_DEPRECATED_MSG(BENCHMARK_DONOTOPTIMIZE_CONST_REF_DEPRECATED_MSG)
|
|
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
|
|
asm volatile("" : : "r,m"(value) : "memory");
|
|
}
|
|
|
|
template <class Tp>
|
|
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) {
|
|
#if defined(__clang__)
|
|
asm volatile("" : "+r,m"(value) : : "memory");
|
|
#else
|
|
asm volatile("" : "+m,r"(value) : : "memory");
|
|
#endif
|
|
}
|
|
|
|
template <class Tp>
|
|
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp&& value) {
|
|
#if defined(__clang__)
|
|
asm volatile("" : "+r,m"(value) : : "memory");
|
|
#else
|
|
asm volatile("" : "+m,r"(value) : : "memory");
|
|
#endif
|
|
}
|
|
#elif (__GNUC__ >= 5)
|
|
template <class Tp>
|
|
BENCHMARK_DEPRECATED_MSG(BENCHMARK_DONOTOPTIMIZE_CONST_REF_DEPRECATED_MSG)
|
|
inline BENCHMARK_ALWAYS_INLINE
|
|
typename std::enable_if<std::is_trivially_copyable<Tp>::value &&
|
|
(sizeof(Tp) <= sizeof(Tp*))>::type
|
|
DoNotOptimize(Tp const& value) {
|
|
asm volatile("" : : "r,m"(value) : "memory");
|
|
}
|
|
|
|
template <class Tp>
|
|
BENCHMARK_DEPRECATED_MSG(BENCHMARK_DONOTOPTIMIZE_CONST_REF_DEPRECATED_MSG)
|
|
inline BENCHMARK_ALWAYS_INLINE
|
|
typename std::enable_if<!std::is_trivially_copyable<Tp>::value ||
|
|
(sizeof(Tp) > sizeof(Tp*))>::type
|
|
DoNotOptimize(Tp const& value) {
|
|
asm volatile("" : : "m"(value) : "memory");
|
|
}
|
|
|
|
template <class Tp>
|
|
inline BENCHMARK_ALWAYS_INLINE
|
|
typename std::enable_if<std::is_trivially_copyable<Tp>::value &&
|
|
(sizeof(Tp) <= sizeof(Tp*))>::type
|
|
DoNotOptimize(Tp& value) {
|
|
asm volatile("" : "+m,r"(value) : : "memory");
|
|
}
|
|
|
|
template <class Tp>
|
|
inline BENCHMARK_ALWAYS_INLINE
|
|
typename std::enable_if<!std::is_trivially_copyable<Tp>::value ||
|
|
(sizeof(Tp) > sizeof(Tp*))>::type
|
|
DoNotOptimize(Tp& value) {
|
|
asm volatile("" : "+m"(value) : : "memory");
|
|
}
|
|
|
|
template <class Tp>
|
|
inline BENCHMARK_ALWAYS_INLINE
|
|
typename std::enable_if<std::is_trivially_copyable<Tp>::value &&
|
|
(sizeof(Tp) <= sizeof(Tp*))>::type
|
|
DoNotOptimize(Tp&& value) {
|
|
asm volatile("" : "+m,r"(value) : : "memory");
|
|
}
|
|
|
|
template <class Tp>
|
|
inline BENCHMARK_ALWAYS_INLINE
|
|
typename std::enable_if<!std::is_trivially_copyable<Tp>::value ||
|
|
(sizeof(Tp) > sizeof(Tp*))>::type
|
|
DoNotOptimize(Tp&& value) {
|
|
asm volatile("" : "+m"(value) : : "memory");
|
|
}
|
|
#endif
|
|
|
|
#elif defined(_MSC_VER)
|
|
template <class Tp>
|
|
BENCHMARK_DEPRECATED_MSG(BENCHMARK_DONOTOPTIMIZE_CONST_REF_DEPRECATED_MSG)
|
|
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
|
|
internal::UseCharPointer(&reinterpret_cast<char const volatile&>(value));
|
|
ClobberMemory();
|
|
}
|
|
|
|
template <class Tp>
|
|
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) {
|
|
internal::UseCharPointer(&reinterpret_cast<char const volatile&>(value));
|
|
ClobberMemory();
|
|
}
|
|
|
|
template <class Tp>
|
|
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp&& value) {
|
|
internal::UseCharPointer(&reinterpret_cast<char const volatile&>(value));
|
|
ClobberMemory();
|
|
}
|
|
#else
|
|
template <class Tp>
|
|
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp&& value) {
|
|
internal::UseCharPointer(&reinterpret_cast<char const volatile&>(value));
|
|
}
|
|
#endif
|
|
|
|
#undef BENCHMARK_DONOTOPTIMIZE_CONST_REF_DEPRECATED_MSG
|
|
|
|
} // end namespace benchmark
|
|
|
|
#endif // BENCHMARK_UTILS_H_
|