views:

107

answers:

2

Hello,

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?

+1  A: 

The umull instruction produces its results into two 32-bit registers. I suggest explicitly reassembling the 64-bit value with something like that:

/* assuming the 64-bit result was stored in "hi" (upper
   half) and "lo" (lower half) */
uint64_t v = ((uint64_t)hi << 32) | (uint64_t)lo;

The compiler optimizer should notice that the left-shift is pure data routing, and the resulting code should be fine. To be sure, just use -S to check the compiler output.

Thomas Pornin
+2  A: 
martinwguy
Thanks for the answer! Indeed the C version does what I want it to do, very cool.And many thanks for the %Q and %R syntax, that's what I was looking for in the beginning.