libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
libmicroemu::internal::BitManip< T > Class Template Reference

Static Public Member Functions

template<T alignment>
static constexpr T AlignDown (const T &address)
 Aligns the given address down to the nearest multiple of the specified alignment.
 
template<T alignment>
static constexpr T AlignUp (const T &address)
 Aligns the given address up to the nearest multiple of the specified alignment.
 
template<unsigned bit>
static constexpr T GenerateBitMask ()
 Generates a mask for the bit 'bit'.
 
template<unsigned last_bit, unsigned first_bit>
static constexpr T GenerateBitMask ()
 Generates a mask of 1 bits in the region [last_bit:first_bit].
 
static constexpr T GenerateBitMask (unsigned last_bit, unsigned first_bit)
 Generates a mask of 1 bits in the region [last_bit:first_bit].
 
template<unsigned bit>
static constexpr T IsolateBit (const T &value)
 Isolates the given bit "bit" in the value.
 
template<unsigned bit>
static constexpr bool IsBitSet (const T &value)
 Checks if the given bit "bit" is set in the value.
 
template<unsigned last_bit, unsigned first_bit>
static constexpr T ExtractBits1R (const T &value)
 Extracts bits from value in the region [last_bit:first_bit].
 
template<typename U>
static U ExtractType (T value, u32 start_byte)
 Extracts bits from an value and returns the result as the specified type.
 
template<typename U>
static T InsertType (T value, u32 start_byte, U insert_val)
 Inserts bits of a shorter type into a value at the specified byte position.
 
template<unsigned r2_last_bit, unsigned r2_first_bit, unsigned r1_last_bit, unsigned r1_first_bit>
static constexpr T ExtractBits2R (const T &value)
 Extracts bits from value in 2 bit regions and concatenates them.
 
template<typename U>
static U ZeroExtend (const T &value)
 Takes a value of type T and converts it to type U by extending the missing bits with 0.
 
template<typename U, unsigned top_bit>
static U SignExtend (const T &value)
 Takes a value of type T and converts it to type U by extending the given top bit.
 
static T IsZeroBit (const T &value)
 Checks if the given value is zero.
 
static T BitCount (const T &value)
 Counts the number of bits set in the given value.
 
static T LowestBitSet (const T &value)
 Finds the position of the lowest bit set in the given value.
 
static T CountLeadingZeros (const T &value)
 

Member Function Documentation

◆ AlignDown()

template<typename T>
template<T alignment>
static constexpr T libmicroemu::internal::BitManip< T >::AlignDown ( const T & address)
inlinestaticconstexpr

Aligns the given address down to the nearest multiple of the specified alignment.

This function takes an address and aligns it downwards to the nearest multiple of the alignment. If the alignment is 0, it simply returns the original address.

Template Parameters
alignmentThe alignment value, must be a power of 2.
TThe type of the address, typically an integer type.
Parameters
addressThe address to be aligned.
Returns
The address aligned down to the nearest multiple of the specified alignment.

◆ AlignUp()

template<typename T>
template<T alignment>
static constexpr T libmicroemu::internal::BitManip< T >::AlignUp ( const T & address)
inlinestaticconstexpr

Aligns the given address up to the nearest multiple of the specified alignment.

This function takes an address and aligns it upwards to the nearest multiple of the alignment. If the alignment is 0, it simply returns the original address.

Template Parameters
alignmentThe alignment value, must be a power of 2.
TThe type of the address, typically an integer type.
Parameters
addressThe address to be aligned.
Returns
The address aligned up to the nearest multiple of the specified alignment.

◆ BitCount()

template<typename T>
static T libmicroemu::internal::BitManip< T >::BitCount ( const T & value)
inlinestatic

Counts the number of bits set in the given value.

Parameters
valueThe value to count the bits.
Returns
The number of bits set.

◆ ExtractBits1R()

template<typename T>
template<unsigned last_bit, unsigned first_bit>
static constexpr T libmicroemu::internal::BitManip< T >::ExtractBits1R ( const T & value)
inlinestaticconstexpr

Extracts bits from value in the region [last_bit:first_bit].

Template Parameters
last_bitThe last bit position.
first_bitThe first bit position.
Parameters
valueThe value to extract bits from.
Returns
The extracted bits.

◆ ExtractBits2R()

template<typename T>
template<unsigned r2_last_bit, unsigned r2_first_bit, unsigned r1_last_bit, unsigned r1_first_bit>
static constexpr T libmicroemu::internal::BitManip< T >::ExtractBits2R ( const T & value)
inlinestaticconstexpr

Extracts bits from value in 2 bit regions and concatenates them.

Template Parameters
r2_last_bitThe last bit position of the second region.
r2_first_bitThe first bit position of the second region.
r1_last_bitThe last bit position of the first region.
r1_first_bitThe first bit position of the first region.
Parameters
valueThe value to extract bits from.
Returns
The concatenated bits.

◆ ExtractType()

template<typename T>
template<typename U>
static U libmicroemu::internal::BitManip< T >::ExtractType ( T value,
u32 start_byte )
inlinestatic

Extracts bits from an value and returns the result as the specified type.

This function takes an value and extracts bits starting from the specified byte position. The extracted bits are then casted to the specified type and returned.

Template Parameters
UThe type to cast the extracted bits to.
Parameters
valueThe value to extract bits from.
start_byteThe starting byte position of the bits to extract.
Returns
The extracted bits casted to the specified type.

◆ GenerateBitMask() [1/3]

template<typename T>
template<unsigned bit>
static constexpr T libmicroemu::internal::BitManip< T >::GenerateBitMask ( )
inlinestaticconstexpr

Generates a mask for the bit 'bit'.

Template Parameters
bitThe bit position.
Returns
The generated mask.

◆ GenerateBitMask() [2/3]

template<typename T>
template<unsigned last_bit, unsigned first_bit>
static constexpr T libmicroemu::internal::BitManip< T >::GenerateBitMask ( )
inlinestaticconstexpr

Generates a mask of 1 bits in the region [last_bit:first_bit].

Template Parameters
last_bitThe last bit position.
first_bitThe first bit position.
Returns
The generated mask.

◆ GenerateBitMask() [3/3]

template<typename T>
static constexpr T libmicroemu::internal::BitManip< T >::GenerateBitMask ( unsigned last_bit,
unsigned first_bit )
inlinestaticconstexpr

Generates a mask of 1 bits in the region [last_bit:first_bit].

Parameters
last_bitThe last bit position.
first_bitThe first bit position.
Returns
The generated mask.

◆ InsertType()

template<typename T>
template<typename U>
static T libmicroemu::internal::BitManip< T >::InsertType ( T value,
u32 start_byte,
U insert_val )
inlinestatic

Inserts bits of a shorter type into a value at the specified byte position.

Template Parameters
UThe type of the bits to insert.
Parameters
valueThe value to insert the bits into.
start_byteThe starting byte position to insert the value.
insert_valThe value of the type to be inserted.
Returns
The value with the inserted bits.

◆ IsBitSet()

template<typename T>
template<unsigned bit>
static constexpr bool libmicroemu::internal::BitManip< T >::IsBitSet ( const T & value)
inlinestaticconstexpr

Checks if the given bit "bit" is set in the value.

Template Parameters
bitThe bit position.
Parameters
valueThe value to check.
Returns
True if the bit is set, false otherwise.

◆ IsolateBit()

template<typename T>
template<unsigned bit>
static constexpr T libmicroemu::internal::BitManip< T >::IsolateBit ( const T & value)
inlinestaticconstexpr

Isolates the given bit "bit" in the value.

Template Parameters
bitThe bit position.
Parameters
valueThe value to isolate the bit from.
Returns
The isolated bit.

◆ IsZeroBit()

template<typename T>
static T libmicroemu::internal::BitManip< T >::IsZeroBit ( const T & value)
inlinestatic

Checks if the given value is zero.

Parameters
valueThe value to check.
Returns
1 if the value is zero, 0 otherwise.

◆ LowestBitSet()

template<typename T>
static T libmicroemu::internal::BitManip< T >::LowestBitSet ( const T & value)
inlinestatic

Finds the position of the lowest bit set in the given value.

Parameters
valueThe value to find the lowest bit set.
Returns
The position of the lowest bit set.

◆ SignExtend()

template<typename T>
template<typename U, unsigned top_bit>
static U libmicroemu::internal::BitManip< T >::SignExtend ( const T & value)
inlinestatic

Takes a value of type T and converts it to type U by extending the given top bit.

Template Parameters
UThe type to convert to.
top_bitThe top bit position.
Parameters
valueThe value to convert.
Returns
The converted value.

◆ ZeroExtend()

template<typename T>
template<typename U>
static U libmicroemu::internal::BitManip< T >::ZeroExtend ( const T & value)
inlinestatic

Takes a value of type T and converts it to type U by extending the missing bits with 0.

Template Parameters
UThe type to convert to.
Parameters
valueThe value to convert.
Returns
The converted value.

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