[wellylug] asm stylings?
Daniel Pittman
daniel at rimspace.net
Mon Feb 19 12:13:27 NZDT 2007
Rob Giltrap <rob at kiwihq.com> writes:
> Daniel Pittman wrote:
>> Rob Giltrap <rob at kiwihq.com> writes:
>>> Daniel Pittman wrote:
>>>
>>>> #define __MULH64(__x, __y) \
>>>> ({ uint64 __lo, __hi; \
>>>> __asm__("mulq %3"
>>>> : "=a" (__lo), "=d" (__hi) /* output */
>>>> : "%0" (__x), "rm" (__y) /* input */)
>>>> ; __hi; /* return value*/
>>>> })
>>>>
>>>> So what we want is a function that multiplies two 64
>>>> bit values together and returns the upper 64 bit value.
>>>>
>>>> The asm becomes an inline for SunStudio as follows:
>>>>
>>>> .inline __MULH64, 8
>>>> movq %rdi,%rax
>>>> mulq %rsi
>>>> movl %edx,%eax
>>>> .end
>>>>
>>> So now what I need is to decipher the next three lines...
>>>
>>> #define MUL64x32( __x,__y,__lo,__hi) asm("mulq %3" : "=a" (__lo),
>>> "=d" (__hi) : "%0" (__x), "rm" (__y) );
>>
>> I presume you know what mulq means.
[...]
> If this piece of code is multiplying a 64bit number * 32bit number
> then does one of the registers have to be 64 bit e.g movl %eax becomes
> movq %rax?
Sorry, yes. mulq is a 64-bit instruction, so I should have said 'rax'
and 'rdx' rather than 'eax' and 'edx' in there. Force of habit; I still
think of the 32-bit full width registers as the "full width registers."
Regards,
Daniel
--
Digital Infrastructure Solutions -- making IT simple, stable and secure
Phone: 0401 155 707 email: contact at digital-infrastructure.com.au
http://digital-infrastructure.com.au/
More information about the wellylug
mailing list