From: Matt Turner Subject: [RFC libdrm] Use __sync_val_compare_and_swap to implement DRM_CAS Date: Thu, 28 Oct 2010 19:59:13 -0400 Message-ID: <20101028235913.GA18345@Sempron.nc.rr.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0594929746==" Return-path: Received: from mail-gy0-f177.google.com (mail-gy0-f177.google.com [209.85.160.177]) by gabe.freedesktop.org (Postfix) with ESMTP id 0CDBD9E75C for ; Thu, 28 Oct 2010 16:59:05 -0700 (PDT) Received: by gyb11 with SMTP id 11so1798859gyb.36 for ; Thu, 28 Oct 2010 16:59:05 -0700 (PDT) List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org Errors-To: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org To: dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org --===============0594929746== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Qxx1br4bt0+wmkIi" Content-Disposition: inline --Qxx1br4bt0+wmkIi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Can we use gcc's __sync_val_compare_and_swap to implement DRM_CAS? (If so, do we actually need the __sync_val version, or can we use __sync_bool?) I just threw the patch together in two minutes, so I've got no idea if it's right, just looking for feedback. The purpose of this is to remove a lot of inline assembly that hasn't been touched since the file was added in 2004, including some awesome already-assembled SPARC instructions. Apparently someone had this idea before me. Way before me, as this code already exists in the Itanium section, though commented out for some reason long forgotten. I don't have any idea when gcc added this. I just said 4.0, but this must be wrong, given the previous paragraph. http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html --- xf86drm.h | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/xf86drm.h b/xf86drm.h index 9b89f56..1459b5a 100644 --- a/xf86drm.h +++ b/xf86drm.h @@ -333,7 +333,12 @@ typedef struct _drmSetVersion { #define DRM_LOCK_HELD 0x80000000U /**< Hardware lock is held */ #define DRM_LOCK_CONT 0x40000000U /**< Hardware lock is contended */ =20 -#if defined(__GNUC__) && (__GNUC__ >=3D 2) +#if defined(__GNUC__) && (__GNUC__ >=3D 4) + +#define DRM_CAS(lock, old, new, __ret) \ + __ret =3D __sync_val_compare_and_swap(i&__drm_dummy_lock(lock), (old), (n= ew)) !=3D (old) + +#elif defined(__GNUC__) && (__GNUC__ >=3D 2) # if defined(__i386) || defined(__AMD64__) || defined(__x86_64__) || defin= ed(__amd64__) /* Reflect changes here to drmP.h */ #define DRM_CAS(lock,old,new,__ret) \ --=20 1.7.2.2 --Qxx1br4bt0+wmkIi Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) iEYEARECAAYFAkzKDlEACgkQTVUdg23rv52pjQCfRuLKyrRXPa2R6G9gXnL+rBux kM4AnAk3SjAIxROLpM0yIKVKIp+/t/8D =P94V -----END PGP SIGNATURE----- --Qxx1br4bt0+wmkIi-- --===============0594929746== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/dri-devel --===============0594929746==--