Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 2 Aug 2013 10:53:48 +0200
From:      Jilles Tjoelker <jilles@stack.nl>
To:        Jung-uk Kim <jkim@FreeBSD.org>
Cc:        svn-src-projects@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r253875 - in projects/atomic64/sys: amd64/include i386/include
Message-ID:  <20130802085348.GA49944@stack.nl>
In-Reply-To: <201308012351.r71NpKxk092536@svn.freebsd.org>
References:  <201308012351.r71NpKxk092536@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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 = (<type>)1 << s % (sizeof(<type>) * 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130802085348.GA49944>