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 "runtime_internal.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  for (int i = 0; i < kWordCount; ++i) {
36  known[i] = 0;
37  available[i] = 0;
38  }
39  }
40 
41  uint64_t known[kWordCount]; // mask of the CPU features we know how to detect
42  uint64_t available[kWordCount]; // mask of the CPU features that are available
43  // (always a subset of 'known')
44 };
45 
47 
48 } // namespace Internal
49 } // namespace Runtime
50 } // namespace Halide
51 
52 #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:23
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
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:1406
Halide::Runtime::Internal::CpuFeatures::CpuFeatures
ALWAYS_INLINE CpuFeatures()
Definition: cpu_features.h:34
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:55
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:41
WEAK
#define WEAK
Definition: runtime_internal.h:52
runtime_internal.h
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:42
Halide::Runtime::Internal::CpuFeatures::test_known
ALWAYS_INLINE bool test_known(int i) const
Definition: cpu_features.h:25