【问题标题】:How to use boost preprocessor to easier gcc neon inline assesmbly?如何使用 boost 预处理器来简化 gcc neon 内联汇编?
【发布时间】:2020-11-26 14:39:43
【问题描述】:

在编写 gcc neon 内联汇编程序时,如果使用大量寄存器,通常必须编写很长的 clobber。如何编写一个宏来列出clobber部分中的寄存器序列?更好地使用boost预处理器。谢谢。

当前方法:

__asm(
  "mov r0, #0\n"
  "mov r1, #1\n"
  "mov r2, #2\n"
  "mov r3, #3\n"
  :
  :
  : "r0", "r1", "r2", "r3"
)

更好的方法:

__asm(
  "mov r0, #0\n"
  "mov r1, #1\n"
  "mov r2, #2\n"
  "mov r3, #3\n"
  :
  :
  : MACRO_RANGE(r, 0, 3)
)

【问题讨论】:

    标签: c-preprocessor inline-assembly c99


    【解决方案1】:

    我修复如下:

    // 构建字符串

    #define __asmpp_str(x) #x

    #define asmpp_xstr(x) __asmpp_str(x)

    #define __asmpp_reg_str_list(z, regNumber, regPrefix) asmpp_xstr( regPrefix ## regNumber ) BOOST_PP_COMMA() #define asmpp_reg_str_list(regPrefix, first, last) BOOST_PP_REPEAT_FROM_TO(first, last, __asmpp_reg_str_list, regPrefix) asmpp_xstr( regPrefix ## last)

    __asm(

    "mov r0, #0\n"

    "mov r1, #1\n"

    "mov r2, #2\n"

    "mov r3, #3\n"

    : asmpp_reg_str_list(r, 0, 3)

    )

    【讨论】:

      猜你喜欢
      • 2011-09-01
      • 2012-10-20
      • 2019-05-11
      • 2019-10-03
      • 2023-03-14
      • 2011-06-25
      • 2012-03-07
      • 2011-01-07
      • 1970-01-01
      相关资源
      最近更新 更多