CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
Toggle main menu visibility
Loading...
Searching...
No Matches
sdk
include
ds
bits.h
Go to the documentation of this file.
1
// Copyright Microsoft and CHERIoT Contributors.
2
// SPDX-License-Identifier: MIT
3
4
/**
5
* @file
6
* \brief Bit manipulation utilities
7
*/
8
9
#pragma once
10
11
#include <concepts>
12
13
namespace
ds::bits
14
{
15
16
/**
17
* Isolate the least significant set bit. That is, clear all bits to the
18
* left of the first set bit.
19
*/
20
template
<
typename
T>
21
__always_inline T
isolate_least
(T v)
22
{
23
return
v & -v;
24
}
25
26
/**
27
* Mask of all bits above and including the least significant set bit.
28
*/
29
template
<
typename
T>
30
__always_inline T
above_or_least
(T v)
31
{
32
return
v | -v;
33
}
34
35
/**
36
* Mask of all bits above the least significant set bit.
37
*/
38
template
<
typename
T>
39
__always_inline T
above_least
(T v)
40
{
41
return
above_or_least
(v << 1);
42
}
43
44
}
// namespace ds::bits
ds::bits::above_least
T above_least(T v)
Mask of all bits above the least significant set bit.
Definition
bits.h:39
ds::bits::above_or_least
T above_or_least(T v)
Mask of all bits above and including the least significant set bit.
Definition
bits.h:30
ds::bits::isolate_least
T isolate_least(T v)
Isolate the least significant set bit.
Definition
bits.h:21
Generated by
1.18.0