VirtualBox

Changeset 58953 in vbox for trunk/include/iprt


Ignore:
Timestamp:
Dec 2, 2015 2:54:58 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
104465
Message:

iprt/cdefs.h: Added generic bit field access macros RT_BF_GET, RT_BF_MAKE, and RT_BF_ZMASK. These works on bit fields inside integer values. The fields are defined by two macros: <FieldNm>_SHIFT and <FieldMm>_MASK.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cdefs.h

    r58790 r58953  
    15051505#define RT_BIT_64(bit)                          ( UINT64_C(1) << (bit) )
    15061506
     1507
     1508/** @def RT_BF_GET
     1509 * Gets the value of a bit field in an integer value.
     1510 *
     1511 * This requires a couple of macros to be defined for the field:
     1512 *      - \<a_FieldNm\>_SHIFT: The shift count to get to the field.
     1513 *      - \<a_FieldNm\>_MASK:  The field mask.
     1514 *
     1515 * @param   a_uValue        The integer value containing the field.
     1516 * @param   a_FieldNm       The field name prefix for getting at the _SHIFT and
     1517 *                          _MASK macros.
     1518 * @sa      #RT_BF_MAKE, #RT_BF_ZMASK
     1519 */
     1520#define RT_BF_GET(a_uValue, a_FieldNm)          ( ((a_uValue) >> RT_CONCAT(a_FieldNm,_SHIFT)) & RT_BF_ZMASK(a_FieldNm) )
     1521
     1522/** @def RT_BF_MAKE
     1523 * Shifts and masks a bit field value into position in the integer value.
     1524 *
     1525 * This requires a couple of macros to be defined for the field:
     1526 *      - \<a_FieldNm\>_SHIFT: The shift count to get to the field.
     1527 *      - \<a_FieldNm\>_MASK:  The field mask.
     1528 *
     1529 * @param   a_FieldNm       The field name prefix for getting at the _SHIFT and
     1530 *                          _MASK macros.
     1531 * @param   a_uFieldValue   The field value that should be masked and shifted
     1532 *                          into position.
     1533 * @sa      #RT_BF_GET, #RT_BF_ZMASK
     1534 */
     1535#define RT_BF_MAKE(a_FieldNm, a_uFieldValue)    ( ((a_uFieldValue) & RT_BF_ZMASK(a_FieldNm) ) << RT_CONCAT(a_FieldNm,_SHIFT) )
     1536
     1537/** @def RT_BF_ZMASK
     1538 * Helper for getting the field mask shifted to bit position zero.
     1539 *
     1540 * @param   a_FieldNm       The field name prefix for getting at the _SHIFT and
     1541 *                          _MASK macros.
     1542 * @sa      #RT_BF_GET, #RT_BF_MAKE
     1543 */
     1544#define RT_BF_ZMASK(a_FieldNm)                  ( RT_CONCAT(a_FieldNm,_MASK) >> RT_CONCAT(a_FieldNm,_SHIFT) )
     1545
     1546
    15071547/** @def RT_ALIGN
    15081548 * Align macro.
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette