Re: Big git diff speedup by avoiding x86 "fast string" memcmp
From: Nick Piggin
Date: Thu Dec 16 2010 - 09:15:52 EST
On Fri, Dec 17, 2010 at 1:03 AM, Boaz Harrosh <bharrosh@xxxxxxxxxxx> 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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/