1*8a716df0Smartin /*	$NetBSD: atomic_cas_64_cas.c,v 1.2 2014/02/18 12:23:07 martin Exp $	*/
2749ebe7aSmartin 
3749ebe7aSmartin /*-
4749ebe7aSmartin  * Copyright (c) 2014 The NetBSD Foundation, Inc.
5749ebe7aSmartin  * All rights reserved.
6749ebe7aSmartin  *
7749ebe7aSmartin  * This code is derived from software contributed to The NetBSD Foundation
8749ebe7aSmartin  * by Jason R. Thorpe.
9749ebe7aSmartin  *
10749ebe7aSmartin  * Redistribution and use in source and binary forms, with or without
11749ebe7aSmartin  * modification, are permitted provided that the following conditions
12749ebe7aSmartin  * are met:
13749ebe7aSmartin  * 1. Redistributions of source code must retain the above copyright
14749ebe7aSmartin  *    notice, this list of conditions and the following disclaimer.
15749ebe7aSmartin  * 2. Redistributions in binary form must reproduce the above copyright
16749ebe7aSmartin  *    notice, this list of conditions and the following disclaimer in the
17749ebe7aSmartin  *    documentation and/or other materials provided with the distribution.
18749ebe7aSmartin  *
19749ebe7aSmartin  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20749ebe7aSmartin  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21749ebe7aSmartin  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22749ebe7aSmartin  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23749ebe7aSmartin  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24749ebe7aSmartin  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25749ebe7aSmartin  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26749ebe7aSmartin  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27749ebe7aSmartin  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28749ebe7aSmartin  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29749ebe7aSmartin  * POSSIBILITY OF SUCH DAMAGE.
30749ebe7aSmartin  */
31749ebe7aSmartin 
32*8a716df0Smartin #if !defined(_KERNEL) && !defined(_STANDALONE)
33749ebe7aSmartin #include <stdbool.h>
34*8a716df0Smartin #endif
35749ebe7aSmartin #include <sys/atomic.h>
36749ebe7aSmartin 
37749ebe7aSmartin #ifdef __HAVE_ATOMIC64_OPS
38749ebe7aSmartin 
39749ebe7aSmartin bool bool_compare_and_swap_8(volatile uint64_t *, uint64_t, uint64_t, ...)
40749ebe7aSmartin     asm("__sync_bool_compare_and_swap_8");
41749ebe7aSmartin 
42749ebe7aSmartin bool
bool_compare_and_swap_8(volatile uint64_t * addr,uint64_t oldval,uint64_t newval,...)43749ebe7aSmartin bool_compare_and_swap_8(volatile uint64_t *addr, uint64_t oldval,
44749ebe7aSmartin 	uint64_t newval, ...)
45749ebe7aSmartin {
46749ebe7aSmartin 	return atomic_cas_64(addr, oldval, newval) == oldval;
47749ebe7aSmartin }
48749ebe7aSmartin 
49749ebe7aSmartin #endif
50