[Pcre-svn] [146] code/trunk: Get rid of remaining FIXMEs in …

トップ ページ
このメッセージを削除
著者: Subversion repository
日付:  
To: pcre-svn
題目: [Pcre-svn] [146] code/trunk: Get rid of remaining FIXMEs in the code; implement JIT compile timing.
Revision: 146
          http://www.exim.org/viewvc/pcre2?view=rev&revision=146
Author:   ph10
Date:     2014-11-12 17:46:02 +0000 (Wed, 12 Nov 2014)


Log Message:
-----------
Get rid of remaining FIXMEs in the code; implement JIT compile timing.

Modified Paths:
--------------
    code/trunk/doc/pcre2test.1
    code/trunk/src/pcre2_compile.c
    code/trunk/src/pcre2_dfa_match.c
    code/trunk/src/pcre2_jit_match.c
    code/trunk/src/pcre2_match.c
    code/trunk/src/pcre2_pattern_info.c
    code/trunk/src/pcre2test.c


Modified: code/trunk/doc/pcre2test.1
===================================================================
--- code/trunk/doc/pcre2test.1    2014-11-12 17:15:10 UTC (rev 145)
+++ code/trunk/doc/pcre2test.1    2014-11-12 17:46:02 UTC (rev 146)
@@ -160,10 +160,11 @@
 .TP 10
 \fB-t\fP
 Run each compile and match many times with a timer, and output the resulting
-times per compile or match. You can control the number of iterations that are
-used for timing by following \fB-t\fP with a number (as a separate item on the
-command line). For example, "-t 1000" iterates 1000 times. The default is to
-iterate 500,000 times.
+times per compile or match. When JIT is used, separate times are given for the
+initial compile and the JIT compile. You can control the number of iterations
+that are used for timing by following \fB-t\fP with a number (as a separate
+item on the command line). For example, "-t 1000" iterates 1000 times. The
+default is to iterate 500,000 times.
 .TP 10
 \fB-tm\fP
 This is like \fB-t\fP except that it times only the matching phase, not the


Modified: code/trunk/src/pcre2_compile.c
===================================================================
--- code/trunk/src/pcre2_compile.c    2014-11-12 17:15:10 UTC (rev 145)
+++ code/trunk/src/pcre2_compile.c    2014-11-12 17:46:02 UTC (rev 146)
@@ -7734,10 +7734,6 @@
 re->top_backref = cb.top_backref;
 re->max_lookbehind = cb.max_lookbehind;


-#ifdef FIXME  /* Is this necessary? Set above */
-re->flags = cb.external_flags | PCRE2_MODE;
-#endif
-
 if (cb.had_accept)
   {
   reqcu = 0;              /* Must disable after (*ACCEPT) */


Modified: code/trunk/src/pcre2_dfa_match.c
===================================================================
--- code/trunk/src/pcre2_dfa_match.c    2014-11-12 17:15:10 UTC (rev 145)
+++ code/trunk/src/pcre2_dfa_match.c    2014-11-12 17:46:02 UTC (rev 146)
@@ -3103,25 +3103,11 @@
 if (wscount < 20) return PCRE2_ERROR_DFA_WSSIZE;
 if (start_offset > length) return PCRE2_ERROR_BADOFFSET;


-/* FIXME: Remove BADENDIANNESS if saving/restoring is not to be implemented. */
-
/* Check that the first field in the block is the magic number. If it is not,
return with PCRE2_ERROR_BADMAGIC. */

if (re->magic_number != MAGIC_NUMBER) return PCRE2_ERROR_BADMAGIC;

-#ifdef FIXME
-If saving restoring gets implemented, define PCRE2_ERROR_BADENDIANNESS, and add
-this comment and code:
-
-/* However, if the magic number is equal to REVERSED_MAGIC_NUMBER we return
-with PCRE2_ERROR_BADENDIANNESS, which means that the pattern is likely compiled
-with different endianness. */
-
-  return re->magic_number == REVERSED_MAGIC_NUMBER?
-    PCRE2_ERROR_BADENDIANNESS:PCRE2_ERROR_BADMAGIC;
-#endif
-
 /* Check the code unit width. */


if ((re->flags & PCRE2_MODE_MASK) != PCRE2_CODE_UNIT_WIDTH/8)

Modified: code/trunk/src/pcre2_jit_match.c
===================================================================
--- code/trunk/src/pcre2_jit_match.c    2014-11-12 17:15:10 UTC (rev 145)
+++ code/trunk/src/pcre2_jit_match.c    2014-11-12 17:46:02 UTC (rev 146)
@@ -82,8 +82,6 @@
                  < -1 => some kind of unexpected problem
 */


-/* FIXME: this is currently a placeholder function */
-
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_jit_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length,
PCRE2_SIZE start_offset, uint32_t options, pcre2_match_data *match_data,

Modified: code/trunk/src/pcre2_match.c
===================================================================
--- code/trunk/src/pcre2_match.c    2014-11-12 17:15:10 UTC (rev 145)
+++ code/trunk/src/pcre2_match.c    2014-11-12 17:46:02 UTC (rev 146)
@@ -6412,18 +6412,6 @@


if (re->magic_number != MAGIC_NUMBER) return PCRE2_ERROR_BADMAGIC;

-#ifdef FIXME
-If saving restoring gets implemented, define PCRE2_ERROR_BADENDIANNESS, and add
-this comment and code:
-
-/* However, if the magic number is equal to REVERSED_MAGIC_NUMBER we return
-with PCRE2_ERROR_BADENDIANNESS, which means that the pattern is likely compiled
-with different endianness. */
-
-  return re->magic_number == REVERSED_MAGIC_NUMBER?
-    PCRE2_ERROR_BADENDIANNESS:PCRE2_ERROR_BADMAGIC;
-#endif
-
 /* Check the code unit width. */


if ((re->flags & PCRE2_MODE_MASK) != PCRE2_CODE_UNIT_WIDTH/8)

Modified: code/trunk/src/pcre2_pattern_info.c
===================================================================
--- code/trunk/src/pcre2_pattern_info.c    2014-11-12 17:15:10 UTC (rev 145)
+++ code/trunk/src/pcre2_pattern_info.c    2014-11-12 17:46:02 UTC (rev 146)
@@ -110,18 +110,6 @@


if (re->magic_number != MAGIC_NUMBER) return PCRE2_ERROR_BADMAGIC;

-#ifdef FIXME
-If saving restoring gets implemented, define PCRE2_ERROR_BADENDIANNESS, and add
-this comment and code:
-
-/* However, if the magic number is equal to REVERSED_MAGIC_NUMBER we return
-with PCRE2_ERROR_BADENDIANNESS, which means that the pattern is likely compiled
-with different endianness. */
-
-  return re->magic_number == REVERSED_MAGIC_NUMBER?
-    PCRE2_ERROR_BADENDIANNESS:PCRE2_ERROR_BADMAGIC;
-#endif
-
 /* Check that this pattern was compiled in the correct bit mode */


if ((re->flags & (PCRE2_CODE_UNIT_WIDTH/8)) == 0) return PCRE2_ERROR_BADMODE;

Modified: code/trunk/src/pcre2test.c
===================================================================
--- code/trunk/src/pcre2test.c    2014-11-12 17:15:10 UTC (rev 145)
+++ code/trunk/src/pcre2test.c    2014-11-12 17:46:02 UTC (rev 146)
@@ -651,6 +651,7 @@
 static int timeitm = 0;


clock_t total_compile_time = 0;
+clock_t total_jit_compile_time = 0;
clock_t total_match_time = 0;

 static uint32_t dfa_matched;
@@ -3933,23 +3934,22 @@
 if (timeit > 0)
   {
   register int i;
-  clock_t time_taken;
-  clock_t start_time = clock();
+  clock_t time_taken = 0;
   for (i = 0; i < timeit; i++)
     {
+    clock_t start_time = clock();
     PCRE2_COMPILE(compiled_code, pbuffer, patlen,
       pat_patctl.options|forbid_utf, &errorcode, &erroroffset, pat_context);
+    time_taken += clock() - start_time;
     if (TEST(compiled_code, !=, NULL))
       { SUB1(pcre2_code_free, compiled_code); }
     }
-  total_compile_time += (time_taken = clock() - start_time);
+  total_compile_time += time_taken;
   fprintf(outfile, "Compile time %.4f milliseconds\n",
     (((double)time_taken * 1000.0) / (double)timeit) /
       (double)CLOCKS_PER_SEC);
   }


-/* FIXME: implement timing for JIT compile. */
-
/* A final compile that is used "for real". */

PCRE2_COMPILE(compiled_code, pbuffer, patlen, pat_patctl.options|forbid_utf,
@@ -3974,11 +3974,35 @@
if (pattern_info(PCRE2_INFO_MAXLOOKBEHIND, &maxlookbehind, FALSE) != 0)
return PR_ABEND;

-/* Call the JIT compiler if requested. */
+/* Call the JIT compiler if requested. When timing, we must free and recompile
+the pattern each time because that is the only way to free the JIT compiled
+code. We know that compilation will always succeed. */

 if (pat_patctl.jit != 0)
   {
-  PCRE2_JIT_COMPILE(compiled_code, pat_patctl.jit);
+  if (timeit > 0)
+    {
+    register int i;
+    clock_t time_taken = 0;
+    for (i = 0; i < timeit; i++)
+      {
+      clock_t start_time;
+      SUB1(pcre2_code_free, compiled_code);
+      PCRE2_COMPILE(compiled_code, pbuffer, patlen,
+        pat_patctl.options|forbid_utf, &errorcode, &erroroffset, pat_context);
+      start_time = clock();
+      PCRE2_JIT_COMPILE(compiled_code, pat_patctl.jit);
+      time_taken += clock() - start_time; 
+      }
+    total_jit_compile_time += time_taken;
+    fprintf(outfile, "JIT compile  %.4f milliseconds\n",
+      (((double)time_taken * 1000.0) / (double)timeit) /
+        (double)CLOCKS_PER_SEC);
+    }
+  else
+    { 
+    PCRE2_JIT_COMPILE(compiled_code, pat_patctl.jit);
+    } 
   }


/* Output code size and other information if requested. */
@@ -6290,14 +6314,20 @@

 if (showtotaltimes)
   {
+  const char *pad = ""; 
   fprintf(outfile, "--------------------------------------\n");
   if (timeit > 0)
     {
     fprintf(outfile, "Total compile time %.4f milliseconds\n",
       (((double)total_compile_time * 1000.0) / (double)timeit) /
         (double)CLOCKS_PER_SEC);
+    if (total_jit_compile_time > 0)
+      fprintf(outfile, "Total JIT compile  %.4f milliseconds\n",
+        (((double)total_jit_compile_time * 1000.0) / (double)timeit) /
+          (double)CLOCKS_PER_SEC);
+    pad = "  ";       
     }
-  fprintf(outfile, "Total match time %.4f milliseconds\n",
+  fprintf(outfile, "Total match time %s%.4f milliseconds\n", pad,
     (((double)total_match_time * 1000.0) / (double)timeitm) /
       (double)CLOCKS_PER_SEC);
   }