This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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:

test_c:
       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
       ret

test_asm:
       subl    $16, %esp
       movl    20(%esp), %eax
#APP
       mull 24(%esp)
#NO_APP
       movl    %eax, 8(%esp)
       movl    %edx, 12(%esp)
       addl    $16, %esp
       ret

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

Uros.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]