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 set_knownCpuFeatures17 ALWAYS_INLINE void set_known(int i) { 18 known[i >> 6] |= ((uint64_t)1) << (i & 63); 19 } 20 set_availableCpuFeatures21 ALWAYS_INLINE void set_available(int i) { 22 available[i >> 6] |= ((uint64_t)1) << (i & 63); 23 } 24 test_knownCpuFeatures25 ALWAYS_INLINE bool test_known(int i) const { 26 return (known[i >> 6] & ((uint64_t)1) << (i & 63)) != 0; 27 } 28 test_availableCpuFeatures29 ALWAYS_INLINE bool test_available(int i) const { 30 return (available[i >> 6] & ((uint64_t)1) << (i & 63)) != 0; 31 } 32 33 ALWAYS_INLINE CpuFeaturesCpuFeatures34 CpuFeatures() { 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 48 extern WEAK CpuFeatures halide_get_cpu_features(); 49 50 } // namespace Internal 51 } // namespace Runtime 52 } // namespace Halide 53 54 #endif // HALIDE_CPU_FEATURES_H 55