svn commit: r253875 - in projects/atomic64/sys: amd64/include i386/include
Jilles Tjoelker
jilles at stack.nl
Fri Aug 2 08:53:51 UTC 2013
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
More information about the svn-src-projects
mailing list