This is the mail archive of the
cygwin-developers
mailing list for the Cygwin project.
Re: Bad codegen in pthread_mutex causing 100% cpu spin loop related to inline asm ilockcmpexchg
- From: Christopher Faylor <cgf-use-the-mailinglist-please at cygwin dot com>
- To: cygwin-developers at cygwin dot com
- Date: Thu, 28 May 2009 18:52:06 -0400
- Subject: Re: Bad codegen in pthread_mutex causing 100% cpu spin loop related to inline asm ilockcmpexchg
- References: <4A1EC4BC.9070104@gmail.com> <4A1EDCDB.8020005@gmail.com> <4A1F06F6.9000306@gmail.com>
- Reply-to: cygwin-developers at cygwin dot com
On Thu, May 28, 2009 at 10:49:42PM +0100, Dave Korn wrote:
>Dave Korn wrote:
>
>> This new version changes the approach to use an "m" constraint to refer
>> directly to the contents of *t, and not hope the compiler can infer the
>> relationship between the address of t in operand 2 and the content of t in
>> operand 1. It requires rewriting the instruction template, and will generate
>> more different addressing modes than the original, which would only create
>> register-indirect addressing:
>>
>> extern __inline__ long
>> ilockcmpexch (volatile long *t, long v, long c)
>> {
>> register int __res;
>> __asm__ __volatile__ ("\n\
>> lock cmpxchgl %2,%1\n\
>> ": "=a" (__res), "+m" (*t) : "q" (v), "0" (c) : "memory", "cc");
>> return __res;
>> }
>
> Then I thought, why not go the whole hog and get rid of the matching
>constraints altogether by making __res an in/out operand and passing 'c' in
>it. So I tried this:
I got these functions from some well-known source like linux, glibc,
uclibc or freebsd. We can just go back to the same well and be assured
that we are getting something that is tested.
cgf