new beta-0.90.0
[luatex.git] / source / libs / luajit / LuaJIT-src / src / lj_arch.h
blobd95848fe5cf6542a74f32c27d53cd004c1f84cb6
1 /*
2 ** Target architecture selection.
3 ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
4 */
6 #ifndef _LJ_ARCH_H
7 #define _LJ_ARCH_H
9 #include "lua.h"
11 /* Target endianess. */
12 #define LUAJIT_LE 0
13 #define LUAJIT_BE 1
15 /* Target architectures. */
16 #define LUAJIT_ARCH_X86 1
17 #define LUAJIT_ARCH_x86 1
18 #define LUAJIT_ARCH_X64 2
19 #define LUAJIT_ARCH_x64 2
20 #define LUAJIT_ARCH_ARM 3
21 #define LUAJIT_ARCH_arm 3
22 #define LUAJIT_ARCH_ARM64 4
23 #define LUAJIT_ARCH_arm64 4
24 #define LUAJIT_ARCH_PPC 5
25 #define LUAJIT_ARCH_ppc 5
26 #define LUAJIT_ARCH_MIPS 6
27 #define LUAJIT_ARCH_mips 6
29 /* Target OS. */
30 #define LUAJIT_OS_OTHER 0
31 #define LUAJIT_OS_WINDOWS 1
32 #define LUAJIT_OS_LINUX 2
33 #define LUAJIT_OS_OSX 3
34 #define LUAJIT_OS_BSD 4
35 #define LUAJIT_OS_POSIX 5
37 /* Select native target if no target defined. */
38 #ifndef LUAJIT_TARGET
40 #if defined(__i386) || defined(__i386__) || defined(_M_IX86)
41 #define LUAJIT_TARGET LUAJIT_ARCH_X86
42 #elif defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
43 #define LUAJIT_TARGET LUAJIT_ARCH_X64
44 #elif defined(__arm__) || defined(__arm) || defined(__ARM__) || defined(__ARM)
45 #define LUAJIT_TARGET LUAJIT_ARCH_ARM
46 #elif defined(__aarch64__)
47 #define LUAJIT_TARGET LUAJIT_ARCH_ARM64
48 #elif defined(__ppc__) || defined(__ppc) || defined(__PPC__) || defined(__PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__POWERPC) || defined(_M_PPC)
49 #define LUAJIT_TARGET LUAJIT_ARCH_PPC
50 #elif defined(__mips__) || defined(__mips) || defined(__MIPS__) || defined(__MIPS)
51 #define LUAJIT_TARGET LUAJIT_ARCH_MIPS
52 #else
53 #error "No support for this architecture (yet)"
54 #endif
56 #endif
58 /* Select native OS if no target OS defined. */
59 #ifndef LUAJIT_OS
61 #if defined(_WIN32) && !defined(_XBOX_VER)
62 #define LUAJIT_OS LUAJIT_OS_WINDOWS
63 #elif defined(__linux__)
64 #define LUAJIT_OS LUAJIT_OS_LINUX
65 #elif defined(__MACH__) && defined(__APPLE__)
66 #define LUAJIT_OS LUAJIT_OS_OSX
67 #elif (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
68 defined(__NetBSD__) || defined(__OpenBSD__) || \
69 defined(__DragonFly__)) && !defined(__ORBIS__)
70 #define LUAJIT_OS LUAJIT_OS_BSD
71 #elif (defined(__sun__) && defined(__svr4__)) || defined(__CYGWIN__)
72 #define LUAJIT_OS LUAJIT_OS_POSIX
73 #else
74 #define LUAJIT_OS LUAJIT_OS_OTHER
75 #endif
77 #endif
79 /* Set target OS properties. */
80 #if LUAJIT_OS == LUAJIT_OS_WINDOWS
81 #define LJ_OS_NAME "Windows"
82 #elif LUAJIT_OS == LUAJIT_OS_LINUX
83 #define LJ_OS_NAME "Linux"
84 #elif LUAJIT_OS == LUAJIT_OS_OSX
85 #define LJ_OS_NAME "OSX"
86 #elif LUAJIT_OS == LUAJIT_OS_BSD
87 #define LJ_OS_NAME "BSD"
88 #elif LUAJIT_OS == LUAJIT_OS_POSIX
89 #define LJ_OS_NAME "POSIX"
90 #else
91 #define LJ_OS_NAME "Other"
92 #endif
94 #define LJ_TARGET_WINDOWS (LUAJIT_OS == LUAJIT_OS_WINDOWS)
95 #define LJ_TARGET_LINUX (LUAJIT_OS == LUAJIT_OS_LINUX)
96 #define LJ_TARGET_OSX (LUAJIT_OS == LUAJIT_OS_OSX)
97 #define LJ_TARGET_IOS (LJ_TARGET_OSX && (LUAJIT_TARGET == LUAJIT_ARCH_ARM || LUAJIT_TARGET == LUAJIT_ARCH_ARM64))
98 #define LJ_TARGET_POSIX (LUAJIT_OS > LUAJIT_OS_WINDOWS)
99 #define LJ_TARGET_DLOPEN LJ_TARGET_POSIX
101 #ifdef __CELLOS_LV2__
102 #define LJ_TARGET_PS3 1
103 #define LJ_TARGET_CONSOLE 1
104 #endif
106 #ifdef __ORBIS__
107 #define LJ_TARGET_PS4 1
108 #define LJ_TARGET_CONSOLE 1
109 #undef NULL
110 #define NULL ((void*)0)
111 #endif
113 #ifdef __psp2__
114 #define LJ_TARGET_PSVITA 1
115 #define LJ_TARGET_CONSOLE 1
116 #endif
118 #if _XBOX_VER >= 200
119 #define LJ_TARGET_XBOX360 1
120 #define LJ_TARGET_CONSOLE 1
121 #endif
123 #ifdef _DURANGO
124 #define LJ_TARGET_XBOXONE 1
125 #define LJ_TARGET_CONSOLE 1
126 #define LJ_TARGET_GC64 1
127 #endif
129 #define LJ_NUMMODE_SINGLE 0 /* Single-number mode only. */
130 #define LJ_NUMMODE_SINGLE_DUAL 1 /* Default to single-number mode. */
131 #define LJ_NUMMODE_DUAL 2 /* Dual-number mode only. */
132 #define LJ_NUMMODE_DUAL_SINGLE 3 /* Default to dual-number mode. */
134 /* Set target architecture properties. */
135 #if LUAJIT_TARGET == LUAJIT_ARCH_X86
137 #define LJ_ARCH_NAME "x86"
138 #define LJ_ARCH_BITS 32
139 #define LJ_ARCH_ENDIAN LUAJIT_LE
140 #if LJ_TARGET_WINDOWS || __CYGWIN__
141 #define LJ_ABI_WIN 1
142 #else
143 #define LJ_ABI_WIN 0
144 #endif
145 #define LJ_TARGET_X86 1
146 #define LJ_TARGET_X86ORX64 1
147 #define LJ_TARGET_EHRETREG 0
148 #define LJ_TARGET_MASKSHIFT 1
149 #define LJ_TARGET_MASKROT 1
150 #define LJ_TARGET_UNALIGNED 1
151 #define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE_DUAL
153 #elif LUAJIT_TARGET == LUAJIT_ARCH_X64
155 #define LJ_ARCH_NAME "x64"
156 #define LJ_ARCH_BITS 64
157 #define LJ_ARCH_ENDIAN LUAJIT_LE
158 #if LJ_TARGET_WINDOWS || __CYGWIN__
159 #define LJ_ABI_WIN 1
160 #else
161 #define LJ_ABI_WIN 0
162 #endif
163 #define LJ_TARGET_X64 1
164 #define LJ_TARGET_X86ORX64 1
165 #define LJ_TARGET_EHRETREG 0
166 #define LJ_TARGET_JUMPRANGE 31 /* +-2^31 = +-2GB */
167 #define LJ_TARGET_MASKSHIFT 1
168 #define LJ_TARGET_MASKROT 1
169 #define LJ_TARGET_UNALIGNED 1
170 #define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE_DUAL
171 #ifdef LUAJIT_ENABLE_GC64
172 #define LJ_TARGET_GC64 1
173 #endif
175 #elif LUAJIT_TARGET == LUAJIT_ARCH_ARM
177 #define LJ_ARCH_NAME "arm"
178 #define LJ_ARCH_BITS 32
179 #define LJ_ARCH_ENDIAN LUAJIT_LE
180 #if !defined(LJ_ARCH_HASFPU) && __SOFTFP__
181 #define LJ_ARCH_HASFPU 0
182 #endif
183 #if !defined(LJ_ABI_SOFTFP) && !__ARM_PCS_VFP
184 #define LJ_ABI_SOFTFP 1
185 #endif
186 #define LJ_ABI_EABI 1
187 #define LJ_TARGET_ARM 1
188 #define LJ_TARGET_EHRETREG 0
189 #define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */
190 #define LJ_TARGET_MASKSHIFT 0
191 #define LJ_TARGET_MASKROT 1
192 #define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */
193 #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL
195 #if __ARM_ARCH____ARM_ARCH_8__ || __ARM_ARCH_8A__
196 #define LJ_ARCH_VERSION 80
197 #elif __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH_7S__ || __ARM_ARCH_7VE__
198 #define LJ_ARCH_VERSION 70
199 #elif __ARM_ARCH_6T2__
200 #define LJ_ARCH_VERSION 61
201 #elif __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6K__ || __ARM_ARCH_6Z__ || __ARM_ARCH_6ZK__
202 #define LJ_ARCH_VERSION 60
203 #else
204 #define LJ_ARCH_VERSION 50
205 #endif
207 #elif LUAJIT_TARGET == LUAJIT_ARCH_ARM64
209 #define LJ_ARCH_NAME "arm64"
210 #define LJ_ARCH_BITS 64
211 #define LJ_ARCH_ENDIAN LUAJIT_LE
212 #define LJ_TARGET_ARM64 1
213 #define LJ_TARGET_EHRETREG 0
214 #define LJ_TARGET_JUMPRANGE 27 /* +-2^27 = +-128MB */
215 #define LJ_TARGET_MASKSHIFT 1
216 #define LJ_TARGET_MASKROT 1
217 #define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */
218 #define LJ_TARGET_GC64 1
219 #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL
220 #define LJ_ARCH_NOJIT 1 /* NYI */
222 #define LJ_ARCH_VERSION 80
224 #elif LUAJIT_TARGET == LUAJIT_ARCH_PPC
226 #ifndef LJ_ARCH_ENDIAN
227 #if __BYTE_ORDER__ != __ORDER_BIG_ENDIAN__
228 #define LJ_ARCH_ENDIAN LUAJIT_LE
229 #else
230 #define LJ_ARCH_ENDIAN LUAJIT_BE
231 #endif
232 #endif
234 #if _LP64
235 #define LJ_ARCH_BITS 64
236 #if LJ_ARCH_ENDIAN == LUAJIT_LE
237 #define LJ_ARCH_NAME "ppc64le"
238 #else
239 #define LJ_ARCH_NAME "ppc64"
240 #endif
241 #else
242 #define LJ_ARCH_BITS 32
243 #define LJ_ARCH_NAME "ppc"
244 #endif
246 #define LJ_TARGET_PPC 1
247 #define LJ_TARGET_EHRETREG 3
248 #define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */
249 #define LJ_TARGET_MASKSHIFT 0
250 #define LJ_TARGET_MASKROT 1
251 #define LJ_TARGET_UNIFYROT 1 /* Want only IR_BROL. */
252 #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL_SINGLE
254 #if LJ_TARGET_CONSOLE
255 #define LJ_ARCH_PPC32ON64 1
256 #define LJ_ARCH_NOFFI 1
257 #elif LJ_ARCH_BITS == 64
258 #define LJ_ARCH_PPC64 1
259 #define LJ_TARGET_GC64 1
260 #define LJ_ARCH_NOJIT 1 /* NYI */
261 #endif
263 #if _ARCH_PWR7
264 #define LJ_ARCH_VERSION 70
265 #elif _ARCH_PWR6
266 #define LJ_ARCH_VERSION 60
267 #elif _ARCH_PWR5X
268 #define LJ_ARCH_VERSION 51
269 #elif _ARCH_PWR5
270 #define LJ_ARCH_VERSION 50
271 #elif _ARCH_PWR4
272 #define LJ_ARCH_VERSION 40
273 #else
274 #define LJ_ARCH_VERSION 0
275 #endif
276 #if _ARCH_PPCSQ
277 #define LJ_ARCH_SQRT 1
278 #endif
279 #if _ARCH_PWR5X
280 #define LJ_ARCH_ROUND 1
281 #endif
282 #if __PPU__
283 #define LJ_ARCH_CELL 1
284 #endif
285 #if LJ_TARGET_XBOX360
286 #define LJ_ARCH_XENON 1
287 #endif
289 #elif LUAJIT_TARGET == LUAJIT_ARCH_MIPS
291 #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL)
292 #define LJ_ARCH_NAME "mipsel"
293 #define LJ_ARCH_ENDIAN LUAJIT_LE
294 #else
295 #define LJ_ARCH_NAME "mips"
296 #define LJ_ARCH_ENDIAN LUAJIT_BE
297 #endif
299 #if !defined(LJ_ARCH_HASFPU)
300 #ifdef __mips_soft_float
301 #define LJ_ARCH_HASFPU 0
302 #else
303 #define LJ_ARCH_HASFPU 1
304 #endif
305 #endif
307 /* Temporarily disable features until the code has been merged. */
308 #if !defined(LUAJIT_NO_UNWIND) && __GNU_COMPACT_EH__
309 #define LUAJIT_NO_UNWIND 1
310 #endif
312 #if !defined(LJ_ABI_SOFTFP)
313 #ifdef __mips_soft_float
314 #define LJ_ABI_SOFTFP 1
315 #else
316 #define LJ_ABI_SOFTFP 0
317 #endif
318 #endif
320 #define LJ_ARCH_BITS 32
321 #define LJ_TARGET_MIPS 1
322 #define LJ_TARGET_EHRETREG 4
323 #define LJ_TARGET_JUMPRANGE 27 /* 2*2^27 = 256MB-aligned region */
324 #define LJ_TARGET_MASKSHIFT 1
325 #define LJ_TARGET_MASKROT 1
326 #define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */
327 #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL
329 #if _MIPS_ARCH_MIPS32R2
330 #define LJ_ARCH_VERSION 20
331 #else
332 #define LJ_ARCH_VERSION 10
333 #endif
335 #else
336 #error "No target architecture defined"
337 #endif
339 #ifndef LJ_PAGESIZE
340 #define LJ_PAGESIZE 4096
341 #endif
343 /* Check for minimum required compiler versions. */
344 #if defined(__GNUC__)
345 #if LJ_TARGET_X86
346 #if (__GNUC__ < 3) || ((__GNUC__ == 3) && __GNUC_MINOR__ < 4)
347 #error "Need at least GCC 3.4 or newer"
348 #endif
349 #elif LJ_TARGET_X64
350 #if __GNUC__ < 4
351 #error "Need at least GCC 4.0 or newer"
352 #endif
353 #elif LJ_TARGET_ARM || LJ_TARGET_PPC
354 #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 2)
355 #error "Need at least GCC 4.2 or newer"
356 #endif
357 #elif LJ_TARGET_ARM64
358 #if __clang__
359 #if (__clang_major__ < 3) || ((__clang_major__ == 3) && __clang_minor__ < 5)
360 #error "Need at least Clang 3.5 or newer"
361 #endif
362 #else
363 #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 8)
364 #error "Need at least GCC 4.8 or newer"
365 #endif
366 #endif
367 #elif !LJ_TARGET_PS3
368 #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3)
369 #error "Need at least GCC 4.3 or newer"
370 #endif
371 #endif
372 #endif
374 /* Check target-specific constraints. */
375 #ifndef _BUILDVM_H
376 #if LJ_TARGET_X64
377 #if __USING_SJLJ_EXCEPTIONS__
378 #error "Need a C compiler with native exception handling on x64"
379 #endif
380 #elif LJ_TARGET_ARM
381 #if defined(__ARMEB__)
382 #error "No support for big-endian ARM"
383 #endif
384 #if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__
385 #error "No support for Cortex-M CPUs"
386 #endif
387 #if !(__ARM_EABI__ || LJ_TARGET_IOS)
388 #error "Only ARM EABI or iOS 3.0+ ABI is supported"
389 #endif
390 #elif LJ_TARGET_ARM64
391 #if defined(__AARCH64EB__)
392 #error "No support for big-endian ARM64"
393 #endif
394 #if defined(_ILP32)
395 #error "No support for ILP32 model on ARM64"
396 #endif
397 #elif LJ_TARGET_PPC
398 #if defined(_SOFT_FLOAT) || defined(_SOFT_DOUBLE)
399 #error "No support for PowerPC CPUs without double-precision FPU"
400 #endif
401 #if !LJ_ARCH_PPC64 && LJ_ARCH_ENDIAN == LUAJIT_LE
402 #error "No support for little-endian PPC32"
403 #endif
404 #if LJ_ARCH_PPC64
405 #error "No support for PowerPC 64 bit mode (yet)"
406 #endif
407 #ifdef __NO_FPRS__
408 #error "No support for PPC/e500 anymore (use LuaJIT 2.0)"
409 #endif
410 #elif LJ_TARGET_MIPS
411 #if defined(_LP64)
412 #error "No support for MIPS64"
413 #endif
414 #endif
415 #endif
417 /* Enable or disable the dual-number mode for the VM. */
418 #if (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE && LUAJIT_NUMMODE == 2) || \
419 (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL && LUAJIT_NUMMODE == 1)
420 #error "No support for this number mode on this architecture"
421 #endif
422 #if LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL || \
423 (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL_SINGLE && LUAJIT_NUMMODE != 1) || \
424 (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE_DUAL && LUAJIT_NUMMODE == 2)
425 #define LJ_DUALNUM 1
426 #else
427 #define LJ_DUALNUM 0
428 #endif
430 #if LJ_TARGET_IOS || LJ_TARGET_CONSOLE
431 /* Runtime code generation is restricted on iOS. Complain to Apple, not me. */
432 /* Ditto for the consoles. Complain to Sony or MS, not me. */
433 #ifndef LUAJIT_ENABLE_JIT
434 #define LJ_OS_NOJIT 1
435 #endif
436 #endif
438 /* 64 bit GC references. */
439 #if LJ_TARGET_GC64
440 #define LJ_GC64 1
441 #else
442 #define LJ_GC64 0
443 #endif
445 /* 2-slot frame info. */
446 #if LJ_GC64
447 #define LJ_FR2 1
448 #else
449 #define LJ_FR2 0
450 #endif
452 /* Disable or enable the JIT compiler. */
453 #if defined(LUAJIT_DISABLE_JIT) || defined(LJ_ARCH_NOJIT) || defined(LJ_OS_NOJIT) || LJ_FR2 || LJ_GC64
454 #define LJ_HASJIT 0
455 #else
456 #define LJ_HASJIT 1
457 #endif
459 /* Disable or enable the FFI extension. */
460 #if defined(LUAJIT_DISABLE_FFI) || defined(LJ_ARCH_NOFFI)
461 #define LJ_HASFFI 0
462 #else
463 #define LJ_HASFFI 1
464 #endif
466 #if defined(LUAJIT_DISABLE_PROFILE)
467 #define LJ_HASPROFILE 0
468 #elif LJ_TARGET_POSIX
469 #define LJ_HASPROFILE 1
470 #define LJ_PROFILE_SIGPROF 1
471 #elif LJ_TARGET_PS3
472 #define LJ_HASPROFILE 1
473 #define LJ_PROFILE_PTHREAD 1
474 #elif LJ_TARGET_WINDOWS || LJ_TARGET_XBOX360
475 #define LJ_HASPROFILE 1
476 #define LJ_PROFILE_WTHREAD 1
477 #else
478 #define LJ_HASPROFILE 0
479 #endif
481 #ifndef LJ_ARCH_HASFPU
482 #define LJ_ARCH_HASFPU 1
483 #endif
484 #ifndef LJ_ABI_SOFTFP
485 #define LJ_ABI_SOFTFP 0
486 #endif
487 #define LJ_SOFTFP (!LJ_ARCH_HASFPU)
489 #if LJ_ARCH_ENDIAN == LUAJIT_BE
490 #define LJ_LE 0
491 #define LJ_BE 1
492 #define LJ_ENDIAN_SELECT(le, be) be
493 #define LJ_ENDIAN_LOHI(lo, hi) hi lo
494 #else
495 #define LJ_LE 1
496 #define LJ_BE 0
497 #define LJ_ENDIAN_SELECT(le, be) le
498 #define LJ_ENDIAN_LOHI(lo, hi) lo hi
499 #endif
501 #if LJ_ARCH_BITS == 32
502 #define LJ_32 1
503 #define LJ_64 0
504 #else
505 #define LJ_32 0
506 #define LJ_64 1
507 #endif
509 #ifndef LJ_TARGET_UNALIGNED
510 #define LJ_TARGET_UNALIGNED 0
511 #endif
513 /* Various workarounds for embedded operating systems or weak C runtimes. */
514 #if defined(__ANDROID__) || defined(__symbian__) || LJ_TARGET_XBOX360 || LJ_TARGET_WINDOWS
515 #define LUAJIT_NO_LOG2
516 #endif
517 #if defined(__symbian__) || LJ_TARGET_WINDOWS
518 #define LUAJIT_NO_EXP2
519 #endif
520 #if LJ_TARGET_CONSOLE || (LJ_TARGET_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0)
521 #define LJ_NO_SYSTEM 1
522 #endif
524 #if defined(LUAJIT_NO_UNWIND) || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 || LJ_TARGET_PS4
525 #define LJ_NO_UNWIND 1
526 #endif
528 /* Compatibility with Lua 5.1 vs. 5.2. */
529 #ifdef LUAJIT_ENABLE_LUA52COMPAT
530 #define LJ_52 1
531 #else
532 #define LJ_52 0
533 #endif
535 #endif