Re: [RFC PATCH] pre-process: add __VA_OPT__ support
Al Viro <[email protected]> Thu, 19 Mar 2026 05:34:57 +0000
| Newsgroups | org.kernel.vger.linux-sparse |
|---|---|
| Message-ID | <20260319053457.GH3836593@ZenIV> |
On Wed, Mar 18, 2026 at 09:07:17PM -0700, Linus Torvalds wrote:
> I looked at clang at one point, and iirc it generated *much* better
> code, because I think it does tth esmart thing, which is to get rid of
> the notion of bitfields as quickly as possible, and then doing just
> regular integer optimizations.
FWIW, with the local tokenizer patches the single worst spot at the moment
(both for clang and for gcc build) is this:
p = &hash_table[hash];
while ((ident = *p) != NULL) {
if (ident->len == (unsigned char) len) {
in create_hashed_ident(). This is from clang build, where
it's inlined into tokenize_stream():
0.14 │ mov (%rdx,%rcx,8),%rax
12.34 │ mov %r12d,%r15d
0.02 │ test %rax,%rax
0.43 │ ↓ je 33e
│ mov %rsp,%r14
0.29 │ ↓ jmp 319
│ nop
│310:┌─→mov 0x0(%r13),%rax
2.00 │ │ test %rax,%rax
0.07 │ │↓ je 345
0.00 │319:│ mov %rax,%r13
│ │if (ident->len == (unsigned char) len) {
0.19 │ ├──cmp %r12b,0x10(%rax)
16.86 │ └──jne 310
and this is gcc build, where it's not inlined, so the percentages are
several times higher (out of 5.9% vs. out of 17.1% on the profiles I'm
looking at):
│ p = &hash_table[hash]; ▒
0.77 │ mov (%rax,%rdx,8),%rbx ▒
│ while ((ident = *p) != NULL) { ▒
27.77 │ test %rbx,%rbx ◆
0.98 │ ↓ jne 3b ▒
│ ↓ jmp c2 ▒
│ nop ▒
│ ident_hit++; ▒
│ return ident; ▒
│ } ▒
│ next: ▒
│ //misses++; ▒
│ p = &ident->next; ▒
0.00 │30:┌─→mov (%rbx),%rax ▒
│ │while ((ident = *p) != NULL) { ▒
6.11 │ │ test %rax,%rax ▒
0.24 │ │↓ je 70 ▒
│ │ mov %rax,%rbx ▒
│ │if (ident->len == (unsigned char) len) { ▒
0.81 │3b:├──cmp %bpl,0x10(%rbx) ▒
50.82 │ └──jne 30 ▒
Most of the accesses are to single-element chain; it's not walking the
lists that hurts, it's the very first step. The profiles are for userland
cycles; looking for stalled-cycles-frontend gives exact same hotspots.
The next one is lookup_symbol(); there we also walk linked lists.
The only difference is that lists are often longer than one entry...
Not sure what can be done about either.