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 #ifndef CPU_FEATURES_INCLUDE_INTERNAL_BIT_UTILS_H_
16 #define CPU_FEATURES_INCLUDE_INTERNAL_BIT_UTILS_H_
21 #include "cpu_features_macros.h"
23 CPU_FEATURES_START_CPP_NAMESPACE
25 inline static bool IsBitSet(uint32_t reg, uint32_t bit) {
26 return (reg >> bit) & 0x1;
29 inline static uint32_t ExtractBitRange(uint32_t reg, uint32_t msb,
31 const uint64_t bits = msb - lsb + 1;
32 const uint64_t mask = (1ULL << bits) - 1ULL;
34 return (reg >> lsb) & mask;
37 CPU_FEATURES_END_CPP_NAMESPACE
39 #endif // CPU_FEATURES_INCLUDE_INTERNAL_BIT_UTILS_H_