我怎样才能让 ARM MULL 指令在 gcc 的 uint64_t 中产生它的输出? [英] 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,结果马上变成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 位寄存器.参见 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.
这篇关于我怎样才能让 ARM MULL 指令在 gcc 的 uint64_t 中产生它的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!