c - 枚举类型如何用于分配寄存器

标签 c

我无法理解下面代码的用途。看octeon的sdk时,enum类型是怎么分配寄存器的?我该如何使用 cvmx_fau_reg_64_t?

/*************************  FAU allocation ********************************/
/* The fetch and add registers are allocated here.  They are arranged
    in order of descending size so that all alignment constraints are
    automatically met.
    The enums are linked so that the following enum continues allocating
    where the previous one left off, so the numbering within each
    enum always starts with zero.  The macros take care of the address
    increment size, so the values entered always increase by 1.
    FAU registers are accessed with byte addresses. */

#define CVMX_FAU_REG_64_ADDR(x) ((x <<3) + CVMX_FAU_REG_64_START)
typedef enum
{
    CVMX_FAU_REG_64_START          = 0, 
    CVMX_FAU_REG_64_END            = CVMX_FAU_REG_64_ADDR(0),
} cvmx_fau_reg_64_t;

#define CVMX_FAU_REG_32_ADDR(x) ((x <<2) + CVMX_FAU_REG_32_START)
typedef enum
{
    CVMX_FAU_REG_32_START          = CVMX_FAU_REG_64_END,
    CVMX_FAU_REG_32_END            = CVMX_FAU_REG_32_ADDR(0),
} cvmx_fau_reg_32_t;

#define CVMX_FAU_REG_16_ADDR(x) ((x <<1) + CVMX_FAU_REG_16_START)
typedef enum
{
    CVMX_FAU_REG_16_START          = CVMX_FAU_REG_32_END,
    CVMX_FAU_REG_16_END            = CVMX_FAU_REG_16_ADDR(0),
} cvmx_fau_reg_16_t;

#define CVMX_FAU_REG_8_ADDR(x) ((x) + CVMX_FAU_REG_8_START)
typedef enum {
    CVMX_FAU_REG_8_START           = CVMX_FAU_REG_16_END,
    CVMX_FAU_REG_8_END             = CVMX_FAU_REG_8_ADDR(0),
} cvmx_fau_reg_8_t;

/* The name CVMX_FAU_REG_AVAIL_BASE is provided to indicate the first available
   FAU address that is not allocated in cvmx-config.h. This is 64 bit aligned. */
#define CVMX_FAU_REG_AVAIL_BASE ((CVMX_FAU_REG_8_END + 0x7) & (~0x7ULL))
#define CVMX_FAU_REG_END (2048)

最佳答案

在C语言中,枚举类型类似于有符号整数数据类型。这是您应该如何使用 cvmx_fau_reg_64_t:

cvmx_fau_reg_64_t myRegister;

myRegister=CVMX_FAU_REG_64_START;

//Do something with the *myRegister* variable

myRegister=CVMX_FAU_REG_64_END;

关于c - 枚举类型如何用于分配寄存器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11822206/

相关文章:

Delphi 上的 C dll 头文件

c++ - 如何在 C/C++ 中做 TCP 连接池

C - 数组、排序和修改

c - C中char**的动态分配

c - 如何在主函数中初始化结构

c - 我正在尝试编写一个 C 代码来对 String 进行排序,但第 13 行总是显示错误消息

c - 对数刻度步长

c++ - 如何同时等待 I/O 完成端口和事件?

c - 该位运算符代码是副作用(K&R C 书中使用的术语)还是依赖于机器的处理指令?

c - 当我们在 linux 中为进程及其线程设置不同的处理器关联时会发生什么?