tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: [PATCH] ld.elf_so - Cache objects checked

On 02/24/10 20:56, David Laight wrote:
On Wed, Feb 24, 2010 at 08:48:00PM +0000, Roy Marples wrote:

Also a C loop for the name compare works faster than strcmp().

I would be suprised if this would help that much here.

It is a massive gain!
gcc inlines strcmp() to a 'rep cmpsb' instruction.
Since what is being searched is a hashed list, it almost always fails
on the first byte.
However the setup cost for 'rep cmpsb' is something like 40 clocks
on some x86 cpus (netburst P4 are very bad).

Since the string table hash table has slightly less that 'the power of
2 below the number of strings' entries, you do about 1.5 such compares
per shared library during symbol lookup.

One the symbol tables info for each shared library has been faulted in,
the name compare dominates the symbol lookup.

So we currently have this in symbol.c

name[1] == strp[1] && !strcmp(name, strp)

Would swapping this out to a C loop still be a overall speed gain vs any concerns regarding correctness and readability (which I don't personally have a concern with)?

The other strcmp are nothing todo with hash tables that I can see and as such aren't relevant to this discussion.



Home | Main Index | Thread Index | Old Index