1*504e8e68Sjoerg /* $NetBSD: atomic_and_64_cas.c,v 1.10 2014/06/23 21:53:45 joerg Exp $ */
279085586Sad
379085586Sad /*-
479085586Sad * Copyright (c) 2007 The NetBSD Foundation, Inc.
579085586Sad * All rights reserved.
679085586Sad *
779085586Sad * This code is derived from software contributed to The NetBSD Foundation
879085586Sad * by Jason R. Thorpe.
979085586Sad *
1079085586Sad * Redistribution and use in source and binary forms, with or without
1179085586Sad * modification, are permitted provided that the following conditions
1279085586Sad * are met:
1379085586Sad * 1. Redistributions of source code must retain the above copyright
1479085586Sad * notice, this list of conditions and the following disclaimer.
1579085586Sad * 2. Redistributions in binary form must reproduce the above copyright
1679085586Sad * notice, this list of conditions and the following disclaimer in the
1779085586Sad * documentation and/or other materials provided with the distribution.
1879085586Sad *
1979085586Sad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2079085586Sad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2179085586Sad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2279085586Sad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2379085586Sad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2479085586Sad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2579085586Sad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2679085586Sad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2779085586Sad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2879085586Sad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2979085586Sad * POSSIBILITY OF SUCH DAMAGE.
3079085586Sad */
3179085586Sad
3279085586Sad #include "atomic_op_namespace.h"
3379085586Sad
3479085586Sad #include <sys/atomic.h>
3579085586Sad
36695c2bc2Sad #ifdef __HAVE_ATOMIC64_OPS
37695c2bc2Sad
388ee8f2a2Sjoerg uint64_t fetch_and_and_8(volatile uint64_t *, uint64_t, ...)
398ee8f2a2Sjoerg asm("__sync_fetch_and_and_8");
4056b80ae3Smatt
4156b80ae3Smatt uint64_t
fetch_and_and_8(volatile uint64_t * addr,uint64_t val,...)428ee8f2a2Sjoerg fetch_and_and_8(volatile uint64_t *addr, uint64_t val, ...)
4379085586Sad {
4479085586Sad uint64_t old, new;
4579085586Sad
4679085586Sad do {
4779085586Sad old = *addr;
4879085586Sad new = old & val;
4979085586Sad } while (atomic_cas_64(addr, old, new) != old);
507544d0a2Smatt return old;
5179085586Sad }
5279085586Sad
5356b80ae3Smatt void
atomic_and_64(volatile uint64_t * addr,uint64_t val)5456b80ae3Smatt atomic_and_64(volatile uint64_t *addr, uint64_t val)
5556b80ae3Smatt {
568ee8f2a2Sjoerg (void) fetch_and_and_8(addr, val);
5756b80ae3Smatt }
5856b80ae3Smatt
59*504e8e68Sjoerg __strong_alias(__atomic_fetch_and_8,__sync_fetch_and_and_8)
60*504e8e68Sjoerg
6179085586Sad #undef atomic_and_64
6279085586Sad atomic_op_alias(atomic_and_64,_atomic_and_64)
633f7729adSmatt
6479085586Sad #if defined(_LP64)
6579085586Sad #undef atomic_and_ulong
6679085586Sad atomic_op_alias(atomic_and_ulong,_atomic_and_64)
6779085586Sad __strong_alias(_atomic_and_ulong,_atomic_and_64)
6879085586Sad #endif /* _LP64 */
69695c2bc2Sad
70695c2bc2Sad #endif
71