CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
Loading...
Searching...
No Matches
Bitpack< StorageParam > Class Template Reference

The Bitpack structure itself, templated on the underlying Storage type. More...

#include <bitpack.hh>

Classes

struct  Numeric
 Convenience wrapper for the types of numeric fields. More...
struct  FieldInfo
 Information about a field within a Bitpack. More...
struct  Field
 A particular Field within a Bitpack. More...

Public Types

using Storage = StorageParam
 Expose the underlying storage type.

Public Member Functions

constexpr Bitpack ()
 Construct a Bitpack value with an underlying Storage of all zero bits.
constexpr Bitpack (Storage v)
 Construct a Bitpack value from a value of its underlying Storage type.
template<typename Self>
constexpr Self && operator= (this Self &&self, const std::remove_cvref_t< Self > &b)
 Assign a whole Bitpack at once given a non-volatile Bitpack of the same (or convertible, including derived) type.
template<typename Self>
requires (!std::is_volatile_v<Self>)
constexpr bool operator== (this Self &&self, const std::remove_cvref_t< Self > &b)
 Compare Bitpack-s for equality (reflecting that of Storage).
template<typename Self>
requires (!std::is_volatile_v<Self>)
constexpr auto operator<=> (this Self &&self, const std::remove_cvref_t< Self > &b)
 Spaceship operator on Bitpack-s (reflecing that of Storage).
constexpr operator Storage () const
 Extract the underlying Storage value.
constexpr Storage raw () const
 A shorter way of spelling static_cast<Storage>(...).
template<typename Self>
const auto read (this Self &&self)
 Return a snapshot of the underlying Storage.
template<typename FieldType, typename Self>
requires std::is_convertible_v< decltype(std::remove_cvref_t<Self>::template field_info_for_type< FieldType>()), const FieldInfo>
constexpr auto member (this Self &&self)
 Build a Field::Proxy proxy by asking the derived Self class for a FieldInfo structure computed from template expansion of Self::field_info_for_type<FieldType>().
template<typename FieldType, typename Self>
constexpr FieldType get (this Self &&self)
 Fetch the value of a field in this Bitpack based on the field type.
template<typename FieldType, typename Self>
constexpr std::remove_cvref_t< Self > with (this Self &&self, FieldType v)
 Compute a new Bitpack value with an updated field of a given type.
template<typename FieldType, typename Self>
constexpr void set (this Self &&self, FieldType v)
 Compute a new Bitpack value with an updated field of a given type.
template<typename Self>
requires std::is_invocable_r_v<std::remove_cvref_t<Self>, decltype(f), std::remove_cvref_t<Self>>
constexpr void alter (this Self &&self, auto &&f)
 Convenience function for unconditionally changing several sub-fields at once.
template<typename Self>
requires std::is_invocable_r_v<std::remove_cvref_t<Self>, decltype(f), std::remove_cvref_t<Self>>
constexpr void assign_from (this Self &&self, auto &&f)
 Convenience function for unconditionally assigning an entire Bitpack from a computed value.

Protected Member Functions

template<typename FieldType, FieldInfo Info, typename Self>
constexpr auto member (this Self &&self)
 Build a Field::Proxy of an explicitly given type and info.

Detailed Description

template<typename StorageParam>
requires std::is_unsigned_v<StorageParam>
class Bitpack< StorageParam >

The Bitpack structure itself, templated on the underlying Storage type.

This should be the sole (non-empty) superclass of a type representing a bitfield-esque composite structure.

Definition at line 318 of file bitpack.hh.

Member Typedef Documentation

◆ Storage

template<typename StorageParam>
using Bitpack< StorageParam >::Storage = StorageParam

Expose the underlying storage type.

Definition at line 322 of file bitpack.hh.

Constructor & Destructor Documentation

◆ Bitpack() [1/2]

template<typename StorageParam>
Bitpack< StorageParam >::Bitpack ( )
inlineconstexpr

Construct a Bitpack value with an underlying Storage of all zero bits.

Definition at line 329 of file bitpack.hh.

Referenced by Bitpack< StorageParam >::Field< TypeParam, InfoParam >::raw_with().

◆ Bitpack() [2/2]

template<typename StorageParam>
Bitpack< StorageParam >::Bitpack ( Storage v)
inlineexplicitconstexpr

Construct a Bitpack value from a value of its underlying Storage type.

This is marked explicit to make things like "device->register = 0x7;" slightly harder to spell, with the intent of encouraging use of named constants.

Definition at line 338 of file bitpack.hh.

Member Function Documentation

◆ alter()

template<typename StorageParam>
template<typename Self>
requires std::is_invocable_r_v<std::remove_cvref_t<Self>, decltype(f), std::remove_cvref_t<Self>>
void Bitpack< StorageParam >::alter ( this Self && self,
auto && f )
inlineconstexpr

Convenience function for unconditionally changing several sub-fields at once.

Intended particularly for use with volatile Bitpack-s, to help ensure only one read and one write takes place, as the callback operates on a non-volatile Bitpack.

Definition at line 879 of file bitpack.hh.

◆ assign_from()

template<typename StorageParam>
template<typename Self>
requires std::is_invocable_r_v<std::remove_cvref_t<Self>, decltype(f), std::remove_cvref_t<Self>>
void Bitpack< StorageParam >::assign_from ( this Self && self,
auto && f )
inlineconstexpr

Convenience function for unconditionally assigning an entire Bitpack from a computed value.

The function receives a zero-valued instance of the Bitpack type.

Definition at line 894 of file bitpack.hh.

◆ get()

template<typename StorageParam>
template<typename FieldType, typename Self>
FieldType Bitpack< StorageParam >::get ( this Self && self)
inlineconstexpr

Fetch the value of a field in this Bitpack based on the field type.

For volatile Bitpacks, this will perform a load.

Definition at line 845 of file bitpack.hh.

References member().

◆ member() [1/2]

template<typename StorageParam>
template<typename FieldType, typename Self>
requires std::is_convertible_v< decltype(std::remove_cvref_t<Self>::template field_info_for_type< FieldType>()), const FieldInfo>
auto Bitpack< StorageParam >::member ( this Self && self)
inlineconstexpr

Build a Field::Proxy proxy by asking the derived Self class for a FieldInfo structure computed from template expansion of Self::field_info_for_type<FieldType>().

Definition at line 827 of file bitpack.hh.

References member().

◆ member() [2/2]

template<typename StorageParam>
template<typename FieldType, FieldInfo Info, typename Self>
auto Bitpack< StorageParam >::member ( this Self && self)
inlineconstexprprotected

Build a Field::Proxy of an explicitly given type and info.

This is protected so that it is available to subclasses but not more generally.

Definition at line 811 of file bitpack.hh.

Referenced by get(), member(), set(), and with().

◆ operator Storage()

template<typename StorageParam>
Bitpack< StorageParam >::operator Storage ( ) const
inlineexplicitconstexpr

Extract the underlying Storage value.

The Bitpack must not be volatile. Use .read() first.

Definition at line 393 of file bitpack.hh.

◆ operator<=>()

template<typename StorageParam>
template<typename Self>
requires (!std::is_volatile_v<Self>)
auto Bitpack< StorageParam >::operator<=> ( this Self && self,
const std::remove_cvref_t< Self > & b )
inlineconstexpr

Spaceship operator on Bitpack-s (reflecing that of Storage).

Neither side may be volatile; use explicit .read()-s first.

Definition at line 382 of file bitpack.hh.

References operator<=>().

Referenced by operator<=>().

◆ operator=()

template<typename StorageParam>
template<typename Self>
Self && Bitpack< StorageParam >::operator= ( this Self && self,
const std::remove_cvref_t< Self > & b )
inlineconstexpr

Assign a whole Bitpack at once given a non-volatile Bitpack of the same (or convertible, including derived) type.

To assign from a volatile Bitpack, perform an explicit .read() first.

"Deducing this" gives us CRTP-esque behavior without, well, the CRTP, so this will not accept an unrelated derived Bitpack class. (But will accept types that can be converted, so assigning to a Bitpack, as opposed to a derived class, will accept any derived class, for example. Probably best avoid that.)

Definition at line 355 of file bitpack.hh.

◆ operator==()

template<typename StorageParam>
template<typename Self>
requires (!std::is_volatile_v<Self>)
bool Bitpack< StorageParam >::operator== ( this Self && self,
const std::remove_cvref_t< Self > & b )
inlineconstexpr

Compare Bitpack-s for equality (reflecting that of Storage).

Neither side may be volatile; use explicit .read()-s first.

Definition at line 369 of file bitpack.hh.

◆ raw()

template<typename StorageParam>
Storage Bitpack< StorageParam >::raw ( ) const
inlinenodiscardconstexpr

A shorter way of spelling static_cast<Storage>(...).

The Bitpack must not be volatile. Use .read() first.

Definition at line 403 of file bitpack.hh.

Referenced by OpenTitanUart::interrupt_enable().

◆ read()

template<typename StorageParam>
template<typename Self>
const auto Bitpack< StorageParam >::read ( this Self && self)
inline

Return a snapshot of the underlying Storage.

Notably, this can be used to get a const Bitpack from a volatile Bitpack (const or not).

Definition at line 415 of file bitpack.hh.

◆ set()

template<typename StorageParam>
template<typename FieldType, typename Self>
void Bitpack< StorageParam >::set ( this Self && self,
FieldType v )
inlineconstexpr

Compute a new Bitpack value with an updated field of a given type.

For volatile Bitpacks, this will perform a load and store.

Definition at line 867 of file bitpack.hh.

References member().

◆ with()

template<typename StorageParam>
template<typename FieldType, typename Self>
std::remove_cvref_t< Self > Bitpack< StorageParam >::with ( this Self && self,
FieldType v )
inlineconstexpr

Compute a new Bitpack value with an updated field of a given type.

For volatile Bitpacks, this will perform a load.

Definition at line 856 of file bitpack.hh.

References member().


The documentation for this class was generated from the following file: