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 -Oor higher without resorting to assembler:or if you feel you must use machine-specific asm, you can go:
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.