Add support for the Linux io_uring system calls
[valgrind.git] / coregrind / m_compiler.c
blob9e792e8a4321cce9815d46509e8237bb298e3068
1 /* -*- mode: C; c-basic-offset: 3; -*- */
3 /*--------------------------------------------------------------------*/
4 /*--- Compiler specific stuff. m_compiler.c ---*/
5 /*--------------------------------------------------------------------*/
7 /*
8 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
11 Copyright (C) 2014-2017 Florian Krohm
12 florian@eich-krohm.de
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, see <http://www.gnu.org/licenses/>.
27 The GNU General Public License is contained in the file COPYING.
30 /* Currently, this file provides definitions for builtins that not all
31 compilers or compiler versions provide.
33 Missing builtins are rare. Therefore, no attempt has been made to
34 provide efficient implementations.
37 #include "config.h"
38 #include "pub_core_basics.h"
39 #include "pub_core_libcbase.h"
40 #include "pub_core_libcassert.h"
41 #include "pub_core_debuglog.h"
43 #ifndef HAVE_BUILTIN_POPCOUT
45 /* From the GCC documentation:
46 Returns the number of 1-bits in x. */
48 UInt
49 __builtin_popcount(UInt x)
51 UInt i, count = 0;
53 for (i = 0; i < 32; ++i) {
54 count += x & 1;
55 x >>= 1;
57 return count;
60 UInt
61 __builtin_popcountll(ULong x)
63 UInt i, count = 0;
65 for (i = 0; i < 64; ++i) {
66 count += x & 1;
67 x >>= 1;
69 return count;
71 #endif
73 #ifndef HAVE_BUILTIN_CLZ
75 /* From the GCC documentation:
76 Returns the number of leading 0-bits in x, starting at the most
77 significant position. If x is 0, the result is undefined. */
79 UInt
80 __builtin_clz(UInt x)
82 UInt count = 32;
83 UInt y;
85 y = x >> 16; if (y != 0) { count -= 16; x = y; }
86 y = x >> 8; if (y != 0) { count -= 8; x = y; }
87 y = x >> 4; if (y != 0) { count -= 4; x = y; }
88 y = x >> 2; if (y != 0) { count -= 2; x = y; }
89 y = x >> 1; if (y != 0) return count - 2;
90 return count - x;
93 UInt
94 __builtin_clzll(ULong x)
96 UInt count = 64;
97 ULong y;
99 y = x >> 32; if (y != 0) { count -= 32; x = y; }
100 y = x >> 16; if (y != 0) { count -= 16; x = y; }
101 y = x >> 8; if (y != 0) { count -= 8; x = y; }
102 y = x >> 4; if (y != 0) { count -= 4; x = y; }
103 y = x >> 2; if (y != 0) { count -= 2; x = y; }
104 y = x >> 1; if (y != 0) return count - 2;
105 return count - x;
107 #endif
109 #ifndef HAVE_BUILTIN_CTZ
111 /* From the GCC documentation:
112 Returns the number of trailing 0-bits in x, starting at the least
113 significant bit position. If x is 0, the result is undefined. */
115 UInt
116 __builtin_ctz(UInt x)
118 UInt i, count = 0;
120 for (i = 0; i < 32; ++i) {
121 if (x & 1) break;
122 ++count;
123 x >>= 1;
125 return count;
128 UInt
129 __builtin_ctzll(ULong x)
131 UInt i, count = 0;
133 for (i = 0; i < 64; ++i) {
134 if (x & 1) break;
135 ++count;
136 x >>= 1;
138 return count;
140 #endif
143 #ifdef __INTEL_COMPILER
145 /* Provide certain functions Intel's ICC compiler expects to be defined. */
147 void *
148 __intel_memcpy(void *dest, const void *src, SizeT sz)
150 return VG_(memcpy)( dest, src, sz );
153 void *
154 __intel_mic_avx512f_memcpy(void *dest, const void *src, SizeT sz)
156 return VG_(memcpy)( dest, src, sz );
159 void *
160 __intel_new_memcpy(void *dest, const void *src, SizeT sz)
162 return VG_(memcpy)( dest, src, sz );
165 void *
166 __intel_ssse3_memcpy(void *dest, const void *src, SizeT sz)
168 return VG_(memcpy)( dest, src, sz );
171 void *
172 __intel_ssse3_rep_memcpy(void *dest, const void *src, SizeT sz)
174 return VG_(memcpy)( dest, src, sz );
177 void *
178 _intel_fast_memcpy(void *dest, const void *src, SizeT sz)
180 return VG_(memcpy)( dest, src, sz );
183 void *
184 __intel_lrb_memcpy(void *dest, const void *src, SizeT sz)
186 return VG_(memcpy)( dest, src, sz );
189 void *
190 __intel_memset(void *dest, int value, SizeT num)
192 return VG_(memset)( dest, value, num );
195 void *
196 __intel_new_memset(void *dest, int value, SizeT num)
198 return VG_(memset)( dest, value, num );
201 void *
202 __intel_mic_avx512f_memset(void *dest, int value, SizeT num)
204 return VG_(memset)( dest, value, num );
207 void *
208 __intel_lrb_memset(void *dest, int value, SizeT num)
210 return VG_(memset)( dest, value, num );
213 void *
214 _intel_fast_memset(void *dest, int value, SizeT num)
216 return VG_(memset)( dest, value, num );
219 #endif
222 /*====================================================================*/
223 /*=== gcc -fsanitize=undefined helper function support ===*/
224 /*====================================================================*/
226 void __ubsan_handle_type_mismatch ( void );
227 void __ubsan_handle_type_mismatch ( void )
229 VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
230 vg_assert(0);
233 void __ubsan_handle_type_mismatch_v1 ( void );
234 void __ubsan_handle_type_mismatch_v1 ( void )
236 VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
237 vg_assert(0);
240 void __ubsan_handle_mul_overflow ( void );
241 void __ubsan_handle_mul_overflow ( void )
243 VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
244 vg_assert(0);
247 void __ubsan_handle_add_overflow ( void );
248 void __ubsan_handle_add_overflow ( void )
250 VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
251 vg_assert(0);
254 void __ubsan_handle_sub_overflow ( void );
255 void __ubsan_handle_sub_overflow ( void )
257 VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
258 vg_assert(0);
261 void __ubsan_handle_divrem_overflow ( void );
262 void __ubsan_handle_divrem_overflow ( void )
264 VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
265 vg_assert(0);
268 void __ubsan_handle_negate_overflow ( void );
269 void __ubsan_handle_negate_overflow ( void )
271 VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
272 vg_assert(0);
275 void __ubsan_handle_pointer_overflow ( void );
276 void __ubsan_handle_pointer_overflow ( void )
278 VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
279 vg_assert(0);
282 void __ubsan_handle_out_of_bounds ( void );
283 void __ubsan_handle_out_of_bounds ( void )
285 VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
286 vg_assert(0);
289 void __ubsan_handle_shift_out_of_bounds ( void );
290 void __ubsan_handle_shift_out_of_bounds ( void )
292 VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
293 vg_assert(0);
296 void __ubsan_handle_vla_bound_not_positive ( void );
297 void __ubsan_handle_vla_bound_not_positive ( void )
299 VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
300 vg_assert(0);
303 void __ubsan_handle_nonnull_arg ( void );
304 void __ubsan_handle_nonnull_arg ( void )
306 VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
307 vg_assert(0);
310 void __ubsan_handle_invalid_builtin ( void );
311 void __ubsan_handle_invalid_builtin ( void )
313 VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
314 vg_assert(0);
317 /*--------------------------------------------------------------------*/
318 /*--- end ---*/
319 /*--------------------------------------------------------------------*/