1 // Copyright 2017 Google Inc.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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 // CapabilityConfig provides a way to map cpu features to hardware caps and
16 // /proc/cpuinfo flags. We then provide functions to update capabilities from
18 #ifndef CPU_FEATURES_INCLUDE_INTERNAL_LINUX_FEATURES_AGGREGATOR_H_
19 #define CPU_FEATURES_INCLUDE_INTERNAL_LINUX_FEATURES_AGGREGATOR_H_
23 #include "cpu_features_macros.h"
24 #include "internal/hwcaps.h"
25 #include "internal/string_view.h"
27 CPU_FEATURES_START_CPP_NAMESPACE
29 // Use the following macro to declare setter functions to be used in
31 #define DECLARE_SETTER(FeatureType, FeatureName) \
32 static void set_##FeatureName(void* const features, bool value) { \
33 ((FeatureType*)features)->FeatureName = value; \
36 // Describes the relationship between hardware caps and /proc/cpuinfo flags.
38 const HardwareCapabilities hwcaps_mask;
39 const char* const proc_cpuinfo_flag;
40 void (*set_bit)(void* const, bool); // setter for the corresponding bit.
43 // For every config, looks into flags_line for the presence of the
44 // corresponding proc_cpuinfo_flag, calls `set_bit` accordingly.
45 // Note: features is a pointer to the underlying Feature struct.
46 void CpuFeatures_SetFromFlags(const size_t configs_size,
47 const CapabilityConfig* configs,
48 const StringView flags_line,
49 void* const features);
51 // For every config, looks into hwcaps for the presence of the feature. Calls
52 // `set_bit` with true if the hardware capability is found.
53 // Note: features is a pointer to the underlying Feature struct.
54 void CpuFeatures_OverrideFromHwCaps(const size_t configs_size,
55 const CapabilityConfig* configs,
56 const HardwareCapabilities hwcaps,
57 void* const features);
59 CPU_FEATURES_END_CPP_NAMESPACE
60 #endif // CPU_FEATURES_INCLUDE_INTERNAL_LINUX_FEATURES_AGGREGATOR_H_