From owner-freebsd-hackers Thu Jul 26 17:29:22 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from k7.locore.ca (k7.locore.ca [198.96.117.169]) by hub.freebsd.org (Postfix) with ESMTP id 4B6A737B405; Thu, 26 Jul 2001 17:29:19 -0700 (PDT) (envelope-from jake@k7.locore.ca) Received: from k7.locore.ca (localhost [127.0.0.1]) by k7.locore.ca (8.11.4/8.11.4) with ESMTP id f6R0ax916080; Thu, 26 Jul 2001 20:36:59 -0400 (EDT) (envelope-from jake@k7.locore.ca) Message-Id: <200107270036.f6R0ax916080@k7.locore.ca> X-Mailer: exmh version 2.3.1 01/18/2001 with nmh-1.0.4 To: Arun Sharma Cc: John Baldwin , hackers@FreeBSD.ORG Subject: Re: Need a clean room implementation of this function In-Reply-To: Message from Arun Sharma of "Thu, 26 Jul 2001 16:22:26 PDT." <20010726162226.A23558@sharmas.dhs.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Thu, 26 Jul 2001 20:36:59 -0400 From: Jake Burkholder Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > On Thu, Jul 26, 2001 at 03:49:58PM -0700, John Baldwin wrote: > > > That does set, not test-and-set. What I want is exactly what the Intel > > > BTS instruction does: atomically test and set a bit. > > > > Unfortunately that is very ia32 specific. The code would be more > > friendly on alpha and ia64 at least if the algo was changed to use > > cmpset on a word instead of test-and-set of a bit. > > Another way to look at it is as an IA-32 specific optimization. For > other architectures, we could just use the code you posted earlier. > If I wasn't going to use a non-blocking synchronization loop, this is how I'd do it. static __inline int test_and_set_bit(int nr, volatile void *addr) { char c; __asm __volatile("lock ; bts %2, %1 ; setc %0" : "=br" (c) : "m" (*(volatile int *)addr), "r" (nr)); return (c != 0); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message