2 ** Target architecture selection.
3 ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
11 /* Target endianess. */
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
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. */
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
53 #error "No support for this architecture (yet)"
58 /* Select native OS if no target OS defined. */
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
74 #define LUAJIT_OS LUAJIT_OS_OTHER
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"
91 #define LJ_OS_NAME "Other"
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
107 #define LJ_TARGET_PS4 1
108 #define LJ_TARGET_CONSOLE 1
110 #define NULL ((void*)0)
114 #define LJ_TARGET_PSVITA 1
115 #define LJ_TARGET_CONSOLE 1
119 #define LJ_TARGET_XBOX360 1
120 #define LJ_TARGET_CONSOLE 1
124 #define LJ_TARGET_XBOXONE 1
125 #define LJ_TARGET_CONSOLE 1
126 #define LJ_TARGET_GC64 1
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__
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__
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
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
183 #if !defined(LJ_ABI_SOFTFP) && !__ARM_PCS_VFP
184 #define LJ_ABI_SOFTFP 1
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
204 #define LJ_ARCH_VERSION 50
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
230 #define LJ_ARCH_ENDIAN LUAJIT_BE
235 #define LJ_ARCH_BITS 64
236 #if LJ_ARCH_ENDIAN == LUAJIT_LE
237 #define LJ_ARCH_NAME "ppc64le"
239 #define LJ_ARCH_NAME "ppc64"
242 #define LJ_ARCH_BITS 32
243 #define LJ_ARCH_NAME "ppc"
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 */
264 #define LJ_ARCH_VERSION 70
266 #define LJ_ARCH_VERSION 60
268 #define LJ_ARCH_VERSION 51
270 #define LJ_ARCH_VERSION 50
272 #define LJ_ARCH_VERSION 40
274 #define LJ_ARCH_VERSION 0
277 #define LJ_ARCH_SQRT 1
280 #define LJ_ARCH_ROUND 1
283 #define LJ_ARCH_CELL 1
285 #if LJ_TARGET_XBOX360
286 #define LJ_ARCH_XENON 1
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
295 #define LJ_ARCH_NAME "mips"
296 #define LJ_ARCH_ENDIAN LUAJIT_BE
299 #if !defined(LJ_ARCH_HASFPU)
300 #ifdef __mips_soft_float
301 #define LJ_ARCH_HASFPU 0
303 #define LJ_ARCH_HASFPU 1
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
312 #if !defined(LJ_ABI_SOFTFP)
313 #ifdef __mips_soft_float
314 #define LJ_ABI_SOFTFP 1
316 #define LJ_ABI_SOFTFP 0
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
332 #define LJ_ARCH_VERSION 10
336 #error "No target architecture defined"
340 #define LJ_PAGESIZE 4096
343 /* Check for minimum required compiler versions. */
344 #if defined(__GNUC__)
346 #if (__GNUC__ < 3) || ((__GNUC__ == 3) && __GNUC_MINOR__ < 4)
347 #error "Need at least GCC 3.4 or newer"
351 #error "Need at least GCC 4.0 or newer"
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"
357 #elif LJ_TARGET_ARM64
359 #if (__clang_major__ < 3) || ((__clang_major__ == 3) && __clang_minor__ < 5)
360 #error "Need at least Clang 3.5 or newer"
363 #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 8)
364 #error "Need at least GCC 4.8 or newer"
368 #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3)
369 #error "Need at least GCC 4.3 or newer"
374 /* Check target-specific constraints. */
377 #if __USING_SJLJ_EXCEPTIONS__
378 #error "Need a C compiler with native exception handling on x64"
381 #if defined(__ARMEB__)
382 #error "No support for big-endian ARM"
384 #if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__
385 #error "No support for Cortex-M CPUs"
387 #if !(__ARM_EABI__ || LJ_TARGET_IOS)
388 #error "Only ARM EABI or iOS 3.0+ ABI is supported"
390 #elif LJ_TARGET_ARM64
391 #if defined(__AARCH64EB__)
392 #error "No support for big-endian ARM64"
395 #error "No support for ILP32 model on ARM64"
398 #if defined(_SOFT_FLOAT) || defined(_SOFT_DOUBLE)
399 #error "No support for PowerPC CPUs without double-precision FPU"
401 #if !LJ_ARCH_PPC64 && LJ_ARCH_ENDIAN == LUAJIT_LE
402 #error "No support for little-endian PPC32"
405 #error "No support for PowerPC 64 bit mode (yet)"
408 #error "No support for PPC/e500 anymore (use LuaJIT 2.0)"
412 #error "No support for MIPS64"
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"
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)
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
438 /* 64 bit GC references. */
445 /* 2-slot frame info. */
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
459 /* Disable or enable the FFI extension. */
460 #if defined(LUAJIT_DISABLE_FFI) || defined(LJ_ARCH_NOFFI)
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
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
478 #define LJ_HASPROFILE 0
481 #ifndef LJ_ARCH_HASFPU
482 #define LJ_ARCH_HASFPU 1
484 #ifndef LJ_ABI_SOFTFP
485 #define LJ_ABI_SOFTFP 0
487 #define LJ_SOFTFP (!LJ_ARCH_HASFPU)
489 #if LJ_ARCH_ENDIAN == LUAJIT_BE
492 #define LJ_ENDIAN_SELECT(le, be) be
493 #define LJ_ENDIAN_LOHI(lo, hi) hi lo
497 #define LJ_ENDIAN_SELECT(le, be) le
498 #define LJ_ENDIAN_LOHI(lo, hi) lo hi
501 #if LJ_ARCH_BITS == 32
509 #ifndef LJ_TARGET_UNALIGNED
510 #define LJ_TARGET_UNALIGNED 0
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
517 #if defined(__symbian__) || LJ_TARGET_WINDOWS
518 #define LUAJIT_NO_EXP2
520 #if LJ_TARGET_CONSOLE || (LJ_TARGET_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0)
521 #define LJ_NO_SYSTEM 1
524 #if defined(LUAJIT_NO_UNWIND) || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 || LJ_TARGET_PS4
525 #define LJ_NO_UNWIND 1
528 /* Compatibility with Lua 5.1 vs. 5.2. */
529 #ifdef LUAJIT_ENABLE_LUA52COMPAT