2 * Amiga Generic Set - set of libraries and includes to ease sw development for all Amiga platforms
3 * Copyright (C) 2001-2011 Tomasz Wiszkowski Tomasz.Wiszkowski at gmail.com.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 static inline void _atomic_stack_push(struct _atomic_stack
* list
, struct _atomic_item
* item
)
26 asm volatile(" move.l %0,%/a0\n"
28 "1: bset.b %#0,4(%/a1)\n"
30 "2: move.l (%/a1),(%/a0)\n"
31 " move.l %/a0,(%/a1)\n"
32 " bclr.b %#0,4(%/a1)\n"
34 : "m" (item
), "m" (list
)
35 : "a0", "a1", "cc", "memory"
39 static inline struct _atomic_item
* _atomic_stack_pop(struct _atomic_stack
* list
)
41 register struct _atomic_item
*n
;
43 asm volatile(" move.l %1,%/a1\n"
44 "1: bset.b %#0,4(%/a1)\n"
46 "2: move.l (%/a1),%/d0\n"
49 " move.l (%/a0),(%/a1)\n"
50 "3: bclr.b %#0,4(%/a1)\n"
54 : "a0", "a1", "d0", "cc", "memory"
59 static inline void _atomic_cnt_inc(struct _atomic_cnt
* cnt
)
61 asm volatile(" move.l %0,%/a0\n"
62 " addq.l %#1,(%/a0)\n"
65 : "a0", "cc", "memory"
69 static inline void _atomic_cnt_dec(struct _atomic_cnt
* cnt
)
71 asm volatile(" move.l %0,%/a0\n"
72 " subq.l %#1,(%/a0)\n"
75 : "a0", "cc", "memory"
79 static inline int32
_atomic_slock_trywrite(struct _atomic_slock
* lock
)
83 asm volatile(" move.l %1,%/a0\n"
84 "1: bset.b %#7,(%/a0)\n"
86 " move.l (%/a0),%/d0\n"
92 " move.l %/d1,(%/a0)\n"
93 "2: bclr.b %#7,(%/a0)\n"
97 : "a0", "d0", "d1", "cc", "memory");
101 static inline void _atomic_slock_unlockwrite(struct _atomic_slock
* lock
)
103 asm volatile(" move.l %0,%/a0\n"
104 "1: bset.b %#7,(%/a0)\n"
106 " move.l (%/a0),%/d0\n"
111 " move.l %/d0,(%/a0)\n"
112 "2: bclr.b %#7,(%/a0)\n"
115 : "a0", "d0", "d1", "cc", "memory");
118 static inline int32
_atomic_slock_tryread(struct _atomic_slock
* lock
)
122 asm volatile(" move.l %1,%/a0\n"
123 "1: bset.b %#7,(%/a0)\n"
125 " move.l (%/a0),%/d0\n"
126 " moveq.l %#-1,%/d1\n"
129 " addq.l %#1,(%/a0)\n"
130 " bclr.b %#31,%/d0\n"
131 "2: bclr.b %#7,(%/a0)\n"
135 : "a0", "d0", "d1", "cc", "memory");
139 static inline int32
_atomic_slock_unlockread(struct _atomic_slock
* lock
)
143 asm volatile(" move.l %1,%/a0\n"
144 "1: bset.b %#7,(%/a0)\n"
146 " move.l (%/a0),%/d0\n"
147 " moveq.l %#-1,%/d0\n"
150 " subq.l %#1,(%/a0)\n"
151 " bclr.b %#31,%/d0\n"
152 " bclr.b %#7,(%/a0)\n"
153 "2: move.l %/d0,%0\n"
156 : "a0", "d0", "d1", "cc", "memory");