chiark / gitweb /
Patch from Graham Inggs to add symbols support (Closes: #767374)
[pcre3.git] / sljit / sljitConfigInternal.h
1 /*
2  *    Stack-less Just-In-Time compiler
3  *
4  *    Copyright 2009-2012 Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without modification, are
7  * permitted provided that the following conditions are met:
8  *
9  *   1. Redistributions of source code must retain the above copyright notice, this list of
10  *      conditions and the following disclaimer.
11  *
12  *   2. Redistributions in binary form must reproduce the above copyright notice, this list
13  *      of conditions and the following disclaimer in the documentation and/or other materials
14  *      provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19  * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #ifndef _SLJIT_CONFIG_INTERNAL_H_
28 #define _SLJIT_CONFIG_INTERNAL_H_
29
30 /*
31    SLJIT defines the following architecture dependent types and macros:
32
33    Types:
34      sljit_sb, sljit_ub : signed and unsigned 8 bit byte
35      sljit_sh, sljit_uh : signed and unsigned 16 bit half-word (short) type
36      sljit_si, sljit_ui : signed and unsigned 32 bit integer type
37      sljit_sw, sljit_uw : signed and unsigned machine word, enough to store a pointer
38      sljit_p : unsgined pointer value (usually the same as sljit_uw, but
39                some 64 bit ABIs may use 32 bit pointers)
40      sljit_s : single precision floating point value
41      sljit_d : double precision floating point value
42
43    Macros for feature detection (boolean):
44      SLJIT_32BIT_ARCHITECTURE : 32 bit architecture
45      SLJIT_64BIT_ARCHITECTURE : 64 bit architecture
46      SLJIT_LITTLE_ENDIAN : little endian architecture
47      SLJIT_BIG_ENDIAN : big endian architecture
48      SLJIT_UNALIGNED : allows unaligned memory accesses for non-fpu operations (only!)
49      SLJIT_INDIRECT_CALL : see SLJIT_FUNC_OFFSET() for more information
50
51    Constants:
52      SLJIT_NUMBER_OF_REGISTERS : number of available registers
53      SLJIT_NUMBER_OF_SCRATCH_REGISTERS : number of available scratch registers
54      SLJIT_NUMBER_OF_SAVED_REGISTERS : number of available saved registers
55      SLJIT_NUMBER_OF_FLOAT_REGISTERS : number of available floating point registers
56      SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS : number of available floating point scratch registers
57      SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS : number of available floating point saved registers
58      SLJIT_WORD_SHIFT : the shift required to apply when accessing a sljit_sw/sljit_uw array by index
59      SLJIT_DOUBLE_SHIFT : the shift required to apply when accessing
60                           a double precision floating point array by index
61      SLJIT_SINGLE_SHIFT : the shift required to apply when accessing
62                           a single precision floating point array by index
63      SLJIT_LOCALS_OFFSET : local space starting offset (SLJIT_SP + SLJIT_LOCALS_OFFSET)
64      SLJIT_RETURN_ADDRESS_OFFSET : a return instruction always adds this offset to the return address
65
66    Other macros:
67      SLJIT_CALL : C calling convention define for both calling JIT form C and C callbacks for JIT
68      SLJIT_W(number) : defining 64 bit constants on 64 bit architectures (compiler independent helper)
69 */
70
71 /*****************/
72 /* Sanity check. */
73 /*****************/
74
75 #if !((defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
76         || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
77         || (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) \
78         || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
79         || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
80         || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
81         || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
82         || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
83         || (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
84         || (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) \
85         || (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) \
86         || (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX) \
87         || (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO) \
88         || (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED))
89 #error "An architecture must be selected"
90 #endif
91
92 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
93         + (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
94         + (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) \
95         + (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
96         + (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
97         + (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
98         + (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
99         + (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
100         + (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX) \
101         + (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
102         + (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) \
103         + (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) \
104         + (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO) \
105         + (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) >= 2
106 #error "Multiple architectures are selected"
107 #endif
108
109 /********************************************************/
110 /* Automatic CPU detection (requires compiler support). */
111 /********************************************************/
112
113 #if (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO)
114
115 #ifndef _WIN32
116
117 #if defined(__i386__) || defined(__i386)
118 #define SLJIT_CONFIG_X86_32 1
119 #elif defined(__x86_64__)
120 # if defined(__ILP32__)
121 #  define SLJIT_CONFIG_UNSUPPORTED 1
122 # else
123 #  define SLJIT_CONFIG_X86_64 1
124 # endif
125 #elif defined(__arm__) || defined(__ARM__)
126 #ifdef __thumb2__
127 #define SLJIT_CONFIG_ARM_THUMB2 1
128 #elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__)
129 #define SLJIT_CONFIG_ARM_V7 1
130 #else
131 #define SLJIT_CONFIG_ARM_V5 1
132 #endif
133 #elif defined (__aarch64__)
134 #define SLJIT_CONFIG_ARM_64 1
135 #elif defined(__ppc64__) || defined(__powerpc64__) || defined(_ARCH_PPC64) || (defined(_POWER) && defined(__64BIT__))
136 #define SLJIT_CONFIG_PPC_64 1
137 #elif defined(__ppc__) || defined(__powerpc__) || defined(_ARCH_PPC) || defined(_ARCH_PWR) || defined(_ARCH_PWR2) || defined(_POWER)
138 # ifndef __NO_FPRS__
139 #  define SLJIT_CONFIG_PPC_32 1
140 # else
141 #  define SLJIT_CONFIG_UNSUPPORTED 1
142 # endif
143 #elif defined(__mips__) && !defined(_LP64)
144 #define SLJIT_CONFIG_MIPS_32 1
145 #elif defined(__mips64)
146 #define SLJIT_CONFIG_MIPS_64 1
147 #elif defined(__sparc__) || defined(__sparc)
148 # if defined(__arch64__)
149 #  define SLJIT_CONFIG_UNSUPPORTED 1
150 # else
151 #  define SLJIT_CONFIG_SPARC_32 1
152 # endif
153 #elif defined(__tilegx__)
154 #define SLJIT_CONFIG_TILEGX 1
155 #else
156 /* Unsupported architecture */
157 #define SLJIT_CONFIG_UNSUPPORTED 1
158 #endif
159
160 #else /* !_WIN32 */
161
162 #if defined(_M_X64) || defined(__x86_64__)
163 #define SLJIT_CONFIG_X86_64 1
164 #elif defined(_ARM_)
165 #define SLJIT_CONFIG_ARM_V5 1
166 #else
167 #define SLJIT_CONFIG_X86_32 1
168 #endif
169
170 #endif /* !WIN32 */
171 #endif /* SLJIT_CONFIG_AUTO */
172
173 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
174 #undef SLJIT_EXECUTABLE_ALLOCATOR
175 #endif
176
177 /******************************/
178 /* CPU family type detection. */
179 /******************************/
180
181 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
182         || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
183 #define SLJIT_CONFIG_ARM_32 1
184 #endif
185
186 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
187 #define SLJIT_CONFIG_X86 1
188 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
189 #define SLJIT_CONFIG_ARM 1
190 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
191 #define SLJIT_CONFIG_PPC 1
192 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) || (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
193 #define SLJIT_CONFIG_MIPS 1
194 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) || (defined SLJIT_CONFIG_SPARC_64 && SLJIT_CONFIG_SPARC_64)
195 #define SLJIT_CONFIG_SPARC 1
196 #endif
197
198 /**********************************/
199 /* External function definitions. */
200 /**********************************/
201
202 #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED)
203
204 /* These libraries are needed for the macros below. */
205 #include <stdlib.h>
206 #include <string.h>
207
208 #endif /* SLJIT_STD_MACROS_DEFINED */
209
210 /* General macros:
211    Note: SLJIT is designed to be independent from them as possible.
212
213    In release mode (SLJIT_DEBUG is not defined) only the following
214    external functions are needed:
215 */
216
217 #ifndef SLJIT_MALLOC
218 #define SLJIT_MALLOC(size, allocator_data) malloc(size)
219 #endif
220
221 #ifndef SLJIT_FREE
222 #define SLJIT_FREE(ptr, allocator_data) free(ptr)
223 #endif
224
225 #ifndef SLJIT_MEMMOVE
226 #define SLJIT_MEMMOVE(dest, src, len) memmove(dest, src, len)
227 #endif
228
229 #ifndef SLJIT_ZEROMEM
230 #define SLJIT_ZEROMEM(dest, len) memset(dest, 0, len)
231 #endif
232
233 /***************************/
234 /* Compiler helper macros. */
235 /***************************/
236
237 #if !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY)
238
239 #if defined(__GNUC__) && (__GNUC__ >= 3)
240 #define SLJIT_LIKELY(x)         __builtin_expect((x), 1)
241 #define SLJIT_UNLIKELY(x)       __builtin_expect((x), 0)
242 #else
243 #define SLJIT_LIKELY(x)         (x)
244 #define SLJIT_UNLIKELY(x)       (x)
245 #endif
246
247 #endif /* !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY) */
248
249 #ifndef SLJIT_INLINE
250 /* Inline functions. Some old compilers do not support them. */
251 #if defined(__SUNPRO_C) && __SUNPRO_C <= 0x510
252 #define SLJIT_INLINE
253 #else
254 #define SLJIT_INLINE __inline
255 #endif
256 #endif /* !SLJIT_INLINE */
257
258 #ifndef SLJIT_NOINLINE
259 /* Not inline functions. */
260 #if defined(__GNUC__)
261 #define SLJIT_NOINLINE __attribute__ ((noinline))
262 #else
263 #define SLJIT_NOINLINE
264 #endif
265 #endif /* !SLJIT_INLINE */
266
267 #ifndef SLJIT_CONST
268 /* Const variables. */
269 #define SLJIT_CONST const
270 #endif
271
272 #ifndef SLJIT_UNUSED_ARG
273 /* Unused arguments. */
274 #define SLJIT_UNUSED_ARG(arg) (void)arg
275 #endif
276
277 /*********************************/
278 /* Type of public API functions. */
279 /*********************************/
280
281 #if (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC)
282 /* Static ABI functions. For all-in-one programs. */
283
284 #if defined(__GNUC__)
285 /* Disable unused warnings in gcc. */
286 #define SLJIT_API_FUNC_ATTRIBUTE static __attribute__((unused))
287 #else
288 #define SLJIT_API_FUNC_ATTRIBUTE static
289 #endif
290
291 #else
292 #define SLJIT_API_FUNC_ATTRIBUTE
293 #endif /* (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC) */
294
295 /****************************/
296 /* Instruction cache flush. */
297 /****************************/
298
299 #ifndef SLJIT_CACHE_FLUSH
300
301 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
302
303 /* Not required to implement on archs with unified caches. */
304 #define SLJIT_CACHE_FLUSH(from, to)
305
306 #elif defined __APPLE__
307
308 /* Supported by all macs since Mac OS 10.5.
309    However, it does not work on non-jailbroken iOS devices,
310    although the compilation is successful. */
311
312 #define SLJIT_CACHE_FLUSH(from, to) \
313         sys_icache_invalidate((char*)(from), (char*)(to) - (char*)(from))
314
315 #elif defined __ANDROID__
316
317 /* Android lacks __clear_cache; instead, cacheflush should be used. */
318
319 #define SLJIT_CACHE_FLUSH(from, to) \
320     cacheflush((long)(from), (long)(to), 0)
321
322 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
323
324 /* The __clear_cache() implementation of GCC is a dummy function on PowerPC. */
325 #define SLJIT_CACHE_FLUSH(from, to) \
326         ppc_cache_flush((from), (to))
327
328 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
329
330 /* The __clear_cache() implementation of GCC is a dummy function on Sparc. */
331 #define SLJIT_CACHE_FLUSH(from, to) \
332         sparc_cache_flush((from), (to))
333
334 #else
335
336 /* Calls __ARM_NR_cacheflush on ARM-Linux. */
337 #define SLJIT_CACHE_FLUSH(from, to) \
338         __clear_cache((char*)(from), (char*)(to))
339
340 #endif
341
342 #endif /* !SLJIT_CACHE_FLUSH */
343
344 /******************************************************/
345 /* Byte/half/int/word/single/double type definitions. */
346 /******************************************************/
347
348 /* 8 bit byte type. */
349 typedef unsigned char sljit_ub;
350 typedef signed char sljit_sb;
351
352 /* 16 bit half-word type. */
353 typedef unsigned short int sljit_uh;
354 typedef signed short int sljit_sh;
355
356 /* 32 bit integer type. */
357 typedef unsigned int sljit_ui;
358 typedef signed int sljit_si;
359
360 /* Machine word type. Enough for storing a pointer.
361      32 bit for 32 bit machines.
362      64 bit for 64 bit machines. */
363 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
364 /* Just to have something. */
365 #define SLJIT_WORD_SHIFT 0
366 typedef unsigned long int sljit_uw;
367 typedef long int sljit_sw;
368 #elif !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
369         && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
370         && !(defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
371         && !(defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) \
372         && !(defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
373 #define SLJIT_32BIT_ARCHITECTURE 1
374 #define SLJIT_WORD_SHIFT 2
375 typedef unsigned int sljit_uw;
376 typedef int sljit_sw;
377 #else
378 #define SLJIT_64BIT_ARCHITECTURE 1
379 #define SLJIT_WORD_SHIFT 3
380 #ifdef _WIN32
381 typedef unsigned __int64 sljit_uw;
382 typedef __int64 sljit_sw;
383 #else
384 typedef unsigned long int sljit_uw;
385 typedef long int sljit_sw;
386 #endif
387 #endif
388
389 typedef sljit_uw sljit_p;
390
391 /* Floating point types. */
392 typedef float sljit_s;
393 typedef double sljit_d;
394
395 /* Shift for pointer sized data. */
396 #define SLJIT_POINTER_SHIFT SLJIT_WORD_SHIFT
397
398 /* Shift for double precision sized data. */
399 #define SLJIT_DOUBLE_SHIFT 3
400 #define SLJIT_SINGLE_SHIFT 2
401
402 #ifndef SLJIT_W
403
404 /* Defining long constants. */
405 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
406 #define SLJIT_W(w)      (w##ll)
407 #else
408 #define SLJIT_W(w)      (w)
409 #endif
410
411 #endif /* !SLJIT_W */
412
413 /*************************/
414 /* Endianness detection. */
415 /*************************/
416
417 #if !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN)
418
419 /* These macros are mostly useful for the applications. */
420 #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
421         || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
422
423 #ifdef __LITTLE_ENDIAN__
424 #define SLJIT_LITTLE_ENDIAN 1
425 #else
426 #define SLJIT_BIG_ENDIAN 1
427 #endif
428
429 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
430         || (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
431
432 #ifdef __MIPSEL__
433 #define SLJIT_LITTLE_ENDIAN 1
434 #else
435 #define SLJIT_BIG_ENDIAN 1
436 #endif
437
438 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
439
440 #define SLJIT_BIG_ENDIAN 1
441
442 #else
443 #define SLJIT_LITTLE_ENDIAN 1
444 #endif
445
446 #endif /* !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) */
447
448 /* Sanity check. */
449 #if (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
450 #error "Exactly one endianness must be selected"
451 #endif
452
453 #if !(defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && !(defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
454 #error "Exactly one endianness must be selected"
455 #endif
456
457 #ifndef SLJIT_UNALIGNED
458
459 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
460         || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
461         || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
462         || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
463         || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
464         || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
465         || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
466 #define SLJIT_UNALIGNED 1
467 #endif
468
469 #endif /* !SLJIT_UNALIGNED */
470
471 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
472 /* Auto detect SSE2 support using CPUID.
473    On 64 bit x86 cpus, sse2 must be present. */
474 #define SLJIT_DETECT_SSE2 1
475 #endif
476
477 /*****************************************************************************************/
478 /* Calling convention of functions generated by SLJIT or called from the generated code. */
479 /*****************************************************************************************/
480
481 #ifndef SLJIT_CALL
482
483 #if (defined SLJIT_USE_CDECL_CALLING_CONVENTION && SLJIT_USE_CDECL_CALLING_CONVENTION)
484
485 /* Force cdecl. */
486 #define SLJIT_CALL
487
488 #elif (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
489
490 #if defined(__GNUC__) && !defined(__APPLE__)
491
492 #define SLJIT_CALL __attribute__ ((fastcall))
493 #define SLJIT_X86_32_FASTCALL 1
494
495 #elif defined(_MSC_VER)
496
497 #define SLJIT_CALL __fastcall
498 #define SLJIT_X86_32_FASTCALL 1
499
500 #elif defined(__BORLANDC__)
501
502 #define SLJIT_CALL __msfastcall
503 #define SLJIT_X86_32_FASTCALL 1
504
505 #else /* Unknown compiler. */
506
507 /* The cdecl attribute is the default. */
508 #define SLJIT_CALL
509
510 #endif
511
512 #else /* Non x86-32 architectures. */
513
514 #define SLJIT_CALL
515
516 #endif /* SLJIT_CONFIG_X86_32 */
517
518 #endif /* !SLJIT_CALL */
519
520 #ifndef SLJIT_INDIRECT_CALL
521 #if ((defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)) \
522         || ((defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) && defined _AIX)
523 /* It seems certain ppc compilers use an indirect addressing for functions
524    which makes things complicated. */
525 #define SLJIT_INDIRECT_CALL 1
526 #endif
527 #endif /* SLJIT_INDIRECT_CALL */
528
529 /* The offset which needs to be substracted from the return address to
530 determine the next executed instruction after return. */
531 #ifndef SLJIT_RETURN_ADDRESS_OFFSET
532 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
533 #define SLJIT_RETURN_ADDRESS_OFFSET 8
534 #else
535 #define SLJIT_RETURN_ADDRESS_OFFSET 0
536 #endif
537 #endif /* SLJIT_RETURN_ADDRESS_OFFSET */
538
539 /***************************************************/
540 /* Functions of the built-in executable allocator. */
541 /***************************************************/
542
543 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
544 SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size);
545 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void* ptr);
546 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_unused_memory_exec(void);
547 #define SLJIT_MALLOC_EXEC(size) sljit_malloc_exec(size)
548 #define SLJIT_FREE_EXEC(ptr) sljit_free_exec(ptr)
549 #endif
550
551 /**********************************************/
552 /* Registers and locals offset determination. */
553 /**********************************************/
554
555 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
556
557 #define SLJIT_NUMBER_OF_REGISTERS 10
558 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 7
559 #if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL)
560 #define SLJIT_LOCALS_OFFSET_BASE ((2 + 4) * sizeof(sljit_sw))
561 #else
562 /* Maximum 3 arguments are passed on the stack, +1 for double alignment. */
563 #define SLJIT_LOCALS_OFFSET_BASE ((3 + 1 + 4) * sizeof(sljit_sw))
564 #endif /* SLJIT_X86_32_FASTCALL */
565
566 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
567
568 #ifndef _WIN64
569 #define SLJIT_NUMBER_OF_REGISTERS 12
570 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 6
571 #define SLJIT_LOCALS_OFFSET_BASE (sizeof(sljit_sw))
572 #else
573 #define SLJIT_NUMBER_OF_REGISTERS 12
574 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
575 #define SLJIT_LOCALS_OFFSET_BASE ((4 + 2) * sizeof(sljit_sw))
576 #endif /* _WIN64 */
577
578 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
579
580 #define SLJIT_NUMBER_OF_REGISTERS 11
581 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
582 #define SLJIT_LOCALS_OFFSET_BASE 0
583
584 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
585
586 #define SLJIT_NUMBER_OF_REGISTERS 11
587 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 7
588 #define SLJIT_LOCALS_OFFSET_BASE 0
589
590 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
591
592 #define SLJIT_NUMBER_OF_REGISTERS 25
593 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 10
594 #define SLJIT_LOCALS_OFFSET_BASE (2 * sizeof(sljit_sw))
595
596 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
597
598 #define SLJIT_NUMBER_OF_REGISTERS 22
599 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 17
600 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) || (defined _AIX)
601 #define SLJIT_LOCALS_OFFSET_BASE ((6 + 8) * sizeof(sljit_sw))
602 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
603 /* Add +1 for double alignment. */
604 #define SLJIT_LOCALS_OFFSET_BASE ((3 + 1) * sizeof(sljit_sw))
605 #else
606 #define SLJIT_LOCALS_OFFSET_BASE (3 * sizeof(sljit_sw))
607 #endif /* SLJIT_CONFIG_PPC_64 || _AIX */
608
609 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
610
611 #define SLJIT_NUMBER_OF_REGISTERS 17
612 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
613 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
614 #define SLJIT_LOCALS_OFFSET_BASE (4 * sizeof(sljit_sw))
615 #else
616 #define SLJIT_LOCALS_OFFSET_BASE 0
617 #endif
618
619 #elif (defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
620
621 #define SLJIT_NUMBER_OF_REGISTERS 18
622 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 14
623 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
624 /* Add +1 for double alignment. */
625 #define SLJIT_LOCALS_OFFSET_BASE ((23 + 1) * sizeof(sljit_sw))
626 #endif
627
628 #elif (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
629
630 #define SLJIT_NUMBER_OF_REGISTERS 10
631 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 5
632 #define SLJIT_LOCALS_OFFSET_BASE 0
633
634 #elif (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
635
636 #define SLJIT_NUMBER_OF_REGISTERS 0
637 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 0
638 #define SLJIT_LOCALS_OFFSET_BASE 0
639
640 #endif
641
642 #define SLJIT_LOCALS_OFFSET (SLJIT_LOCALS_OFFSET_BASE)
643
644 #define SLJIT_NUMBER_OF_SCRATCH_REGISTERS \
645         (SLJIT_NUMBER_OF_REGISTERS - SLJIT_NUMBER_OF_SAVED_REGISTERS)
646
647 #define SLJIT_NUMBER_OF_FLOAT_REGISTERS 6
648 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) && (defined _WIN64)
649 #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 1
650 #else
651 #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 0
652 #endif
653
654 #define SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS \
655         (SLJIT_NUMBER_OF_FLOAT_REGISTERS - SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS)
656
657 /*************************************/
658 /* Debug and verbose related macros. */
659 /*************************************/
660
661 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
662 #include <stdio.h>
663 #endif
664
665 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
666
667 #if !defined(SLJIT_ASSERT) || !defined(SLJIT_ASSERT_STOP)
668
669 /* SLJIT_HALT_PROCESS must halt the process. */
670 #ifndef SLJIT_HALT_PROCESS
671 #include <stdlib.h>
672
673 #define SLJIT_HALT_PROCESS() \
674         abort();
675 #endif /* !SLJIT_HALT_PROCESS */
676
677 #include <stdio.h>
678
679 #endif /* !SLJIT_ASSERT || !SLJIT_ASSERT_STOP */
680
681 /* Feel free to redefine these two macros. */
682 #ifndef SLJIT_ASSERT
683
684 #define SLJIT_ASSERT(x) \
685         do { \
686                 if (SLJIT_UNLIKELY(!(x))) { \
687                         printf("Assertion failed at " __FILE__ ":%d\n", __LINE__); \
688                         SLJIT_HALT_PROCESS(); \
689                 } \
690         } while (0)
691
692 #endif /* !SLJIT_ASSERT */
693
694 #ifndef SLJIT_ASSERT_STOP
695
696 #define SLJIT_ASSERT_STOP() \
697         do { \
698                 printf("Should never been reached " __FILE__ ":%d\n", __LINE__); \
699                 SLJIT_HALT_PROCESS(); \
700         } while (0)
701
702 #endif /* !SLJIT_ASSERT_STOP */
703
704 #else /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
705
706 /* Forcing empty, but valid statements. */
707 #undef SLJIT_ASSERT
708 #undef SLJIT_ASSERT_STOP
709
710 #define SLJIT_ASSERT(x) \
711         do { } while (0)
712 #define SLJIT_ASSERT_STOP() \
713         do { } while (0)
714
715 #endif /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
716
717 #ifndef SLJIT_COMPILE_ASSERT
718
719 /* Should be improved eventually. */
720 #define SLJIT_COMPILE_ASSERT(x, description) \
721         SLJIT_ASSERT(x)
722
723 #endif /* !SLJIT_COMPILE_ASSERT */
724
725 #endif