modified dll/win32/srclient/srclient_main.c
[reactos.git] / reactos / include / crt / mingw32 / intrin_arm.h
1 /*
2 Compatibility <intrin.h> header for GCC -- GCC equivalents of intrinsic
3 Microsoft Visual C++ functions. Originally developed for the ReactOS
4 (<http://www.reactos.org/>) and TinyKrnl (<http://www.tinykrnl.org/>)
5 projects.
6
7 Copyright (c) 2006 KJK::Hyperion <hackbunny@reactos.com>
8
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the "Software"),
11 to deal in the Software without restriction, including without limitation
12 the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26 */
27
28 #ifndef KJK_INTRIN_ARM_H_
29 #define KJK_INTRIN_ARM_H_
30
31 #ifndef __GNUC__
32 #error Unsupported compiler
33 #endif
34
35 #define _ReadWriteBarrier() __sync_synchronize()
36
37 __INTRIN_INLINE long _InterlockedCompareExchange(volatile long * const dest, const long exch, const long comp)
38 {
39 long a, b;
40
41 __asm__ __volatile__ ( "0:\n\t"
42 "ldr %1, [%2]\n\t"
43 "cmp %1, %4\n\t"
44 "bne 1f\n\t"
45 "swp %0, %3, [%2]\n\t"
46 "cmp %0, %1\n\t"
47 "swpne %3, %0, [%2]\n\t"
48 "bne 0b\n\t"
49 "1:"
50 : "=&r" (a), "=&r" (b)
51 : "r" (dest), "r" (exch), "r" (comp)
52 : "cc", "memory");
53
54 return a;
55 }
56
57 __INTRIN_INLINE long long _InterlockedCompareExchange64(volatile long long * const dest, const long long exch, const long long comp)
58 {
59 //
60 // FIXME
61 //
62 long long result;
63 result = *dest;
64 if (*dest == comp) *dest = exch;
65 return result;
66 }
67
68 __INTRIN_INLINE void * _InterlockedCompareExchangePointer(void * volatile * const Destination, void * const Exchange, void * const Comperand)
69 {
70 return (void*)_InterlockedCompareExchange((volatile long* const)Destination, (const long)Exchange, (const long)Comperand);
71 }
72
73
74 __INTRIN_INLINE long _InterlockedExchangeAdd(volatile long * const dest, const long add)
75 {
76 long a, b, c;
77
78 __asm__ __volatile__ ( "0:\n\t"
79 "ldr %0, [%3]\n\t"
80 "add %1, %0, %4\n\t"
81 "swp %2, %1, [%3]\n\t"
82 "cmp %0, %2\n\t"
83 "swpne %1, %2, [%3]\n\t"
84 "bne 0b"
85 : "=&r" (a), "=&r" (b), "=&r" (c)
86 : "r" (dest), "r" (add)
87 : "cc", "memory");
88
89 return a;
90 }
91
92 __INTRIN_INLINE long _InterlockedExchange(volatile long * const dest, const long exch)
93 {
94 long a;
95
96 __asm__ __volatile__ ( "swp %0, %2, [%1]"
97 : "=&r" (a)
98 : "r" (dest), "r" (exch));
99
100 return a;
101 }
102
103
104 __INTRIN_INLINE void * _InterlockedExchangePointer(void * volatile * const Target, void * const Value)
105 {
106 return _InterlockedExchange(Target, Value);
107 }
108
109 __INTRIN_INLINE char _InterlockedAnd8(volatile char * const value, const char mask)
110 {
111 char x;
112 char y;
113
114 y = *value;
115
116 do
117 {
118 x = y;
119 y = _InterlockedCompareExchange8(value, x & mask, x);
120 }
121 while(y != x);
122
123 return y;
124 }
125
126 __INTRIN_INLINE short _InterlockedAnd16(volatile short * const value, const short mask)
127 {
128 short x;
129 short y;
130
131 y = *value;
132
133 do
134 {
135 x = y;
136 y = _InterlockedCompareExchange16(value, x & mask, x);
137 }
138 while(y != x);
139
140 return y;
141 }
142
143 __INTRIN_INLINE long _InterlockedAnd(volatile long * const value, const long mask)
144 {
145 long x;
146 long y;
147
148 y = *value;
149
150 do
151 {
152 x = y;
153 y = _InterlockedCompareExchange(value, x & mask, x);
154 }
155 while(y != x);
156
157 return y;
158 }
159
160 __INTRIN_INLINE char _InterlockedOr8(volatile char * const value, const char mask)
161 {
162 char x;
163 char y;
164
165 y = *value;
166
167 do
168 {
169 x = y;
170 y = _InterlockedCompareExchange8(value, x | mask, x);
171 }
172 while(y != x);
173
174 return y;
175 }
176
177 __INTRIN_INLINE short _InterlockedOr16(volatile short * const value, const short mask)
178 {
179 short x;
180 short y;
181
182 y = *value;
183
184 do
185 {
186 x = y;
187 y = _InterlockedCompareExchange16(value, x | mask, x);
188 }
189 while(y != x);
190
191 return y;
192 }
193
194 __INTRIN_INLINE long _InterlockedOr(volatile long * const value, const long mask)
195 {
196 long x;
197 long y;
198
199 y = *value;
200
201 do
202 {
203 x = y;
204 y = _InterlockedCompareExchange(value, x | mask, x);
205 }
206 while(y != x);
207
208 return y;
209 }
210
211 __INTRIN_INLINE char _InterlockedXor8(volatile char * const value, const char mask)
212 {
213 char x;
214 char y;
215
216 y = *value;
217
218 do
219 {
220 x = y;
221 y = _InterlockedCompareExchange8(value, x ^ mask, x);
222 }
223 while(y != x);
224
225 return y;
226 }
227
228 __INTRIN_INLINE short _InterlockedXor16(volatile short * const value, const short mask)
229 {
230 short x;
231 short y;
232
233 y = *value;
234
235 do
236 {
237 x = y;
238 y = _InterlockedCompareExchange16(value, x ^ mask, x);
239 }
240 while(y != x);
241
242 return y;
243 }
244
245 __INTRIN_INLINE long _InterlockedXor(volatile long * const value, const long mask)
246 {
247 long x;
248 long y;
249
250 y = *value;
251
252 do
253 {
254 x = y;
255 y = _InterlockedCompareExchange(value, x ^ mask, x);
256 }
257 while(y != x);
258
259 return y;
260 }
261
262 __INTRIN_INLINE long _InterlockedDecrement(volatile long * const lpAddend)
263 {
264 return _InterlockedExchangeAdd(lpAddend, -1) - 1;
265 }
266
267 __INTRIN_INLINE long _InterlockedIncrement(volatile long * const lpAddend)
268 {
269 return _InterlockedExchangeAdd(lpAddend, 1) + 1;
270 }
271
272 __INTRIN_INLINE long _InterlockedDecrement16(volatile short * const lpAddend)
273 {
274 return _InterlockedExchangeAdd16(lpAddend, -1) - 1;
275 }
276
277 __INTRIN_INLINE long _InterlockedIncrement16(volatile short * const lpAddend)
278 {
279 return _InterlockedExchangeAdd16(lpAddend, 1) + 1;
280 }
281
282 __INTRIN_INLINE void _disable(void)
283 {
284 __asm__ __volatile__
285 (
286 "mrs r1, cpsr;"
287 "orr r1, r1, #0x80;"
288 "msr cpsr, r1;"
289 );
290 }
291
292 __INTRIN_INLINE void _enable(void)
293 {
294 __asm__ __volatile__
295 (
296 "mrs r1, cpsr;"
297 "bic r1, r1, #0x80;"
298 "msr cpsr, r1;"
299 );
300 }
301
302 #ifndef __MSVCRT__
303 __INTRIN_INLINE unsigned long _rotl(const unsigned long value, const unsigned char shift)
304 {
305 return (((value) << ((int)(shift))) | ((value) >> (32 - (int)(shift))));
306 }
307 #endif
308
309 #define _clz(a) \
310 ({ ULONG __value, __arg = (a); \
311 asm ("clz\t%0, %1": "=r" (__value): "r" (__arg)); \
312 __value; })
313
314 #endif
315 /* EOF */