TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / external / cpu_features / include / internal / bit_utils.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 #ifndef CPU_FEATURES_INCLUDE_INTERNAL_BIT_UTILS_H_
16 #define CPU_FEATURES_INCLUDE_INTERNAL_BIT_UTILS_H_
17
18 #include <assert.h>
19 #include <stdbool.h>
20 #include <stdint.h>
21 #include "cpu_features_macros.h"
22
23 CPU_FEATURES_START_CPP_NAMESPACE
24
25 inline static bool IsBitSet(uint32_t reg, uint32_t bit) {
26   return (reg >> bit) & 0x1;
27 }
28
29 inline static uint32_t ExtractBitRange(uint32_t reg, uint32_t msb,
30                                        uint32_t lsb) {
31   const uint64_t bits = msb - lsb + 1;
32   const uint64_t mask = (1ULL << bits) - 1ULL;
33   assert(msb >= lsb);
34   return (reg >> lsb) & mask;
35 }
36
37 CPU_FEATURES_END_CPP_NAMESPACE
38
39 #endif  // CPU_FEATURES_INCLUDE_INTERNAL_BIT_UTILS_H_