Re: Semaphore assembly-code bug

From: Gabriel Paubert
Date: Fri Oct 29 2004 - 20:58:44 EST


On Fri, Oct 29, 2004 at 07:46:06AM -0700, Linus Torvalds wrote:
>
>
> On Fri, 29 Oct 2004, linux-os wrote:
> >
> > Linus, please check this out.
>
> Yes, I concur. However, I'd suggest changing the "addl $4,%esp" into a
> "popl %ecx", which is smaller and apparently faster on some CPU's (ecx
> obviously gets immediately overwritten by the next popl).

Rather popl %eax or popl %edx then, a basic and MMX Pentium
cannot pair:

popl %ecx
popl %ecx

for the simple reason that two instructions that have the
same destination register can't be paired.

OTOH, the other argument about reading or not memory in
this thread are a red herring. An additional memory read
is cheap for data that is guaranteed to be in a cache line
used by adjacent (in time) instructions.

Otherwise regparm(1) might even be better, movl %ecx,%eax is
the same size as push+pop, is faster, and may even reduce
stack usage by 4 bytes.

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