Add basic arm target support to the build system.
[reactos.git] / reactos / include / psdk / 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 FORCEINLINE char _InterlockedCompareExchange8(volatile char * const Destination, const char Exchange, const char Comperand)
38 {
39 return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
40 }
41
42 FORCEINLINE short _InterlockedCompareExchange16(volatile short * const Destination, const short Exchange, const short Comperand)
43 {
44 return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
45 }
46
47 FORCEINLINE long _InterlockedCompareExchange(volatile long * const Destination, const long Exchange, const long Comperand)
48 {
49 return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
50 }
51
52 FORCEINLINE long long _InterlockedCompareExchange64(volatile long long * const Destination, const long long Exchange, const long long Comperand)
53 {
54 return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
55 }
56
57 FORCEINLINE void * _InterlockedCompareExchangePointer(void * volatile * const Destination, void * const Exchange, void * const Comperand)
58 {
59 return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
60 }
61
62 FORCEINLINE long _InterlockedExchange(volatile long * const Target, const long Value)
63 {
64 /* NOTE: __sync_lock_test_and_set would be an acquire barrier, so we force a full barrier */
65 __sync_synchronize();
66 return __sync_lock_test_and_set(Target, Value);
67 }
68
69 FORCEINLINE void * _InterlockedExchangePointer(void * volatile * const Target, void * const Value)
70 {
71 /* NOTE: ditto */
72 __sync_synchronize();
73 return __sync_lock_test_and_set(Target, Value);
74 }
75
76 static __inline__ __attribute__((always_inline)) long _InterlockedExchangeAdd16(volatile short * const Addend, const short Value)
77 {
78 return __sync_fetch_and_add(Addend, Value);
79 }
80
81 FORCEINLINE long _InterlockedExchangeAdd(volatile long * const Addend, const long Value)
82 {
83 return __sync_fetch_and_add(Addend, Value);
84 }
85
86 FORCEINLINE char _InterlockedAnd8(volatile char * const value, const char mask)
87 {
88 return __sync_fetch_and_and(value, mask);
89 }
90
91 FORCEINLINE short _InterlockedAnd16(volatile short * const value, const short mask)
92 {
93 return __sync_fetch_and_and(value, mask);
94 }
95
96 FORCEINLINE long _InterlockedAnd(volatile long * const value, const long mask)
97 {
98 return __sync_fetch_and_and(value, mask);
99 }
100
101 FORCEINLINE char _InterlockedOr8(volatile char * const value, const char mask)
102 {
103 return __sync_fetch_and_or(value, mask);
104 }
105
106 FORCEINLINE short _InterlockedOr16(volatile short * const value, const short mask)
107 {
108 return __sync_fetch_and_or(value, mask);
109 }
110
111 FORCEINLINE long _InterlockedOr(volatile long * const value, const long mask)
112 {
113 return __sync_fetch_and_or(value, mask);
114 }
115
116 FORCEINLINE char _InterlockedXor8(volatile char * const value, const char mask)
117 {
118 return __sync_fetch_and_xor(value, mask);
119 }
120
121 FORCEINLINE short _InterlockedXor16(volatile short * const value, const short mask)
122 {
123 return __sync_fetch_and_xor(value, mask);
124 }
125
126 FORCEINLINE long _InterlockedXor(volatile long * const value, const long mask)
127 {
128 return __sync_fetch_and_xor(value, mask);
129 }
130
131 static __inline__ __attribute__((always_inline)) long _InterlockedDecrement(volatile long * const lpAddend)
132 {
133 return _InterlockedExchangeAdd(lpAddend, -1) - 1;
134 }
135
136 static __inline__ __attribute__((always_inline)) long _InterlockedIncrement(volatile long * const lpAddend)
137 {
138 return _InterlockedExchangeAdd(lpAddend, 1) + 1;
139 }
140
141 static __inline__ __attribute__((always_inline)) long _InterlockedDecrement16(volatile short * const lpAddend)
142 {
143 return _InterlockedExchangeAdd16(lpAddend, -1) - 1;
144 }
145
146 static __inline__ __attribute__((always_inline)) long _InterlockedIncrement16(volatile short * const lpAddend)
147 {
148 return _InterlockedExchangeAdd16(lpAddend, 1) + 1;
149 }
150
151 #endif
152 /* EOF */