blob: 5939565c94f6a8941308fac0a8a71fe84ab20410 [file] [log] [blame]
Guillaume Chatelet439d3712018-02-01 10:03:09 +01001// 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 THIRD_PARTY_CPU_FEATURES_INCLUDE_INTERNAL_LINUX_FEATURES_AGGREGATOR_H_
19#define THIRD_PARTY_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
27START_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.
37typedef 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.
46void SetFromFlags(const size_t configs_size, const CapabilityConfig* configs,
47 const StringView flags_line, void* const features);
48
49// For every config, looks into hwcaps for the presence of the feature. Calls
50// `set_bit` with true if the hardware capability is found.
51// Note: features is a pointer to the underlying Feature struct.
52void OverrideFromHwCaps(const size_t configs_size,
53 const CapabilityConfig* configs,
54 const HardwareCapabilities hwcaps,
55 void* const features);
56
57END_CPP_NAMESPACE
58#endif // THIRD_PARTY_CPU_FEATURES_INCLUDE_INTERNAL_LINUX_FEATURES_AGGREGATOR_H_