qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paul Brook <paul@codesourcery.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] testandset asm fix
Date: Sun, 6 Feb 2005 14:43:38 +0000	[thread overview]
Message-ID: <200502061443.38384.paul@codesourcery.com> (raw)

The inline assembly used for the x86/x86-64 host testandset routine is bogus.
The operand constraints are wrong (Fails to compile at -O0).
Also the return value is incorrect. It should return 0 if the lock was 
successfully acquired. 

Patch below fixes it. The additional sete test is unnecessary, we can just use 
the comparison/writeback value.

Paul

Index: exec-all.h
===================================================================
RCS file: /cvsroot/qemu/qemu/exec-all.h,v
retrieving revision 1.26
diff -u -p -r1.26 exec-all.h
--- exec-all.h 10 Jan 2005 23:23:48 -0000 1.26
+++ exec-all.h 6 Feb 2005 14:35:43 -0000
@@ -392,28 +392,24 @@ static inline int testandset (int *p)
 #ifdef __i386__
 static inline int testandset (int *p)
 {
-    char ret;
-    long int readval;
-    
-    __asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0"
-                          : "=q" (ret), "=m" (*p), "=a" (readval)
-                          : "r" (1), "m" (*p), "a" (0)
-                          : "memory");
-    return ret;
+    long int readval = 0;
+
+    __asm__ __volatile__ ("lock; cmpxchgl %2, %0"
+                          : "+m" (*p), "+a" (readval)
+                          : "r" (1));
+    return readval;
 }
 #endif
 
 #ifdef __x86_64__
 static inline int testandset (int *p)
 {
-    char ret;
-    int readval;
-    
-    __asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0"
-                          : "=q" (ret), "=m" (*p), "=a" (readval)
-                          : "r" (1), "m" (*p), "a" (0)
-                          : "memory");
-    return ret;
+    long int readval = 0;
+
+    __asm__ __volatile__ ("lock; cmpxchgl %2, %0"
+                          : "+m" (*p), "+a" (readval)
+                          : "r" (1));
+    return readval;
 }
 #endif
 

             reply	other threads:[~2005-02-06 15:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-06 14:43 Paul Brook [this message]
2005-02-07 13:03 ` [Qemu-devel] testandset asm fix Piotras
2005-02-07 13:47 ` Fabrice Bellard
2005-02-07 14:26   ` Piotras
2005-02-07 14:28     ` Piotras
2005-02-07 17:34   ` Lennert Buytenhek
2005-02-07 18:46     ` Fabrice Bellard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200502061443.38384.paul@codesourcery.com \
    --to=paul@codesourcery.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).