another attempt at making the asm inlines portable, the syntax should now be complian...
[AROS-Contrib.git] / FryingPan / framework / LowLevel / Atomic_m68k.h
blob7b05f40503f362b7e0d3f95287910599cd18f160
1 /*
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.
4 *
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.
9 *
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
20 #ifndef ATOMIC_68K_H
21 #define ATOMIC_68K_H
24 static inline void _atomic_stack_push(struct _atomic_stack* list, struct _atomic_item* item)
26 asm volatile(" move.l %0,%/a0\n"
27 " move.l %1,%/a1\n"
28 "1: bset.b %#0,4(%/a1)\n"
29 " bne.b 1b\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"
45 " bne.b 1b\n"
46 "2: move.l (%/a1),%/d0\n"
47 " beq 3f\n"
48 " move.l %/d0,%/a0\n"
49 " move.l (%/a0),(%/a1)\n"
50 "3: bclr.b %#0,4(%/a1)\n"
51 " move.l %/d0,%0\n"
52 : "=g" (n)
53 : "m" (list)
54 : "a0", "a1", "d0", "cc", "memory"
56 return n;
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"
64 : "m" (cnt)
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"
74 : "m" (cnt)
75 : "a0", "cc", "memory"
79 static inline int32 _atomic_slock_trywrite(struct _atomic_slock* lock)
81 register int32 res;
83 asm volatile(" move.l %1,%/a0\n"
84 "1: bset.b %#7,(%/a0)\n"
85 " bne.b 1b\n"
86 " move.l (%/a0),%/d0\n"
87 " bclr.b %#31,%/d0\n"
88 " moveq %#0,%/d1\n"
89 " tst.l %/d0\n"
90 " bne.b 2f\n"
91 " moveq %#-1,%/d1\n"
92 " move.l %/d1,(%/a0)\n"
93 "2: bclr.b %#7,(%/a0)\n"
94 " move.l %/d1,%0\n"
95 : "=g"(res)
96 : "m"(lock)
97 : "a0", "d0", "d1", "cc", "memory");
98 return res;
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"
105 " bne.b 1b\n"
106 " move.l (%/a0),%/d0\n"
107 " moveq %#-1,%/d1\n"
108 " cmp.l %/d0,%/d1\n"
109 " bne.b 2f\n"
110 " moveq %#0,%/d0\n"
111 " move.l %/d0,(%/a0)\n"
112 "2: bclr.b %#7,(%/a0)\n"
114 : "m"(lock)
115 : "a0", "d0", "d1", "cc", "memory");
118 static inline int32 _atomic_slock_tryread(struct _atomic_slock* lock)
120 register int32 res;
122 asm volatile(" move.l %1,%/a0\n"
123 "1: bset.b %#7,(%/a0)\n"
124 " bne.b 1b\n"
125 " move.l (%/a0),%/d0\n"
126 " moveq.l %#-1,%/d1\n"
127 " cmp.l %/d0,%/d1\n"
128 " beq.b 2f\n"
129 " addq.l %#1,(%/a0)\n"
130 " bclr.b %#31,%/d0\n"
131 "2: bclr.b %#7,(%/a0)\n"
132 " move.l %/d0,%0\n"
133 : "=g"(res)
134 : "m"(lock)
135 : "a0", "d0", "d1", "cc", "memory");
136 return res;
139 static inline int32 _atomic_slock_unlockread(struct _atomic_slock* lock)
141 register int32 res;
143 asm volatile(" move.l %1,%/a0\n"
144 "1: bset.b %#7,(%/a0)\n"
145 " bne.b 1b\n"
146 " move.l (%/a0),%/d0\n"
147 " moveq.l %#-1,%/d0\n"
148 " cmp.l %/d0,%/d1\n"
149 " beq.b 2f\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"
154 : "=g"(res)
155 : "m"(lock)
156 : "a0", "d0", "d1", "cc", "memory");
157 return res;
160 #endif