diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/gtest/benchmark/BlackBox.h | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/gtest/benchmark/BlackBox.h')
-rw-r--r-- | testing/gtest/benchmark/BlackBox.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/testing/gtest/benchmark/BlackBox.h b/testing/gtest/benchmark/BlackBox.h new file mode 100644 index 0000000000..568f383735 --- /dev/null +++ b/testing/gtest/benchmark/BlackBox.h @@ -0,0 +1,61 @@ +// 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 GTEST_BLACKBOX_H +#define GTEST_BLACKBOX_H + +#include "mozilla/Attributes.h" +#if defined(_MSC_VER) +# include <intrin.h> +#endif // _MSC_VER + +namespace mozilla { + +#if defined(_MSC_VER) + +char volatile* UseCharPointer(char volatile*); + +MOZ_ALWAYS_INLINE_EVEN_DEBUG void* BlackBoxVoidPtr(void* aPtr) { + aPtr = const_cast<char*>(UseCharPointer(reinterpret_cast<char*>(aPtr))); + _ReadWriteBarrier(); + return aPtr; +} + +#else + +// See: https://youtu.be/nXaxk27zwlk?t=2441 +MOZ_ALWAYS_INLINE_EVEN_DEBUG void* BlackBoxVoidPtr(void* aPtr) { + // "g" is what we want here, but the comment in the Google + // benchmark code suggests that GCC likes "i,r,m" better. + // However, on Mozilla try server i,r,m breaks GCC but g + // works in GCC, so using g for both clang and GCC. + // godbolt.org indicates that g works already in GCC 4.9, + // which is the oldest GCC we support at the time of this + // code landing. godbolt.org suggests that this clearly + // works is LLVM 5, but it's unclear if this inhibits + // all relevant optimizations properly on earlier LLVM. + asm volatile("" : "+g"(aPtr) : "g"(aPtr) : "memory"); + return aPtr; +} + +#endif // _MSC_VER + +template <class T> +MOZ_ALWAYS_INLINE_EVEN_DEBUG T* BlackBox(T* aPtr) { + return static_cast<T*>(BlackBoxVoidPtr(aPtr)); +} + +} // namespace mozilla + +#endif // GTEST_BLACKBOX_H |