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 #include "internal/linux_features_aggregator.h"
16 #include "internal/string_view.h"
18 void CpuFeatures_SetFromFlags(const size_t configs_size,
19 const CapabilityConfig* configs,
20 const StringView flags_line,
21 void* const features) {
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));
30 static bool IsSet(const uint32_t mask, const uint32_t value) {
31 return (value & mask) == mask;
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);
40 void CpuFeatures_OverrideFromHwCaps(const size_t configs_size,
41 const CapabilityConfig* configs,
42 const HardwareCapabilities hwcaps,
43 void* const features) {
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);