Bug 1842773 - Part 5: Add ArrayBuffer.prototype.{maxByteLength,resizable} getters...
[gecko.git] / testing / gtest / benchmark / BlackBox.h
blob568f3837352b2cf1fb9aa52eb1c20c1e840c7c41
1 // Copyright 2015 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #ifndef GTEST_BLACKBOX_H
16 #define GTEST_BLACKBOX_H
18 #include "mozilla/Attributes.h"
19 #if defined(_MSC_VER)
20 # include <intrin.h>
21 #endif // _MSC_VER
23 namespace mozilla {
25 #if defined(_MSC_VER)
27 char volatile* UseCharPointer(char volatile*);
29 MOZ_ALWAYS_INLINE_EVEN_DEBUG void* BlackBoxVoidPtr(void* aPtr) {
30 aPtr = const_cast<char*>(UseCharPointer(reinterpret_cast<char*>(aPtr)));
31 _ReadWriteBarrier();
32 return aPtr;
35 #else
37 // See: https://youtu.be/nXaxk27zwlk?t=2441
38 MOZ_ALWAYS_INLINE_EVEN_DEBUG void* BlackBoxVoidPtr(void* aPtr) {
39 // "g" is what we want here, but the comment in the Google
40 // benchmark code suggests that GCC likes "i,r,m" better.
41 // However, on Mozilla try server i,r,m breaks GCC but g
42 // works in GCC, so using g for both clang and GCC.
43 // godbolt.org indicates that g works already in GCC 4.9,
44 // which is the oldest GCC we support at the time of this
45 // code landing. godbolt.org suggests that this clearly
46 // works is LLVM 5, but it's unclear if this inhibits
47 // all relevant optimizations properly on earlier LLVM.
48 asm volatile("" : "+g"(aPtr) : "g"(aPtr) : "memory");
49 return aPtr;
52 #endif // _MSC_VER
54 template <class T>
55 MOZ_ALWAYS_INLINE_EVEN_DEBUG T* BlackBox(T* aPtr) {
56 return static_cast<T*>(BlackBoxVoidPtr(aPtr));
59 } // namespace mozilla
61 #endif // GTEST_BLACKBOX_H