ReactOS 0.4.15-dev-7788-g1ad9096
intrin_arm.h
Go to the documentation of this file.
1/*
2 Compatibility <intrin.h> header for GCC -- GCC equivalents of intrinsic
3 Microsoft Visual C++ functions. Originally developed for the ReactOS
4 (<https://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 _ReturnAddress() (__builtin_return_address(0))
36#define _ReadWriteBarrier() __sync_synchronize()
37
38__INTRIN_INLINE void __yield(void) { __asm__ __volatile__("yield"); }
39
40__INTRIN_INLINE void __break(unsigned int value) { __asm__ __volatile__("bkpt %0": : "M" (value)); }
41
42__INTRIN_INLINE unsigned short _byteswap_ushort(unsigned short value)
43{
44 return (value >> 8) | (value << 8);
45}
46
48{
49 return Mask ? __builtin_clz(Mask) : 32;
50}
51
53{
54 return Mask ? __builtin_ctz(Mask) : 32;
55}
56
57__INTRIN_INLINE unsigned char _BitScanForward(unsigned long * const Index, const unsigned long Mask)
58{
59 *Index = __builtin_ctz(Mask);
60 return Mask ? 1 : 0;
61}
62
63__INTRIN_INLINE char _InterlockedCompareExchange8(volatile char * const Destination, const char Exchange, const char Comperand)
64{
65 return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
66}
67
68__INTRIN_INLINE short _InterlockedCompareExchange16(volatile short * const Destination, const short Exchange, const short Comperand)
69{
70 short a, b;
71
72 __asm__ __volatile__ ( "0:\n\t"
73 "ldr %1, [%2]\n\t"
74 "cmp %1, %4\n\t"
75 "bne 1f\n\t"
76 "swp %0, %3, [%2]\n\t"
77 "cmp %0, %1\n\t"
78 "swpne %3, %0, [%2]\n\t"
79 "bne 0b\n\t"
80 "1:"
81 : "=&r" (a), "=&r" (b)
82 : "r" (Destination), "r" (Exchange), "r" (Comperand)
83 : "cc", "memory");
84
85 return a;
86}
87
88__INTRIN_INLINE short _InterlockedExchangeAdd16(volatile short * const Addend, const short Value)
89{
90 short a, b, c;
91
92 __asm__ __volatile__ ( "0:\n\t"
93 "ldr %0, [%3]\n\t"
94 "add %1, %0, %4\n\t"
95 "swp %2, %1, [%3]\n\t"
96 "cmp %0, %2\n\t"
97 "swpne %1, %2, [%3]\n\t"
98 "bne 0b"
99 : "=&r" (a), "=&r" (b), "=&r" (c)
100 : "r" (Value), "r" (Addend)
101 : "cc", "memory");
102
103 return a;
104}
105
106__INTRIN_INLINE long _InterlockedCompareExchange(volatile long * const dest, const long exch, const long comp)
107{
108 long a, b;
109
110 __asm__ __volatile__ ( "0:\n\t"
111 "ldr %1, [%2]\n\t"
112 "cmp %1, %4\n\t"
113 "bne 1f\n\t"
114 "swp %0, %3, [%2]\n\t"
115 "cmp %0, %1\n\t"
116 "swpne %3, %0, [%2]\n\t"
117 "bne 0b\n\t"
118 "1:"
119 : "=&r" (a), "=&r" (b)
120 : "r" (dest), "r" (exch), "r" (comp)
121 : "cc", "memory");
122
123 return a;
124}
125
126__INTRIN_INLINE long long _InterlockedCompareExchange64(volatile long long * const dest, const long long exch, const long long comp)
127{
128 //
129 // FIXME
130 //
131 long long result;
132 result = *dest;
133 if (*dest == comp) *dest = exch;
134 return result;
135}
136
137__INTRIN_INLINE void * _InterlockedCompareExchangePointer(void * volatile * const Destination, void * const Exchange, void * const Comperand)
138{
139 return (void*)_InterlockedCompareExchange((volatile long* const)Destination, (const long)Exchange, (const long)Comperand);
140}
141
142
143__INTRIN_INLINE long _InterlockedExchangeAdd(volatile long * const dest, const long add)
144{
145 long a, b, c;
146
147 __asm__ __volatile__ ( "0:\n\t"
148 "ldr %0, [%3]\n\t"
149 "add %1, %0, %4\n\t"
150 "swp %2, %1, [%3]\n\t"
151 "cmp %0, %2\n\t"
152 "swpne %1, %2, [%3]\n\t"
153 "bne 0b"
154 : "=&r" (a), "=&r" (b), "=&r" (c)
155 : "r" (dest), "r" (add)
156 : "cc", "memory");
157
158 return a;
159}
160
161__INTRIN_INLINE long _InterlockedExchange(volatile long * const dest, const long exch)
162{
163 long a;
164
165 __asm__ __volatile__ ( "swp %0, %2, [%1]"
166 : "=&r" (a)
167 : "r" (dest), "r" (exch));
168
169 return a;
170}
171
172
173__INTRIN_INLINE void * _InterlockedExchangePointer(void * volatile * const Target, void * const Value)
174{
175 return (void *)_InterlockedExchange((volatile long * const)Target, (const long)Value);
176}
177
178
179
180__INTRIN_INLINE unsigned char _BitScanReverse(unsigned long * const Index, const unsigned long Mask)
181{
182 *Index = 31 - __builtin_clz(Mask);
183 return Mask ? 1 : 0;
184}
185
186__INTRIN_INLINE char _InterlockedAnd8(volatile char * const value, const char mask)
187{
188 char x;
189 char y;
190
191 y = *value;
192
193 do
194 {
195 x = y;
197 }
198 while(y != x);
199
200 return y;
201}
202
203__INTRIN_INLINE short _InterlockedAnd16(volatile short * const value, const short mask)
204{
205 short x;
206 short y;
207
208 y = *value;
209
210 do
211 {
212 x = y;
214 }
215 while(y != x);
216
217 return y;
218}
219
220__INTRIN_INLINE long _InterlockedAnd(volatile long * const value, const long mask)
221{
222 long x;
223 long y;
224
225 y = *value;
226
227 do
228 {
229 x = y;
231 }
232 while(y != x);
233
234 return y;
235}
236
237__INTRIN_INLINE char _InterlockedOr8(volatile char * const value, const char mask)
238{
239 char x;
240 char y;
241
242 y = *value;
243
244 do
245 {
246 x = y;
248 }
249 while(y != x);
250
251 return y;
252}
253
254__INTRIN_INLINE short _InterlockedOr16(volatile short * const value, const short mask)
255{
256 short x;
257 short y;
258
259 y = *value;
260
261 do
262 {
263 x = y;
265 }
266 while(y != x);
267
268 return y;
269}
270
271__INTRIN_INLINE long _InterlockedOr(volatile long * const value, const long mask)
272{
273 long x;
274 long y;
275
276 y = *value;
277
278 do
279 {
280 x = y;
282 }
283 while(y != x);
284
285 return y;
286}
287
288__INTRIN_INLINE char _InterlockedXor8(volatile char * const value, const char mask)
289{
290 char x;
291 char y;
292
293 y = *value;
294
295 do
296 {
297 x = y;
299 }
300 while(y != x);
301
302 return y;
303}
304
305__INTRIN_INLINE short _InterlockedXor16(volatile short * const value, const short mask)
306{
307 short x;
308 short y;
309
310 y = *value;
311
312 do
313 {
314 x = y;
316 }
317 while(y != x);
318
319 return y;
320}
321
322__INTRIN_INLINE long _InterlockedXor(volatile long * const value, const long mask)
323{
324 long x;
325 long y;
326
327 y = *value;
328
329 do
330 {
331 x = y;
333 }
334 while(y != x);
335
336 return y;
337}
338
339__INTRIN_INLINE long _InterlockedDecrement(volatile long * const lpAddend)
340{
341 return _InterlockedExchangeAdd(lpAddend, -1) - 1;
342}
343
344__INTRIN_INLINE long _InterlockedIncrement(volatile long * const lpAddend)
345{
346 return _InterlockedExchangeAdd(lpAddend, 1) + 1;
347}
348
349__INTRIN_INLINE long _InterlockedDecrement16(volatile short * const lpAddend)
350{
351 return _InterlockedExchangeAdd16(lpAddend, -1) - 1;
352}
353
354__INTRIN_INLINE long _InterlockedIncrement16(volatile short * const lpAddend)
355{
356 return _InterlockedExchangeAdd16(lpAddend, 1) + 1;
357}
358
359__INTRIN_INLINE long _InterlockedAddLargeStatistic(volatile long long * const Addend, const long Value)
360{
361 *Addend += Value;
362 return Value;
363}
364
366{
367 __asm__ __volatile__
368 (
369 "cpsid i @ __cli" : : : "memory", "cc"
370 );
371}
372
374{
375 __asm__ __volatile__
376 (
377 "cpsie i @ __sti" : : : "memory", "cc"
378 );
379}
380
381__INTRIN_INLINE unsigned char _interlockedbittestandset(volatile long * a, const long b)
382{
383 return (_InterlockedOr(a, 1 << b) >> b) & 1;
384}
385
386__INTRIN_INLINE unsigned char _interlockedbittestandreset(volatile long * a, const long b)
387{
388 return (_InterlockedAnd(a, ~(1 << b)) >> b) & 1;
389}
390
391#ifndef __MSVCRT__
392__INTRIN_INLINE unsigned int _rotl(const unsigned int value, int shift)
393{
394 return (((value) << ((int)(shift))) | ((value) >> (32 - (int)(shift))));
395}
396#endif
397
398#define _clz(a) \
399({ ULONG __value, __arg = (a); \
400asm ("clz\t%0, %1": "=r" (__value): "r" (__arg)); \
401__value; })
402
403#endif
404/* EOF */
#define __INTRIN_INLINE
Definition: _mingw.h:248
IN OUT PLONG Addend
Definition: CrNtStubs.h:25
unsigned int Mask
Definition: fpcontrol.c:82
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
const GLubyte * c
Definition: glext.h:8905
GLenum GLint GLuint mask
Definition: glext.h:6028
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLuint64EXT * result
Definition: glext.h:11304
__INTRIN_INLINE short _InterlockedAnd16(volatile short *const value, const short mask)
Definition: intrin_arm.h:203
__INTRIN_INLINE long _InterlockedIncrement(volatile long *const lpAddend)
Definition: intrin_arm.h:344
__INTRIN_INLINE short _InterlockedCompareExchange16(volatile short *const Destination, const short Exchange, const short Comperand)
Definition: intrin_arm.h:68
__INTRIN_INLINE long _InterlockedExchange(volatile long *const dest, const long exch)
Definition: intrin_arm.h:161
__INTRIN_INLINE long _InterlockedIncrement16(volatile short *const lpAddend)
Definition: intrin_arm.h:354
__INTRIN_INLINE void _disable(void)
Definition: intrin_arm.h:365
__INTRIN_INLINE char _InterlockedCompareExchange8(volatile char *const Destination, const char Exchange, const char Comperand)
Definition: intrin_arm.h:63
__INTRIN_INLINE short _InterlockedXor16(volatile short *const value, const short mask)
Definition: intrin_arm.h:305
__INTRIN_INLINE unsigned _CountLeadingZeros(long Mask)
Definition: intrin_arm.h:47
__INTRIN_INLINE long _InterlockedDecrement16(volatile short *const lpAddend)
Definition: intrin_arm.h:349
__INTRIN_INLINE void __yield(void)
Definition: intrin_arm.h:38
__INTRIN_INLINE unsigned char _BitScanForward(unsigned long *const Index, const unsigned long Mask)
Definition: intrin_arm.h:57
__INTRIN_INLINE unsigned short _byteswap_ushort(unsigned short value)
Definition: intrin_arm.h:42
__INTRIN_INLINE long _InterlockedDecrement(volatile long *const lpAddend)
Definition: intrin_arm.h:339
__INTRIN_INLINE void * _InterlockedCompareExchangePointer(void *volatile *const Destination, void *const Exchange, void *const Comperand)
Definition: intrin_arm.h:137
__INTRIN_INLINE long long _InterlockedCompareExchange64(volatile long long *const dest, const long long exch, const long long comp)
Definition: intrin_arm.h:126
__INTRIN_INLINE long _InterlockedOr(volatile long *const value, const long mask)
Definition: intrin_arm.h:271
__INTRIN_INLINE unsigned char _interlockedbittestandset(volatile long *a, const long b)
Definition: intrin_arm.h:381
__INTRIN_INLINE void _enable(void)
Definition: intrin_arm.h:373
__INTRIN_INLINE void * _InterlockedExchangePointer(void *volatile *const Target, void *const Value)
Definition: intrin_arm.h:173
__INTRIN_INLINE long _InterlockedCompareExchange(volatile long *const dest, const long exch, const long comp)
Definition: intrin_arm.h:106
__INTRIN_INLINE void __break(unsigned int value)
Definition: intrin_arm.h:40
__INTRIN_INLINE long _InterlockedExchangeAdd(volatile long *const dest, const long add)
Definition: intrin_arm.h:143
__INTRIN_INLINE unsigned char _interlockedbittestandreset(volatile long *a, const long b)
Definition: intrin_arm.h:386
__INTRIN_INLINE long _InterlockedAddLargeStatistic(volatile long long *const Addend, const long Value)
Definition: intrin_arm.h:359
__INTRIN_INLINE unsigned _CountTrailingZeros(long Mask)
Definition: intrin_arm.h:52
__INTRIN_INLINE unsigned int _rotl(const unsigned int value, int shift)
Definition: intrin_arm.h:392
__INTRIN_INLINE short _InterlockedExchangeAdd16(volatile short *const Addend, const short Value)
Definition: intrin_arm.h:88
__INTRIN_INLINE unsigned char _BitScanReverse(unsigned long *const Index, const unsigned long Mask)
Definition: intrin_arm.h:180
__INTRIN_INLINE char _InterlockedOr8(volatile char *const value, const char mask)
Definition: intrin_arm.h:237
volatile char *const const char modify volatile long *const const long modify _InterlockedOr16
Definition: intrin_ppc.h:269
_InterlockedAnd8
Definition: intrin_ppc.h:265
volatile char *const const char modify volatile long *const const long modify volatile short *const const short modify volatile char *const const char modify _InterlockedXor
Definition: intrin_ppc.h:273
volatile char *const const char modify _InterlockedAnd
Definition: intrin_ppc.h:267
volatile char *const const char modify volatile long *const const long modify volatile short *const const short modify _InterlockedXor8
Definition: intrin_ppc.h:271
#define a
Definition: ke_i.h:78
#define c
Definition: ke_i.h:80
#define b
Definition: ke_i.h:79
static char * dest
Definition: rtl.c:135
#define shift
Definition: input.c:1755
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3004
__asm__(".p2align 4, 0x90\n" ".seh_proc __seh2_global_filter_func\n" "__seh2_global_filter_func:\n" "\tpush %rbp\n" "\t.seh_pushreg %rbp\n" "\tsub $32, %rsp\n" "\t.seh_stackalloc 32\n" "\t.seh_endprologue\n" "\tmov %rdx, %rbp\n" "\tjmp *%rax\n" "__seh2_global_filter_func_exit:\n" "\t.p2align 4\n" "\tadd $32, %rsp\n" "\tpop %rbp\n" "\tret\n" "\t.seh_endproc")
Definition: pdh_main.c:94
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306