From owner-freebsd-alpha@FreeBSD.ORG Thu Aug 7 08:11:10 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 292B037B401; Thu, 7 Aug 2003 08:11:10 -0700 (PDT) Received: from zmamail04.zma.compaq.com (mailout.zma.compaq.com [161.114.64.104]) by mx1.FreeBSD.org (Postfix) with ESMTP id 44E4443F75; Thu, 7 Aug 2003 08:11:09 -0700 (PDT) (envelope-from peter.portante@hp.com) Received: from tayexg11.americas.cpqcorp.net (tayexg11.americas.cpqcorp.net [16.103.130.96]) by zmamail04.zma.compaq.com (Postfix) with ESMTP id A19C07E2B; Thu, 7 Aug 2003 11:11:08 -0400 (EDT) Received: from tayexc17.americas.cpqcorp.net ([16.103.130.15]) by tayexg11.americas.cpqcorp.net with Microsoft SMTPSVC(5.0.2195.6673); Thu, 7 Aug 2003 11:11:08 -0400 X-MimeOLE: Produced By Microsoft Exchange V6.0.6375.0 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Thu, 7 Aug 2003 11:11:07 -0400 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Atomic swap Thread-Index: AcNc6eX1UqPNxXkxQeaTQEJdjGjz9gABprji From: "Portante, Peter" To: X-OriginalArrivalTime: 07 Aug 2003 15:11:08.0514 (UTC) FILETIME=[2131FC20:01C35CF6] cc: alpha@freebsd.org Subject: RE: Atomic swap X-BeenThere: freebsd-alpha@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list 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 15:11:10 -0000 Dan, I don't think you want to do the stq_c if the location already holds the = same value. Instead, check the loaded value to see if it is the same as = the value to be stored, and branch out of the loop returning the result = if it is they are the same. And starting with EV56, the need to do the = branch forward/branch back logic has been removed. And EV6 and later = CPUs do such a good job predicting the branching that it is not worth = the instruction stream space when that space can be used to avoid a = stq_c. Additionally, the stq_c destroys the contents of %2, so you need to move = the value in %2 into another register for use in the stq_c. I don't = know how to do that in the ASM, so I just used raw register names below, = highlighted in red. -Peter > /* > * Atomic swap: > * Atomic (tmp =3D *dst, *dst =3D val), then *res =3D tmp > * > * void atomic_swap_long(long *dst, long val, long *res); > */ > static __inline=20 > void atomic_swap_long(volatile long *dst, long val, long *res) > { > u_int64_t result; >=20 > __asm __volatile ( > "1:\tldq_l %0,%1\n\t" "mov %2,r1\n\t" /* Hide under the load latency */ "cmpeq %0,%2,r0\n\t" "bne r0,3f\n\t" /* Branches out are ok, but not to targets within = ld_l/st_c */ > "stq_c r1,%1\n\t" > "beq r1,1b\n\t" > "3:\n" > : "=3D&r" (result) > : "m" (*dst), "r" (val) > : "memory"); >=20 > *res =3D result; > } >=20