[PATCH, x86_64]: Provide longlong.h definitions for 128bit operations

Uros Bizjak ubizjak@gmail.com
Fri May 18 21:49:00 GMT 2007

Chris Lattner wrote:

> Don't you want:
> unsigned long long int t2(unsigned int a, unsigned int b)
> {
>        return (unsigned long long)a * b;
> }

Please find a testcase for muls below, implemented in asm and C. Again, 
a couple of strange moves are present at the end of a function, 
implemented in pure C.

--cut here--
typedef unsigned SI __attribute__ ((mode (SI)));
typedef unsigned DI __attribute__ ((mode (DI)));

#define umul_ppmm_c(w1, w0, u, v)               \
  {                                             \
    DI __c = (DI) u * v;                        \
    (w0) = (SI) (__c & 0xffffffff);             \
    (w1) = (SI) (__c >> 32);                    \

#define umul_ppmm_asm(w1, w0, u, v)                                     \
  __asm__ ("mull %3"                                                    \
           : "=a" ((SI) (w0)),                                          \
           "=d" ((SI) (w1))                                             \
           : "%0" ((SI) (u)),                                           \
           "rm" ((SI) (v)))

void test_c (SI a, SI b)
 volatile SI x, y;

 umul_ppmm_c (x, y, a, b);

void test_asm (SI a, SI b)
 volatile SI x, y;

 umul_ppmm_asm (x, y, a, b);
--cut here--

gcc -O2 -fomit-frame-pointer:

        subl    $16, %esp
        movl    24(%esp), %eax
        mull    20(%esp)
        movl    %eax, 8(%esp)
        movl    %edx, %eax
        xorl    %edx, %edx
        movl    %eax, 12(%esp)
        addl    $16, %esp

        subl    $16, %esp
        movl    20(%esp), %eax
        mull 24(%esp)
        movl    %eax, 8(%esp)
        movl    %edx, 12(%esp)
        addl    $16, %esp

So even for wide multiply, it is better to stay with asm implementation ATM.


More information about the Gcc-patches mailing list