From owner-freebsd-alpha@FreeBSD.ORG Thu Aug 7 06:43:20 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 64F3637B401 for ; Thu, 7 Aug 2003 06:43:20 -0700 (PDT) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id A1EA243FA3 for ; Thu, 7 Aug 2003 06:43:19 -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 h77DhIuN002814 for ; Thu, 7 Aug 2003 09:43:18 -0400 (EDT) Date: Thu, 7 Aug 2003 09:43:18 -0400 (EDT) From: Daniel Eischen X-Sender: eischen@pcnet5.pcnet.com To: alpha@freebsd.org Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: 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 13:43:20 -0000 [ I'm not subscribed to alpha@; please keep me on the CC ] I need an atomic swap function for libpthread. Here's my hack of an implementation: /* * Atomic swap: * Atomic (tmp = *dst, *dst = val), then *res = tmp * * void atomic_swap_long(long *dst, long val, long *res); */ static __inline void atomic_swap_long(volatile long *dst, long val, long *res) { u_int64_t result; __asm __volatile ( "1:\tldq_l %0,%1\n\t" "stq_c %2,%1\n\t" "beq %2,2f\n\t" /* Why is this beq instead of bne 1b? */ "br 3f\n" "2:\tbr 1b\n" "3:\n" : "=&r" (result) : "m" (*dst), "r" (val) : "memory"); *res = result; } As annotated above, there seems to be one more branch than necessary. Can someone look this over for me? I really don't quite know what I'm doing when it comes to inline assembly. -- Dan Eischen