atomic_dec.S revision 1.7
11.7Sskrll/*	$NetBSD: atomic_dec.S,v 1.7 2020/08/06 10:00:21 skrll Exp $	*/
21.2Smatt
31.2Smatt/*-
41.2Smatt * Copyright (c) 2008 The NetBSD Foundation, Inc.
51.2Smatt * All rights reserved.
61.2Smatt *
71.2Smatt * Redistribution and use in source and binary forms, with or without
81.2Smatt * modification, are permitted provided that the following conditions
91.2Smatt * are met:
101.2Smatt * 1. Redistributions of source code must retain the above copyright
111.2Smatt *    notice, this list of conditions and the following disclaimer.
121.2Smatt * 2. Redistributions in binary form must reproduce the above copyright
131.2Smatt *    notice, this list of conditions and the following disclaimer in the
141.2Smatt *    documentation and/or other materials provided with the distribution.
151.6Sskrll *
161.2Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
171.2Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
181.2Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
191.2Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
201.2Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211.2Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
221.2Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
231.2Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
241.2Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
251.2Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
261.2Smatt * POSSIBILITY OF SUCH DAMAGE.
271.2Smatt */
281.2Smatt
291.2Smatt#include <machine/asm.h>
301.2Smatt#include "atomic_op_asm.h"
311.2Smatt
321.7SskrllRCSID("$NetBSD: atomic_dec.S,v 1.7 2020/08/06 10:00:21 skrll Exp $")
331.2Smatt
341.2Smatt	.text
351.3Sbouyer	.set	noreorder
361.3Sbouyer#ifdef _KERNEL_OPT
371.3Sbouyer#include "opt_cputype.h"
381.3Sbouyer#ifndef MIPS3_LOONGSON2F
391.3Sbouyer	.set	noat
401.3Sbouyer	.set	nomacro
411.3Sbouyer#endif
421.3Sbouyer#else /* _KERNEL_OPT */
431.2Smatt	.set	noat
441.2Smatt	.set	nomacro
451.3Sbouyer#endif /* _KERNEL_OPT */
461.2Smatt
471.2SmattLEAF(_atomic_dec_32)
481.5Smatt#if defined(_MIPS_ARCH_OCTEONP) || defined(_MIPS_ARCH_OCTEON2)
491.5Smatt	li		t0, -1
501.5Smatt	saa		t0, (a0)
511.5Smatt#else
521.7Sskrll	LLSCSYNC
531.2Smatt1:	INT_LL		t0, 0(a0)
541.2Smatt	 nop
551.2Smatt	INT_ADDU	t0, -1
561.2Smatt	INT_SC		t0, 0(a0)
571.2Smatt	beq		t0, zero, 1b
581.2Smatt 	 nop
591.5Smatt#endif
601.2Smatt	j		ra
611.2Smatt	 nop
621.2SmattEND(_atomic_dec_32)
631.2SmattATOMIC_OP_ALIAS(atomic_dec_32, _atomic_dec_32)
641.2Smatt
651.2SmattLEAF(_atomic_dec_32_nv)
661.7Sskrll	LLSCSYNC
671.2Smatt1:	INT_LL		v0, 0(a0)
681.2Smatt	 nop
691.2Smatt	INT_ADDU	v0, -1
701.2Smatt	move		t0, v0
711.2Smatt	INT_SC		t0, 0(a0)
721.2Smatt	beq		t0, zero, 1b
731.2Smatt 	 nop
741.2Smatt	j		ra
751.2Smatt	 nop
761.2SmattEND(_atomic_dec_32_nv)
771.2SmattATOMIC_OP_ALIAS(atomic_dec_32_nv, _atomic_dec_32_nv)
781.2Smatt
791.2Smatt#if !defined(__mips_o32)
801.2SmattLEAF(_atomic_dec_64)
811.5Smatt#if defined(_MIPS_ARCH_OCTEONP) || defined(_MIPS_ARCH_OCTEON2)
821.5Smatt	li		t0, -1
831.5Smatt	saad		t0, (a0)
841.5Smatt#else
851.7Sskrll	LLSCSYNC
861.2Smatt1:	REG_LL		t0, 0(a0)
871.2Smatt	 nop
881.2Smatt	REG_ADDU	t0, -1
891.2Smatt	REG_SC		t0, 0(a0)
901.2Smatt	beq		t0, zero, 1b
911.2Smatt 	 nop
921.5Smatt#endif
931.2Smatt	j		ra
941.2Smatt	 nop
951.2SmattEND(_atomic_dec_64)
961.2SmattATOMIC_OP_ALIAS(atomic_dec_64, _atomic_dec_64)
971.2Smatt
981.2SmattLEAF(_atomic_dec_64_nv)
991.7Sskrll	LLSCSYNC
1001.2Smatt1:	REG_LL		v0, 0(a0)
1011.2Smatt	 nop
1021.2Smatt	REG_ADDU	v0, -1
1031.2Smatt	move		t0, v0
1041.2Smatt	REG_SC		t0, 0(a0)
1051.2Smatt	beq		t0, zero, 1b
1061.2Smatt 	 nop
1071.2Smatt	j		ra
1081.2Smatt	 nop
1091.2SmattEND(_atomic_dec_64_nv)
1101.2SmattATOMIC_OP_ALIAS(atomic_dec_64_nv, _atomic_dec_64_nv)
1111.2Smatt#endif
1121.2Smatt
1131.2Smatt#ifdef _LP64
1141.2SmattSTRONG_ALIAS(_atomic_dec_ptr,		_atomic_dec_64)
1151.2SmattSTRONG_ALIAS(_atomic_dec_ptr_nv,	_atomic_dec_64_nv)
1161.2SmattSTRONG_ALIAS(_atomic_dec_ulong,		_atomic_dec_64)
1171.2SmattSTRONG_ALIAS(_atomic_dec_ulong_nv,	_atomic_dec_64_nv)
1181.2Smatt#else
1191.2SmattSTRONG_ALIAS(_atomic_dec_ptr,		_atomic_dec_32)
1201.2SmattSTRONG_ALIAS(_atomic_dec_ptr_nv,	_atomic_dec_32_nv)
1211.2SmattSTRONG_ALIAS(_atomic_dec_ulong,		_atomic_dec_32)
1221.2SmattSTRONG_ALIAS(_atomic_dec_ulong_nv,	_atomic_dec_32_nv)
1231.2Smatt#endif
1241.2SmattSTRONG_ALIAS(_atomic_dec_uint,		_atomic_dec_32)
1251.2SmattSTRONG_ALIAS(_atomic_dec_uint_nv,	_atomic_dec_32_nv)
1261.2Smatt
1271.2SmattATOMIC_OP_ALIAS(atomic_dec_ptr,		_atomic_dec_ptr)
1281.2SmattATOMIC_OP_ALIAS(atomic_dec_ptr_nv,	_atomic_dec_ptr_nv)
1291.2SmattATOMIC_OP_ALIAS(atomic_dec_uint,	_atomic_dec_uint)
1301.2SmattATOMIC_OP_ALIAS(atomic_dec_uint_nv,	_atomic_dec_uint_nv)
1311.2SmattATOMIC_OP_ALIAS(atomic_dec_ulong,	_atomic_dec_ulong)
1321.2SmattATOMIC_OP_ALIAS(atomic_dec_ulong_nv,	_atomic_dec_ulong_nv)
133