Guillaume Chatelet | 439d371 | 2018-02-01 10:03:09 +0100 | [diff] [blame^] | 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 SetFromFlags(const size_t configs_size, const CapabilityConfig* configs, |
| 19 | const StringView flags_line, void* const features) { |
| 20 | size_t i = 0; |
| 21 | for (; i < configs_size; ++i) { |
| 22 | const CapabilityConfig config = configs[i]; |
| 23 | config.set_bit(features, HasWord(flags_line, config.proc_cpuinfo_flag)); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | static bool IsSet(const uint32_t mask, const uint32_t value) { |
| 28 | return (value & mask) == mask; |
| 29 | } |
| 30 | |
| 31 | static bool IsHwCapsSet(const HardwareCapabilities hwcaps_mask, |
| 32 | const HardwareCapabilities hwcaps) { |
| 33 | return IsSet(hwcaps_mask.hwcaps, hwcaps.hwcaps) && |
| 34 | IsSet(hwcaps_mask.hwcaps2, hwcaps.hwcaps2); |
| 35 | } |
| 36 | |
| 37 | void OverrideFromHwCaps(const size_t configs_size, |
| 38 | const CapabilityConfig* configs, |
| 39 | const HardwareCapabilities hwcaps, |
| 40 | void* const features) { |
| 41 | size_t i = 0; |
| 42 | for (; i < configs_size; ++i) { |
| 43 | const CapabilityConfig* config = &configs[i]; |
| 44 | if (IsHwCapsSet(config->hwcaps_mask, hwcaps)) { |
| 45 | config->set_bit(features, true); |
| 46 | } |
| 47 | } |
| 48 | } |