GNU Radio's DVBS2RX Package
bit_utils.h
Go to the documentation of this file.
1// Copyright 2017 Google LLC
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
22#include "cpu_features_macros.h"
23
25
26inline static bool IsBitSet(uint32_t reg, uint32_t bit) {
27 return (reg >> bit) & 0x1;
28}
29
30inline static uint32_t ExtractBitRange(uint32_t reg, uint32_t msb,
31 uint32_t lsb) {
32 const uint64_t bits = msb - lsb + 1ULL;
33 const uint64_t mask = (1ULL << bits) - 1ULL;
34 assert(msb >= lsb);
35 return (reg >> lsb) & mask;
36}
37
39
40#endif // CPU_FEATURES_INCLUDE_INTERNAL_BIT_UTILS_H_
static CPU_FEATURES_START_CPP_NAMESPACE bool IsBitSet(uint32_t reg, uint32_t bit)
Definition bit_utils.h:26
static uint32_t ExtractBitRange(uint32_t reg, uint32_t msb, uint32_t lsb)
Definition bit_utils.h:30
#define CPU_FEATURES_START_CPP_NAMESPACE
Definition cpu_features_macros.h:127
#define CPU_FEATURES_END_CPP_NAMESPACE
Definition cpu_features_macros.h:128