Re: Semaphore assembly-code bug

From: Denis Vlasenko
Date: Sat Oct 30 2004 - 16:01:49 EST


On Saturday 30 October 2004 20:53, Linus Torvalds wrote:
> > > > movl 4(%esp),%ecx
> > > > movl 8(%esp),%edx
> > > > movl 12(%esp),%eax
> > > > addl $16,%esp
> > > >
> > > > which is also one of the biggest alternatives.
> > >
> > > For K8 it should be the fastest way. K7 probably too.
> >
> > Pity. I always loved 1 byte insns :)
>
> I personally am a _huge_ believer in small code.

Thankfully you are not alone - a horde of uclibc/dietlibc/busybox
users shares these views. Also see http://smarden.org/pape/

> The sequence
>
> popl %eax
> popl %ecx
> popl %edx
> popl %eax
>
> is four bytes. In contrast, the three moves and an add is 15 bytes. That's
> almost 4 times as big.
>
> And size _does_ matter. The extra 11 bytes means that if you have six of
> these sequences in your program, you are pretty much _guaranteed_ one more
> icache miss from memory. That's a few hundred cycles these days.
> Considering that you _maybe_ won a cycle or two each time it was executed,
> it's not at all clear that it's a win, except in benchmarks that have huge
> repeat-rates. Real life doesn't usually have that. In many real-life
> schenarios, repeat rates are in the tens of hundreds for most code...

If only glibc / X / KDE / OpenOffice (ugggh) people could hear you more...

PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME CPU COMMAND
15364 root 15 0 38008 26M 28496 S 0,0 10,8 0:57 0 kmail
20022 root 16 0 40760 24M 23920 S 0,1 10,0 0:04 0 mozilla-bin
1627 root 14 -1 71064 19M 53192 S < 0,1 7,9 3:16 0 X
1700 root 15 0 25348 16M 23508 S 0,1 6,5 0:46 0 kdeinit
3578 root 15 0 24032 14M 21524 S 0,5 5,8 0:23 0 konsole
--
vda

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