[Pcre-svn] [1222] code/trunk/sljit: JIT compiler update.

Kezdőlap
Üzenet törlése
Szerző: Subversion repository
Dátum:  
Címzett: pcre-svn
Tárgy: [Pcre-svn] [1222] code/trunk/sljit: JIT compiler update.
Revision: 1222
          http://vcs.pcre.org/viewvc?view=rev&revision=1222
Author:   zherczeg
Date:     2012-11-19 08:04:03 +0000 (Mon, 19 Nov 2012)


Log Message:
-----------
JIT compiler update.

Modified Paths:
--------------
    code/trunk/sljit/sljitConfigInternal.h
    code/trunk/sljit/sljitLir.c
    code/trunk/sljit/sljitLir.h
    code/trunk/sljit/sljitNativeMIPS_common.c
    code/trunk/sljit/sljitNativeSPARC_common.c
    code/trunk/sljit/sljitNativeX86_32.c
    code/trunk/sljit/sljitNativeX86_common.c


Modified: code/trunk/sljit/sljitConfigInternal.h
===================================================================
--- code/trunk/sljit/sljitConfigInternal.h    2012-11-11 20:27:03 UTC (rev 1221)
+++ code/trunk/sljit/sljitConfigInternal.h    2012-11-19 08:04:03 UTC (rev 1222)
@@ -309,20 +309,24 @@
 #define SLJIT_CALL __attribute__ ((fastcall))
 #define SLJIT_X86_32_FASTCALL 1


-#elif defined(_WIN32)
+#elif defined(_MSC_VER)

-#ifdef __BORLANDC__
-#define SLJIT_CALL __msfastcall
-#else /* __BORLANDC__ */
#define SLJIT_CALL __fastcall
-#endif /* __BORLANDC__ */
#define SLJIT_X86_32_FASTCALL 1

-#else /* defined(_WIN32) */
-#define SLJIT_CALL __stdcall
+#elif defined(__BORLANDC__)
+
+#define SLJIT_CALL __msfastcall
+#define SLJIT_X86_32_FASTCALL 1
+
+#else /* Unknown compiler. */
+
+/* The cdecl attribute is the default. */
+#define SLJIT_CALL
+
#endif

-#else /* Other architectures. */
+#else /* Non x86-32 architectures. */

#define SLJIT_CALL


Modified: code/trunk/sljit/sljitLir.c
===================================================================
--- code/trunk/sljit/sljitLir.c    2012-11-11 20:27:03 UTC (rev 1221)
+++ code/trunk/sljit/sljitLir.c    2012-11-19 08:04:03 UTC (rev 1222)
@@ -193,7 +193,10 @@


#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
#define SLJIT_HAS_VARIABLE_LOCALS_OFFSET 1
+#if !(defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL)
+#define FIXED_LOCALS_OFFSET (3 * sizeof(sljit_sw))
#endif
+#endif

#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
#define SLJIT_HAS_FIXED_LOCALS_OFFSET 1

Modified: code/trunk/sljit/sljitLir.h
===================================================================
--- code/trunk/sljit/sljitLir.h    2012-11-11 20:27:03 UTC (rev 1221)
+++ code/trunk/sljit/sljitLir.h    2012-11-19 08:04:03 UTC (rev 1222)
@@ -881,7 +881,7 @@
 SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw init_value);


 /* After the code generation the address for label, jump and const instructions
-   are computed. Since these structures are freed sljit_free_compiler, the
+   are computed. Since these structures are freed by sljit_free_compiler, the
    addresses must be preserved by the user program elsewere. */
 static SLJIT_INLINE sljit_uw sljit_get_label_addr(struct sljit_label *label) { return label->addr; }
 static SLJIT_INLINE sljit_uw sljit_get_jump_addr(struct sljit_jump *jump) { return jump->addr; }
@@ -898,12 +898,12 @@
 #define SLJIT_MAJOR_VERSION    0
 #define SLJIT_MINOR_VERSION    90


-/* Get the human readable name of the platfrom. Can be useful on platforms
+/* Get the human readable name of the platform. Can be useful on platforms
    like ARM, where ARM and Thumb2 functions can be mixed, and
    it is useful to know the type of the code generator. */
 SLJIT_API_FUNC_ATTRIBUTE SLJIT_CONST char* sljit_get_platform_name(void);


-/* Portble helper function to get an offset of a member. */
+/* Portable helper function to get an offset of a member. */
#define SLJIT_OFFSETOF(base, member) ((sljit_sw)(&((base*)0x10)->member) - 0x10)

#if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK)
@@ -966,7 +966,7 @@

/* All JIT related code should be placed in the same context (library, binary, etc.). */

-#define SLJIT_FUNC_OFFSET(func_name)    ((sljit_sw)*(void**)func_name)
+#define SLJIT_FUNC_OFFSET(func_name)    (*(sljit_sw*)(void*)func_name)


/* For powerpc64, the function pointers point to a context descriptor. */
struct sljit_function_context {

Modified: code/trunk/sljit/sljitNativeMIPS_common.c
===================================================================
--- code/trunk/sljit/sljitNativeMIPS_common.c    2012-11-11 20:27:03 UTC (rev 1221)
+++ code/trunk/sljit/sljitNativeMIPS_common.c    2012-11-19 08:04:03 UTC (rev 1222)
@@ -24,14 +24,18 @@
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */


+/* Latest MIPS architecture. */
+/* Automatically detect SLJIT_MIPS_32_64 */
+
 SLJIT_API_FUNC_ATTRIBUTE SLJIT_CONST char* sljit_get_platform_name(void)
 {
+#if (defined SLJIT_MIPS_32_64 && SLJIT_MIPS_32_64)
     return "MIPS" SLJIT_CPUINFO;
+#else
+    return "MIPS III" SLJIT_CPUINFO;
+#endif
 }


-/* Latest MIPS architecture. */
-/* Detect SLJIT_MIPS_32_64 */
-
 /* Length of an instruction word
    Both for mips-32 and mips-64 */
 typedef sljit_ui sljit_ins;


Modified: code/trunk/sljit/sljitNativeSPARC_common.c
===================================================================
--- code/trunk/sljit/sljitNativeSPARC_common.c    2012-11-11 20:27:03 UTC (rev 1221)
+++ code/trunk/sljit/sljitNativeSPARC_common.c    2012-11-19 08:04:03 UTC (rev 1222)
@@ -153,10 +153,11 @@
    Useful for reordering instructions in the delay slot. */
 static sljit_si push_inst(struct sljit_compiler *compiler, sljit_ins ins, sljit_si delay_slot)
 {
+    sljit_ins *ptr;
     SLJIT_ASSERT((delay_slot & DST_INS_MASK) == UNMOVABLE_INS
         || (delay_slot & DST_INS_MASK) == MOVABLE_INS
         || (delay_slot & DST_INS_MASK) == ((ins >> 25) & 0x1f));
-    sljit_ins *ptr = (sljit_ins*)ensure_buf(compiler, sizeof(sljit_ins));
+    ptr = (sljit_ins*)ensure_buf(compiler, sizeof(sljit_ins));
     FAIL_IF(!ptr);
     *ptr = ins;
     compiler->size++;


Modified: code/trunk/sljit/sljitNativeX86_32.c
===================================================================
--- code/trunk/sljit/sljitNativeX86_32.c    2012-11-11 20:27:03 UTC (rev 1221)
+++ code/trunk/sljit/sljitNativeX86_32.c    2012-11-19 08:04:03 UTC (rev 1222)
@@ -136,7 +136,12 @@
     }
 #endif


+#if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL)
     locals_offset = 2 * sizeof(sljit_uw);
+#else
+    SLJIT_COMPILE_ASSERT(FIXED_LOCALS_OFFSET >= 2 * sizeof(sljit_uw), require_at_least_two_words);
+    locals_offset = FIXED_LOCALS_OFFSET;
+#endif
     compiler->scratches_start = locals_offset;
     if (scratches > 3)
         locals_offset += (scratches - 3) * sizeof(sljit_uw);
@@ -146,19 +151,24 @@
     compiler->locals_offset = locals_offset;
     local_size = locals_offset + ((local_size + sizeof(sljit_uw) - 1) & ~(sizeof(sljit_uw) - 1));


+    compiler->local_size = local_size;
 #ifdef _WIN32
     if (local_size > 1024) {
+#if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL)
         FAIL_IF(emit_do_imm(compiler, MOV_r_i32 + reg_map[SLJIT_SCRATCH_REG1], local_size));
+#else
+        local_size -= FIXED_LOCALS_OFFSET;
+        FAIL_IF(emit_do_imm(compiler, MOV_r_i32 + reg_map[SLJIT_SCRATCH_REG1], local_size));
+        FAIL_IF(emit_non_cum_binary(compiler, SUB_r_rm, SUB_rm_r, SUB, SUB_EAX_i32,
+            SLJIT_LOCALS_REG, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, FIXED_LOCALS_OFFSET));
+#endif
         FAIL_IF(sljit_emit_ijump(compiler, SLJIT_CALL1, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_grow_stack)));
     }
 #endif


-    compiler->local_size = local_size;
     SLJIT_ASSERT(local_size > 0);
     return emit_non_cum_binary(compiler, SUB_r_rm, SUB_rm_r, SUB, SUB_EAX_i32,
         SLJIT_LOCALS_REG, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, local_size);
-
-    return SLJIT_SUCCESS;
 }


 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_context(struct sljit_compiler *compiler, sljit_si args, sljit_si scratches, sljit_si saveds, sljit_si local_size)
@@ -175,7 +185,11 @@
     compiler->logical_local_size = local_size;
 #endif


+#if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL)
     locals_offset = 2 * sizeof(sljit_uw);
+#else
+    locals_offset = FIXED_LOCALS_OFFSET;
+#endif
     compiler->scratches_start = locals_offset;
     if (scratches > 3)
         locals_offset += (scratches - 3) * sizeof(sljit_uw);
@@ -228,10 +242,7 @@
     else
         RET();
 #else
-    if (compiler->args > 0)
-        RET_I16(compiler->args * sizeof(sljit_sw));
-    else
-        RET();
+    RET();
 #endif


     return SLJIT_SUCCESS;
@@ -438,14 +449,26 @@
     *inst++ = MOV_r_rm;
     *inst++ = MOD_REG | (reg_map[SLJIT_SCRATCH_REG3] << 3) | reg_map[SLJIT_SCRATCH_REG1];
 #else
-    inst = (sljit_ub*)ensure_buf(compiler, type - SLJIT_CALL0 + 1);
+    inst = (sljit_ub*)ensure_buf(compiler, 1 + 4 * (type - SLJIT_CALL0));
     FAIL_IF(!inst);
-    INC_SIZE(type - SLJIT_CALL0);
-    if (type >= SLJIT_CALL3)
-        PUSH_REG(reg_map[SLJIT_SCRATCH_REG3]);
-    if (type >= SLJIT_CALL2)
-        PUSH_REG(reg_map[SLJIT_SCRATCH_REG2]);
-    PUSH_REG(reg_map[SLJIT_SCRATCH_REG1]);
+    INC_SIZE(4 * (type - SLJIT_CALL0));
+
+    *inst++ = MOV_rm_r;
+    *inst++ = MOD_DISP8 | (reg_map[SLJIT_SCRATCH_REG1] << 3) | 0x4 /* SIB */;
+    *inst++ = (0x4 /* none*/ << 3) | reg_map[SLJIT_LOCALS_REG];
+    *inst++ = 0;
+    if (type >= SLJIT_CALL2) {
+        *inst++ = MOV_rm_r;
+        *inst++ = MOD_DISP8 | (reg_map[SLJIT_SCRATCH_REG2] << 3) | 0x4 /* SIB */;
+        *inst++ = (0x4 /* none*/ << 3) | reg_map[SLJIT_LOCALS_REG];
+        *inst++ = sizeof(sljit_sw);
+    }
+    if (type >= SLJIT_CALL3) {
+        *inst++ = MOV_rm_r;
+        *inst++ = MOD_DISP8 | (reg_map[SLJIT_SCRATCH_REG3] << 3) | 0x4 /* SIB */;
+        *inst++ = (0x4 /* none*/ << 3) | reg_map[SLJIT_LOCALS_REG];
+        *inst++ = 2 * sizeof(sljit_sw);
+    }
 #endif
     return SLJIT_SUCCESS;
 }


Modified: code/trunk/sljit/sljitNativeX86_common.c
===================================================================
--- code/trunk/sljit/sljitNativeX86_common.c    2012-11-11 20:27:03 UTC (rev 1221)
+++ code/trunk/sljit/sljitNativeX86_common.c    2012-11-19 08:04:03 UTC (rev 1222)
@@ -268,8 +268,12 @@
 static sljit_si cpu_has_cmov = -1;


#if defined(_MSC_VER) && (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
+#if _MSC_VER >= 1400
#include <intrin.h>
+#else
+#error "MSVC does not support inline assembly in 64 bit mode"
#endif
+#endif /* _MSC_VER && SLJIT_CONFIG_X86_64 */

static void get_cpu_features(void)
{
@@ -277,9 +281,9 @@

#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)

-#if defined(__GNUC__) || defined(__SUNPRO_C)
+#if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_C)
     /* AT&T syntax. */
-    asm (
+    __asm__ (
         "pushl %%ebx\n"
         "movl $0x1, %%eax\n"
         "cpuid\n"
@@ -304,9 +308,9 @@


#else /* SLJIT_CONFIG_X86_32 */

-#if defined(__GNUC__) || defined(__SUNPRO_C)
+#if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_C)
     /* AT&T syntax. */
-    asm (
+    __asm__ (
         "pushq %%rbx\n"
         "movl $0x1, %%eax\n"
         "cpuid\n"
@@ -316,13 +320,19 @@
         :
         : "%rax", "%rcx", "%rdx"
     );
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) && _MSC_VER >= 1400
     int CPUInfo[4];


     __cpuid(CPUInfo, 1);
     features = (sljit_ui)CPUInfo[3];
 #else
-#    error "SLJIT_DETECT_SSE2 is not implemented for this C compiler"
+    __asm {
+        mov eax, 1
+        push rbx
+        cpuid
+        pop rbx
+        mov features, edx
+    }
 #endif


 #endif /* SLJIT_CONFIG_X86_32 */
@@ -2554,9 +2564,6 @@
         }
         if (src == SLJIT_MEM1(SLJIT_LOCALS_REG) && type >= SLJIT_CALL3)
             srcw += sizeof(sljit_sw);
-#else
-        if (src == SLJIT_MEM1(SLJIT_LOCALS_REG))
-            srcw += sizeof(sljit_sw) * (type - SLJIT_CALL0);
 #endif
 #endif
 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) && defined(_WIN64)