root/lj_arch.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2 ** Target architecture selection.
   3 ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
   4 */
   5 
   6 #ifndef _LJ_ARCH_H
   7 #define _LJ_ARCH_H
   8 
   9 #include "lua.h"
  10 
  11 /* Target endianess. */
  12 #define LUAJIT_LE       0
  13 #define LUAJIT_BE       1
  14 
  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
  28 
  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
  36 
  37 /* Select native target if no target defined. */
  38 #ifndef LUAJIT_TARGET
  39 
  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)
  47 #ifdef __NO_FPRS__
  48 #define LUAJIT_TARGET   LUAJIT_ARCH_PPCSPE
  49 #else
  50 #define LUAJIT_TARGET   LUAJIT_ARCH_PPC
  51 #endif
  52 #elif defined(__mips__) || defined(__mips) || defined(__MIPS__) || defined(__MIPS)
  53 #define LUAJIT_TARGET   LUAJIT_ARCH_MIPS
  54 #else
  55 #error "No support for this architecture (yet)"
  56 #endif
  57 
  58 #endif
  59 
  60 /* Select native OS if no target OS defined. */
  61 #ifndef LUAJIT_OS
  62 
  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        defined(__DragonFly__)) && !defined(__ORBIS__)
  72 #define LUAJIT_OS       LUAJIT_OS_BSD
  73 #elif (defined(__sun__) && defined(__svr4__))
  74 #define LUAJIT_OS       LUAJIT_OS_POSIX
  75 #elif defined(__CYGWIN__)
  76 #define LJ_TARGET_CYGWIN        1
  77 #define LUAJIT_OS       LUAJIT_OS_POSIX
  78 #else
  79 #define LUAJIT_OS       LUAJIT_OS_OTHER
  80 #endif
  81 
  82 #endif
  83 
  84 /* Set target OS properties. */
  85 #if LUAJIT_OS == LUAJIT_OS_WINDOWS
  86 #define LJ_OS_NAME      "Windows"
  87 #elif LUAJIT_OS == LUAJIT_OS_LINUX
  88 #define LJ_OS_NAME      "Linux"
  89 #elif LUAJIT_OS == LUAJIT_OS_OSX
  90 #define LJ_OS_NAME      "OSX"
  91 #elif LUAJIT_OS == LUAJIT_OS_BSD
  92 #define LJ_OS_NAME      "BSD"
  93 #elif LUAJIT_OS == LUAJIT_OS_POSIX
  94 #define LJ_OS_NAME      "POSIX"
  95 #else
  96 #define LJ_OS_NAME      "Other"
  97 #endif
  98 
  99 #define LJ_TARGET_WINDOWS       (LUAJIT_OS == LUAJIT_OS_WINDOWS)
 100 #define LJ_TARGET_LINUX         (LUAJIT_OS == LUAJIT_OS_LINUX)
 101 #define LJ_TARGET_OSX           (LUAJIT_OS == LUAJIT_OS_OSX)
 102 #define LJ_TARGET_IOS           (LJ_TARGET_OSX && LUAJIT_TARGET == LUAJIT_ARCH_ARM)
 103 #define LJ_TARGET_POSIX         (LUAJIT_OS > LUAJIT_OS_WINDOWS)
 104 #define LJ_TARGET_DLOPEN        LJ_TARGET_POSIX
 105 
 106 #ifdef __CELLOS_LV2__
 107 #define LJ_TARGET_PS3           1
 108 #define LJ_TARGET_CONSOLE       1
 109 #endif
 110 
 111 #ifdef __ORBIS__
 112 #define LJ_TARGET_PS4           1
 113 #define LJ_TARGET_CONSOLE       1
 114 #undef NULL
 115 #define NULL ((void*)0)
 116 #endif
 117 
 118 #ifdef __psp2__
 119 #define LJ_TARGET_PSVITA        1
 120 #define LJ_TARGET_CONSOLE       1
 121 #endif
 122 
 123 #if _XBOX_VER >= 200
 124 #define LJ_TARGET_XBOX360       1
 125 #define LJ_TARGET_CONSOLE       1
 126 #endif
 127 
 128 #define LJ_NUMMODE_SINGLE       0       /* Single-number mode only. */
 129 #define LJ_NUMMODE_SINGLE_DUAL  1       /* Default to single-number mode. */
 130 #define LJ_NUMMODE_DUAL         2       /* Dual-number mode only. */
 131 #define LJ_NUMMODE_DUAL_SINGLE  3       /* Default to dual-number mode. */
 132 
 133 /* Set target architecture properties. */
 134 #if LUAJIT_TARGET == LUAJIT_ARCH_X86
 135 
 136 #define LJ_ARCH_NAME            "x86"
 137 #define LJ_ARCH_BITS            32
 138 #define LJ_ARCH_ENDIAN          LUAJIT_LE
 139 #if LJ_TARGET_WINDOWS || LJ_TARGET_CYGWIN
 140 #define LJ_ABI_WIN              1
 141 #else
 142 #define LJ_ABI_WIN              0
 143 #endif
 144 #define LJ_TARGET_X86           1
 145 #define LJ_TARGET_X86ORX64      1
 146 #define LJ_TARGET_EHRETREG      0
 147 #define LJ_TARGET_MASKSHIFT     1
 148 #define LJ_TARGET_MASKROT       1
 149 #define LJ_TARGET_UNALIGNED     1
 150 #define LJ_ARCH_NUMMODE         LJ_NUMMODE_SINGLE_DUAL
 151 
 152 #elif LUAJIT_TARGET == LUAJIT_ARCH_X64
 153 
 154 #define LJ_ARCH_NAME            "x64"
 155 #define LJ_ARCH_BITS            64
 156 #define LJ_ARCH_ENDIAN          LUAJIT_LE
 157 #if LJ_TARGET_WINDOWS || LJ_TARGET_CYGWIN
 158 #define LJ_ABI_WIN              1
 159 #else
 160 #define LJ_ABI_WIN              0
 161 #endif
 162 #define LJ_TARGET_X64           1
 163 #define LJ_TARGET_X86ORX64      1
 164 #define LJ_TARGET_EHRETREG      0
 165 #define LJ_TARGET_JUMPRANGE     31      /* +-2^31 = +-2GB */
 166 #define LJ_TARGET_MASKSHIFT     1
 167 #define LJ_TARGET_MASKROT       1
 168 #define LJ_TARGET_UNALIGNED     1
 169 #define LJ_ARCH_NUMMODE         LJ_NUMMODE_SINGLE_DUAL
 170 
 171 #elif LUAJIT_TARGET == LUAJIT_ARCH_ARM
 172 
 173 #define LJ_ARCH_NAME            "arm"
 174 #define LJ_ARCH_BITS            32
 175 #define LJ_ARCH_ENDIAN          LUAJIT_LE
 176 #if !defined(LJ_ARCH_HASFPU) && __SOFTFP__
 177 #define LJ_ARCH_HASFPU          0
 178 #endif
 179 #if !defined(LJ_ABI_SOFTFP) && !__ARM_PCS_VFP
 180 #define LJ_ABI_SOFTFP           1
 181 #endif
 182 #define LJ_ABI_EABI             1
 183 #define LJ_TARGET_ARM           1
 184 #define LJ_TARGET_EHRETREG      0
 185 #define LJ_TARGET_JUMPRANGE     25      /* +-2^25 = +-32MB */
 186 #define LJ_TARGET_MASKSHIFT     0
 187 #define LJ_TARGET_MASKROT       1
 188 #define LJ_TARGET_UNIFYROT      2       /* Want only IR_BROR. */
 189 #define LJ_ARCH_NUMMODE         LJ_NUMMODE_DUAL
 190 
 191 #if __ARM_ARCH____ARM_ARCH_8__ || __ARM_ARCH_8A__
 192 #define LJ_ARCH_VERSION         80
 193 #elif __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH_7S__ || __ARM_ARCH_7VE__
 194 #define LJ_ARCH_VERSION         70
 195 #elif __ARM_ARCH_6T2__
 196 #define LJ_ARCH_VERSION         61
 197 #elif __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6K__ || __ARM_ARCH_6Z__ || __ARM_ARCH_6ZK__
 198 #define LJ_ARCH_VERSION         60
 199 #else
 200 #define LJ_ARCH_VERSION         50
 201 #endif
 202 
 203 #elif LUAJIT_TARGET == LUAJIT_ARCH_PPC
 204 
 205 #define LJ_ARCH_NAME            "ppc"
 206 #if _LP64
 207 #define LJ_ARCH_BITS            64
 208 #else
 209 #define LJ_ARCH_BITS            32
 210 #endif
 211 #define LJ_ARCH_ENDIAN          LUAJIT_BE
 212 #define LJ_TARGET_PPC           1
 213 #define LJ_TARGET_EHRETREG      3
 214 #define LJ_TARGET_JUMPRANGE     25      /* +-2^25 = +-32MB */
 215 #define LJ_TARGET_MASKSHIFT     0
 216 #define LJ_TARGET_MASKROT       1
 217 #define LJ_TARGET_UNIFYROT      1       /* Want only IR_BROL. */
 218 #define LJ_ARCH_NUMMODE         LJ_NUMMODE_DUAL_SINGLE
 219 
 220 #if _ARCH_PWR7
 221 #define LJ_ARCH_VERSION         70
 222 #elif _ARCH_PWR6
 223 #define LJ_ARCH_VERSION         60
 224 #elif _ARCH_PWR5X
 225 #define LJ_ARCH_VERSION         51
 226 #elif _ARCH_PWR5
 227 #define LJ_ARCH_VERSION         50
 228 #elif _ARCH_PWR4
 229 #define LJ_ARCH_VERSION         40
 230 #else
 231 #define LJ_ARCH_VERSION         0
 232 #endif
 233 #if __PPC64__ || __powerpc64__ || LJ_TARGET_CONSOLE
 234 #define LJ_ARCH_PPC64           1
 235 #define LJ_ARCH_NOFFI           1
 236 #endif
 237 #if _ARCH_PPCSQ
 238 #define LJ_ARCH_SQRT            1
 239 #endif
 240 #if _ARCH_PWR5X
 241 #define LJ_ARCH_ROUND           1
 242 #endif
 243 #if __PPU__
 244 #define LJ_ARCH_CELL            1
 245 #endif
 246 #if LJ_TARGET_XBOX360
 247 #define LJ_ARCH_XENON           1
 248 #endif
 249 
 250 #elif LUAJIT_TARGET == LUAJIT_ARCH_PPCSPE
 251 
 252 #define LJ_ARCH_NAME            "ppcspe"
 253 #define LJ_ARCH_BITS            32
 254 #define LJ_ARCH_ENDIAN          LUAJIT_BE
 255 #ifndef LJ_ABI_SOFTFP
 256 #define LJ_ABI_SOFTFP           1
 257 #endif
 258 #define LJ_ABI_EABI             1
 259 #define LJ_TARGET_PPCSPE        1
 260 #define LJ_TARGET_EHRETREG      3
 261 #define LJ_TARGET_JUMPRANGE     25      /* +-2^25 = +-32MB */
 262 #define LJ_TARGET_MASKSHIFT     0
 263 #define LJ_TARGET_MASKROT       1
 264 #define LJ_TARGET_UNIFYROT      1       /* Want only IR_BROL. */
 265 #define LJ_ARCH_NUMMODE         LJ_NUMMODE_SINGLE
 266 #define LJ_ARCH_NOFFI           1       /* NYI: comparisons, calls. */
 267 #define LJ_ARCH_NOJIT           1
 268 
 269 #elif LUAJIT_TARGET == LUAJIT_ARCH_MIPS
 270 
 271 #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL)
 272 #define LJ_ARCH_NAME            "mipsel"
 273 #define LJ_ARCH_ENDIAN          LUAJIT_LE
 274 #else
 275 #define LJ_ARCH_NAME            "mips"
 276 #define LJ_ARCH_ENDIAN          LUAJIT_BE
 277 #endif
 278 #define LJ_ARCH_BITS            32
 279 #define LJ_TARGET_MIPS          1
 280 #define LJ_TARGET_EHRETREG      4
 281 #define LJ_TARGET_JUMPRANGE     27      /* 2*2^27 = 256MB-aligned region */
 282 #define LJ_TARGET_MASKSHIFT     1
 283 #define LJ_TARGET_MASKROT       1
 284 #define LJ_TARGET_UNIFYROT      2       /* Want only IR_BROR. */
 285 #define LJ_ARCH_NUMMODE         LJ_NUMMODE_SINGLE
 286 
 287 #if _MIPS_ARCH_MIPS32R2
 288 #define LJ_ARCH_VERSION         20
 289 #else
 290 #define LJ_ARCH_VERSION         10
 291 #endif
 292 
 293 #else
 294 #error "No target architecture defined"
 295 #endif
 296 
 297 #ifndef LJ_PAGESIZE
 298 #define LJ_PAGESIZE             4096
 299 #endif
 300 
 301 /* Check for minimum required compiler versions. */
 302 #if defined(__GNUC__)
 303 #if LJ_TARGET_X86
 304 #if (__GNUC__ < 3) || ((__GNUC__ == 3) && __GNUC_MINOR__ < 4)
 305 #error "Need at least GCC 3.4 or newer"
 306 #endif
 307 #elif LJ_TARGET_X64
 308 #if __GNUC__ < 4
 309 #error "Need at least GCC 4.0 or newer"
 310 #endif
 311 #elif LJ_TARGET_ARM
 312 #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 2)
 313 #error "Need at least GCC 4.2 or newer"
 314 #endif
 315 #elif !LJ_TARGET_PS3
 316 #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3)
 317 #error "Need at least GCC 4.3 or newer"
 318 #endif
 319 #endif
 320 #endif
 321 
 322 /* Check target-specific constraints. */
 323 #ifndef _BUILDVM_H
 324 #if LJ_TARGET_X64
 325 #if __USING_SJLJ_EXCEPTIONS__
 326 #error "Need a C compiler with native exception handling on x64"
 327 #endif
 328 #elif LJ_TARGET_ARM
 329 #if defined(__ARMEB__)
 330 #error "No support for big-endian ARM"
 331 #endif
 332 #if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__
 333 #error "No support for Cortex-M CPUs"
 334 #endif
 335 #if !(__ARM_EABI__ || LJ_TARGET_IOS)
 336 #error "Only ARM EABI or iOS 3.0+ ABI is supported"
 337 #endif
 338 #elif LJ_TARGET_PPC || LJ_TARGET_PPCSPE
 339 #if defined(_SOFT_FLOAT) || defined(_SOFT_DOUBLE)
 340 #error "No support for PowerPC CPUs without double-precision FPU"
 341 #endif
 342 #if defined(_LITTLE_ENDIAN)
 343 #error "No support for little-endian PowerPC"
 344 #endif
 345 #if defined(_LP64)
 346 #error "No support for PowerPC 64 bit mode"
 347 #endif
 348 #elif LJ_TARGET_MIPS
 349 #if defined(__mips_soft_float)
 350 #error "No support for MIPS CPUs without FPU"
 351 #endif
 352 #if defined(_LP64)
 353 #error "No support for MIPS64"
 354 #endif
 355 #endif
 356 #endif
 357 
 358 /* Enable or disable the dual-number mode for the VM. */
 359 #if (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE && LUAJIT_NUMMODE == 2) || \
 360     (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL && LUAJIT_NUMMODE == 1)
 361 #error "No support for this number mode on this architecture"
 362 #endif
 363 #if LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL || \
 364     (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL_SINGLE && LUAJIT_NUMMODE != 1) || \
 365     (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE_DUAL && LUAJIT_NUMMODE == 2)
 366 #define LJ_DUALNUM              1
 367 #else
 368 #define LJ_DUALNUM              0
 369 #endif
 370 
 371 #if LJ_TARGET_IOS || LJ_TARGET_CONSOLE
 372 /* Runtime code generation is restricted on iOS. Complain to Apple, not me. */
 373 /* Ditto for the consoles. Complain to Sony or MS, not me. */
 374 #ifndef LUAJIT_ENABLE_JIT
 375 #define LJ_OS_NOJIT             1
 376 #endif
 377 #endif
 378 
 379 /* Disable or enable the JIT compiler. */
 380 #if defined(LUAJIT_DISABLE_JIT) || defined(LJ_ARCH_NOJIT) || defined(LJ_OS_NOJIT)
 381 #define LJ_HASJIT               0
 382 #else
 383 #define LJ_HASJIT               1
 384 #endif
 385 
 386 /* Disable or enable the FFI extension. */
 387 #if defined(LUAJIT_DISABLE_FFI) || defined(LJ_ARCH_NOFFI)
 388 #define LJ_HASFFI               0
 389 #else
 390 #define LJ_HASFFI               1
 391 #endif
 392 
 393 #ifndef LJ_ARCH_HASFPU
 394 #define LJ_ARCH_HASFPU          1
 395 #endif
 396 #ifndef LJ_ABI_SOFTFP
 397 #define LJ_ABI_SOFTFP           0
 398 #endif
 399 #define LJ_SOFTFP               (!LJ_ARCH_HASFPU)
 400 
 401 #if LJ_ARCH_ENDIAN == LUAJIT_BE
 402 #define LJ_LE                   0
 403 #define LJ_BE                   1
 404 #define LJ_ENDIAN_SELECT(le, be)        be
 405 #define LJ_ENDIAN_LOHI(lo, hi)          hi lo
 406 #else
 407 #define LJ_LE                   1
 408 #define LJ_BE                   0
 409 #define LJ_ENDIAN_SELECT(le, be)        le
 410 #define LJ_ENDIAN_LOHI(lo, hi)          lo hi
 411 #endif
 412 
 413 #if LJ_ARCH_BITS == 32
 414 #define LJ_32                   1
 415 #define LJ_64                   0
 416 #else
 417 #define LJ_32                   0
 418 #define LJ_64                   1
 419 #endif
 420 
 421 #ifndef LJ_TARGET_UNALIGNED
 422 #define LJ_TARGET_UNALIGNED     0
 423 #endif
 424 
 425 /* Various workarounds for embedded operating systems. */
 426 #if (defined(__ANDROID__) && !defined(LJ_TARGET_X86ORX64)) || defined(__symbian__) || LJ_TARGET_XBOX360
 427 #define LUAJIT_NO_LOG2
 428 #endif
 429 #if defined(__symbian__)
 430 #define LUAJIT_NO_EXP2
 431 #endif
 432 #if LJ_TARGET_CONSOLE || (LJ_TARGET_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0)
 433 #define LJ_NO_SYSTEM            1
 434 #endif
 435 
 436 #if !defined(LUAJIT_NO_UNWIND) && __GNU_COMPACT_EH__
 437 /* NYI: no support for compact unwind specification, yet. */
 438 #define LUAJIT_NO_UNWIND        1
 439 #endif
 440 
 441 #if defined(LUAJIT_NO_UNWIND) || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 || LJ_TARGET_PS4
 442 #define LJ_NO_UNWIND            1
 443 #endif
 444 
 445 /* Compatibility with Lua 5.1 vs. 5.2. */
 446 #ifdef LUAJIT_ENABLE_LUA52COMPAT
 447 #define LJ_52                   1
 448 #else
 449 #define LJ_52                   0
 450 #endif
 451 
 452 #endif

/* [<][>][^][v][top][bottom][index][help] */