2 ** Target architecture selection.
3 ** Copyright (C) 2005-2013 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_PPC 4
23 #define LUAJIT_ARCH_ppc 4
24 #define LUAJIT_ARCH_PPCSPE 5
25 #define LUAJIT_ARCH_ppcspe 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(__ppc__) || defined(__ppc) || defined(__PPC__) || defined(__PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__POWERPC) || defined(_M_PPC)
48 #define LUAJIT_TARGET LUAJIT_ARCH_PPCSPE
50 #define LUAJIT_TARGET LUAJIT_ARCH_PPC
52 #elif defined(__mips__) || defined(__mips) || defined(__MIPS__) || defined(__MIPS)
53 #define LUAJIT_TARGET LUAJIT_ARCH_MIPS
55 #error "No support for this architecture (yet)"
60 /* Select native OS if no target OS defined. */
63 #if defined(_WIN32) && !defined(_XBOX_VER)
64 #define LUAJIT_OS LUAJIT_OS_WINDOWS
65 #elif defined(__linux__)
66 #define LUAJIT_OS LUAJIT_OS_LINUX
67 #elif defined(__MACH__) && defined(__APPLE__)
68 #define LUAJIT_OS LUAJIT_OS_OSX
69 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
70 defined(__NetBSD__) || defined(__OpenBSD__)
71 #define LUAJIT_OS LUAJIT_OS_BSD
72 #elif (defined(__sun__) && defined(__svr4__)) || defined(__CYGWIN__)
73 #define LUAJIT_OS LUAJIT_OS_POSIX
75 #define LUAJIT_OS LUAJIT_OS_OTHER
80 /* Set target OS properties. */
81 #if LUAJIT_OS == LUAJIT_OS_WINDOWS
82 #define LJ_OS_NAME "Windows"
83 #elif LUAJIT_OS == LUAJIT_OS_LINUX
84 #define LJ_OS_NAME "Linux"
85 #elif LUAJIT_OS == LUAJIT_OS_OSX
86 #define LJ_OS_NAME "OSX"
87 #elif LUAJIT_OS == LUAJIT_OS_BSD
88 #define LJ_OS_NAME "BSD"
89 #elif LUAJIT_OS == LUAJIT_OS_POSIX
90 #define LJ_OS_NAME "POSIX"
92 #define LJ_OS_NAME "Other"
95 #define LJ_TARGET_WINDOWS (LUAJIT_OS == LUAJIT_OS_WINDOWS)
96 #define LJ_TARGET_LINUX (LUAJIT_OS == LUAJIT_OS_LINUX)
97 #define LJ_TARGET_OSX (LUAJIT_OS == LUAJIT_OS_OSX)
98 #define LJ_TARGET_IOS (LJ_TARGET_OSX && LUAJIT_TARGET == LUAJIT_ARCH_ARM)
99 #define LJ_TARGET_POSIX (LUAJIT_OS > LUAJIT_OS_WINDOWS)
100 #define LJ_TARGET_DLOPEN LJ_TARGET_POSIX
102 #ifdef __CELLOS_LV2__
103 #define LJ_TARGET_PS3 1
104 #define LJ_TARGET_CONSOLE 1
108 #define LJ_TARGET_XBOX360 1
109 #define LJ_TARGET_CONSOLE 1
112 #define LJ_NUMMODE_SINGLE 0 /* Single-number mode only. */
113 #define LJ_NUMMODE_SINGLE_DUAL 1 /* Default to single-number mode. */
114 #define LJ_NUMMODE_DUAL 2 /* Dual-number mode only. */
115 #define LJ_NUMMODE_DUAL_SINGLE 3 /* Default to dual-number mode. */
117 /* Set target architecture properties. */
118 #if LUAJIT_TARGET == LUAJIT_ARCH_X86
120 #define LJ_ARCH_NAME "x86"
121 #define LJ_ARCH_BITS 32
122 #define LJ_ARCH_ENDIAN LUAJIT_LE
123 #if LJ_TARGET_WINDOWS || __CYGWIN__
128 #define LJ_TARGET_X86 1
129 #define LJ_TARGET_X86ORX64 1
130 #define LJ_TARGET_EHRETREG 0
131 #define LJ_TARGET_MASKSHIFT 1
132 #define LJ_TARGET_MASKROT 1
133 #define LJ_TARGET_UNALIGNED 1
134 #define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE_DUAL
136 #elif LUAJIT_TARGET == LUAJIT_ARCH_X64
138 #define LJ_ARCH_NAME "x64"
139 #define LJ_ARCH_BITS 64
140 #define LJ_ARCH_ENDIAN LUAJIT_LE
141 #define LJ_ABI_WIN LJ_TARGET_WINDOWS
142 #define LJ_TARGET_X64 1
143 #define LJ_TARGET_X86ORX64 1
144 #define LJ_TARGET_EHRETREG 0
145 #define LJ_TARGET_JUMPRANGE 31 /* +-2^31 = +-2GB */
146 #define LJ_TARGET_MASKSHIFT 1
147 #define LJ_TARGET_MASKROT 1
148 #define LJ_TARGET_UNALIGNED 1
149 #define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE_DUAL
151 #elif LUAJIT_TARGET == LUAJIT_ARCH_ARM
153 #define LJ_ARCH_NAME "arm"
154 #define LJ_ARCH_BITS 32
155 #define LJ_ARCH_ENDIAN LUAJIT_LE
156 #if !defined(LJ_ARCH_HASFPU) && __SOFTFP__
157 #define LJ_ARCH_HASFPU 0
159 #if !defined(LJ_ABI_SOFTFP) && !__ARM_PCS_VFP
160 #define LJ_ABI_SOFTFP 1
162 #define LJ_ABI_EABI 1
163 #define LJ_TARGET_ARM 1
164 #define LJ_TARGET_EHRETREG 0
165 #define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */
166 #define LJ_TARGET_MASKSHIFT 0
167 #define LJ_TARGET_MASKROT 1
168 #define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */
169 #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL
171 #if __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH_7S__
172 #define LJ_ARCH_VERSION 70
173 #elif __ARM_ARCH_6T2__
174 #define LJ_ARCH_VERSION 61
175 #elif __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6K__ || __ARM_ARCH_6Z__ || __ARM_ARCH_6ZK__
176 #define LJ_ARCH_VERSION 60
178 #define LJ_ARCH_VERSION 50
181 #elif LUAJIT_TARGET == LUAJIT_ARCH_PPC
183 #define LJ_ARCH_NAME "ppc"
185 #define LJ_ARCH_BITS 64
187 #define LJ_ARCH_BITS 32
189 #define LJ_ARCH_ENDIAN LUAJIT_BE
190 #define LJ_TARGET_PPC 1
191 #define LJ_TARGET_EHRETREG 3
192 #define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */
193 #define LJ_TARGET_MASKSHIFT 0
194 #define LJ_TARGET_MASKROT 1
195 #define LJ_TARGET_UNIFYROT 1 /* Want only IR_BROL. */
196 #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL_SINGLE
199 #define LJ_ARCH_VERSION 70
201 #define LJ_ARCH_VERSION 60
203 #define LJ_ARCH_VERSION 51
205 #define LJ_ARCH_VERSION 50
207 #define LJ_ARCH_VERSION 40
209 #define LJ_ARCH_VERSION 0
211 #if __PPC64__ || __powerpc64__ || LJ_TARGET_CONSOLE
212 #define LJ_ARCH_PPC64 1
213 #define LJ_ARCH_NOFFI 1
216 #define LJ_ARCH_SQRT 1
219 #define LJ_ARCH_ROUND 1
222 #define LJ_ARCH_CELL 1
224 #if LJ_TARGET_XBOX360
225 #define LJ_ARCH_XENON 1
228 #elif LUAJIT_TARGET == LUAJIT_ARCH_PPCSPE
230 #define LJ_ARCH_NAME "ppcspe"
231 #define LJ_ARCH_BITS 32
232 #define LJ_ARCH_ENDIAN LUAJIT_BE
233 #ifndef LJ_ABI_SOFTFP
234 #define LJ_ABI_SOFTFP 1
236 #define LJ_ABI_EABI 1
237 #define LJ_TARGET_PPCSPE 1
238 #define LJ_TARGET_EHRETREG 3
239 #define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */
240 #define LJ_TARGET_MASKSHIFT 0
241 #define LJ_TARGET_MASKROT 1
242 #define LJ_TARGET_UNIFYROT 1 /* Want only IR_BROL. */
243 #define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE
244 #define LJ_ARCH_NOFFI 1 /* NYI: comparisons, calls. */
245 #define LJ_ARCH_NOJIT 1
247 #elif LUAJIT_TARGET == LUAJIT_ARCH_MIPS
249 #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL)
250 #define LJ_ARCH_NAME "mipsel"
251 #define LJ_ARCH_ENDIAN LUAJIT_LE
253 #define LJ_ARCH_NAME "mips"
254 #define LJ_ARCH_ENDIAN LUAJIT_BE
256 #define LJ_ARCH_BITS 32
257 #define LJ_TARGET_MIPS 1
258 #define LJ_TARGET_EHRETREG 4
259 #define LJ_TARGET_JUMPRANGE 27 /* 2*2^27 = 256MB-aligned region */
260 #define LJ_TARGET_MASKSHIFT 1
261 #define LJ_TARGET_MASKROT 1
262 #define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */
263 #define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE
265 #if _MIPS_ARCH_MIPS32R2
266 #define LJ_ARCH_VERSION 20
268 #define LJ_ARCH_VERSION 10
272 #error "No target architecture defined"
276 #define LJ_PAGESIZE 4096
279 /* Check for minimum required compiler versions. */
280 #if defined(__GNUC__)
282 #if (__GNUC__ < 3) || ((__GNUC__ == 3) && __GNUC_MINOR__ < 4)
283 #error "Need at least GCC 3.4 or newer"
287 #error "Need at least GCC 4.0 or newer"
290 #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 2)
291 #error "Need at least GCC 4.2 or newer"
294 #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3)
295 #error "Need at least GCC 4.3 or newer"
300 /* Check target-specific constraints. */
303 #if __USING_SJLJ_EXCEPTIONS__
304 #error "Need a C compiler with native exception handling on x64"
307 #if defined(__ARMEB__)
308 #error "No support for big-endian ARM"
310 #if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__
311 #error "No support for Cortex-M CPUs"
313 #if !(__ARM_EABI__ || LJ_TARGET_IOS)
314 #error "Only ARM EABI or iOS 3.0+ ABI is supported"
316 #elif LJ_TARGET_PPC || LJ_TARGET_PPCSPE
317 #if defined(_SOFT_FLOAT) || defined(_SOFT_DOUBLE)
318 #error "No support for PowerPC CPUs without double-precision FPU"
320 #if defined(_LITTLE_ENDIAN)
321 #error "No support for little-endian PowerPC"
324 #error "No support for PowerPC 64 bit mode"
327 #if defined(__mips_soft_float)
328 #error "No support for MIPS CPUs without FPU"
333 /* Enable or disable the dual-number mode for the VM. */
334 #if (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE && LUAJIT_NUMMODE == 2) || \
335 (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL && LUAJIT_NUMMODE == 1)
336 #error "No support for this number mode on this architecture"
338 #if LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL || \
339 (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL_SINGLE && LUAJIT_NUMMODE != 1) || \
340 (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE_DUAL && LUAJIT_NUMMODE == 2)
346 #if LJ_TARGET_IOS || LJ_TARGET_CONSOLE
347 /* Runtime code generation is restricted on iOS. Complain to Apple, not me. */
348 /* Ditto for the consoles. Complain to Sony or MS, not me. */
349 #ifndef LUAJIT_ENABLE_JIT
350 #define LJ_OS_NOJIT 1
354 /* Disable or enable the JIT compiler. */
355 #if defined(LUAJIT_DISABLE_JIT) || defined(LJ_ARCH_NOJIT) || defined(LJ_OS_NOJIT)
361 /* Disable or enable the FFI extension. */
362 #if defined(LUAJIT_DISABLE_FFI) || defined(LJ_ARCH_NOFFI)
368 #ifndef LJ_ARCH_HASFPU
369 #define LJ_ARCH_HASFPU 1
371 #ifndef LJ_ABI_SOFTFP
372 #define LJ_ABI_SOFTFP 0
374 #define LJ_SOFTFP (!LJ_ARCH_HASFPU)
376 #if LJ_ARCH_ENDIAN == LUAJIT_BE
379 #define LJ_ENDIAN_SELECT(le, be) be
380 #define LJ_ENDIAN_LOHI(lo, hi) hi lo
384 #define LJ_ENDIAN_SELECT(le, be) le
385 #define LJ_ENDIAN_LOHI(lo, hi) lo hi
388 #if LJ_ARCH_BITS == 32
396 #ifndef LJ_TARGET_UNALIGNED
397 #define LJ_TARGET_UNALIGNED 0
400 /* Various workarounds for embedded operating systems. */
401 #if (defined(__ANDROID__) && !defined(LJ_TARGET_X86ORX64)) || defined(__symbian__) || LJ_TARGET_XBOX360
402 #define LUAJIT_NO_LOG2
404 #if defined(__symbian__)
405 #define LUAJIT_NO_EXP2
408 #if defined(LUAJIT_NO_UNWIND) || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3
409 #define LJ_NO_UNWIND 1
412 /* Compatibility with Lua 5.1 vs. 5.2. */
413 #ifdef LUAJIT_ENABLE_LUA52COMPAT