From owner-freebsd-alpha@FreeBSD.ORG Thu Aug 7 12:31:57 2003 Return-Path: Delivered-To: freebsd-alpha@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 19F0F37B407; Thu, 7 Aug 2003 12:31:57 -0700 (PDT) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id 30AF643F3F; Thu, 7 Aug 2003 12:31:56 -0700 (PDT) (envelope-from eischen@vigrid.com) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mail.pcnet.com (8.12.8/8.12.1) with ESMTP id h77JVtuN005586; Thu, 7 Aug 2003 15:31:55 -0400 (EDT) Date: Thu, 7 Aug 2003 15:31:55 -0400 (EDT) From: Daniel Eischen X-Sender: eischen@pcnet5.pcnet.com To: Marcel Moolenaar In-Reply-To: <20030807192426.GC559@athlon.pn.xcllnt.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: deischen@freebsd.org cc: "Portante, Peter" cc: alpha@freebsd.org Subject: Re: Atomic swap X-BeenThere: freebsd-alpha@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: deischen@freebsd.org List-Id: Porting FreeBSD to the Alpha List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Aug 2003 19:31:57 -0000 On Thu, 7 Aug 2003, Marcel Moolenaar wrote: > On Thu, Aug 07, 2003 at 03:06:33PM -0400, Portante, Peter wrote: > > Marcel, > > > > > atomic_swap_long(volatile long *dst, long val, long *res) > > > { > > > __asm ( "1: ldq_l t0,%0\n" > > > " mov %1,t1\n" > > > " stq_c t1,%0\n" > > > " beq t1,1b\n" > > > " stq t0,%3\n" > ^^^^^^^^^^^^^^^^^^^^ > > Whoops, typo: %3 should be %2. Yup, I caught that but didn't want to complain when something is handed to me on a silver platter ;-) > > > :: "m"(*dst), "r"(val), "m"(*res) : "memory"); > > > } > > > > > A word of caution on performing that stq without an MB before it: > > another processor cannot read that location and the destination > > location and assume anything about their contents based on what > > they read unless an MB is between them. > > Good point. I don't think we have to worry about it, though. This > function has a specific usage (see src/lib/libpthread/sys/lock.c). > If I understand the code correctly, *res is never used other than > the caller of atomic_swap_long that writes to *res. Yes, perhaps the interface should be: long atomic_swap_long(volatile long *dst, long val) instead of having the result as the 3rd argument. But it's already used this way in libpthread, so I didn't want to change it. I can always do that later. Hmm, it would be nice just to have atomic_swap (or atomic_xchg, or whatever you want to call it) in . -- Dan Eischen