xref: /minix3/common/lib/libc/arch/mips/atomic/atomic_dec.S (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc/*	$NetBSD: atomic_dec.S,v 1.5 2015/06/01 23:16:54 matt Exp $	*/
2b6cbf720SGianluca Guida
3b6cbf720SGianluca Guida/*-
4b6cbf720SGianluca Guida * Copyright (c) 2008 The NetBSD Foundation, Inc.
5b6cbf720SGianluca Guida * All rights reserved.
6b6cbf720SGianluca Guida *
7b6cbf720SGianluca Guida * Redistribution and use in source and binary forms, with or without
8b6cbf720SGianluca Guida * modification, are permitted provided that the following conditions
9b6cbf720SGianluca Guida * are met:
10b6cbf720SGianluca Guida * 1. Redistributions of source code must retain the above copyright
11b6cbf720SGianluca Guida *    notice, this list of conditions and the following disclaimer.
12b6cbf720SGianluca Guida * 2. Redistributions in binary form must reproduce the above copyright
13b6cbf720SGianluca Guida *    notice, this list of conditions and the following disclaimer in the
14b6cbf720SGianluca Guida *    documentation and/or other materials provided with the distribution.
15b6cbf720SGianluca Guida *
16b6cbf720SGianluca Guida * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17b6cbf720SGianluca Guida * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18b6cbf720SGianluca Guida * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19b6cbf720SGianluca Guida * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20b6cbf720SGianluca Guida * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21b6cbf720SGianluca Guida * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22b6cbf720SGianluca Guida * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23b6cbf720SGianluca Guida * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24b6cbf720SGianluca Guida * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25b6cbf720SGianluca Guida * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26b6cbf720SGianluca Guida * POSSIBILITY OF SUCH DAMAGE.
27b6cbf720SGianluca Guida */
28b6cbf720SGianluca Guida
29b6cbf720SGianluca Guida#include <machine/asm.h>
30b6cbf720SGianluca Guida#include "atomic_op_asm.h"
31b6cbf720SGianluca Guida
32*0a6a1f1dSLionel SambucRCSID("$NetBSD: atomic_dec.S,v 1.5 2015/06/01 23:16:54 matt Exp $")
33b6cbf720SGianluca Guida
34b6cbf720SGianluca Guida	.text
35b6cbf720SGianluca Guida	.set	noreorder
36f14fb602SLionel Sambuc#ifdef _KERNEL_OPT
37f14fb602SLionel Sambuc#include "opt_cputype.h"
38f14fb602SLionel Sambuc#ifndef MIPS3_LOONGSON2F
39f14fb602SLionel Sambuc	.set	noat
40b6cbf720SGianluca Guida	.set	nomacro
41f14fb602SLionel Sambuc#endif
42f14fb602SLionel Sambuc#else /* _KERNEL_OPT */
43f14fb602SLionel Sambuc	.set	noat
44f14fb602SLionel Sambuc	.set	nomacro
45f14fb602SLionel Sambuc#endif /* _KERNEL_OPT */
46b6cbf720SGianluca Guida
47b6cbf720SGianluca GuidaLEAF(_atomic_dec_32)
48*0a6a1f1dSLionel Sambuc#if defined(_MIPS_ARCH_OCTEONP) || defined(_MIPS_ARCH_OCTEON2)
49*0a6a1f1dSLionel Sambuc	li		t0, -1
50*0a6a1f1dSLionel Sambuc	saa		t0, (a0)
51*0a6a1f1dSLionel Sambuc#else
52b6cbf720SGianluca Guida1:	INT_LL		t0, 0(a0)
53b6cbf720SGianluca Guida	 nop
54b6cbf720SGianluca Guida	INT_ADDU	t0, -1
55b6cbf720SGianluca Guida	INT_SC		t0, 0(a0)
56b6cbf720SGianluca Guida	beq		t0, zero, 1b
57b6cbf720SGianluca Guida 	 nop
58*0a6a1f1dSLionel Sambuc#endif
59b6cbf720SGianluca Guida	j		ra
60b6cbf720SGianluca Guida	 nop
61b6cbf720SGianluca GuidaEND(_atomic_dec_32)
62b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_32, _atomic_dec_32)
63b6cbf720SGianluca Guida
64b6cbf720SGianluca GuidaLEAF(_atomic_dec_32_nv)
65b6cbf720SGianluca Guida1:	INT_LL		v0, 0(a0)
66b6cbf720SGianluca Guida	 nop
67b6cbf720SGianluca Guida	INT_ADDU	v0, -1
68b6cbf720SGianluca Guida	move		t0, v0
69b6cbf720SGianluca Guida	INT_SC		t0, 0(a0)
70b6cbf720SGianluca Guida	beq		t0, zero, 1b
71b6cbf720SGianluca Guida 	 nop
72b6cbf720SGianluca Guida	j		ra
73b6cbf720SGianluca Guida	 nop
74b6cbf720SGianluca GuidaEND(_atomic_dec_32_nv)
75b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_32_nv, _atomic_dec_32_nv)
76b6cbf720SGianluca Guida
77b6cbf720SGianluca Guida#if !defined(__mips_o32)
78b6cbf720SGianluca GuidaLEAF(_atomic_dec_64)
79*0a6a1f1dSLionel Sambuc#if defined(_MIPS_ARCH_OCTEONP) || defined(_MIPS_ARCH_OCTEON2)
80*0a6a1f1dSLionel Sambuc	li		t0, -1
81*0a6a1f1dSLionel Sambuc	saad		t0, (a0)
82*0a6a1f1dSLionel Sambuc#else
83b6cbf720SGianluca Guida1:	REG_LL		t0, 0(a0)
84b6cbf720SGianluca Guida	 nop
85b6cbf720SGianluca Guida	REG_ADDU	t0, -1
86b6cbf720SGianluca Guida	REG_SC		t0, 0(a0)
87b6cbf720SGianluca Guida	beq		t0, zero, 1b
88b6cbf720SGianluca Guida 	 nop
89*0a6a1f1dSLionel Sambuc#endif
90b6cbf720SGianluca Guida	j		ra
91b6cbf720SGianluca Guida	 nop
92b6cbf720SGianluca GuidaEND(_atomic_dec_64)
93b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_64, _atomic_dec_64)
94b6cbf720SGianluca Guida
95b6cbf720SGianluca GuidaLEAF(_atomic_dec_64_nv)
96b6cbf720SGianluca Guida1:	REG_LL		v0, 0(a0)
97b6cbf720SGianluca Guida	 nop
98b6cbf720SGianluca Guida	REG_ADDU	v0, -1
99b6cbf720SGianluca Guida	move		t0, v0
100b6cbf720SGianluca Guida	REG_SC		t0, 0(a0)
101b6cbf720SGianluca Guida	beq		t0, zero, 1b
102b6cbf720SGianluca Guida 	 nop
103b6cbf720SGianluca Guida	j		ra
104b6cbf720SGianluca Guida	 nop
105b6cbf720SGianluca GuidaEND(_atomic_dec_64_nv)
106b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_64_nv, _atomic_dec_64_nv)
107b6cbf720SGianluca Guida#endif
108b6cbf720SGianluca Guida
109b6cbf720SGianluca Guida#ifdef _LP64
110b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_dec_ptr,		_atomic_dec_64)
111b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_dec_ptr_nv,	_atomic_dec_64_nv)
112b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_dec_ulong,		_atomic_dec_64)
113b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_dec_ulong_nv,	_atomic_dec_64_nv)
114b6cbf720SGianluca Guida#else
115b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_dec_ptr,		_atomic_dec_32)
116b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_dec_ptr_nv,	_atomic_dec_32_nv)
117b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_dec_ulong,		_atomic_dec_32)
118b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_dec_ulong_nv,	_atomic_dec_32_nv)
119b6cbf720SGianluca Guida#endif
120b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_dec_uint,		_atomic_dec_32)
121b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_dec_uint_nv,	_atomic_dec_32_nv)
122b6cbf720SGianluca Guida
123b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_ptr,		_atomic_dec_ptr)
124b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_ptr_nv,	_atomic_dec_ptr_nv)
125b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_uint,	_atomic_dec_uint)
126b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_uint_nv,	_atomic_dec_uint_nv)
127b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_ulong,	_atomic_dec_ulong)
128b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_ulong_nv,	_atomic_dec_ulong_nv)
129