lkml.org 
[lkml]   [2009]   [Apr]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH] X86-32: Let gcc decide whether to inline memcpy was Re: New x86 warning
    On Wed, Apr 22, 2009 at 01:56:54PM -0700, Linus Torvalds wrote:
    >
    >
    > On Wed, 22 Apr 2009, Andi Kleen wrote:
    > >
    > > Modern gcc (and that is all that is supported now) should be able to
    > > generate this code on its own already. So if you call __builtin_* it
    > > will just work (that is what 64bit does) without that explicit code.
    >
    > Last time we tried that, it wasn't true. Gcc wouldn't inline even trivial
    > cases of constant sizes.

    AFAIK it's all true on 3.2+ when it can figure out the alignment
    (but some gcc versions had problems passing the alignment around e.g.
    through inlining), under the assumption that out of line can do
    a better job with unaligned data. That's not true with my patch,
    but could be true in theory.

    Quick test here:

    char a[10];
    char b[2];
    char c[4];
    char d[8];

    short x;
    long y;

    char xyz[100];


    f()
    {
    #define C(x) memcpy(&x, xyz, sizeof(x));
    C(x)
    C(y)
    C(a)
    C(b)
    C(c)
    C(d)
    }

    and everything gets inlined with gcc 3.2 which is the oldest
    we still care about:

    gcc version 3.2.3

    movzwl xyz+8(%rip), %eax
    movzwl xyz(%rip), %ecx
    movq xyz(%rip), %rdx
    movw %ax, a+8(%rip)
    movw %cx, x(%rip)
    movw %cx, b(%rip)
    movl xyz(%rip), %eax
    movq %rdx, y(%rip)
    movq %rdx, a(%rip)
    movq %rdx, d(%rip)
    movl %eax, c(%rip)
    ret

    -Andi
    --
    ak@linux.intel.com -- Speaking for myself only.


    \
     
     \ /
      Last update: 2009-04-22 23:13    [W:0.025 / U:60.332 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site