• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 Google LLC
2 //
3 // This source code is licensed under the BSD-style license found in the
4 // LICENSE file in the root directory of this source tree.
5 
6 #pragma once
7 
8 #include <cstddef>
9 #include <cstdint>
10 
11 #include <benchmark/benchmark.h>
12 
13 namespace benchmark {
14 namespace utils {
15 
16 uint32_t WipeCache();
17 uint32_t PrefetchToL1(const void* ptr, size_t size);
18 
19 // Disable support for denormalized numbers in floating-point units.
20 void DisableDenormals();
21 
22 // Return clock rate, in Hz, for the currently used logical processor.
23 uint64_t GetCurrentCpuFrequency();
24 
25 // Return maximum (across all cores/clusters/sockets) last level cache size.
26 // Can overestimate, but not underestimate LLC size.
27 size_t GetMaxCacheSize();
28 
29 // Set multi-threading parameters appropriate for the processor.
30 void MultiThreadingParameters(benchmark::internal::Benchmark* benchmark);
31 
32 typedef bool (*IsaCheckFunction)(benchmark::State& state);
33 
34 // Check if ARM NEON extension is supported.
35 // If NEON is unsupported, report error in benchmark state, and return false.
36 bool CheckNEON(benchmark::State& state);
37 
38 // Check if ARM NEON-FMA extension is supported.
39 // If NEON-FMA is unsupported, report error in benchmark state, and return false.
40 bool CheckNEONFMA(benchmark::State& state);
41 
42 // Check if x86 SSE4.1 extension is supported.
43 // If SSE4.1 is unsupported, report error in benchmark state, and return false.
44 bool CheckSSE41(benchmark::State& state);
45 
46 // Check if x86 AVX extension is supported.
47 // If AVX is unsupported, report error in benchmark state, and return false.
48 bool CheckAVX(benchmark::State& state);
49 
50 // Check if x86 FMA3 extension is supported.
51 // If FMA3 is unsupported, report error in benchmark state, and return false.
52 bool CheckFMA3(benchmark::State& state);
53 
54 // Check if x86 AVX2 extension is supported.
55 // If AVX2 is unsupported, report error in benchmark state, and return false.
56 bool CheckAVX2(benchmark::State& state);
57 
58 // Check if x86 AVX512F extension is supported.
59 // If AVX512F is unsupported, report error in benchmark state, and return false.
60 bool CheckAVX512F(benchmark::State& state);
61 
62 template <class T>
DivideRoundUp(T x,T q)63 inline T DivideRoundUp(T x, T q) {
64   return x / q + T(x % q != 0);
65 }
66 
67 template <class T>
RoundUp(T x,T q)68 inline T RoundUp(T x, T q) {
69   return q * DivideRoundUp(x, q);
70 }
71 
72 template <class T>
Doz(T a,T b)73 inline T Doz(T a, T b) {
74   return a >= b ? a - b : T(0);
75 }
76 
77 }  // namespace utils
78 }  // namespace benchmark
79