Author: Dieter Buerssner
Date: 14:26:07 12/09/02
Go up one level in this thread
On December 09, 2002 at 17:15:12, Robert Hyatt wrote:
>void __inline__ LockX86(volatile int * lock) {
> int dummy;
> asm __volatile__ (
> "1: movl $1, %0" "\n\t"
> " xchgl (%1), %0" "\n\t"
> " test %0, %0" "\n\t"
> " jz 3f" "\n\t"
> "2: pause" "\n\t"
> " movl (%1), %0" "\n\t"
> " test %0, %0" "\n\t"
> " jz 2b" "\n\t"
> " jmp 1b" "\n\t"
> "3:" "\n\t"
> : "=&r" (dummy)
> : "r" (lock)
> : "cc");
: "cc", "memory");
>}
>
>I tried changing the "r" to "q" to limit the register choices in case esi/edi
>won't work
>in some of the above, but I don't see anything wrong. If I remove the
>__inline__ then it
>seems to work just fine. With the inline in, it breaks things in unpredictable
>ways...
>
>Anything obvious (or not-so-obvious) that jumps out at you?
I don't know much about locks. Have you tried to give the lock prefix in front
of the xchgl? To me it looks, like any register should do, so I agree with "r"
(and "q" seems unneeded).
I never tried "=&r". I allways used "=r&" when the "&" was needed. However I
cannot remember, if this is needed. Another formal error, is that you don't tell
the compiler, that you change memory. However, I don't know, if he actually uses
this info. See the line above in the code.
I would use testl instead of test, but I think, it won't make a difference.
Regards,
Dieter
This page took 0.01 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.