[Pcre-svn] [875] code/trunk: JIT compiler update

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [875] code/trunk: JIT compiler update
Revision: 875
          http://vcs.pcre.org/viewvc?view=rev&revision=875
Author:   zherczeg
Date:     2012-01-14 17:05:53 +0000 (Sat, 14 Jan 2012)


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

Modified Paths:
--------------
    code/trunk/pcre_jit_compile.c
    code/trunk/sljit/sljitConfigInternal.h
    code/trunk/sljit/sljitLir.c
    code/trunk/sljit/sljitLir.h
    code/trunk/sljit/sljitNativeARM_Thumb2.c
    code/trunk/sljit/sljitNativeARM_v5.c
    code/trunk/sljit/sljitNativeMIPS_common.c
    code/trunk/sljit/sljitNativePPC_common.c
    code/trunk/sljit/sljitNativeX86_32.c
    code/trunk/sljit/sljitNativeX86_64.c


Modified: code/trunk/pcre_jit_compile.c
===================================================================
--- code/trunk/pcre_jit_compile.c    2012-01-14 17:03:15 UTC (rev 874)
+++ code/trunk/pcre_jit_compile.c    2012-01-14 17:05:53 UTC (rev 875)
@@ -6532,7 +6532,7 @@
 /* This means we have a match. Update the ovector. */
 copy_ovector(common, re->top_bracket + 1);
 leave = LABEL();
-sljit_emit_return(compiler, SLJIT_UNUSED, 0);
+sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);


empty_match_fallback = LABEL();
compile_fallbackpath(common, rootfallback.top);

Modified: code/trunk/sljit/sljitConfigInternal.h
===================================================================
--- code/trunk/sljit/sljitConfigInternal.h    2012-01-14 17:03:15 UTC (rev 874)
+++ code/trunk/sljit/sljitConfigInternal.h    2012-01-14 17:05:53 UTC (rev 875)
@@ -230,7 +230,12 @@
 /* Machine word type. Can encapsulate a pointer.
      32 bit for 32 bit machines.
      64 bit for 64 bit machines. */
-#if !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) && !(defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
+#if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
+/* Just to have something. */
+#define SLJIT_WORD_SHIFT 0
+typedef unsigned long int sljit_uw;
+typedef long int sljit_w;
+#elif !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) && !(defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
 #define SLJIT_32BIT_ARCHITECTURE 1
 #define SLJIT_WORD_SHIFT 2
 typedef unsigned int sljit_uw;


Modified: code/trunk/sljit/sljitLir.c
===================================================================
--- code/trunk/sljit/sljitLir.c    2012-01-14 17:03:15 UTC (rev 874)
+++ code/trunk/sljit/sljitLir.c    2012-01-14 17:05:53 UTC (rev 875)
@@ -714,25 +714,31 @@
 #endif
 }


-static SLJIT_INLINE void check_sljit_emit_return(struct sljit_compiler *compiler, int src, sljit_w srcw)
+static SLJIT_INLINE void check_sljit_emit_return(struct sljit_compiler *compiler, int op, int src, sljit_w srcw)
 {
     /* If debug and verbose are disabled, all arguments are unused. */
     SLJIT_UNUSED_ARG(compiler);
+    SLJIT_UNUSED_ARG(op);
     SLJIT_UNUSED_ARG(src);
     SLJIT_UNUSED_ARG(srcw);


 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
-    if (src != SLJIT_UNUSED) {
+    if (op != SLJIT_UNUSED) {
+        SLJIT_ASSERT(op >= SLJIT_MOV && op <= SLJIT_MOV_SI);
         FUNCTION_CHECK_SRC(src, srcw);
     }
     else
-        SLJIT_ASSERT(srcw == 0);
+        SLJIT_ASSERT(src == 0 && srcw == 0);
 #endif
 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
     if (SLJIT_UNLIKELY(!!compiler->verbose)) {
-        fprintf(compiler->verbose, "  return ");
-        sljit_verbose_param(src, srcw);
-        fprintf(compiler->verbose, "\n");
+        if (op == SLJIT_UNUSED)
+            fprintf(compiler->verbose, "  return\n");
+        else {
+            fprintf(compiler->verbose, "  return %s ", op_names[op]);
+            sljit_verbose_param(src, srcw);
+            fprintf(compiler->verbose, "\n");
+        }
     }
 #endif
 }
@@ -814,6 +820,13 @@
     SLJIT_UNUSED_ARG(src);
     SLJIT_UNUSED_ARG(srcw);


+#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
+    if (SLJIT_UNLIKELY(compiler->skip_checks)) {
+        compiler->skip_checks = 0;
+        return;
+    }
+#endif
+
     SLJIT_ASSERT(GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_CLZ);
 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
     FUNCTION_CHECK_OP();
@@ -895,13 +908,6 @@
     int dst, sljit_w dstw,
     int src, sljit_w srcw)
 {
-#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
-    if (SLJIT_UNLIKELY(compiler->skip_checks)) {
-        compiler->skip_checks = 0;
-        return;
-    }
-#endif
-
     /* If debug and verbose are disabled, all arguments are unused. */
     SLJIT_UNUSED_ARG(compiler);
     SLJIT_UNUSED_ARG(op);
@@ -910,6 +916,13 @@
     SLJIT_UNUSED_ARG(src);
     SLJIT_UNUSED_ARG(srcw);


+#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
+    if (SLJIT_UNLIKELY(compiler->skip_checks)) {
+        compiler->skip_checks = 0;
+        return;
+    }
+#endif
+
     SLJIT_ASSERT(sljit_is_fpu_available());
     SLJIT_ASSERT(GET_OPCODE(op) >= SLJIT_FCMP && GET_OPCODE(op) <= SLJIT_FABS);
 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
@@ -1120,6 +1133,26 @@
 #endif
 }


+static SLJIT_INLINE int emit_mov_before_return(struct sljit_compiler *compiler, int op, int src, sljit_w srcw)
+{
+    /* Return if don't need to do anything. */
+    if (op == SLJIT_UNUSED)
+        return SLJIT_SUCCESS;
+
+#if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
+    if (src == SLJIT_RETURN_REG && op == SLJIT_MOV)
+        return SLJIT_SUCCESS;
+#else
+    if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_UI || op == SLJIT_MOV_SI))
+        return SLJIT_SUCCESS;
+#endif
+
+#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
+    compiler->skip_checks = 1;
+#endif
+    return sljit_emit_op1(compiler, op, SLJIT_RETURN_REG, 0, src, srcw);
+}
+
 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
     #include "sljitNativeX86_common.c"
 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
@@ -1306,9 +1339,10 @@
     SLJIT_ASSERT_STOP();
 }


-SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int src, sljit_w srcw)
+SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int op, int src, sljit_w srcw)
 {
     SLJIT_UNUSED_ARG(compiler);
+    SLJIT_UNUSED_ARG(op);
     SLJIT_UNUSED_ARG(src);
     SLJIT_UNUSED_ARG(srcw);
     SLJIT_ASSERT_STOP();
@@ -1376,6 +1410,22 @@
     return SLJIT_ERR_UNSUPPORTED;
 }


+SLJIT_API_FUNC_ATTRIBUTE int sljit_get_register_index(int reg)
+{
+    SLJIT_ASSERT_STOP();
+    return reg;
+}
+
+SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_op_custom(struct sljit_compiler *compiler,
+    void *instruction, int size)
+{
+    SLJIT_UNUSED_ARG(compiler);
+    SLJIT_UNUSED_ARG(instruction);
+    SLJIT_UNUSED_ARG(size);
+    SLJIT_ASSERT_STOP();
+    return SLJIT_ERR_UNSUPPORTED;
+}
+
 SLJIT_API_FUNC_ATTRIBUTE int sljit_is_fpu_available(void)
 {
     SLJIT_ASSERT_STOP();


Modified: code/trunk/sljit/sljitLir.h
===================================================================
--- code/trunk/sljit/sljitLir.h    2012-01-14 17:03:15 UTC (rev 874)
+++ code/trunk/sljit/sljitLir.h    2012-01-14 17:05:53 UTC (rev 875)
@@ -337,7 +337,8 @@


 #define SLJIT_MAX_LOCAL_SIZE    65536


-SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_enter(struct sljit_compiler *compiler, int args, int temporaries, int generals, int local_size);
+SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_enter(struct sljit_compiler *compiler,
+    int args, int temporaries, int generals, int local_size);


 /* The machine code has a context (which contains the local stack space size,
    number of used registers, etc.) which initialized by sljit_emit_enter. Several
@@ -351,10 +352,16 @@


/* Note: multiple calls of this function overwrites the previous call. */

-SLJIT_API_FUNC_ATTRIBUTE void sljit_set_context(struct sljit_compiler *compiler, int args, int temporaries, int generals, int local_size);
+SLJIT_API_FUNC_ATTRIBUTE void sljit_set_context(struct sljit_compiler *compiler,
+    int args, int temporaries, int generals, int local_size);


-/* Return from jit. See below the possible values for src and srcw. */
-SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int src, sljit_w srcw);
+/* Return from machine code.  The op argument can be SLJIT_UNUSED which means the
+   function does not return with anything or any opcode between SLJIT_MOV and
+   SLJIT_MOV_SI (see sljit_emit_op1). As for src and srcw they must be 0 if op
+   is SLJIT_UNUSED, otherwise see below the description about source and
+   destination arguments. */
+SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int op,
+    int src, sljit_w srcw);


 /* Really fast calling method for utility functions inside sljit (see SLJIT_FAST_CALL).
    All registers and even the stack frame is passed to the callee. The return address is


Modified: code/trunk/sljit/sljitNativeARM_Thumb2.c
===================================================================
--- code/trunk/sljit/sljitNativeARM_Thumb2.c    2012-01-14 17:03:15 UTC (rev 874)
+++ code/trunk/sljit/sljitNativeARM_Thumb2.c    2012-01-14 17:05:53 UTC (rev 875)
@@ -1169,21 +1169,14 @@
     compiler->local_size = local_size;
 }


-SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int src, sljit_w srcw)
+SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int op, int src, sljit_w srcw)
 {
     sljit_ins pop;


     CHECK_ERROR();
-    check_sljit_emit_return(compiler, src, srcw);
+    check_sljit_emit_return(compiler, op, src, srcw);


-    if (src != SLJIT_UNUSED && src != SLJIT_RETURN_REG) {
-        if (src >= SLJIT_TEMPORARY_REG1 && src <= TMP_REG3)
-            FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(SLJIT_RETURN_REG, src)));
-        else if (src & SLJIT_IMM)
-            FAIL_IF(load_immediate(compiler, SLJIT_RETURN_REG, srcw));
-        else
-            FAIL_IF(emit_op_mem(compiler, WORD_SIZE, SLJIT_RETURN_REG, src, srcw));
-    }
+    FAIL_IF(emit_mov_before_return(compiler, op, src, srcw));


     if (compiler->local_size > 0) {
         if (compiler->local_size <= (127 << 2))


Modified: code/trunk/sljit/sljitNativeARM_v5.c
===================================================================
--- code/trunk/sljit/sljitNativeARM_v5.c    2012-01-14 17:03:15 UTC (rev 874)
+++ code/trunk/sljit/sljitNativeARM_v5.c    2012-01-14 17:05:53 UTC (rev 875)
@@ -890,15 +890,14 @@
     compiler->local_size = local_size;
 }


-SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int src, sljit_w srcw)
+SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int op, int src, sljit_w srcw)
 {
     sljit_uw pop;


     CHECK_ERROR();
-    check_sljit_emit_return(compiler, src, srcw);
+    check_sljit_emit_return(compiler, op, src, srcw);


-    if (src != SLJIT_UNUSED && src != SLJIT_RETURN_REG)
-        FAIL_IF(emit_op(compiler, SLJIT_MOV, ALLOW_ANY_IMM, SLJIT_RETURN_REG, 0, TMP_REG1, 0, src, srcw));
+    FAIL_IF(emit_mov_before_return(compiler, op, src, srcw));


     if (compiler->local_size > 0)
         FAIL_IF(emit_op(compiler, SLJIT_ADD, ALLOW_IMM, SLJIT_LOCALS_REG, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, compiler->local_size));


Modified: code/trunk/sljit/sljitNativeMIPS_common.c
===================================================================
--- code/trunk/sljit/sljitNativeMIPS_common.c    2012-01-14 17:03:15 UTC (rev 874)
+++ code/trunk/sljit/sljitNativeMIPS_common.c    2012-01-14 17:05:53 UTC (rev 875)
@@ -527,19 +527,17 @@
     compiler->local_size = (local_size + 15) & ~0xf;
 }


-SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int src, sljit_w srcw)
+SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int op, int src, sljit_w srcw)
 {
     int local_size;
     sljit_ins base;


     CHECK_ERROR();
-    check_sljit_emit_return(compiler, src, srcw);
+    check_sljit_emit_return(compiler, op, src, srcw);


-    local_size = compiler->local_size;
+    FAIL_IF(emit_mov_before_return(compiler, op, src, srcw));


-    if (src != SLJIT_UNUSED && src != SLJIT_RETURN_REG)
-        FAIL_IF(emit_op(compiler, SLJIT_MOV, WORD_DATA, SLJIT_RETURN_REG, 0, TMP_REG1, 0, src, srcw));
-
+    local_size = compiler->local_size;
     if (local_size <= SIMM_MAX)
         base = S(REAL_STACK_PTR);
     else {


Modified: code/trunk/sljit/sljitNativePPC_common.c
===================================================================
--- code/trunk/sljit/sljitNativePPC_common.c    2012-01-14 17:03:15 UTC (rev 874)
+++ code/trunk/sljit/sljitNativePPC_common.c    2012-01-14 17:05:53 UTC (rev 875)
@@ -517,13 +517,12 @@
     compiler->local_size = (compiler->local_size + 15) & ~0xf;
 }


-SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int src, sljit_w srcw)
+SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int op, int src, sljit_w srcw)
 {
     CHECK_ERROR();
-    check_sljit_emit_return(compiler, src, srcw);
+    check_sljit_emit_return(compiler, op, src, srcw);


-    if (src != SLJIT_UNUSED && src != SLJIT_RETURN_REG)
-        FAIL_IF(emit_op(compiler, SLJIT_MOV, WORD_DATA, SLJIT_RETURN_REG, 0, TMP_REG1, 0, src, srcw));
+    FAIL_IF(emit_mov_before_return(compiler, op, src, srcw));


     if (compiler->local_size <= SIMM_MAX)
         FAIL_IF(push_inst(compiler, ADDI | D(REAL_STACK_PTR) | A(REAL_STACK_PTR) | IMM(compiler->local_size)));


Modified: code/trunk/sljit/sljitNativeX86_32.c
===================================================================
--- code/trunk/sljit/sljitNativeX86_32.c    2012-01-14 17:03:15 UTC (rev 874)
+++ code/trunk/sljit/sljitNativeX86_32.c    2012-01-14 17:05:53 UTC (rev 875)
@@ -173,21 +173,18 @@
         compiler->local_size += (generals - 3) * sizeof(sljit_uw);
 }


-SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int src, sljit_w srcw)
+SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int op, int src, sljit_w srcw)
 {
     int size;
     sljit_ub *buf;


     CHECK_ERROR();
-    check_sljit_emit_return(compiler, src, srcw);
+    check_sljit_emit_return(compiler, op, src, srcw);
     SLJIT_ASSERT(compiler->args >= 0);


     compiler->flags_saved = 0;
-    CHECK_EXTRA_REGS(src, srcw, (void)0);
+    FAIL_IF(emit_mov_before_return(compiler, op, src, srcw));


-    if (src != SLJIT_UNUSED && src != SLJIT_RETURN_REG)
-        FAIL_IF(emit_mov(compiler, SLJIT_RETURN_REG, 0, src, srcw));
-
     if (compiler->local_size > 0)
         FAIL_IF(emit_cum_binary(compiler, 0x03, 0x01, 0x0 << 3, 0x05,
                 SLJIT_LOCALS_REG, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, compiler->local_size));


Modified: code/trunk/sljit/sljitNativeX86_64.c
===================================================================
--- code/trunk/sljit/sljitNativeX86_64.c    2012-01-14 17:03:15 UTC (rev 874)
+++ code/trunk/sljit/sljitNativeX86_64.c    2012-01-14 17:05:53 UTC (rev 875)
@@ -297,21 +297,17 @@
 #endif
 }


-SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int src, sljit_w srcw)
+SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int op, int src, sljit_w srcw)
 {
     int size;
     sljit_ub *buf;


     CHECK_ERROR();
-    check_sljit_emit_return(compiler, src, srcw);
+    check_sljit_emit_return(compiler, op, src, srcw);


     compiler->flags_saved = 0;
+    FAIL_IF(emit_mov_before_return(compiler, op, src, srcw));


-    if (src != SLJIT_UNUSED && src != SLJIT_RETURN_REG) {
-        compiler->mode32 = 0;
-        FAIL_IF(emit_mov(compiler, SLJIT_RETURN_REG, 0, src, srcw));
-    }
-
     if (compiler->local_size > 0) {
         if (compiler->local_size <= 127) {
             buf = (sljit_ub*)ensure_buf(compiler, 1 + 4);