lkml.org 
[lkml]   [2011]   [Aug]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    SubjectRE: [PATCH] add slice by 8 algorithm to crc32.c
    Date
    > >
    > > >
    > > > >
    > > > > Modify all 'i' loops from for (i = 0; i < foo; i++) { ... } to for
    (i =
    > > foo
    > > > > - 1; i >= 0; i--) { ... }
    > > >
    > > > That should be (i = foo; i ; --i) { ... }
    > >
    > > Shouldn't make much difference, branch on zero bit or branch on sign
    bit.
    > > But at the end of the day didn't help on Nehalem.

    I figured out why "for (i = 0; i < len; i++) {...}" is faster than "for (;
    len; len--) {...}" on my system.
    The current code is

    for (; Ien; len--) {
    load *++p
    ...
    }

    Which turns into (in fake assembly)

    top:
    dec len
    inc p
    load p
    ...
    test len
    branch neq top

    But when I replace that with

    for(i = 0; i < len; i++) {
    load *++p
    ...
    }

    Gcc turns it into

    top:
    load p[i]
    i++
    ...
    compare i, len
    branch lt top

    which is fewer instructions and i++ is well scheduled. Incrementing the
    pointer has been moved out of the loop.



    \
     
     \ /
      Last update: 2011-08-05 19:29    [W:0.023 / U:30.680 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site