From owner-svn-src-projects@FreeBSD.ORG Fri Aug 2 08:53:51 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 50A5EB94; Fri, 2 Aug 2013 08:53:51 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 174C62C1A; Fri, 2 Aug 2013 08:53:51 +0000 (UTC) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id A612E3592F7; Fri, 2 Aug 2013 10:53:48 +0200 (CEST) Received: by snail.stack.nl (Postfix, from userid 1677) id 8C5DB28494; Fri, 2 Aug 2013 10:53:48 +0200 (CEST) Date: Fri, 2 Aug 2013 10:53:48 +0200 From: Jilles Tjoelker To: Jung-uk Kim Subject: Re: svn commit: r253875 - in projects/atomic64/sys: amd64/include i386/include Message-ID: <20130802085348.GA49944@stack.nl> References: <201308012351.r71NpKxk092536@svn.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201308012351.r71NpKxk092536@svn.freebsd.org> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: svn-src-projects@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Aug 2013 08:53:51 -0000 On Thu, Aug 01, 2013 at 11:51:20PM +0000, Jung-uk Kim wrote: > Author: jkim > Date: Thu Aug 1 23:51:20 2013 > New Revision: 253875 > URL: http://svnweb.freebsd.org/changeset/base/253875 > Log: > Add a new atomic operation atomic_testandset for x86. This operation > atomically tests and sets a bit, i. e., > tmp = (*p & v) != 0; *p |= v; return (tmp) > where > > v = ()1 << s % (sizeof() * NBBY) > Modified: > projects/atomic64/sys/amd64/include/atomic.h > projects/atomic64/sys/i386/include/atomic.h > Modified: projects/atomic64/sys/amd64/include/atomic.h > ============================================================================== > --- projects/atomic64/sys/amd64/include/atomic.h Thu Aug 1 23:38:57 2013 (r253874) > +++ projects/atomic64/sys/amd64/include/atomic.h Thu Aug 1 23:51:20 2013 (r253875) > [snip] > +static __inline int > +atomic_testandset_int(volatile u_int *p, int v) > +{ > + u_char res; > + > + __asm __volatile( > + " " MPLOCKED " " > + " btsl %2, %1 ; " > + " setc %0 ; " > + "# atomic_testandset_int" > + : "=r" (res), /* 0 */ > + "=m" (*p) /* 1 */ > + : "r" (v), /* 2 */ > + "m" (*p) /* 3 */ > + : "cc"); > + return (res); > +} > [snip] On most processors, a BTS on memory is faster if the bit number is an immediate than if it is a register. This could be permitted in the constraint. Side effect: on the machine code level, the immediate is limited to the number of bits in the operand size; only few assemblers adjust the operand's offset to compensate. Therefore, behaviour may change for bit numbers greater than 31 or 63. -- Jilles Tjoelker