将内联 ASM 转换为 Intrinsic
我接到一项任务,将一小段汇编代码转换为内在函数,以测试性能。 我从未为其中任何一个开发过任何代码,但我了解 asm 和 c,并阅读了内在语法。但我找不到有关内在如何处理访问寄存器的信息。我发现了 2 个函数:
getReg() 和 setReg()
getReg() 附带了一个包含不同寄存器表及其 ID/编号的表: - 通用整数寄存器 -应用程序寄存器 -控制寄存器 - 间接寄存器 但它们似乎都与 rax、rdi 等 asm 寄存器相对应。
如何在内部寻址寄存器,例如 rcx、rdi 等? 或者换句话说,我如何将其转换为:
mov %0, %rcx
到内在等效项?
I've been give a task to convert small piece of asm into intrinsic in order to test performance.
I ve never developed any code for either one, but I understand asm and c, and reading up on intrinsic syntax. But I cant find info on how intrinsic is dealing with accessing registers. i found 2 functions:
getReg() and setReg()
getReg() comes with a table of different register tables and their id/number:
-General Integer Registers
-Application Registers
-Control Registers
-Indirect Registers
But none of them seems to correspond to asm registers like rax,rdi and so on.
How can I address registers eg rcx, rdi and so on in intrinsic?
Or in other words how can I convert this:
mov %0, %rcx
to intrinsic equivalent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您错过了内在函数的要点 - 使用内在函数时无需担心寄存器分配(除了在某些情况下访问特殊寄存器的情况)。总体思路是让编译器为您处理所有此类低级内务处理工作。要将原始 asm 移植到内在函数,您需要首先对 asm 代码进行逆向工程,以便了解它的用途,然后使用内在函数重新实现等效代码。如果您发布一些实际代码,那么您可能会得到更具体的建议。
You're missing the point of intrinsics - you don't need to worry about register allocation when using intrinsics (except perhaps in the case of access to special registers in some cases). The general idea is to let the compiler take care of all this kind of low level house-keeping for you. To port raw asm to intrinsics you need to firstly reverse-engineer the asm code, so that you understand what it is meant to do, then re-implement the equivalent code using intrinsics. If you post some of the actual code then you may get more specific suggestions.
看看您是否可以使用其中任何一个:
GCC:X86 内置函数
MSVC++:按字母顺序排列的内部函数列表
See if you can use any of these:
GCC: X86 Built-in Functions
MSVC++: Alphabetical Listing of Intrinsic Functions