Cleanup CPU detection and tuning for old CPUs.

This commit is contained in:
Mike Pall
2020-05-20 20:42:04 +02:00
parent 5bf0da3d7c
commit 0eddcbead2
9 changed files with 86 additions and 137 deletions

View File

@@ -9,47 +9,49 @@
#include "lj_obj.h"
#include "lj_ir.h"
/* JIT engine flags. */
/* -- JIT engine flags ---------------------------------------------------- */
/* General JIT engine flags. 4 bits. */
#define JIT_F_ON 0x00000001
/* CPU-specific JIT engine flags. */
/* CPU-specific JIT engine flags. 12 bits. Flags and strings must match. */
#define JIT_F_CPU 0x00000010
#if LJ_TARGET_X86ORX64
#define JIT_F_SSE2 0x00000010
#define JIT_F_SSE3 0x00000020
#define JIT_F_SSE4_1 0x00000040
#define JIT_F_PREFER_IMUL 0x00000080
#define JIT_F_LEA_AGU 0x00000100
#define JIT_F_BMI2 0x00000200
/* Names for the CPU-specific flags. Must match the order above. */
#define JIT_F_CPU_FIRST JIT_F_SSE2
#define JIT_F_CPUSTRING "\4SSE2\4SSE3\6SSE4.1\3AMD\4ATOM\4BMI2"
#define JIT_F_SSE3 (JIT_F_CPU << 0)
#define JIT_F_SSE4_1 (JIT_F_CPU << 1)
#define JIT_F_BMI2 (JIT_F_CPU << 2)
#define JIT_F_CPUSTRING "\4SSE3\6SSE4.1\4BMI2"
#elif LJ_TARGET_ARM
#define JIT_F_ARMV6_ 0x00000010
#define JIT_F_ARMV6T2_ 0x00000020
#define JIT_F_ARMV7 0x00000040
#define JIT_F_VFPV2 0x00000080
#define JIT_F_VFPV3 0x00000100
#define JIT_F_ARMV6 (JIT_F_ARMV6_|JIT_F_ARMV6T2_|JIT_F_ARMV7)
#define JIT_F_ARMV6T2 (JIT_F_ARMV6T2_|JIT_F_ARMV7)
#define JIT_F_ARMV6_ (JIT_F_CPU << 0)
#define JIT_F_ARMV6T2_ (JIT_F_CPU << 1)
#define JIT_F_ARMV7 (JIT_F_CPU << 2)
#define JIT_F_ARMV8 (JIT_F_CPU << 3)
#define JIT_F_VFPV2 (JIT_F_CPU << 4)
#define JIT_F_VFPV3 (JIT_F_CPU << 5)
#define JIT_F_ARMV6 (JIT_F_ARMV6_|JIT_F_ARMV6T2_|JIT_F_ARMV7|JIT_F_ARMV8)
#define JIT_F_ARMV6T2 (JIT_F_ARMV6T2_|JIT_F_ARMV7|JIT_F_ARMV8)
#define JIT_F_VFP (JIT_F_VFPV2|JIT_F_VFPV3)
/* Names for the CPU-specific flags. Must match the order above. */
#define JIT_F_CPU_FIRST JIT_F_ARMV6_
#define JIT_F_CPUSTRING "\5ARMv6\7ARMv6T2\5ARMv7\5VFPv2\5VFPv3"
#define JIT_F_CPUSTRING "\5ARMv6\7ARMv6T2\5ARMv7\5ARMv8\5VFPv2\5VFPv3"
#elif LJ_TARGET_PPC
#define JIT_F_SQRT 0x00000010
#define JIT_F_ROUND 0x00000020
/* Names for the CPU-specific flags. Must match the order above. */
#define JIT_F_CPU_FIRST JIT_F_SQRT
#define JIT_F_SQRT (JIT_F_CPU << 0)
#define JIT_F_ROUND (JIT_F_CPU << 1)
#define JIT_F_CPUSTRING "\4SQRT\5ROUND"
#elif LJ_TARGET_MIPS
#define JIT_F_MIPSXXR2 0x00000010
/* Names for the CPU-specific flags. Must match the order above. */
#define JIT_F_CPU_FIRST JIT_F_MIPSXXR2
#elif LJ_TARGET_MIPS
#define JIT_F_MIPSXXR2 (JIT_F_CPU << 0)
#if LJ_TARGET_MIPS32
#if LJ_TARGET_MIPSR6
#define JIT_F_CPUSTRING "\010MIPS32R6"
@@ -63,27 +65,29 @@
#define JIT_F_CPUSTRING "\010MIPS64R2"
#endif
#endif
#else
#define JIT_F_CPU_FIRST 0
#define JIT_F_CPUSTRING ""
#endif
/* Optimization flags. */
/* Optimization flags. 12 bits. */
#define JIT_F_OPT 0x00010000
#define JIT_F_OPT_MASK 0x0fff0000
#define JIT_F_OPT_FOLD 0x00010000
#define JIT_F_OPT_CSE 0x00020000
#define JIT_F_OPT_DCE 0x00040000
#define JIT_F_OPT_FWD 0x00080000
#define JIT_F_OPT_DSE 0x00100000
#define JIT_F_OPT_NARROW 0x00200000
#define JIT_F_OPT_LOOP 0x00400000
#define JIT_F_OPT_ABC 0x00800000
#define JIT_F_OPT_SINK 0x01000000
#define JIT_F_OPT_FUSE 0x02000000
#define JIT_F_OPT_FOLD (JIT_F_OPT << 0)
#define JIT_F_OPT_CSE (JIT_F_OPT << 1)
#define JIT_F_OPT_DCE (JIT_F_OPT << 2)
#define JIT_F_OPT_FWD (JIT_F_OPT << 3)
#define JIT_F_OPT_DSE (JIT_F_OPT << 4)
#define JIT_F_OPT_NARROW (JIT_F_OPT << 5)
#define JIT_F_OPT_LOOP (JIT_F_OPT << 6)
#define JIT_F_OPT_ABC (JIT_F_OPT << 7)
#define JIT_F_OPT_SINK (JIT_F_OPT << 8)
#define JIT_F_OPT_FUSE (JIT_F_OPT << 9)
/* Optimizations names for -O. Must match the order above. */
#define JIT_F_OPT_FIRST JIT_F_OPT_FOLD
#define JIT_F_OPTSTRING \
"\4fold\3cse\3dce\3fwd\3dse\6narrow\4loop\3abc\4sink\4fuse"
@@ -95,6 +99,8 @@
JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_ABC|JIT_F_OPT_SINK|JIT_F_OPT_FUSE)
#define JIT_F_OPT_DEFAULT JIT_F_OPT_3
/* -- JIT engine parameters ----------------------------------------------- */
#if LJ_TARGET_WINDOWS || LJ_64
/* See: http://blogs.msdn.com/oldnewthing/archive/2003/10/08/55239.aspx */
#define JIT_P_sizemcode_DEFAULT 64
@@ -137,6 +143,8 @@ JIT_PARAMDEF(JIT_PARAMENUM)
#define JIT_PARAMSTR(len, name, value) #len #name
#define JIT_P_STRING JIT_PARAMDEF(JIT_PARAMSTR)
/* -- JIT engine data structures ------------------------------------------ */
/* Trace compiler state. */
typedef enum {
LJ_TRACE_IDLE, /* Trace compiler idle. */