Re: [tip:x86/asm] x86/i386: Use less assembly in strlen(), speedthings up a bit

From: Linus Torvalds
Date: Mon Dec 12 2011 - 13:55:22 EST


On Mon, Dec 12, 2011 at 10:37 AM, tip-bot for Alexey Dobriyan
<adobriyan@xxxxxxxxx> wrote:
>
> x86/i386: Use less assembly in strlen(), speed things up a bit

We could probably remove the thing entirely, and just use the generic
strlen. Some of the rep instruction usage is just purely historic,
there's little point.

Using "repne; scasb" is possibly worth it when inlined. And especially
with the change in this patch-set, where inlining also combines with
things like expression simplification, and then things like
"strlen(s)+1" (common for sizing allocations) the compiler can
actually remove the "-1" part entirely. Then the advantage of 'repne
scas' is that it's short.

But for out-of-line, we might actually be better off with just a
traditional loop. Not because we can do multiple bytes in a go (most
kernel strings are likely short enough that it's not a big deal), but
simply because 'repne scas' is not generally all that fast.

I dunno. strlen() usually isn't very hot, so it probably doesn't
matter. The really hot paths tend to do something like computing a
hash at the same time as checking the length of the string or need
something more complex anyway (ie the "hash and find '\0' or '/' in a
pathname" that path walking does). Pure strlen() is reasonably rare.

So it probably doesn't matter. The patch looks like a nice cleanup.

Linus
--
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/