diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /testing/gtest/benchmark/BlackBox.h | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
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 |