Halide
cpu_features.h
Go to the documentation of this file.
1 #ifndef HALIDE_CPU_FEATURES_H
2 #define HALIDE_CPU_FEATURES_H
3 
4 #include "HalideRuntime.h"
5 #include "cpu_features.h"
6 
7 namespace Halide {
8 namespace Runtime {
9 namespace Internal {
10 
11 // Return two masks:
12 // One with all the CPU-specific features that might possible be available on this architecture ('known'),
13 // and one with the subset that are actually present ('available').
14 struct CpuFeatures {
15  static const int kWordCount = (halide_target_feature_end + 63) / (sizeof(uint64_t) * 8);
16 
17  ALWAYS_INLINE void set_known(int i) {
18  known[i >> 6] |= ((uint64_t)1) << (i & 63);
19  }
20 
22  available[i >> 6] |= ((uint64_t)1) << (i & 63);
23  }
24 
25  ALWAYS_INLINE bool test_known(int i) const {
26  return (known[i >> 6] & ((uint64_t)1) << (i & 63)) != 0;
27  }
28 
29  ALWAYS_INLINE bool test_available(int i) const {
30  return (available[i >> 6] & ((uint64_t)1) << (i & 63)) != 0;
31  }
32 
35  // Can't use in-class initing of these without C++11 enabled,
36  // which isn't the case for all runtime builds
37  for (int i = 0; i < kWordCount; ++i) {
38  known[i] = 0;
39  available[i] = 0;
40  }
41  }
42 
43  uint64_t known[kWordCount]; // mask of the CPU features we know how to detect
44  uint64_t available[kWordCount]; // mask of the CPU features that are available
45  // (always a subset of 'known')
46 };
47 
49 
50 } // namespace Internal
51 } // namespace Runtime
52 } // namespace Halide
53 
54 #endif // HALIDE_CPU_FEATURES_H
Halide::Runtime::Internal::halide_get_cpu_features
WEAK CpuFeatures halide_get_cpu_features()
uint64_t
unsigned __INT64_TYPE__ uint64_t
Definition: runtime_internal.h:19
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AddAtomicMutex.h:21
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::Runtime::Internal::CpuFeatures::set_known
ALWAYS_INLINE void set_known(int i)
Definition: cpu_features.h:17
halide_target_feature_end
@ halide_target_feature_end
A sentinel. Every target is considered to have this feature, and setting this feature does nothing.
Definition: HalideRuntime.h:1323
Halide::Runtime::Internal::CpuFeatures::CpuFeatures
ALWAYS_INLINE CpuFeatures()
Definition: cpu_features.h:34
cpu_features.h
Halide::Runtime::Internal::CpuFeatures::test_available
ALWAYS_INLINE bool test_available(int i) const
Definition: cpu_features.h:29
ALWAYS_INLINE
#define ALWAYS_INLINE
Definition: runtime_internal.h:53
Halide::Runtime::Internal::CpuFeatures::set_available
ALWAYS_INLINE void set_available(int i)
Definition: cpu_features.h:21
HalideRuntime.h
Halide::Runtime::Internal::CpuFeatures
Definition: cpu_features.h:14
Halide::Runtime::Internal::CpuFeatures::known
uint64_t known[kWordCount]
Definition: cpu_features.h:43
WEAK
#define WEAK
Definition: runtime_internal.h:50
Halide::Runtime::Internal::CpuFeatures::kWordCount
static const int kWordCount
Definition: cpu_features.h:15
Halide::Runtime::Internal::CpuFeatures::available
uint64_t available[kWordCount]
Definition: cpu_features.h:44
Halide::Runtime::Internal::CpuFeatures::test_known
ALWAYS_INLINE bool test_known(int i) const
Definition: cpu_features.h:25