lkml.org 
[lkml]   [2010]   [Dec]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: Big git diff speedup by avoiding x86 "fast string" memcmp
From
On Fri, Dec 17, 2010 at 1:03 AM, Boaz Harrosh <bharrosh@panasas.com> wrote:
> On 12/16/2010 03:13 PM, Nick Piggin wrote:
> static inline int dentry_memcmp_long(const unsigned char *cs,
>                                const unsigned char *ct, ssize_t count)
> {
>        int ret;
>        const unsigned long *ls = (const unsigned long *)cs;
>        const unsigned long *lt = (const unsigned long *)ct;
>
>        while (count > 8) {
>                ret = (*cs != *ct);
>                if (ret)
>                        break;
>                cs++;
>                ct++;
>                count-=8;
>        }
>        if (count) {
>                unsigned long t = *ct & ((0xffffffffffffffff >> ((8 - count) * 8))
>                ret = (*cs != t)
>        }
>
>        return ret;
> }
>
> Same as yours but just to avoid the branch inside the loop
> and slightly smaller code.

That's true, it should make the branch more predictable too. Well,
maybe. I'm going to leave it as-is for now, but I would welcome any
test results or ideas for improvements.


> BTW: On some ARCHs ++foo is faster than foo++
>     and Also, is there a reason not to write the above loop as:
>
>     while(c-- && (ret = (*cs++ != *ct++)))
>                ;

gcc should turn it into the same thing these days. I prefer avoiding
expressions with side effects in control statements (other than a
simple counter).

Thanks,
Nick
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2010-12-16 15:19    [W:0.046 / U:0.464 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site