如何在gcc的uint64_t中获取ARM MULL指令以产生其输出? [英] how can I get the ARM MULL instruction to produce its output in a uint64_t in gcc?
问题描述
我想将一些汇编代码引入c99代码库。我想使用ARM CPU的UMULL指令将2 uint32_t乘以2,并将结果立即转换为uint64_t。
现在,uint64_t需要2个寄存器,所以我该怎么办?指定输出和asm块的约束?
好问题!
以下代码使用 GCC -O
或更高版本输出所需内容,而无需借助汇编程序:
uint32_t a,b;
uint64_t c;
...
c =(uint64_t)a *(uint64_t)b;
,或者如果您觉得必须使用机器专用的asm,则可以执行以下操作:
uint32_t a,b;
uint64_t c;
asm( umull%Q0,%R0,%1,%2: = r(c): r (a), r(b));
c
的寄存器名称是寄存器对中的第一对,而%Q和%R选择该对的低32位和高32位寄存器。有关示例,请参见gcc / config / arm / arm.md-> umulsidi3。
但是,如果您可以停留在C中,那么优化程序就有机会执行更多操作并且对您程序的读者更友善。
I would like to introduce some assembly code into a c99 codebase. I want to use the UMULL instruction from the ARM CPU to multiply 2 uint32_t and get the result immediately into a uint64_t.
Now a uint64_t needs 2 registers, so how do I specify the output and the constraints of the asm block?
Good question!
The following code outputs what you want using GCC -O
or higher without resorting to assembler:
uint32_t a, b; uint64_t c; ... c = (uint64_t)a * (uint64_t)b;or if you feel you must use machine-specific asm, you can go:
uint32_t a, b; uint64_t c;asm ("umull %Q0, %R0, %1, %2" : "=r"(c) : "r"(a), "r"(b));
c
's register name is the first of the register pair, and %Q and %R pick out the lower and upper 32-bit registers of the pair. See gcc/config/arm/arm.md -> umulsidi3 for an example.
However, if you can stay in C, that gives the optimizer a chance to do more and is kinder on readers of your program.
这篇关于如何在gcc的uint64_t中获取ARM MULL指令以产生其输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!