[wellylug] asm stylings?

Rob Giltrap rob at kiwihq.com
Sun Feb 18 17:00:34 NZDT 2007


Daniel Pittman wrote:
> Rob Giltrap <rob at kiwihq.com> writes:
>
>   
>> Anyone on the list familiar with C code including GCC asm code?
>>
>> I got a small bit of asm code I don't understand and need to convert
>> over to something readable by SunStudio C compiler.
>>
>> If anyone can lend their knowledge I would greatly appreciate it.
>>     
>
> I am far from expert at GCC inline assembler and know zero about the
> SunStudio version, but I can probably help you understand what the
> snippet is doing -- which means you only need write the Sun part.
>
> Post it here and we will see what we can do.
>
>      Daniel
>   
Okay here goes. First the example...

> #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) );

#define MUL_LOHI64(__x,__y,__lo,__hi)    asm("mulq %3" : "=a" (__lo), 
"=d" (__hi) : "%0" (__x), "rm" (__y) );

#define SQR_LOHI64(__x,    __lo,__hi)    asm("mulq %0" : "=a" (__lo), 
"=d" (__hi) : "0"  (__x) );

This link provides some useful information on decoding asm instructions....

http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html

Any help greatly appreciated.

Thanks, Rob.




More information about the wellylug mailing list