CBMC
gcc.c
Go to the documentation of this file.
1 /* FUNCTION: __builtin_ia32_sfence */
2 
3 #if defined(__i386__) || defined(__x86_64__)
4 
5 void __builtin_ia32_sfence(void)
6 {
7  __asm("sfence");
8 }
9 
10 #endif
11 
12 /* FUNCTION: __builtin_ia32_lfence */
13 
14 #if defined(__i386__) || defined(__x86_64__)
15 
16 void __builtin_ia32_lfence(void)
17 {
18  __asm("lfence");
19 }
20 
21 #endif
22 
23 /* FUNCTION: __builtin_ia32_mfence */
24 
25 #if defined(__i386__) || defined(__x86_64__)
26 
27 void __builtin_ia32_mfence(void)
28 {
29  __asm("mfence");
30 }
31 
32 #endif
33 
34 /* FUNCTION: __sync_synchronize */
35 
37 {
38  // WARNING: this was a NOP before gcc 4.3.1,
39  // but is now believed to be the strongest possible barrier.
40 
41  #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40301
42  __CPROVER_HIDE:;
43  __CPROVER_fence("WWfence", "RRfence", "RWfence", "WRfence",
44  "WWcumul", "RRcumul", "RWcumul", "WRcumul");
45  #endif
46 }
47 
48 /* FUNCTION: __atomic_test_and_set */
49 
50 void __atomic_thread_fence(int memorder);
51 
52 _Bool __atomic_test_and_set(void *ptr, int memorder)
53 {
54 __CPROVER_HIDE:;
56  _Bool result = *(char *)ptr == 1;
57  *(char *)ptr = 1;
58  __atomic_thread_fence(memorder);
60  return result;
61 }
62 
63 /* FUNCTION: __atomic_clear */
64 
65 void __atomic_thread_fence(int memorder);
66 
67 void __atomic_clear(_Bool *ptr, int memorder)
68 {
69 __CPROVER_HIDE:;
71  *(char *)ptr = 0;
72  __atomic_thread_fence(memorder);
74 }
75 
76 /* FUNCTION: __atomic_thread_fence */
77 
78 #if __STDC_VERSION__ >= 201112L
79 // GCC 4.8 did claim to support C++11, but failed to ship stdatomic.h
80 # if !defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__) >= 409
81 # include <stdatomic.h>
82 # endif
83 #endif
84 
85 #ifndef __ATOMIC_RELAXED
86 # define __ATOMIC_RELAXED 0
87 #endif
88 
89 #ifndef __ATOMIC_CONSUME
90 # define __ATOMIC_CONSUME 1
91 #endif
92 
93 #ifndef __ATOMIC_ACQUIRE
94 # define __ATOMIC_ACQUIRE 2
95 #endif
96 
97 #ifndef __ATOMIC_RELEASE
98 # define __ATOMIC_RELEASE 3
99 #endif
100 
101 #ifndef __ATOMIC_ACQ_REL
102 # define __ATOMIC_ACQ_REL 4
103 #endif
104 
105 #ifndef __ATOMIC_SEQ_CST
106 # define __ATOMIC_SEQ_CST 5
107 #endif
108 
109 void __atomic_thread_fence(int memorder)
110 {
111 __CPROVER_HIDE:;
112  if(memorder == __ATOMIC_CONSUME || memorder == __ATOMIC_ACQUIRE)
113  __CPROVER_fence("RRfence", "RWfence", "RRcumul", "RWcumul");
114  else if(memorder == __ATOMIC_RELEASE)
115  __CPROVER_fence("WRfence", "WWfence", "WRcumul", "WWcumul");
116  else if(memorder == __ATOMIC_ACQ_REL || memorder == __ATOMIC_SEQ_CST)
118  "WWfence",
119  "RRfence",
120  "RWfence",
121  "WRfence",
122  "WWcumul",
123  "RRcumul",
124  "RWcumul",
125  "WRcumul");
126 }
127 
128 /* FUNCTION: __atomic_signal_fence */
129 
130 void __atomic_thread_fence(int memorder);
131 
132 void __atomic_signal_fence(int memorder)
133 {
134 __CPROVER_HIDE:;
135  __atomic_thread_fence(memorder);
136 }
137 
138 /* FUNCTION: __atomic_always_lock_free */
139 
140 _Bool __atomic_always_lock_free(__CPROVER_size_t size, void *ptr)
141 {
142 __CPROVER_HIDE:;
143  (void)ptr;
144  return size <= sizeof(__CPROVER_size_t);
145 }
146 
147 /* FUNCTION: __atomic_is_lock_free */
148 
149 _Bool __atomic_is_lock_free(__CPROVER_size_t size, void *ptr)
150 {
151 __CPROVER_HIDE:;
152  (void)ptr;
153  return size <= sizeof(__CPROVER_size_t);
154 }
155 
156 /* FUNCTION: __builtin_ia32_vec_ext_v4hi */
157 
158 typedef short __gcc_v4hi __attribute__((__vector_size__(8)));
159 
160 short __builtin_ia32_vec_ext_v4hi(__gcc_v4hi vec, int offset)
161 {
162  return *((short *)&vec + offset);
163 }
164 
165 /* FUNCTION: __builtin_ia32_vec_ext_v8hi */
166 
167 typedef short __gcc_v8hi __attribute__((__vector_size__(16)));
168 
169 short __builtin_ia32_vec_ext_v8hi(__gcc_v8hi vec, int offset)
170 {
171  return *((short *)&vec + offset);
172 }
173 
174 /* FUNCTION: __builtin_ia32_vec_ext_v4si */
175 
176 typedef int __gcc_v4si __attribute__((__vector_size__(16)));
177 
178 int __builtin_ia32_vec_ext_v4si(__gcc_v4si vec, int offset)
179 {
180  return *((int *)&vec + offset);
181 }
182 
183 /* FUNCTION: __builtin_ia32_vec_ext_v2di */
184 
185 typedef long long __gcc_v2di __attribute__((__vector_size__(16)));
186 
187 long long __builtin_ia32_vec_ext_v2di(__gcc_v2di vec, int offset)
188 {
189  return *((long long *)&vec + offset);
190 }
191 
192 /* FUNCTION: __builtin_ia32_vec_ext_v16qi */
193 
194 typedef char __gcc_v16qi __attribute__((__vector_size__(16)));
195 
196 int __builtin_ia32_vec_ext_v16qi(__gcc_v16qi vec, int offset)
197 {
198  return *((char *)&vec + offset);
199 }
200 
201 /* FUNCTION: __builtin_ia32_vec_ext_v4sf */
202 
203 typedef float __gcc_v4sf __attribute__((__vector_size__(16)));
204 
205 float __builtin_ia32_vec_ext_v4sf(__gcc_v4sf vec, int offset)
206 {
207  return *((float *)&vec + offset);
208 }
209 
210 /* FUNCTION: __builtin_ia32_psubsw128 */
211 
212 #ifndef LIBRARY_CHECK
213 typedef short __gcc_v8hi __attribute__((__vector_size__(16)));
214 #else
215 __gcc_v8hi __CPROVER_saturating_minus(__gcc_v8hi, __gcc_v8hi);
216 #endif
217 
218 __gcc_v8hi __builtin_ia32_psubsw128(__gcc_v8hi a, __gcc_v8hi b)
219 {
220  return __CPROVER_saturating_minus(a, b);
221 }
222 
223 /* FUNCTION: __builtin_ia32_psubusw128 */
224 
225 #ifndef LIBRARY_CHECK
226 typedef short __gcc_v8hi __attribute__((__vector_size__(16)));
227 #else
228 typedef unsigned short v8hi_u __attribute__((__vector_size__(16)));
229 __gcc_v8hi __CPROVER_saturating_minus_v8hi_u(v8hi_u, v8hi_u);
230 # define __CPROVER_saturating_minus __CPROVER_saturating_minus_v8hi_u
231 #endif
232 
233 __gcc_v8hi __builtin_ia32_psubusw128(__gcc_v8hi a, __gcc_v8hi b)
234 {
235  typedef unsigned short v8hi_u __attribute__((__vector_size__(16)));
236  return (__gcc_v8hi)__CPROVER_saturating_minus((v8hi_u)a, (v8hi_u)b);
237 }
238 
239 /* FUNCTION: __builtin_ia32_paddsw */
240 
241 #ifndef LIBRARY_CHECK
242 typedef short __gcc_v4hi __attribute__((__vector_size__(8)));
243 #else
244 __gcc_v4hi __CPROVER_saturating_plus(__gcc_v4hi, __gcc_v4hi);
245 #endif
246 
247 __gcc_v4hi __builtin_ia32_paddsw(__gcc_v4hi a, __gcc_v4hi b)
248 {
249  return __CPROVER_saturating_plus(a, b);
250 }
251 
252 /* FUNCTION: __builtin_ia32_psubsw */
253 
254 #ifndef LIBRARY_CHECK
255 typedef short __gcc_v4hi __attribute__((__vector_size__(8)));
256 #else
257 __gcc_v4hi __CPROVER_saturating_minus_v4hi(__gcc_v4hi, __gcc_v4hi);
258 # undef __CPROVER_saturating_minus
259 # define __CPROVER_saturating_minus __CPROVER_saturating_minus_v4hi
260 #endif
261 
262 __gcc_v4hi __builtin_ia32_psubsw(__gcc_v4hi a, __gcc_v4hi b)
263 {
264  return __CPROVER_saturating_minus(a, b);
265 }
266 
267 #ifdef LIBRARY_CHECK
268 # undef __CPROVER_saturating_minus
269 #endif
270 
271 /* FUNCTION: __builtin_ia32_vec_init_v4hi */
272 
273 #ifndef LIBRARY_CHECK
274 typedef short __gcc_v4hi __attribute__((__vector_size__(8)));
275 #endif
276 
277 __gcc_v4hi __builtin_ia32_vec_init_v4hi(short e0, short e1, short e2, short e3)
278 {
279  return (__gcc_v4hi){e0, e1, e2, e3};
280 }
void __CPROVER_fence(const char *kind,...)
void __CPROVER_atomic_begin(void)
void __CPROVER_atomic_end(void)
#define __ATOMIC_SEQ_CST
Definition: gcc.c:106
long long __builtin_ia32_vec_ext_v2di(__gcc_v2di vec, int offset)
Definition: gcc.c:187
void __sync_synchronize(void)
Definition: gcc.c:36
short __builtin_ia32_vec_ext_v8hi(__gcc_v8hi vec, int offset)
Definition: gcc.c:169
__gcc_v8hi __builtin_ia32_psubusw128(__gcc_v8hi a, __gcc_v8hi b)
Definition: gcc.c:233
__gcc_v4hi __builtin_ia32_psubsw(__gcc_v4hi a, __gcc_v4hi b)
Definition: gcc.c:262
#define __ATOMIC_RELEASE
Definition: gcc.c:98
_Bool __atomic_always_lock_free(__CPROVER_size_t size, void *ptr)
Definition: gcc.c:140
short __builtin_ia32_vec_ext_v4hi(__gcc_v4hi vec, int offset)
Definition: gcc.c:160
#define __ATOMIC_ACQUIRE
Definition: gcc.c:94
#define __ATOMIC_CONSUME
Definition: gcc.c:90
short __gcc_v4hi __attribute__((__vector_size__(8)))
Definition: gcc.c:158
__gcc_v4hi __builtin_ia32_vec_init_v4hi(short e0, short e1, short e2, short e3)
Definition: gcc.c:277
_Bool __atomic_is_lock_free(__CPROVER_size_t size, void *ptr)
Definition: gcc.c:149
void __atomic_clear(_Bool *ptr, int memorder)
Definition: gcc.c:67
float __builtin_ia32_vec_ext_v4sf(__gcc_v4sf vec, int offset)
Definition: gcc.c:205
int __builtin_ia32_vec_ext_v16qi(__gcc_v16qi vec, int offset)
Definition: gcc.c:196
int __builtin_ia32_vec_ext_v4si(__gcc_v4si vec, int offset)
Definition: gcc.c:178
__gcc_v8hi __builtin_ia32_psubsw128(__gcc_v8hi a, __gcc_v8hi b)
Definition: gcc.c:218
#define __ATOMIC_ACQ_REL
Definition: gcc.c:102
void __atomic_thread_fence(int memorder)
Definition: gcc.c:109
void __atomic_signal_fence(int memorder)
Definition: gcc.c:132
_Bool __atomic_test_and_set(void *ptr, int memorder)
Definition: gcc.c:52
__gcc_v4hi __builtin_ia32_paddsw(__gcc_v4hi a, __gcc_v4hi b)
Definition: gcc.c:247
void __builtin_ia32_mfence(void)
void __builtin_ia32_sfence(void)
void __builtin_ia32_lfence(void)