77661d4cb39908704272ede9d4ed6ea70b77ff58
[iec.git] / src / type3_AndroidCloud / anbox-master / external / cpu_features / include / internal / linux_features_aggregator.h
1 // Copyright 2017 Google Inc.
2 //
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
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14
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
17 // either source.
18 #ifndef CPU_FEATURES_INCLUDE_INTERNAL_LINUX_FEATURES_AGGREGATOR_H_
19 #define CPU_FEATURES_INCLUDE_INTERNAL_LINUX_FEATURES_AGGREGATOR_H_
20
21 #include <ctype.h>
22 #include <stdint.h>
23 #include "cpu_features_macros.h"
24 #include "internal/hwcaps.h"
25 #include "internal/string_view.h"
26
27 CPU_FEATURES_START_CPP_NAMESPACE
28
29 // Use the following macro to declare setter functions to be used in
30 // CapabilityConfig.
31 #define DECLARE_SETTER(FeatureType, FeatureName)                    \
32   static void set_##FeatureName(void* const features, bool value) { \
33     ((FeatureType*)features)->FeatureName = value;                  \
34   }
35
36 // Describes the relationship between hardware caps and /proc/cpuinfo flags.
37 typedef struct {
38   const HardwareCapabilities hwcaps_mask;
39   const char* const proc_cpuinfo_flag;
40   void (*set_bit)(void* const, bool);  // setter for the corresponding bit.
41 } CapabilityConfig;
42
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);
50
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);
58
59 CPU_FEATURES_END_CPP_NAMESPACE
60 #endif  // CPU_FEATURES_INCLUDE_INTERNAL_LINUX_FEATURES_AGGREGATOR_H_