xref: /netbsd-src/common/lib/libc/arch/riscv/atomic/atomic_and_32.S (revision 2d9adf0d04e3d93ba1c0324ee24085eaf63c96e5)
1*2d9adf0dSmatt/*	$NetBSD: atomic_and_32.S,v 1.2 2015/03/27 06:42:37 matt Exp $	*/
26cf6fe02Smatt
36cf6fe02Smatt/*-
46cf6fe02Smatt * Copyright (c) 2014 The NetBSD Foundation, Inc.
56cf6fe02Smatt * All rights reserved.
66cf6fe02Smatt *
76cf6fe02Smatt * This code is derived from software contributed to The NetBSD Foundation
86cf6fe02Smatt * by Matt Thomas of 3am Software Foundry.
96cf6fe02Smatt *
106cf6fe02Smatt * Redistribution and use in source and binary forms, with or without
116cf6fe02Smatt * modification, are permitted provided that the following conditions
126cf6fe02Smatt * are met:
136cf6fe02Smatt * 1. Redistributions of source code must retain the above copyright
146cf6fe02Smatt *    notice, this list of conditions and the following disclaimer.
156cf6fe02Smatt * 2. Redistributions in binary form must reproduce the above copyright
166cf6fe02Smatt *    notice, this list of conditions and the following disclaimer in the
176cf6fe02Smatt *    documentation and/or other materials provided with the distribution.
186cf6fe02Smatt *
196cf6fe02Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
206cf6fe02Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
216cf6fe02Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
226cf6fe02Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
236cf6fe02Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
246cf6fe02Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
256cf6fe02Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
266cf6fe02Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
276cf6fe02Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
286cf6fe02Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
296cf6fe02Smatt * POSSIBILITY OF SUCH DAMAGE.
306cf6fe02Smatt */
316cf6fe02Smatt
326cf6fe02Smatt#include "atomic_op_asm.h"
336cf6fe02Smatt
346cf6fe02SmattENTRY_NP(_atomic_and_32)
35*2d9adf0dSmatt	amoand.w.aq	a0, a1, 0(a0)
366cf6fe02Smatt	ret
376cf6fe02SmattEND(_atomic_and_32)
386cf6fe02Smatt
396cf6fe02SmattATOMIC_OP_ALIAS(atomic_and_32,_atomic_and_32)
406cf6fe02SmattATOMIC_OP_ALIAS(atomic_and_uint,_atomic_and_32)
416cf6fe02SmattSTRONG_ALIAS(_atomic_and_uint,_atomic_and_32)
426cf6fe02Smatt#ifndef _LP64
436cf6fe02SmattATOMIC_OP_ALIAS(atomic_and_ulong,_atomic_and_32)
446cf6fe02SmattSTRONG_ALIAS(_atomic_and_ulong,_atomic_and_32)
456cf6fe02Smatt#endif
466cf6fe02SmattCRT_ALIAS(__sync_fetch_and_and_4,_atomic_and_32)
476cf6fe02SmattCRT_ALIAS(__atomic_fetch_and_4,_atomic_and_32)
486cf6fe02Smatt
496cf6fe02SmattENTRY_NP(_atomic_and_32_nv)
50*2d9adf0dSmatt	amoand.w.aq	t0, a1, 0(a0)	/* update memory and get old value */
51*2d9adf0dSmatt	and		a0, t0, a1	/* turn into new value */
526cf6fe02Smatt	ret
536cf6fe02SmattEND(_atomic_and_32_nv)
546cf6fe02SmattATOMIC_OP_ALIAS(atomic_and_32_nv,_atomic_and_32_nv)
556cf6fe02SmattATOMIC_OP_ALIAS(atomic_and_uint_nv,_atomic_and_32_nv)
566cf6fe02SmattSTRONG_ALIAS(_atomic_and_uint_nv,_atomic_and_32_nv)
576cf6fe02Smatt#ifndef _LP64
586cf6fe02SmattATOMIC_OP_ALIAS(atomic_and_ulong_nv,_atomic_and_32_nv)
596cf6fe02SmattSTRONG_ALIAS(_atomic_and_ulong_nv,_atomic_and_32_nv)
606cf6fe02Smatt#endif
616cf6fe02SmattCRT_ALIAS(__sync_and_and_fetch_4,_atomic_and_32_nv)
626cf6fe02SmattCRT_ALIAS(__atomic_and_fetch_4,_atomic_and_32_nv)
63