b7f8f3d955a3d74ad367b5e4a0d492e5a3d7e653
[iec.git] / src / type3_AndroidCloud / anbox-master / external / cpu_features / src / linux_features_aggregator.c
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 #include "internal/linux_features_aggregator.h"
16 #include "internal/string_view.h"
17
18 void CpuFeatures_SetFromFlags(const size_t configs_size,
19                               const CapabilityConfig* configs,
20                               const StringView flags_line,
21                               void* const features) {
22   size_t i = 0;
23   for (; i < configs_size; ++i) {
24     const CapabilityConfig config = configs[i];
25     config.set_bit(features, CpuFeatures_StringView_HasWord(
26                                  flags_line, config.proc_cpuinfo_flag));
27   }
28 }
29
30 static bool IsSet(const uint32_t mask, const uint32_t value) {
31   return (value & mask) == mask;
32 }
33
34 static bool IsHwCapsSet(const HardwareCapabilities hwcaps_mask,
35                         const HardwareCapabilities hwcaps) {
36   return IsSet(hwcaps_mask.hwcaps, hwcaps.hwcaps) &&
37          IsSet(hwcaps_mask.hwcaps2, hwcaps.hwcaps2);
38 }
39
40 void CpuFeatures_OverrideFromHwCaps(const size_t configs_size,
41                                     const CapabilityConfig* configs,
42                                     const HardwareCapabilities hwcaps,
43                                     void* const features) {
44   size_t i = 0;
45   for (; i < configs_size; ++i) {
46     const CapabilityConfig* config = &configs[i];
47     if (IsHwCapsSet(config->hwcaps_mask, hwcaps)) {
48       config->set_bit(features, true);
49     }
50   }
51 }