KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
regfield.h File Reference

Macros to help dealing with register fields. More...

#include <sys/cdefs.h>

Go to the source code of this file.

Macros

#define BIT(bit)
 Create a mask with a bit set.
 
#define GENMASK(h, l)
 Create a mask with a range of bits set.
 
#define FIELD_GET(var, field)
 Extract a field value from a variable.
 
#define FIELD_PREP(field, value)
 Prepare a field with a given value.
 

Detailed Description

Macros to help dealing with register fields.

Author
Paul Cercueil

Macro Definition Documentation

◆ BIT

#define BIT ( bit)
Value:
(1u << (bit))

Create a mask with a bit set.

Parameters
bitThe bit to set (from 0 to 31)
Returns
A 32-bit mask with the corresponding bit set

◆ FIELD_GET

#define FIELD_GET ( var,
field )
Value:
(((var) & (field)) >> __builtin_ctz(field))

Extract a field value from a variable.

Parameters
varThe 32-bit variable containing the field
fieldA 32-bit mask that corresponds to the field
Returns
The value of the field (shifted)

◆ FIELD_PREP

#define FIELD_PREP ( field,
value )
Value:
(((value) << __builtin_ctz(field)) & (field))

Prepare a field with a given value.

Parameters
fieldA 32-bit mask that corresponds to the field
valueThe value to be put in the field

◆ GENMASK

#define GENMASK ( h,
l )
Value:
((0xffffffff << (l)) & (0xffffffff >> (31 - (h))))

Create a mask with a range of bits set.

Parameters
hThe high bit of the range to set, included
lThe low bit of the range to set, included
Returns
A 32-bit mask with the corresponding bits set