/[pcre]/code/trunk/pcre_jit_compile.c
ViewVC logotype

Diff of /code/trunk/pcre_jit_compile.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1015 by ph10, Sun Aug 26 16:07:14 2012 UTC revision 1367 by zherczeg, Mon Oct 7 07:41:44 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11    The machine code generator part (this module) was written by Zoltan Herczeg    The machine code generator part (this module) was written by Zoltan Herczeg
12                        Copyright (c) 2010-2012                        Copyright (c) 2010-2013
13    
14  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
15  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 46  POSSIBILITY OF SUCH DAMAGE. Line 46  POSSIBILITY OF SUCH DAMAGE.
46    
47  #include "pcre_internal.h"  #include "pcre_internal.h"
48    
49  #ifdef SUPPORT_JIT  #if defined SUPPORT_JIT
50    
51  /* All-in-one: Since we use the JIT compiler only from here,  /* All-in-one: Since we use the JIT compiler only from here,
52  we just include it. This way we don't need to touch the build  we just include it. This way we don't need to touch the build
# Line 65  system files. */ Line 65  system files. */
65  #error Unsupported architecture  #error Unsupported architecture
66  #endif  #endif
67    
68    /* Defines for debugging purposes. */
69    
70    /* 1 - Use unoptimized capturing brackets.
71       2 - Enable capture_last_ptr (includes option 1). */
72    /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */
73    
74    /* 1 - Always have a control head. */
75    /* #define DEBUG_FORCE_CONTROL_HEAD 1 */
76    
77  /* Allocate memory for the regex stack on the real machine stack.  /* Allocate memory for the regex stack on the real machine stack.
78  Fast, but limited size. */  Fast, but limited size. */
79  #define MACHINE_STACK_SIZE 32768  #define MACHINE_STACK_SIZE 32768
# Line 157  typedef struct jit_arguments { Line 166  typedef struct jit_arguments {
166    int *offsets;    int *offsets;
167    pcre_uchar *uchar_ptr;    pcre_uchar *uchar_ptr;
168    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
169      void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171    int offsetcount;    pcre_uint32 limit_match;
172    int calllimit;    int real_offset_count;
173      int offset_count;
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 170  typedef struct executable_functions { Line 181  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184      pcre_uint32 top_bracket;
185      pcre_uint32 limit_match;
186    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
187  } executable_functions;  } executable_functions;
188    
# Line 178  typedef struct jump_list { Line 191  typedef struct jump_list {
191    struct jump_list *next;    struct jump_list *next;
192  } jump_list;  } jump_list;
193    
 enum stub_types { stack_alloc };  
   
194  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
195    struct sljit_jump *start;    struct sljit_jump *start;
196    struct sljit_label *quit;    struct sljit_label *quit;
197    struct stub_list *next;    struct stub_list *next;
198  } stub_list;  } stub_list;
199    
200    enum frame_types {
201      no_frame = -1,
202      no_stack = -2
203    };
204    
205    enum control_types {
206      type_mark = 0,
207      type_then_trap = 1
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
213  code generator. It is allocated by compile_matchingpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_backtrackingpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct backtrack_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
# Line 208  typedef struct backtrack_common { Line 227  typedef struct backtrack_common {
227  typedef struct assert_backtrack {  typedef struct assert_backtrack {
228    backtrack_common common;    backtrack_common common;
229    jump_list *condfailed;    jump_list *condfailed;
230    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
231    int framesize;    int framesize;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int private_data_ptr;    int private_data_ptr;
# Line 229  typedef struct bracket_backtrack { Line 248  typedef struct bracket_backtrack {
248      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
249      jump_list *condfailed;      jump_list *condfailed;
250      assert_backtrack *assert;      assert_backtrack *assert;
251      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
252      int framesize;      int framesize;
253    } u;    } u;
254    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
# Line 264  typedef struct recurse_entry { Line 283  typedef struct recurse_entry {
283    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
284    jump_list *calls;    jump_list *calls;
285    /* Points to the starting opcode. */    /* Points to the starting opcode. */
286    int start;    sljit_sw start;
287  } recurse_entry;  } recurse_entry;
288    
289  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
290    backtrack_common common;    backtrack_common common;
291      BOOL inlined_pattern;
292  } recurse_backtrack;  } recurse_backtrack;
293    
294    #define OP_THEN_TRAP OP_TABLE_LENGTH
295    
296    typedef struct then_trap_backtrack {
297      backtrack_common common;
298      /* If then_trap is not NULL, this structure contains the real
299      then_trap for the backtracking path. */
300      struct then_trap_backtrack *then_trap;
301      /* Points to the starting opcode. */
302      sljit_sw start;
303      /* Exit point for the then opcodes of this alternative. */
304      jump_list *quit;
305      /* Frame size of the current alternative. */
306      int framesize;
307    } then_trap_backtrack;
308    
309  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 6
310    
311  typedef struct compiler_common {  typedef struct compiler_common {
312      /* The sljit ceneric compiler. */
313    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
314      /* First byte code. */
315    pcre_uchar *start;    pcre_uchar *start;
   
316    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
317    int *private_data_ptrs;    sljit_si *private_data_ptrs;
318    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
319    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
320      /* Tells whether the starting offset is a target of then. */
321      pcre_uint8 *then_offsets;
322      /* Current position where a THEN must jump. */
323      then_trap_backtrack *then_trap;
324    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
325    int cbraptr;    int cbra_ptr;
326    /* OVector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
327    int ovector_start;    int ovector_start;
328    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
329    int req_char_ptr;    int req_char_ptr;
330    /* Head of the last recursion. */    /* Head of the last recursion. */
331    int recursive_head;    int recursive_head_ptr;
332    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
333    int start_used_ptr;    int start_used_ptr;
334    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 297  typedef struct compiler_common { Line 337  typedef struct compiler_common {
337    int first_line_end;    int first_line_end;
338    /* Points to the marked string. */    /* Points to the marked string. */
339    int mark_ptr;    int mark_ptr;
340      /* Recursive control verb management chain. */
341      int control_head_ptr;
342      /* Points to the last matched capture block index. */
343      int capture_last_ptr;
344      /* Points to the starting position of the current match. */
345      int start_ptr;
346    
347    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
348    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
349    sljit_w lcc;    sljit_sw lcc;
350    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
351    int mode;    int mode;
352      /* \K is found in the pattern. */
353      BOOL has_set_som;
354      /* (*SKIP:arg) is found in the pattern. */
355      BOOL has_skip_arg;
356      /* (*THEN) is found in the pattern. */
357      BOOL has_then;
358      /* Needs to know the start position anytime. */
359      BOOL needs_start_ptr;
360      /* Currently in recurse or negative assert. */
361      BOOL local_exit;
362      /* Currently in a positive assert. */
363      BOOL positive_assert;
364    /* Newline control. */    /* Newline control. */
365    int nltype;    int nltype;
366    int newline;    int newline;
367    int bsr_nltype;    int bsr_nltype;
368    /* Dollar endonly. */    /* Dollar endonly. */
369    int endonly;    int endonly;
   BOOL has_set_som;  
370    /* Tables. */    /* Tables. */
371    sljit_w ctypes;    sljit_sw ctypes;
372    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
373    /* Named capturing brackets. */    /* Named capturing brackets. */
374    sljit_uw name_table;    pcre_uchar *name_table;
375    sljit_w name_count;    sljit_sw name_count;
376    sljit_w name_entry_size;    sljit_sw name_entry_size;
377    
378    /* Labels and jump lists. */    /* Labels and jump lists. */
379    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
380    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
381    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
382      struct sljit_label *accept_label;
383    stub_list *stubs;    stub_list *stubs;
384    recurse_entry *entries;    recurse_entry *entries;
385    recurse_entry *currententry;    recurse_entry *currententry;
386    jump_list *partialmatch;    jump_list *partialmatch;
387    jump_list *quit;    jump_list *quit;
388      jump_list *positive_assert_quit;
389      jump_list *forced_quit;
390    jump_list *accept;    jump_list *accept;
391    jump_list *calllimit;    jump_list *calllimit;
392    jump_list *stackalloc;    jump_list *stackalloc;
# Line 337  typedef struct compiler_common { Line 397  typedef struct compiler_common {
397    jump_list *vspace;    jump_list *vspace;
398    jump_list *casefulcmp;    jump_list *casefulcmp;
399    jump_list *caselesscmp;    jump_list *caselesscmp;
400      jump_list *reset_match;
401    BOOL jscript_compat;    BOOL jscript_compat;
402  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
403    BOOL utf;    BOOL utf;
404  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
405    BOOL use_ucp;    BOOL use_ucp;
406  #endif  #endif
407    #ifndef COMPILE_PCRE32
408    jump_list *utfreadchar;    jump_list *utfreadchar;
409    #endif
410  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
411    jump_list *utfreadtype8;    jump_list *utfreadtype8;
412  #endif  #endif
# Line 361  typedef struct compare_context { Line 424  typedef struct compare_context {
424  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
425    int ucharptr;    int ucharptr;
426    union {    union {
427      sljit_i asint;      sljit_si asint;
428      sljit_uh asushort;      sljit_uh asushort;
429  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
430      sljit_ub asbyte;      sljit_ub asbyte;
431      sljit_ub asuchars[4];      sljit_ub asuchars[4];
432  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
433      sljit_uh asuchars[2];      sljit_uh asuchars[2];
434  #endif  #elif defined COMPILE_PCRE32
435        sljit_ui asuchars[1];
436  #endif  #endif
437    } c;    } c;
438    union {    union {
439      sljit_i asint;      sljit_si asint;
440      sljit_uh asushort;      sljit_uh asushort;
441  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
442      sljit_ub asbyte;      sljit_ub asbyte;
443      sljit_ub asuchars[4];      sljit_ub asuchars[4];
444  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
445      sljit_uh asuchars[2];      sljit_uh asuchars[2];
446  #endif  #elif defined COMPILE_PCRE32
447        sljit_ui asuchars[1];
448  #endif  #endif
449    } oc;    } oc;
450  #endif  #endif
451  } compare_context;  } compare_context;
452    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
453  /* Undefine sljit macros. */  /* Undefine sljit macros. */
454  #undef CMP  #undef CMP
455    
456  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
457  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
458    
459  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
460  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
461  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
462  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
463  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
464  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
465  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
466  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
467  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
468  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
469    
470  /* Local space layout. */  /* Local space layout. */
471  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
472  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
473  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
474  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
475  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
476  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
477  /* Max limit of recursions. */  /* Max limit of recursions. */
478  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
479  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
480  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
481  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
482  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
483  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
484  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
485  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
486  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
487    
488  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
489  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
490  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
491  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
492  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
493  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
494    #elif defined COMPILE_PCRE32
495    #define MOV_UCHAR  SLJIT_MOV_UI
496    #define MOVU_UCHAR SLJIT_MOVU_UI
497  #else  #else
498  #error Unsupported compiling mode  #error Unsupported compiling mode
499  #endif  #endif
 #endif  
500    
501  /* Shortcuts. */  /* Shortcuts. */
502  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 455  the start pointers when the end of the c Line 513  the start pointers when the end of the c
513    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
514  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
515    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
516    #define SET_LABEL(jump, label) \
517      sljit_set_label((jump), (label))
518  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
519    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
520  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
521    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))
522  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
523    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
524  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
525    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
526    
# Line 475  return cc; Line 535  return cc;
535    
536  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
537   next_opcode   next_opcode
538   get_private_data_length   check_opcode_types
539   set_private_data_ptrs   set_private_data_ptrs
540   get_framesize   get_framesize
541   init_frame   init_frame
542   get_private_data_length_for_copy   get_private_data_copy_length
543   copy_private_data   copy_private_data
544   compile_matchingpath   compile_matchingpath
545   compile_backtrackingpath   compile_backtrackingpath
# Line 503  switch(*cc) Line 563  switch(*cc)
563    case OP_WORDCHAR:    case OP_WORDCHAR:
564    case OP_ANY:    case OP_ANY:
565    case OP_ALLANY:    case OP_ALLANY:
566      case OP_NOTPROP:
567      case OP_PROP:
568    case OP_ANYNL:    case OP_ANYNL:
569    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
570    case OP_HSPACE:    case OP_HSPACE:
# Line 515  switch(*cc) Line 577  switch(*cc)
577    case OP_CIRCM:    case OP_CIRCM:
578    case OP_DOLL:    case OP_DOLL:
579    case OP_DOLLM:    case OP_DOLLM:
   case OP_TYPESTAR:  
   case OP_TYPEMINSTAR:  
   case OP_TYPEPLUS:  
   case OP_TYPEMINPLUS:  
   case OP_TYPEQUERY:  
   case OP_TYPEMINQUERY:  
   case OP_TYPEPOSSTAR:  
   case OP_TYPEPOSPLUS:  
   case OP_TYPEPOSQUERY:  
580    case OP_CRSTAR:    case OP_CRSTAR:
581    case OP_CRMINSTAR:    case OP_CRMINSTAR:
582    case OP_CRPLUS:    case OP_CRPLUS:
583    case OP_CRMINPLUS:    case OP_CRMINPLUS:
584    case OP_CRQUERY:    case OP_CRQUERY:
585    case OP_CRMINQUERY:    case OP_CRMINQUERY:
586      case OP_CRRANGE:
587      case OP_CRMINRANGE:
588      case OP_CLASS:
589      case OP_NCLASS:
590      case OP_REF:
591      case OP_REFI:
592      case OP_RECURSE:
593      case OP_CALLOUT:
594      case OP_ALT:
595      case OP_KET:
596      case OP_KETRMAX:
597      case OP_KETRMIN:
598      case OP_KETRPOS:
599      case OP_REVERSE:
600      case OP_ASSERT:
601      case OP_ASSERT_NOT:
602      case OP_ASSERTBACK:
603      case OP_ASSERTBACK_NOT:
604      case OP_ONCE:
605      case OP_ONCE_NC:
606      case OP_BRA:
607      case OP_BRAPOS:
608      case OP_CBRA:
609      case OP_CBRAPOS:
610      case OP_COND:
611      case OP_SBRA:
612      case OP_SBRAPOS:
613      case OP_SCBRA:
614      case OP_SCBRAPOS:
615      case OP_SCOND:
616      case OP_CREF:
617      case OP_DNCREF:
618      case OP_RREF:
619      case OP_DNRREF:
620    case OP_DEF:    case OP_DEF:
621    case OP_BRAZERO:    case OP_BRAZERO:
622    case OP_BRAMINZERO:    case OP_BRAMINZERO:
623    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
624      case OP_PRUNE:
625      case OP_SKIP:
626      case OP_THEN:
627    case OP_COMMIT:    case OP_COMMIT:
628    case OP_FAIL:    case OP_FAIL:
629    case OP_ACCEPT:    case OP_ACCEPT:
630    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
631      case OP_CLOSE:
632    case OP_SKIPZERO:    case OP_SKIPZERO:
633    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
634    
635    case OP_CHAR:    case OP_CHAR:
636    case OP_CHARI:    case OP_CHARI:
# Line 557  switch(*cc) Line 642  switch(*cc)
642    case OP_MINPLUS:    case OP_MINPLUS:
643    case OP_QUERY:    case OP_QUERY:
644    case OP_MINQUERY:    case OP_MINQUERY:
645      case OP_UPTO:
646      case OP_MINUPTO:
647      case OP_EXACT:
648    case OP_POSSTAR:    case OP_POSSTAR:
649    case OP_POSPLUS:    case OP_POSPLUS:
650    case OP_POSQUERY:    case OP_POSQUERY:
651      case OP_POSUPTO:
652    case OP_STARI:    case OP_STARI:
653    case OP_MINSTARI:    case OP_MINSTARI:
654    case OP_PLUSI:    case OP_PLUSI:
655    case OP_MINPLUSI:    case OP_MINPLUSI:
656    case OP_QUERYI:    case OP_QUERYI:
657    case OP_MINQUERYI:    case OP_MINQUERYI:
658      case OP_UPTOI:
659      case OP_MINUPTOI:
660      case OP_EXACTI:
661    case OP_POSSTARI:    case OP_POSSTARI:
662    case OP_POSPLUSI:    case OP_POSPLUSI:
663    case OP_POSQUERYI:    case OP_POSQUERYI:
664      case OP_POSUPTOI:
665    case OP_NOTSTAR:    case OP_NOTSTAR:
666    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
667    case OP_NOTPLUS:    case OP_NOTPLUS:
668    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
669    case OP_NOTQUERY:    case OP_NOTQUERY:
670    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
671      case OP_NOTUPTO:
672      case OP_NOTMINUPTO:
673      case OP_NOTEXACT:
674    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
675    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
676    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
677      case OP_NOTPOSUPTO:
678    case OP_NOTSTARI:    case OP_NOTSTARI:
679    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
680    case OP_NOTPLUSI:    case OP_NOTPLUSI:
681    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
682    case OP_NOTQUERYI:    case OP_NOTQUERYI:
683    case OP_NOTMINQUERYI:    case OP_NOTMINQUERYI:
   case OP_NOTPOSSTARI:  
   case OP_NOTPOSPLUSI:  
   case OP_NOTPOSQUERYI:  
   cc += 2;  
 #ifdef SUPPORT_UTF  
   if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
   return cc;  
   
   case OP_UPTO:  
   case OP_MINUPTO:  
   case OP_EXACT:  
   case OP_POSUPTO:  
   case OP_UPTOI:  
   case OP_MINUPTOI:  
   case OP_EXACTI:  
   case OP_POSUPTOI:  
   case OP_NOTUPTO:  
   case OP_NOTMINUPTO:  
   case OP_NOTEXACT:  
   case OP_NOTPOSUPTO:  
684    case OP_NOTUPTOI:    case OP_NOTUPTOI:
685    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
686    case OP_NOTEXACTI:    case OP_NOTEXACTI:
687      case OP_NOTPOSSTARI:
688      case OP_NOTPOSPLUSI:
689      case OP_NOTPOSQUERYI:
690    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
691    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
692  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
693    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
694  #endif  #endif
695    return cc;    return cc;
696    
697    case OP_NOTPROP:    /* Special cases. */
698    case OP_PROP:    case OP_TYPESTAR:
699    return cc + 1 + 2;    case OP_TYPEMINSTAR:
700      case OP_TYPEPLUS:
701      case OP_TYPEMINPLUS:
702      case OP_TYPEQUERY:
703      case OP_TYPEMINQUERY:
704    case OP_TYPEUPTO:    case OP_TYPEUPTO:
705    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
706    case OP_TYPEEXACT:    case OP_TYPEEXACT:
707      case OP_TYPEPOSSTAR:
708      case OP_TYPEPOSPLUS:
709      case OP_TYPEPOSQUERY:
710    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
711    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_NCREF:  
   case OP_RREF:  
   case OP_NRREF:  
   case OP_CLOSE:  
   cc += 1 + IMM2_SIZE;  
   return cc;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   return cc + 1 + 2 * IMM2_SIZE;  
712    
713    case OP_CLASS:    case OP_ANYBYTE:
714    case OP_NCLASS:  #ifdef SUPPORT_UTF
715    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
716    #endif
717      return cc + 1;
718    
719  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
720    case OP_XCLASS:    case OP_XCLASS:
721    return cc + GET(cc, 1);    return cc + GET(cc, 1);
722  #endif  #endif
723    
   case OP_RECURSE:  
   case OP_ASSERT:  
   case OP_ASSERT_NOT:  
   case OP_ASSERTBACK:  
   case OP_ASSERTBACK_NOT:  
   case OP_REVERSE:  
   case OP_ONCE:  
   case OP_ONCE_NC:  
   case OP_BRA:  
   case OP_BRAPOS:  
   case OP_COND:  
   case OP_SBRA:  
   case OP_SBRAPOS:  
   case OP_SCOND:  
   case OP_ALT:  
   case OP_KET:  
   case OP_KETRMAX:  
   case OP_KETRMIN:  
   case OP_KETRPOS:  
   return cc + 1 + LINK_SIZE;  
   
   case OP_CBRA:  
   case OP_CBRAPOS:  
   case OP_SCBRA:  
   case OP_SCBRAPOS:  
   return cc + 1 + LINK_SIZE + IMM2_SIZE;  
   
724    case OP_MARK:    case OP_MARK:
725      case OP_PRUNE_ARG:
726      case OP_SKIP_ARG:
727      case OP_THEN_ARG:
728    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
729    
730    default:    default:
731      /* All opcodes are supported now! */
732      SLJIT_ASSERT_STOP();
733    return NULL;    return NULL;
734    }    }
735  }  }
736    
737  #define CASE_ITERATOR_PRIVATE_DATA_1 \  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
     case OP_MINSTAR: \  
     case OP_MINPLUS: \  
     case OP_QUERY: \  
     case OP_MINQUERY: \  
     case OP_MINSTARI: \  
     case OP_MINPLUSI: \  
     case OP_QUERYI: \  
     case OP_MINQUERYI: \  
     case OP_NOTMINSTAR: \  
     case OP_NOTMINPLUS: \  
     case OP_NOTQUERY: \  
     case OP_NOTMINQUERY: \  
     case OP_NOTMINSTARI: \  
     case OP_NOTMINPLUSI: \  
     case OP_NOTQUERYI: \  
     case OP_NOTMINQUERYI:  
   
 #define CASE_ITERATOR_PRIVATE_DATA_2A \  
     case OP_STAR: \  
     case OP_PLUS: \  
     case OP_STARI: \  
     case OP_PLUSI: \  
     case OP_NOTSTAR: \  
     case OP_NOTPLUS: \  
     case OP_NOTSTARI: \  
     case OP_NOTPLUSI:  
   
 #define CASE_ITERATOR_PRIVATE_DATA_2B \  
     case OP_UPTO: \  
     case OP_MINUPTO: \  
     case OP_UPTOI: \  
     case OP_MINUPTOI: \  
     case OP_NOTUPTO: \  
     case OP_NOTMINUPTO: \  
     case OP_NOTUPTOI: \  
     case OP_NOTMINUPTOI:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \  
     case OP_TYPEMINSTAR: \  
     case OP_TYPEMINPLUS: \  
     case OP_TYPEQUERY: \  
     case OP_TYPEMINQUERY:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \  
     case OP_TYPESTAR: \  
     case OP_TYPEPLUS:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \  
     case OP_TYPEUPTO: \  
     case OP_TYPEMINUPTO:  
   
 static int get_class_iterator_size(pcre_uchar *cc)  
 {  
 switch(*cc)  
   {  
   case OP_CRSTAR:  
   case OP_CRPLUS:  
   return 2;  
   
   case OP_CRMINSTAR:  
   case OP_CRMINPLUS:  
   case OP_CRQUERY:  
   case OP_CRMINQUERY:  
   return 1;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))  
     return 0;  
   return 2;  
   
   default:  
   return 0;  
   }  
 }  
   
 static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  
738  {  {
739  int private_data_length = 0;  pcre_uchar *slot;
740  pcre_uchar *alternative;  int i;
 pcre_uchar *name;  
 pcre_uchar *end = NULL;  
 int space, size, bracketlen, i;  
741    
742  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
743  while (cc < ccend)  while (cc < ccend)
744    {    {
   space = 0;  
   size = 0;  
   bracketlen = 0;  
745    switch(*cc)    switch(*cc)
746      {      {
747      case OP_SET_SOM:      case OP_SET_SOM:
# Line 785  while (cc < ccend) Line 755  while (cc < ccend)
755      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
756      break;      break;
757    
     case OP_ASSERT:  
     case OP_ASSERT_NOT:  
     case OP_ASSERTBACK:  
     case OP_ASSERTBACK_NOT:  
     case OP_ONCE:  
     case OP_ONCE_NC:  
     case OP_BRAPOS:  
     case OP_SBRA:  
     case OP_SBRAPOS:  
     private_data_length += sizeof(sljit_w);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
758      case OP_CBRAPOS:      case OP_CBRAPOS:
759      case OP_SCBRAPOS:      case OP_SCBRAPOS:
     private_data_length += sizeof(sljit_w);  
760      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
761      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
762      break;      break;
763    
764      case OP_COND:      case OP_COND:
765      case OP_SCOND:      case OP_SCOND:
766      bracketlen = cc[1 + LINK_SIZE];      /* Only AUTO_CALLOUT can insert this opcode. We do
767      if (bracketlen == OP_CREF)         not intend to support this case. */
768        {      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
769        bracketlen = GET2(cc, 1 + LINK_SIZE + 1);        return FALSE;
770        common->optimized_cbracket[bracketlen] = 0;      cc += 1 + LINK_SIZE;
       }  
     else if (bracketlen == OP_NCREF)  
       {  
       bracketlen = GET2(cc, 1 + LINK_SIZE + 1);  
       name = (pcre_uchar *)common->name_table;  
       alternative = name;  
       for (i = 0; i < common->name_count; i++)  
         {  
         if (GET2(name, 0) == bracketlen) break;  
         name += common->name_entry_size;  
         }  
       SLJIT_ASSERT(i != common->name_count);  
   
       for (i = 0; i < common->name_count; i++)  
         {  
         if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)  
           common->optimized_cbracket[GET2(alternative, 0)] = 0;  
         alternative += common->name_entry_size;  
         }  
       }  
   
     if (*cc == OP_COND)  
       {  
       /* Might be a hidden SCOND. */  
       alternative = cc + GET(cc, 1);  
       if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)  
         private_data_length += sizeof(sljit_w);  
       }  
     else  
       private_data_length += sizeof(sljit_w);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_BRA:  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_CBRA:  
     case OP_SCBRA:  
     bracketlen = 1 + LINK_SIZE + IMM2_SIZE;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_1  
     space = 1;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_2A  
     space = 2;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_2B  
     space = 2;  
     size = -(2 + IMM2_SIZE);  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_1  
     space = 1;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_2A  
     if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)  
       space = 2;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_2B  
     if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)  
       space = 2;  
     size = 1 + IMM2_SIZE;  
771      break;      break;
772    
773      case OP_CLASS:      case OP_CREF:
774      case OP_NCLASS:      i = GET2(cc, 1);
775      size += 1 + 32 / sizeof(pcre_uchar);      common->optimized_cbracket[i] = 0;
776      space = get_class_iterator_size(cc + size);      cc += 1 + IMM2_SIZE;
777      break;      break;
778    
779  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8      case OP_DNCREF:
780      case OP_XCLASS:      i = GET2(cc, 1 + IMM2_SIZE);
781      size = GET(cc, 1);      slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
782      space = get_class_iterator_size(cc + size);      while (i-- > 0)
783          {
784          common->optimized_cbracket[GET2(slot, 0)] = 0;
785          slot += common->name_entry_size;
786          }
787        cc += 1 + 2 * IMM2_SIZE;
788      break;      break;
 #endif  
789    
790      case OP_RECURSE:      case OP_RECURSE:
791      /* Set its value only once. */      /* Set its value only once. */
792      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
793        {        {
794        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
795        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
796        }        }
797      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
798      break;      break;
799    
800        case OP_CALLOUT:
801        if (common->capture_last_ptr == 0)
802          {
803          common->capture_last_ptr = common->ovector_start;
804          common->ovector_start += sizeof(sljit_sw);
805          }
806        cc += 2 + 2 * LINK_SIZE;
807        break;
808    
809        case OP_THEN_ARG:
810        common->has_then = TRUE;
811        common->control_head_ptr = 1;
812        /* Fall through. */
813    
814        case OP_PRUNE_ARG:
815        common->needs_start_ptr = TRUE;
816        /* Fall through. */
817    
818      case OP_MARK:      case OP_MARK:
819      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
820        {        {
821        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
822        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
823        }        }
824      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
825      break;      break;
826    
827        case OP_THEN:
828        common->has_then = TRUE;
829        common->control_head_ptr = 1;
830        /* Fall through. */
831    
832        case OP_PRUNE:
833        case OP_SKIP:
834        common->needs_start_ptr = TRUE;
835        cc += 1;
836        break;
837    
838        case OP_SKIP_ARG:
839        common->control_head_ptr = 1;
840        common->has_skip_arg = TRUE;
841        cc += 1 + 2 + cc[1];
842        break;
843    
844      default:      default:
845      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
846      if (cc == NULL)      if (cc == NULL)
847        return -1;        return FALSE;
848      break;      break;
849      }      }
850      }
851    return TRUE;
852    }
853    
854    if (space > 0 && cc >= end)  static int get_class_iterator_size(pcre_uchar *cc)
855      private_data_length += sizeof(sljit_w) * space;  {
856    switch(*cc)
857      {
858      case OP_CRSTAR:
859      case OP_CRPLUS:
860      return 2;
861    
862    if (size != 0)    case OP_CRMINSTAR:
863      case OP_CRMINPLUS:
864      case OP_CRQUERY:
865      case OP_CRMINQUERY:
866      return 1;
867    
868      case OP_CRRANGE:
869      case OP_CRMINRANGE:
870      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
871        return 0;
872      return 2;
873    
874      default:
875      return 0;
876      }
877    }
878    
879    static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
880    {
881    pcre_uchar *end = bracketend(begin);
882    pcre_uchar *next;
883    pcre_uchar *next_end;
884    pcre_uchar *max_end;
885    pcre_uchar type;
886    sljit_sw length = end - begin;
887    int min, max, i;
888    
889    /* Detect fixed iterations first. */
890    if (end[-(1 + LINK_SIZE)] != OP_KET)
891      return FALSE;
892    
893    /* Already detected repeat. */
894    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
895      return TRUE;
896    
897    next = end;
898    min = 1;
899    while (1)
900      {
901      if (*next != *begin)
902        break;
903      next_end = bracketend(next);
904      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
905        break;
906      next = next_end;
907      min++;
908      }
909    
910    if (min == 2)
911      return FALSE;
912    
913    max = 0;
914    max_end = next;
915    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
916      {
917      type = *next;
918      while (1)
919      {      {
920      if (size < 0)      if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
921        {        break;
922        cc += -size;      next_end = bracketend(next + 2 + LINK_SIZE);
923  #ifdef SUPPORT_UTF      if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
924        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        break;
925  #endif      next = next_end;
926        }      max++;
     else  
       cc += size;  
927      }      }
928    
929    if (bracketlen > 0)    if (next[0] == type && next[1] == *begin && max >= 1)
930      {      {
931      if (cc >= end)      next_end = bracketend(next + 1);
932        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
933        {        {
934        end = bracketend(cc);        for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
935        if (end[-1 - LINK_SIZE] == OP_KET)          if (*next_end != OP_KET)
936          end = NULL;            break;
937    
938          if (i == max)
939            {
940            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
941            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
942            /* +2 the original and the last. */
943            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
944            if (min == 1)
945              return TRUE;
946            min--;
947            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
948            }
949        }        }
     cc += bracketlen;  
950      }      }
951    }    }
952  return private_data_length;  
953    if (min >= 3)
954      {
955      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
956      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
957      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
958      return TRUE;
959      }
960    
961    return FALSE;
962  }  }
963    
964  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
965        case OP_MINSTAR: \
966        case OP_MINPLUS: \
967        case OP_QUERY: \
968        case OP_MINQUERY: \
969        case OP_MINSTARI: \
970        case OP_MINPLUSI: \
971        case OP_QUERYI: \
972        case OP_MINQUERYI: \
973        case OP_NOTMINSTAR: \
974        case OP_NOTMINPLUS: \
975        case OP_NOTQUERY: \
976        case OP_NOTMINQUERY: \
977        case OP_NOTMINSTARI: \
978        case OP_NOTMINPLUSI: \
979        case OP_NOTQUERYI: \
980        case OP_NOTMINQUERYI:
981    
982    #define CASE_ITERATOR_PRIVATE_DATA_2A \
983        case OP_STAR: \
984        case OP_PLUS: \
985        case OP_STARI: \
986        case OP_PLUSI: \
987        case OP_NOTSTAR: \
988        case OP_NOTPLUS: \
989        case OP_NOTSTARI: \
990        case OP_NOTPLUSI:
991    
992    #define CASE_ITERATOR_PRIVATE_DATA_2B \
993        case OP_UPTO: \
994        case OP_MINUPTO: \
995        case OP_UPTOI: \
996        case OP_MINUPTOI: \
997        case OP_NOTUPTO: \
998        case OP_NOTMINUPTO: \
999        case OP_NOTUPTOI: \
1000        case OP_NOTMINUPTOI:
1001    
1002    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1003        case OP_TYPEMINSTAR: \
1004        case OP_TYPEMINPLUS: \
1005        case OP_TYPEQUERY: \
1006        case OP_TYPEMINQUERY:
1007    
1008    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1009        case OP_TYPESTAR: \
1010        case OP_TYPEPLUS:
1011    
1012    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1013        case OP_TYPEUPTO: \
1014        case OP_TYPEMINUPTO:
1015    
1016    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1017  {  {
1018  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1019  pcre_uchar *alternative;  pcre_uchar *alternative;
1020  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1021    int private_data_ptr = *private_data_start;
1022  int space, size, bracketlen;  int space, size, bracketlen;
1023    
1024  while (cc < ccend)  while (cc < ccend)
# Line 967  while (cc < ccend) Line 1026  while (cc < ccend)
1026    space = 0;    space = 0;
1027    size = 0;    size = 0;
1028    bracketlen = 0;    bracketlen = 0;
1029      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1030        return;
1031    
1032      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1033        if (detect_repeat(common, cc))
1034          {
1035          /* These brackets are converted to repeats, so no global
1036          based single character repeat is allowed. */
1037          if (cc >= end)
1038            end = bracketend(cc);
1039          }
1040    
1041    switch(*cc)    switch(*cc)
1042      {      {
1043        case OP_KET:
1044        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1045          {
1046          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1047          private_data_ptr += sizeof(sljit_sw);
1048          cc += common->private_data_ptrs[cc + 1 - common->start];
1049          }
1050        cc += 1 + LINK_SIZE;
1051        break;
1052    
1053      case OP_ASSERT:      case OP_ASSERT:
1054      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1055      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 980  while (cc < ccend) Line 1061  while (cc < ccend)
1061      case OP_SBRAPOS:      case OP_SBRAPOS:
1062      case OP_SCOND:      case OP_SCOND:
1063      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1064      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1065      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1066      break;      break;
1067    
1068      case OP_CBRAPOS:      case OP_CBRAPOS:
1069      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1070      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1071      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1072      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1073      break;      break;
1074    
# Line 997  while (cc < ccend) Line 1078  while (cc < ccend)
1078      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1079        {        {
1080        common->private_data_ptrs[cc - common->start] = private_data_ptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1081        private_data_ptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1082        }        }
1083      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1084      break;      break;
# Line 1062  while (cc < ccend) Line 1143  while (cc < ccend)
1143      break;      break;
1144      }      }
1145    
1146      /* Character iterators, which are not inside a repeated bracket,
1147         gets a private slot instead of allocating it on the stack. */
1148    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1149      {      {
1150      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1151      private_data_ptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1152      }      }
1153    
1154    if (size != 0)    if (size != 0)
# Line 1092  while (cc < ccend) Line 1175  while (cc < ccend)
1175      cc += bracketlen;      cc += bracketlen;
1176      }      }
1177    }    }
1178    *private_data_start = private_data_ptr;
1179  }  }
1180    
1181  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1182  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head)
1183  {  {
 pcre_uchar *ccend = bracketend(cc);  
1184  int length = 0;  int length = 0;
1185  BOOL possessive = FALSE;  int possessive = 0;
1186    BOOL stack_restore = FALSE;
1187  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1188  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1189    /* The last capture is a local variable even for recursions. */
1190    BOOL capture_last_found = FALSE;
1191    
1192    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1193    SLJIT_ASSERT(common->control_head_ptr != 0);
1194    *needs_control_head = TRUE;
1195    #else
1196    *needs_control_head = FALSE;
1197    #endif
1198    
1199  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (ccend == NULL)
1200    {    {
1201    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1202    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1203        {
1204        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1205        /* This is correct regardless of common->capture_last_ptr. */
1206        capture_last_found = TRUE;
1207        }
1208      cc = next_opcode(common, cc);
1209    }    }
1210    
 cc = next_opcode(common, cc);  
1211  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1212  while (cc < ccend)  while (cc < ccend)
1213    switch(*cc)    switch(*cc)
1214      {      {
1215      case OP_SET_SOM:      case OP_SET_SOM:
1216      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1217        stack_restore = TRUE;
1218      if (!setsom_found)      if (!setsom_found)
1219        {        {
1220        length += 2;        length += 2;
# Line 1125  while (cc < ccend) Line 1224  while (cc < ccend)
1224      break;      break;
1225    
1226      case OP_MARK:      case OP_MARK:
1227        case OP_PRUNE_ARG:
1228        case OP_THEN_ARG:
1229      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1230        stack_restore = TRUE;
1231      if (!setmark_found)      if (!setmark_found)
1232        {        {
1233        length += 2;        length += 2;
1234        setmark_found = TRUE;        setmark_found = TRUE;
1235        }        }
1236        if (common->control_head_ptr != 0)
1237          *needs_control_head = TRUE;
1238      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1239      break;      break;
1240    
1241      case OP_RECURSE:      case OP_RECURSE:
1242        stack_restore = TRUE;
1243      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1244        {        {
1245        length += 2;        length += 2;
# Line 1145  while (cc < ccend) Line 1250  while (cc < ccend)
1250        length += 2;        length += 2;
1251        setmark_found = TRUE;        setmark_found = TRUE;
1252        }        }
1253        if (common->capture_last_ptr != 0 && !capture_last_found)
1254          {
1255          length += 2;
1256          capture_last_found = TRUE;
1257          }
1258      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1259      break;      break;
1260    
# Line 1152  while (cc < ccend) Line 1262  while (cc < ccend)
1262      case OP_CBRAPOS:      case OP_CBRAPOS:
1263      case OP_SCBRA:      case OP_SCBRA:
1264      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1265        stack_restore = TRUE;
1266        if (common->capture_last_ptr != 0 && !capture_last_found)
1267          {
1268          length += 2;
1269          capture_last_found = TRUE;
1270          }
1271      length += 3;      length += 3;
1272      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1273      break;      break;
1274    
1275      default:      default:
1276        stack_restore = TRUE;
1277        /* Fall through. */
1278    
1279        case OP_NOT_WORD_BOUNDARY:
1280        case OP_WORD_BOUNDARY:
1281        case OP_NOT_DIGIT:
1282        case OP_DIGIT:
1283        case OP_NOT_WHITESPACE:
1284        case OP_WHITESPACE:
1285        case OP_NOT_WORDCHAR:
1286        case OP_WORDCHAR:
1287        case OP_ANY:
1288        case OP_ALLANY:
1289        case OP_ANYBYTE:
1290        case OP_NOTPROP:
1291        case OP_PROP:
1292        case OP_ANYNL:
1293        case OP_NOT_HSPACE:
1294        case OP_HSPACE:
1295        case OP_NOT_VSPACE:
1296        case OP_VSPACE:
1297        case OP_EXTUNI:
1298        case OP_EODN:
1299        case OP_EOD:
1300        case OP_CIRC:
1301        case OP_CIRCM:
1302        case OP_DOLL:
1303        case OP_DOLLM:
1304        case OP_CHAR:
1305        case OP_CHARI:
1306        case OP_NOT:
1307        case OP_NOTI:
1308    
1309        case OP_EXACT:
1310        case OP_POSSTAR:
1311        case OP_POSPLUS:
1312        case OP_POSQUERY:
1313        case OP_POSUPTO:
1314    
1315        case OP_EXACTI:
1316        case OP_POSSTARI:
1317        case OP_POSPLUSI:
1318        case OP_POSQUERYI:
1319        case OP_POSUPTOI:
1320    
1321        case OP_NOTEXACT:
1322        case OP_NOTPOSSTAR:
1323        case OP_NOTPOSPLUS:
1324        case OP_NOTPOSQUERY:
1325        case OP_NOTPOSUPTO:
1326    
1327        case OP_NOTEXACTI:
1328        case OP_NOTPOSSTARI:
1329        case OP_NOTPOSPLUSI:
1330        case OP_NOTPOSQUERYI:
1331        case OP_NOTPOSUPTOI:
1332    
1333        case OP_TYPEEXACT:
1334        case OP_TYPEPOSSTAR:
1335        case OP_TYPEPOSPLUS:
1336        case OP_TYPEPOSQUERY:
1337        case OP_TYPEPOSUPTO:
1338    
1339        case OP_CLASS:
1340        case OP_NCLASS:
1341        case OP_XCLASS:
1342    
1343      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1344      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1345      break;      break;
1346      }      }
1347    
1348  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1349  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1350    return -1;    return stack_restore ? no_frame : no_stack;
1351    
1352  if (length > 0)  if (length > 0)
1353    return length + 1;    return length + 1;
1354  return -1;  return stack_restore ? no_frame : no_stack;
1355  }  }
1356    
1357  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)  static void init_frame(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, int stackpos, int stacktop, BOOL recursive)
1358  {  {
1359  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1360  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1361  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1362    /* The last capture is a local variable even for recursions. */
1363    BOOL capture_last_found = FALSE;
1364  int offset;  int offset;
1365    
1366  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1184  SLJIT_UNUSED_ARG(stacktop); Line 1368  SLJIT_UNUSED_ARG(stacktop);
1368  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1369    
1370  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1371  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1372    cc = next_opcode(common, cc);    {
1373      ccend = bracketend(cc) - (1 + LINK_SIZE);
1374      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1375        cc = next_opcode(common, cc);
1376      }
1377    
1378  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1379  while (cc < ccend)  while (cc < ccend)
1380    switch(*cc)    switch(*cc)
# Line 1195  while (cc < ccend) Line 1384  while (cc < ccend)
1384      if (!setsom_found)      if (!setsom_found)
1385        {        {
1386        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1387        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1388        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1389        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1390        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1391        setsom_found = TRUE;        setsom_found = TRUE;
1392        }        }
1393      cc += 1;      cc += 1;
1394      break;      break;
1395    
1396      case OP_MARK:      case OP_MARK:
1397        case OP_PRUNE_ARG:
1398        case OP_THEN_ARG:
1399      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1400      if (!setmark_found)      if (!setmark_found)
1401        {        {
1402        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1403        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1404        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1405        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1406        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1407        setmark_found = TRUE;        setmark_found = TRUE;
1408        }        }
1409      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1222  while (cc < ccend) Line 1413  while (cc < ccend)
1413      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1414        {        {
1415        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1416        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1417        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1418        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1419        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1420        setsom_found = TRUE;        setsom_found = TRUE;
1421        }        }
1422      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1423        {        {
1424        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1425        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1426        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1427        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1428        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1429        setmark_found = TRUE;        setmark_found = TRUE;
1430        }        }
1431        if (common->capture_last_ptr != 0 && !capture_last_found)
1432          {
1433          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1434          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1435          stackpos += (int)sizeof(sljit_sw);
1436          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1437          stackpos += (int)sizeof(sljit_sw);
1438          capture_last_found = TRUE;
1439          }
1440      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1441      break;      break;
1442    
# Line 1244  while (cc < ccend) Line 1444  while (cc < ccend)
1444      case OP_CBRAPOS:      case OP_CBRAPOS:
1445      case OP_SCBRA:      case OP_SCBRA:
1446      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1447        if (common->capture_last_ptr != 0 && !capture_last_found)
1448          {
1449          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1450          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1451          stackpos += (int)sizeof(sljit_sw);
1452          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1453          stackpos += (int)sizeof(sljit_sw);
1454          capture_last_found = TRUE;
1455          }
1456      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1457      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1458      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1459      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1460      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
1461      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1462      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1463      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1464      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1465    
1466      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1467      break;      break;
# Line 1263  while (cc < ccend) Line 1472  while (cc < ccend)
1472      break;      break;
1473      }      }
1474    
1475  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1476  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1477  }  }
1478    
1479  static SLJIT_INLINE int get_private_data_length_for_copy(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static SLJIT_INLINE int get_private_data_copy_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL needs_control_head)
1480  {  {
1481  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1482  int size;  int size;
1483  pcre_uchar *alternative;  pcre_uchar *alternative;
1484  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1278  while (cc < ccend) Line 1487  while (cc < ccend)
1487    size = 0;    size = 0;
1488    switch(*cc)    switch(*cc)
1489      {      {
1490        case OP_KET:
1491        if (PRIVATE_DATA(cc) != 0)
1492          private_data_length++;
1493        cc += 1 + LINK_SIZE;
1494        break;
1495    
1496      case OP_ASSERT:      case OP_ASSERT:
1497      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1498      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1382  return private_data_length; Line 1597  return private_data_length;
1597  }  }
1598    
1599  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,
1600    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1601  {  {
1602  DEFINE_COMPILER;  DEFINE_COMPILER;
1603  int srcw[2];  int srcw[2];
# Line 1403  stacktop = STACK(stacktop - 1); Line 1618  stacktop = STACK(stacktop - 1);
1618    
1619  if (!save)  if (!save)
1620    {    {
1621    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1622    if (stackptr < stacktop)    if (stackptr < stacktop)
1623      {      {
1624      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1625      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1626      tmp1empty = FALSE;      tmp1empty = FALSE;
1627      }      }
1628    if (stackptr < stacktop)    if (stackptr < stacktop)
1629      {      {
1630      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1631      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1632      tmp2empty = FALSE;      tmp2empty = FALSE;
1633      }      }
1634    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1635    }    }
1636    
1637  while (status != end)  do
1638    {    {
1639    count = 0;    count = 0;
1640    switch(status)    switch(status)
1641      {      {
1642      case start:      case start:
1643      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1644      count = 1;      count = 1;
1645      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1646        if (needs_control_head)
1647          {
1648          SLJIT_ASSERT(common->control_head_ptr != 0);
1649          count = 2;
1650          srcw[1] = common->control_head_ptr;
1651          }
1652      status = loop;      status = loop;
1653      break;      break;
1654    
# Line 1440  while (status != end) Line 1661  while (status != end)
1661    
1662      switch(*cc)      switch(*cc)
1663        {        {
1664          case OP_KET:
1665          if (PRIVATE_DATA(cc) != 0)
1666            {
1667            count = 1;
1668            srcw[0] = PRIVATE_DATA(cc);
1669            }
1670          cc += 1 + LINK_SIZE;
1671          break;
1672    
1673        case OP_ASSERT:        case OP_ASSERT:
1674        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1675        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1504  while (status != end) Line 1734  while (status != end)
1734          {          {
1735          count = 2;          count = 2;
1736          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1737          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1738          }          }
1739        cc += 2;        cc += 2;
1740  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1517  while (status != end) Line 1747  while (status != end)
1747          {          {
1748          count = 2;          count = 2;
1749          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1750          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1751          }          }
1752        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1753  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1539  while (status != end) Line 1769  while (status != end)
1769          {          {
1770          count = 2;          count = 2;
1771          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1772          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1773          }          }
1774        cc += 1;        cc += 1;
1775        break;        break;
# Line 1549  while (status != end) Line 1779  while (status != end)
1779          {          {
1780          count = 2;          count = 2;
1781          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1782          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1783          }          }
1784        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1785        break;        break;
# Line 1573  while (status != end) Line 1803  while (status != end)
1803            case 2:            case 2:
1804            count = 2;            count = 2;
1805            srcw[0] = PRIVATE_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1806            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1807            break;            break;
1808    
1809            default:            default:
# Line 1605  while (status != end) Line 1835  while (status != end)
1835          if (!tmp1empty)          if (!tmp1empty)
1836            {            {
1837            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1838            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1839            }            }
1840          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1841          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1616  while (status != end) Line 1846  while (status != end)
1846          if (!tmp2empty)          if (!tmp2empty)
1847            {            {
1848            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1849            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1850            }            }
1851          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1852          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1633  while (status != end) Line 1863  while (status != end)
1863          if (!tmp1empty)          if (!tmp1empty)
1864            {            {
1865            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1866            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1867            }            }
1868          tmp1next = FALSE;          tmp1next = FALSE;
1869          }          }
# Line 1645  while (status != end) Line 1875  while (status != end)
1875          if (!tmp2empty)          if (!tmp2empty)
1876            {            {
1877            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1878            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1879            }            }
1880          tmp1next = TRUE;          tmp1next = TRUE;
1881          }          }
1882        }        }
1883      }      }
1884    }    }
1885    while (status != end);
1886    
1887  if (save)  if (save)
1888    {    {
# Line 1660  if (save) Line 1891  if (save)
1891      if (!tmp1empty)      if (!tmp1empty)
1892        {        {
1893        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1894        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1895        }        }
1896      if (!tmp2empty)      if (!tmp2empty)
1897        {        {
1898        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1899        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1900        }        }
1901      }      }
1902    else    else
# Line 1673  if (save) Line 1904  if (save)
1904      if (!tmp2empty)      if (!tmp2empty)
1905        {        {
1906        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1907        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1908        }        }
1909      if (!tmp1empty)      if (!tmp1empty)
1910        {        {
1911        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1912        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1913        }        }
1914      }      }
1915    }    }
1916  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1917  }  }
1918    
1919    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1920    {
1921    pcre_uchar *end = bracketend(cc);
1922    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1923    
1924    /* Assert captures then. */
1925    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1926      current_offset = NULL;
1927    /* Conditional block does not. */
1928    if (*cc == OP_COND || *cc == OP_SCOND)
1929      has_alternatives = FALSE;
1930    
1931    cc = next_opcode(common, cc);
1932    if (has_alternatives)
1933      current_offset = common->then_offsets + (cc - common->start);
1934    
1935    while (cc < end)
1936      {
1937      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1938        cc = set_then_offsets(common, cc, current_offset);
1939      else
1940        {
1941        if (*cc == OP_ALT && has_alternatives)
1942          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1943        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1944          *current_offset = 1;
1945        cc = next_opcode(common, cc);
1946        }
1947      }
1948    
1949    return end;
1950    }
1951    
1952  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1953  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1954  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1692  SLJIT_ASSERT(cc == ccend && stackptr == Line 1956  SLJIT_ASSERT(cc == ccend && stackptr ==
1956  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1957  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1958    
1959  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1960  {  {
1961  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1962  }  }
# Line 1703  while (list) Line 1967  while (list)
1967    {    {
1968    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1969    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1970    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1971    list = list->next;    list = list->next;
1972    }    }
1973  }  }
# Line 1719  if (list_item) Line 1983  if (list_item)
1983    }    }
1984  }  }
1985    
1986  static void add_stub(compiler_common *common, enum stub_types type, int data, struct sljit_jump *start)  static void add_stub(compiler_common *common, struct sljit_jump *start)
1987  {  {
1988  DEFINE_COMPILER;  DEFINE_COMPILER;
1989  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1990    
1991  if (list_item)  if (list_item)
1992    {    {
   list_item->type = type;  
   list_item->data = data;  
1993    list_item->start = start;    list_item->start = start;
1994    list_item->quit = LABEL();    list_item->quit = LABEL();
1995    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1743  stub_list* list_item = common->stubs; Line 2005  stub_list* list_item = common->stubs;
2005  while (list_item)  while (list_item)
2006    {    {
2007    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2008    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
     {  
     case stack_alloc:  
     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));  
     break;  
     }  
2009    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2010    list_item = list_item->next;    list_item = list_item->next;
2011    }    }
2012  common->stubs = NULL;  common->stubs = NULL;
2013  }  }
2014    
2015  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2016  {  {
2017  DEFINE_COMPILER;  DEFINE_COMPILER;
2018    
2019  OP2(SLJIT_SUB | SLJIT_SET_E, CALL_COUNT, 0, CALL_COUNT, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1);
2020  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2021  }  }
2022    
# Line 1768  static SLJIT_INLINE void allocate_stack( Line 2025  static SLJIT_INLINE void allocate_stack(
2025  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2026  DEFINE_COMPILER;  DEFINE_COMPILER;
2027    
2028  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
2029  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2030  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2031  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1776  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2033  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2033  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2034  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2035  #endif  #endif
2036  add_stub(common, stack_alloc, 0, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));  add_stub(common, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));
2037  }  }
2038    
2039  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2040  {  {
2041  DEFINE_COMPILER;  DEFINE_COMPILER;
2042  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
2043  }  }
2044    
2045  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1790  static SLJIT_INLINE void reset_ovector(c Line 2047  static SLJIT_INLINE void reset_ovector(c
2047  DEFINE_COMPILER;  DEFINE_COMPILER;
2048  struct sljit_label *loop;  struct sljit_label *loop;
2049  int i;  int i;
2050    
2051  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2052    SLJIT_ASSERT(length > 1);
2053  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2054  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
2055  if (length < 8)  if (length < 8)
2056    {    {
2057    for (i = 0; i < length; i++)    for (i = 1; i < length; i++)
2058      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_TEMPORARY_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2059    }    }
2060  else  else
2061    {    {
2062    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2063    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2064    loop = LABEL();    loop = LABEL();
2065    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2066    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2067    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2068    }    }
2069  }  }
2070    
2071    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2072    {
2073    DEFINE_COMPILER;
2074    struct sljit_label *loop;
2075    int i;
2076    
2077    SLJIT_ASSERT(length > 1);
2078    /* OVECTOR(1) contains the "string begin - 1" constant. */
2079    if (length > 2)
2080      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2081    if (length < 8)
2082      {
2083      for (i = 2; i < length; i++)
2084        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
2085      }
2086    else
2087      {
2088      GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2089      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2090      loop = LABEL();
2091      OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2092      OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2093      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2094      }
2095    
2096    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2097    if (common->mark_ptr != 0)
2098      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2099    if (common->control_head_ptr != 0)
2100      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2101    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2102    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2103    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2104    }
2105    
2106    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2107    {
2108    while (current != NULL)
2109      {
2110      switch (current[-2])
2111        {
2112        case type_then_trap:
2113        break;
2114    
2115        case type_mark:
2116        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2117          return current[-4];
2118        break;
2119    
2120        default:
2121        SLJIT_ASSERT_STOP();
2122        break;
2123        }
2124      current = (sljit_sw*)current[-1];
2125      }
2126    return -1;
2127    }
2128    
2129  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2130  {  {
2131  DEFINE_COMPILER;  DEFINE_COMPILER;
2132  struct sljit_label *loop;  struct sljit_label *loop;
2133  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2134    
2135  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2136  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2137  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);
2138    
2139  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2140  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2141    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
2142  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offset_count));
2143  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2144    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_TEMPORARY_REG3, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);
2145  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
2146  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
2147  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2148  /* Unlikely, but possible */  /* Unlikely, but possible */
2149  earlyexit = CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0);  early_quit = CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
2150  loop = LABEL();  loop = LABEL();
2151  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
2152  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_w));  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
2153  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2154  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2155  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2156  #endif  #endif
2157  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
2158  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2159  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2160  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2161    
2162  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2163  if (topbracket > 1)  if (topbracket > 1)
2164    {    {
2165    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
2166    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2167    
2168    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2169    loop = LABEL();    loop = LABEL();
2170    OP1(SLJIT_MOVU, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), -(2 * (sljit_w)sizeof(sljit_w)));    OP1(SLJIT_MOVU, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -(2 * (sljit_sw)sizeof(sljit_sw)));
2171    OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2172    CMPTO(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG3, 0, loop);    CMPTO(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG3, 0, loop);
2173    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2174    }    }
2175  else  else
2176    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1862  else Line 2179  else
2179  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2180  {  {
2181  DEFINE_COMPILER;  DEFINE_COMPILER;
2182    struct sljit_jump *jump;
2183    
2184  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
2185  SLJIT_ASSERT(common->start_used_ptr != 0 && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));  SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0
2186      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2187    
2188  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2189  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2190  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
2191  CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, quit);  CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2192    
2193  /* Store match begin and end. */  /* Store match begin and end. */
2194  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));
2195  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
2196  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);  
2197    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2198    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);
2199    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2200    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2201    #endif
2202    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2203    JUMPHERE(jump);
2204    
2205    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);
2206  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);
2207  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2208  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2209  #endif  #endif
2210  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);
2211    
2212  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);
2213  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2214  OP2(SLJIT_ASHR, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2215  #endif  #endif
2216  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), 0, SLJIT_TEMPORARY_REG3, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0);
2217    
2218  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2219  }  }
# Line 1998  if (c <= 127 && bit == 0x20) Line 2326  if (c <= 127 && bit == 0x20)
2326    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2327    
2328  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2329  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2330    return 0;    return 0;
2331    
2332  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2333    
2334  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2335  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 2017  if (common->utf && c > 127) Line 2345  if (common->utf && c > 127)
2345  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2346  return (0 << 8) | bit;  return (0 << 8) | bit;
2347    
2348  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2349    
 #ifdef COMPILE_PCRE16  
2350  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2351  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2352    {    {
# Line 2030  if (common->utf && c > 65535) Line 2357  if (common->utf && c > 65535)
2357    }    }
2358  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2359  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2360    
2361  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2362  }  }
2363    
2364  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2365  {  {
2366  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2367  DEFINE_COMPILER;  DEFINE_COMPILER;
2368  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2369    
# Line 2052  else if (common->mode == JIT_PARTIAL_SOF Line 2378  else if (common->mode == JIT_PARTIAL_SOF
2378    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2379    
2380  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2381    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2382  else  else
2383    {    {
2384    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2065  if (jump != NULL) Line 2391  if (jump != NULL)
2391    JUMPHERE(jump);    JUMPHERE(jump);
2392  }  }
2393    
2394  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2395  {  {
2396  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2397  DEFINE_COMPILER;  DEFINE_COMPILER;
2398  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2399    
2400  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2401    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2402      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2403      return;
2404      }
2405    
2406  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2407  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2408    {    {
2409    nohit = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2410    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2411    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2412    }    }
2413  else  else
2414    {    {
2415    return_value = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2416    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2417      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2418    else    else
2419      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2420    }    }
2421  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2422  }  }
2423    
2424  static void detect_partial_match(compiler_common *common, jump_list **backtracks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
# Line 2112  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR Line 2437  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2437  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2438  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2439    {    {
2440    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2441    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2442    }    }
2443  else  else
# Line 2130  static void read_char(compiler_common *c Line 2455  static void read_char(compiler_common *c
2455  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2456  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2457  DEFINE_COMPILER;  DEFINE_COMPILER;
2458  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2459  struct sljit_jump *jump;  struct sljit_jump *jump;
2460  #endif  #endif
2461    
2462  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2463  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2464  if (common->utf)  if (common->utf)
2465    {    {
2466  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2467    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2468  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2469    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2470  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2471    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2472    JUMPHERE(jump);    JUMPHERE(jump);
2473    }    }
2474  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2475  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2476  }  }
2477    
# Line 2157  static void peek_char(compiler_common *c Line 2480  static void peek_char(compiler_common *c
2480  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2481  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2482  DEFINE_COMPILER;  DEFINE_COMPILER;
2483  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2484  struct sljit_jump *jump;  struct sljit_jump *jump;
2485  #endif  #endif
2486    
2487  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2488  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2489  if (common->utf)  if (common->utf)
2490    {    {
2491  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2492    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2493  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2494    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2495  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2496    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2497    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2498    JUMPHERE(jump);    JUMPHERE(jump);
2499    }    }
2500  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2501  }  }
2502    
2503  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2504  {  {
2505  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */
2506  DEFINE_COMPILER;  DEFINE_COMPILER;
2507  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2508  struct sljit_jump *jump;  struct sljit_jump *jump;
2509  #endif  #endif
2510    
# Line 2192  if (common->utf) Line 2513  if (common->utf)
2513    {    {
2514    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2515    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2516  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2517    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2518    it is needed in most cases. */    it is needed in most cases. */
2519    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2520    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2521    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2522    JUMPHERE(jump);    JUMPHERE(jump);
2523  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2524    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2525    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2526    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
# Line 2208  if (common->utf) Line 2528  if (common->utf)
2528    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2529    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2530    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2531    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2532    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2533    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2534  #endif  #elif defined COMPILE_PCRE32
2535  #endif /* COMPILE_PCRE8 */    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2536      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2537      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2538      JUMPHERE(jump);
2539    #endif /* COMPILE_PCRE[8|16|32] */
2540    return;    return;
2541    }    }
2542  #endif  #endif /* SUPPORT_UTF */
2543  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2544  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2545  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2546  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2547  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2548  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2549  #endif  #endif
2550  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2551  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2552  JUMPHERE(jump);  JUMPHERE(jump);
2553  #endif  #endif
2554  }  }
# Line 2233  static void skip_char_back(compiler_comm Line 2557  static void skip_char_back(compiler_comm
2557  {  {
2558  /* Goes one character back. Affects STR_PTR and TMP1. Does not check begin. */  /* Goes one character back. Affects STR_PTR and TMP1. Does not check begin. */
2559  DEFINE_COMPILER;  DEFINE_COMPILER;
2560  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2561    #if defined COMPILE_PCRE8
2562  struct sljit_label *label;  struct sljit_label *label;
2563    
2564  if (common->utf)  if (common->utf)
# Line 2245  if (common->utf) Line 2570  if (common->utf)
2570    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2571    return;    return;
2572    }    }
2573  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2574  if (common->utf)  if (common->utf)
2575    {    {
2576    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
# Line 2254  if (common->utf) Line 2578  if (common->utf)
2578    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2579    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2580    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);
2581    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2582    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2583    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2584    return;    return;
2585    }    }
2586  #endif  #endif /* COMPILE_PCRE[8|16] */
2587    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2588  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2589  }  }
2590    
# Line 2276  if (nltype == NLTYPE_ANY) Line 2601  if (nltype == NLTYPE_ANY)
2601  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2602    {    {
2603    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);
2604    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2605    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);
2606    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
2607    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2608    }    }
2609  else  else
# Line 2290  else Line 2615  else
2615    
2616  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2617    
2618  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2619  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2620  {  {
2621  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
# Line 2378  sljit_emit_fast_return(compiler, RETURN_ Line 2703  sljit_emit_fast_return(compiler, RETURN_
2703  JUMPHERE(jump);  JUMPHERE(jump);
2704    
2705  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2706  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2707  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2708  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2709  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2710  }  }
2711    
2712  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2713    
 #ifdef COMPILE_PCRE16  
2714  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2715  {  {
2716  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char
# Line 2411  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC Line 2735  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2735  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2736  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2737  }  }
 #endif /* COMPILE_PCRE16 */  
2738    
2739  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2740    
2741  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2742    
# Line 2433  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2756  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2756    
2757  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2758  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2759  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(ucd_stage1));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(ucd_stage1));
2760  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2761  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2762  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2763  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2764  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2765  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));
2766  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2767  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2768  }  }
# Line 2453  struct sljit_label *newlinelabel = NULL; Line 2776  struct sljit_label *newlinelabel = NULL;
2776  struct sljit_jump *start;  struct sljit_jump *start;
2777  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2778  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2779  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2780  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2781  #endif  #endif
2782  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2508  if (newlinecheck) Line 2831  if (newlinecheck)
2831    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2832    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2833    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);
2834    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2835  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2836    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2837  #endif  #endif
2838    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2839    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2531  if (newlinecheck) Line 2854  if (newlinecheck)
2854    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);
2855    
2856  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2857  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2858    #if defined COMPILE_PCRE8
2859  if (common->utf)  if (common->utf)
2860    {    {
2861    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2862    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2863    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2864    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2865    }    }
2866  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2867  if (common->utf)  if (common->utf)
2868    {    {
2869    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2870    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2871    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2872    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2873    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2874    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2875    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2876    }    }
2877  #endif  #endif /* COMPILE_PCRE[8|16] */
2878    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2879  JUMPHERE(start);  JUMPHERE(start);
2880    
2881  if (newlinecheck)  if (newlinecheck)
# Line 2563  if (newlinecheck) Line 2887  if (newlinecheck)
2887  return mainloop;  return mainloop;
2888  }  }
2889    
2890  static SLJIT_INLINE BOOL fast_forward_first_two_chars(compiler_common *common, BOOL firstline)  #define MAX_N_CHARS 3
2891    
2892    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2893  {  {
2894  DEFINE_COMPILER;  DEFINE_COMPILER;
2895  struct sljit_label *start;  struct sljit_label *start;
2896  struct sljit_jump *quit;  struct sljit_jump *quit;
2897  struct sljit_jump *found;  pcre_uint32 chars[MAX_N_CHARS * 2];
2898  pcre_int32 chars[4];  pcre_uchar *cc = common->start + 1 + LINK_SIZE;
 pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  
2899  int location = 0;  int location = 0;
2900  pcre_int32 len, c, bit, caseless;  pcre_int32 len, c, bit, caseless;
2901  BOOL must_end;  int must_stop;
   
 #ifdef COMPILE_PCRE8  
 union {  
     sljit_uh ascombined;  
     sljit_ub asuchars[2];  
 } pair;  
 #else  
 union {  
     sljit_ui ascombined;  
     sljit_uh asuchars[2];  
 } pair;  
 #endif  
2902    
2903    /* We do not support alternatives now. */
2904  if (*(common->start + GET(common->start, 1)) == OP_ALT)  if (*(common->start + GET(common->start, 1)) == OP_ALT)
2905    return FALSE;    return FALSE;
2906    
2907  while (TRUE)  while (TRUE)
2908    {    {
2909    caseless = 0;    caseless = 0;
2910    must_end = TRUE;    must_stop = 1;
2911    switch(*cc)    switch(*cc)
2912      {      {
2913      case OP_CHAR:      case OP_CHAR:
2914      must_end = FALSE;      must_stop = 0;
2915      cc++;      cc++;
2916      break;      break;
2917    
2918      case OP_CHARI:      case OP_CHARI:
2919      caseless = 1;      caseless = 1;
2920      must_end = FALSE;      must_stop = 0;
2921      cc++;      cc++;
2922      break;      break;
2923    
# Line 2645  while (TRUE) Line 2959  while (TRUE)
2959      break;      break;
2960    
2961      default:      default:
2962      return FALSE;      must_stop = 2;
2963        break;
2964      }      }
2965    
2966      if (must_stop == 2)
2967          break;
2968    
2969    len = 1;    len = 1;
2970  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2971    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
# Line 2670  while (TRUE) Line 2988  while (TRUE)
2988    else    else
2989      caseless = 0;      caseless = 0;
2990    
2991    while (len > 0 && location < 2 * 2)    while (len > 0 && location < MAX_N_CHARS * 2)
2992      {      {
2993      c = *cc;      c = *cc;
2994      bit = 0;      bit = 0;
# Line 2688  while (TRUE) Line 3006  while (TRUE)
3006      cc++;      cc++;
3007      }      }
3008    
3009    if (location == 2 * 2)    if (location >= MAX_N_CHARS * 2 || must_stop != 0)
3010      break;      break;
   else if (must_end)  
     return FALSE;  
3011    }    }
3012    
3013    /* At least two characters are required. */
3014    if (location < 2 * 2)
3015        return FALSE;
3016    
3017  if (firstline)  if (firstline)
3018    {    {
3019    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3020    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3021    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, 1);    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3022    }    }
3023  else  else
3024    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3025    
3026  start = LABEL();  start = LABEL();
3027  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  
 #ifdef COMPILE_PCRE8  
 OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #else /* COMPILE_PCRE8 */  
 OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #endif  
   
 #else /* SLJIT_UNALIGNED */  
3028    
3029  #if defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 #else /* SLJIT_BIG_ENDIAN */  
3030  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3031  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3032  #endif /* SLJIT_BIG_ENDIAN */  if (chars[1] != 0)
3033      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3034  #ifdef COMPILE_PCRE8  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3035  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 8);  if (location > 2 * 2)
3036  #else /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3037  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 16);  if (chars[3] != 0)
3038  #endif    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
3039  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
3040    if (location > 2 * 2)
3041  #endif    {
3042      if (chars[5] != 0)
3043  if (chars[1] != 0 || chars[3] != 0)      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
3044    {    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);
   pair.asuchars[0] = chars[1];  
   pair.asuchars[1] = chars[3];  
   OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, pair.ascombined);  
3045    }    }
3046    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3047    
 pair.asuchars[0] = chars[0];  
 pair.asuchars[1] = chars[2];  
 found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, pair.ascombined);  
   
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 JUMPTO(SLJIT_JUMP, start);  
 JUMPHERE(found);  
3048  JUMPHERE(quit);  JUMPHERE(quit);
3049    
3050  if (firstline)  if (firstline)
3051    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3052  else  else
3053    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3054  return TRUE;  return TRUE;
3055  }  }
3056    
3057    #undef MAX_N_CHARS
3058    
3059  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
3060  {  {
3061  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2787  if (first_char == oc) Line 3089  if (first_char == oc)
3089  else  else
3090    {    {
3091    bit = first_char ^ oc;    bit = first_char ^ oc;
3092    if (ispowerof2(bit))    if (is_powerof2(bit))
3093      {      {
3094      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3095      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
# Line 2795  else Line 3097  else
3097    else    else
3098      {      {
3099      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char);
3100      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3101      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);
3102      COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3103      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3104      }      }
3105    }    }
# Line 2839  if (common->nltype == NLTYPE_FIXED && co Line 3141  if (common->nltype == NLTYPE_FIXED && co
3141    
3142    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3143    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, TMP1, 0);
3144    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3145  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3146    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3147  #endif  #endif
3148    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3149    
# Line 2882  if (common->nltype == NLTYPE_ANY || comm Line 3184  if (common->nltype == NLTYPE_ANY || comm
3184    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3185    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3186    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);
3187    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3188  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3189    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3190  #endif  #endif
3191    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3192    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
# Line 2897  if (firstline) Line 3199  if (firstline)
3199    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3200  }  }
3201    
3202    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3203    
3204  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)
3205  {  {
3206  DEFINE_COMPILER;  DEFINE_COMPILER;
3207  struct sljit_label *start;  struct sljit_label *start;
3208  struct sljit_jump *quit;  struct sljit_jump *quit;
3209  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3210    jump_list *matches = NULL;
3211    pcre_uint8 inverted_start_bits[32];
3212    int i;
3213  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3214  struct sljit_jump *jump;  struct sljit_jump *jump;
3215  #endif  #endif
3216    
3217    for (i = 0; i < 32; ++i)
3218      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3219    
3220  if (firstline)  if (firstline)
3221    {    {
3222    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
# Line 2921  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3231  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3231  if (common->utf)  if (common->utf)
3232    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3233  #endif  #endif
3234    
3235    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3236      {
3237  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3238  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3239  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3240  JUMPHERE(jump);    JUMPHERE(jump);
3241  #endif  #endif
3242  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3243  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3244  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3245  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3246  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
3247  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3248      }
3249    
3250  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3251  if (common->utf)  if (common->utf)
3252    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3253  #endif  #endif
3254  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3255  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3256    #if defined COMPILE_PCRE8
3257  if (common->utf)  if (common->utf)
3258    {    {
3259    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3260    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
3261    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3262    }    }
3263  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3264  if (common->utf)  if (common->utf)
3265    {    {
3266    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3267    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3268    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
3269    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3270    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3271    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3272    }    }
3273  #endif  #endif /* COMPILE_PCRE[8|16] */
3274    #endif /* SUPPORT_UTF */
3275  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3276  JUMPHERE(found);  if (found != NULL)
3277      JUMPHERE(found);
3278    if (matches != NULL)
3279      set_jumps(matches, LABEL());
3280  JUMPHERE(quit);  JUMPHERE(quit);
3281    
3282  if (firstline)  if (firstline)
# Line 2974  struct sljit_jump *alreadyfound; Line 3292  struct sljit_jump *alreadyfound;
3292  struct sljit_jump *found;  struct sljit_jump *found;
3293  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3294  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3295  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3296    
3297  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3298  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
# Line 3005  if (req_char == oc) Line 3323  if (req_char == oc)
3323  else  else
3324    {    {
3325    bit = req_char ^ oc;    bit = req_char ^ oc;
3326    if (ispowerof2(bit))    if (is_powerof2(bit))
3327      {      {
3328      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3329      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
# Line 3041  GET_LOCAL_BASE(TMP3, 0, 0); Line 3359  GET_LOCAL_BASE(TMP3, 0, 0);
3359  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3360  mainloop = LABEL();  mainloop = LABEL();
3361  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3362  jump = CMP(SLJIT_C_SIG_LESS_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0);
3363    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3364    
3365  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3366  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3367  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
3368  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
3369  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3370    
3371  JUMPHERE(jump);  JUMPHERE(jump);
3372  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3373  /* End of dropping frames. */  /* End of dropping frames. */
3374  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3375    
3376  JUMPHERE(jump);  JUMPHERE(jump);
3377  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3378  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3379  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3380  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), TMP2, 0);  
 JUMPTO(SLJIT_JUMP, mainloop);  
   
 JUMPHERE(jump);  
 if (common->mark_ptr != 0)  
   {  
   jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setmark);  
   OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
   OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);  
   JUMPTO(SLJIT_JUMP, mainloop);  
   
   JUMPHERE(jump);  
   }  
   
 /* Unknown command. */  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
3381  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3382  }  }
3383    
# Line 3082  static void check_wordboundary(compiler_ Line 3385  static void check_wordboundary(compiler_
3385  {  {
3386  DEFINE_COMPILER;  DEFINE_COMPILER;
3387  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3388    jump_list *skipread_list = NULL;
3389  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3390  struct sljit_jump *jump;  struct sljit_jump *jump;
3391  #endif  #endif
# Line 3107  if (common->use_ucp) Line 3411  if (common->use_ucp)
3411    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3412    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3413    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
3414    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3415    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);
3416    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
3417    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3418    JUMPHERE(jump);    JUMPHERE(jump);
3419    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3420    }    }
# Line 3139  else Line 3443  else
3443  JUMPHERE(skipread);  JUMPHERE(skipread);
3444    
3445  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3446  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3447  peek_char(common);  peek_char(common);
3448    
3449  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3151  if (common->use_ucp) Line 3455  if (common->use_ucp)
3455    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3456    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3457    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
3458    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3459    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);
3460    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
3461    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3462    JUMPHERE(jump);    JUMPHERE(jump);
3463    }    }
3464  else  else
# Line 3180  else Line 3484  else
3484      JUMPHERE(jump);      JUMPHERE(jump);
3485  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3486    }    }
3487  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3488    
3489  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3490  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
# Line 3235  switch(ranges[0]) Line 3539  switch(ranges[0])
3539        }        }
3540      return TRUE;      return TRUE;
3541      }      }
3542    if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && ispowerof2(ranges[4] - ranges[2]))    if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))
3543      {      {
3544      if (readch)      if (readch)
3545        read_char(common);        read_char(common);
# Line 3334  sljit_emit_fast_enter(compiler, RETURN_A Line 3638  sljit_emit_fast_enter(compiler, RETURN_A
3638    
3639  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3640  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
3641  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3642  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
3643  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3644  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3645  if (common->utf)  if (common->utf)
3646    {    {
3647  #endif  #endif
3648    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3649    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3650    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
3651  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3652    }    }
3653  #endif  #endif
3654  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3655  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3656  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3657  }  }
3658    
# Line 3360  DEFINE_COMPILER; Line 3664  DEFINE_COMPILER;
3664  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3665    
3666  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);
3667  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3668  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
3669  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3670  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);
3671  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3672  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3673  if (common->utf)  if (common->utf)
3674    {    {
3675  #endif  #endif
3676    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3677    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);
3678    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3679    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);
3680    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3681    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3682    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);
3683    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3684    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);
3685    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3686    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);
3687    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3688    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);
3689  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3690    }    }
3691  #endif  #endif
3692  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3693  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3694    
3695  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3696  }  }
# Line 3400  sljit_emit_fast_enter(compiler, RETURN_A Line 3704  sljit_emit_fast_enter(compiler, RETURN_A
3704    
3705  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3706  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
3707  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3708  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
3709  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3710  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3711  if (common->utf)  if (common->utf)
3712    {    {
3713  #endif  #endif
3714    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3715    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3716    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
3717  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3718    }    }
3719  #endif  #endif
3720  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3721  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3722    
3723  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3724  }  }
# Line 3500  sljit_emit_fast_return(compiler, RETURN_ Line 3804  sljit_emit_fast_return(compiler, RETURN_
3804    
3805  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3806    
3807  static const pcre_uchar *SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)  static const pcre_uchar * SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)
3808  {  {
3809  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3810  int c1, c2;  pcre_uint32 c1, c2;
3811  const pcre_uchar *src2 = args->uchar_ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3812  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
3813    const ucd_record *ur;
3814    const pcre_uint32 *pp;
3815    
3816  while (src1 < end1)  while (src1 < end1)
3817    {    {
# Line 3513  while (src1 < end1) Line 3819  while (src1 < end1)
3819      return (pcre_uchar*)1;      return (pcre_uchar*)1;
3820    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3821    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3822    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return NULL;    ur = GET_UCD(c2);
3823      if (c1 != c2 && c1 != c2 + ur->other_case)
3824        {
3825        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3826        for (;;)
3827          {
3828          if (c1 < *pp) return NULL;
3829          if (c1 == *pp++) break;
3830          }
3831        }
3832    }    }
3833  return src2;  return src2;
3834  }  }
# Line 3535  if (caseless && char_has_othercase(commo Line 3850  if (caseless && char_has_othercase(commo
3850    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3851    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3852    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3853  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3854    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3855    othercasebit &= 0xff;    othercasebit &= 0xff;
3856  #else  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3857  #ifdef COMPILE_PCRE16    /* Note that this code only handles characters in the BMP. If there
3858      ever are characters outside the BMP whose othercase differs in only one
3859      bit from itself (there currently are none), this code will need to be
3860      revised for COMPILE_PCRE32. */
3861    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3862    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3863      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
3864    else    else
3865      othercasebit &= 0xff;      othercasebit &= 0xff;
3866  #endif  #endif /* COMPILE_PCRE[8|16|32] */
 #endif  
3867    }    }
3868    
3869  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3870    {    {
3871  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3872  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3873    if (context->length >= 4)    if (context->length >= 4)
3874      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
# Line 3560  if (context->sourcereg == -1) Line 3877  if (context->sourcereg == -1)
3877    else    else
3878  #endif  #endif
3879      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3880  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
3881  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3882    if (context->length >= 4)    if (context->length >= 4)
3883      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3884    else    else
3885  #endif  #endif
3886      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3887  #endif  #elif defined COMPILE_PCRE32
3888  #endif /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3889    #endif /* COMPILE_PCRE[8|16|32] */
3890    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3891    }    }
3892    
# Line 3583  do Line 3900  do
3900  #endif  #endif
3901    
3902    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3903  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3904    
3905    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3906    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3598  do Line 3915  do
3915      }      }
3916    context->ucharptr++;    context->ucharptr++;
3917    
3918  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3919    if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))    if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))
3920  #else  #else
3921    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
# Line 3606  do Line 3923  do
3923      {      {
3924      if (context->length >= 4)      if (context->length >= 4)
3925        OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
 #ifdef COMPILE_PCRE8  
3926      else if (context->length >= 2)      else if (context->length >= 2)
3927        OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3928    #if defined COMPILE_PCRE8
3929      else if (context->length >= 1)      else if (context->length >= 1)
3930        OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3931  #else  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3932      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3933    
3934      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3648  do Line 3962  do
3962    
3963  #else  #else
3964    
3965    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3966  #ifdef COMPILE_PCRE8    if (context->length >= 1)
3967    if (context->length > 0)      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3968      OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #else  
   if (context->length > 0)  
     OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3969    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3970    
3971    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3705  static void compile_xclass_matchingpath( Line 4015  static void compile_xclass_matchingpath(
4015  DEFINE_COMPILER;  DEFINE_COMPILER;
4016  jump_list *found = NULL;  jump_list *found = NULL;
4017  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;
4018  unsigned int c;  pcre_int32 c, charoffset;
4019  int compares;  const pcre_uint32 *other_cases;
4020  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4021  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4022    int compares, invertcmp, numberofcmps;
4023  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4024  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4025  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4026  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4027  unsigned int typeoffset;  pcre_int32 typeoffset;
4028  #endif  #endif
 int invertcmp, numberofcmps;  
 unsigned int charoffset;  
4029    
4030  /* Although SUPPORT_UTF must be defined, we are  /* Although SUPPORT_UTF must be defined, we are
4031     not necessary in utf mode even in 8 bit mode. */     not necessary in utf mode even in 8 bit mode. */
# Line 3737  if ((*cc++ & XCL_MAP) != 0) Line 4046  if ((*cc++ & XCL_MAP) != 0)
4046      {      {
4047      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4048      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4049      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4050      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4051      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4052      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
# Line 3814  while (*cc != XCL_END) Line 4123  while (*cc != XCL_END)
4123        needschar = TRUE;        needschar = TRUE;
4124        break;        break;
4125    
4126          case PT_CLIST:
4127          case PT_UCNC:
4128          needschar = TRUE;
4129          break;
4130    
4131        default:        default:
4132        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
4133        break;        break;
# Line 3850  if (needstype || needsscript) Line 4164  if (needstype || needsscript)
4164      {      {
4165      if (scriptreg == TMP1)      if (scriptreg == TMP1)
4166        {        {
4167        OP1(SLJIT_MOV, scriptreg, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));        OP1(SLJIT_MOV, scriptreg, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));
4168        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
4169        }        }
4170      else      else
4171        {        {
4172        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
4173        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));
4174        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
4175        }        }
4176      }      }
# Line 3892  while (*cc != XCL_END) Line 4206  while (*cc != XCL_END)
4206      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4207        {        {
4208        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
4209        COND_VALUE(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_EQUAL);
4210        numberofcmps++;        numberofcmps++;
4211        }        }
4212      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4213        {        {
4214        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
4215        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4216        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4217        numberofcmps = 0;        numberofcmps = 0;
4218        }        }
# Line 3931  while (*cc != XCL_END) Line 4245  while (*cc != XCL_END)
4245      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4246        {        {
4247        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
4248        COND_VALUE(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_LESS_EQUAL);
4249        numberofcmps++;        numberofcmps++;
4250        }        }
4251      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4252        {        {
4253        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
4254        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4255        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4256        numberofcmps = 0;        numberofcmps = 0;
4257        }        }
# Line 3968  while (*cc != XCL_END) Line 4282  while (*cc != XCL_END)
4282    
4283        case PT_LAMP:        case PT_LAMP:
4284        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - typeoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - typeoffset);
4285        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4286        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ll - typeoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ll - typeoffset);
4287        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4288        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lt - typeoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lt - typeoffset);
4289        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4290        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4291        break;        break;
4292    
# Line 3992  while (*cc != XCL_END) Line 4306  while (*cc != XCL_END)
4306    
4307        case PT_SPACE:        case PT_SPACE:
4308        case PT_PXSPACE:        case PT_PXSPACE:
       if (*cc == PT_SPACE)  
         {  
         OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  
         jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 11 - charoffset);  
         }  
4309        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4310        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 13 - 9);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 13 - 9);
4311        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
       if (*cc == PT_SPACE)  
         JUMPHERE(jump);  
4312    
4313        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4314        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);
4315        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4316        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4317        break;        break;
4318    
4319        case PT_WORD:        case PT_WORD:
4320        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE - charoffset);
4321        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4322        /* ... fall through */        /* Fall through. */
4323    
4324        case PT_ALNUM:        case PT_ALNUM:
4325        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
4326        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
4327        COND_VALUE((*cc == PT_ALNUM) ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS((*cc == PT_ALNUM) ? SLJIT_MOV : SLJIT_OR, TMP2, 0, (*cc == PT_ALNUM) ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_LESS_EQUAL);
4328        SET_TYPE_OFFSET(ucp_Nd);        SET_TYPE_OFFSET(ucp_Nd);
4329        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_No - ucp_Nd);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_No - ucp_Nd);
4330        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4331          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4332          break;
4333    
4334          case PT_CLIST:
4335          other_cases = PRIV(ucd_caseless_sets) + cc[1];
4336    
4337          /* At least three characters are required.
4338             Otherwise this case would be handled by the normal code path. */
4339          SLJIT_ASSERT(other_cases[0] != NOTACHAR && other_cases[1] != NOTACHAR && other_cases[2] != NOTACHAR);
4340          SLJIT_ASSERT(other_cases[0] < other_cases[1] && other_cases[1] < other_cases[2]);
4341    
4342          /* Optimizing character pairs, if their difference is power of 2. */
4343          if (is_powerof2(other_cases[1] ^ other_cases[0]))
4344            {
4345            if (charoffset == 0)
4346              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4347            else
4348              {
4349              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4350              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4351              }
4352            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[1]);
4353            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4354            other_cases += 2;
4355            }
4356          else if (is_powerof2(other_cases[2] ^ other_cases[1]))
4357            {
4358            if (charoffset == 0)
4359              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[2] ^ other_cases[1]);
4360            else
4361              {
4362              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4363              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4364              }
4365            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[2]);
4366            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4367    
4368            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, other_cases[0] - charoffset);
4369            OP_FLAGS(SLJIT_OR | ((other_cases[3] == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4370    
4371            other_cases += 3;
4372            }
4373          else
4374            {
4375            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4376            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4377            }
4378    
4379          while (*other_cases != NOTACHAR)
4380            {
4381            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4382            OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4383            }
4384          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4385          break;
4386    
4387          case PT_UCNC:
4388          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);
4389          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4390          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);
4391          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4392          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);
4393          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4394    
4395          SET_CHAR_OFFSET(0xa0);
4396          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);
4397          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4398          SET_CHAR_OFFSET(0);
4399          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4400          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4401        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4402        break;        break;
4403        }        }
# Line 4048  int length; Line 4425  int length;
4425  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4426  compare_context context;  compare_context context;
4427  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4428    jump_list *end_list;
4429  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4430  struct sljit_label *label;  struct sljit_label *label;
4431  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4116  switch(type) Line 4494  switch(type)
4494    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4495      {      {
4496      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
4497        end_list = NULL;
4498      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4499        jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);        add_jump(compiler, &end_list, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
4500      else      else
4501        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
4502    
4503      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4504      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));
4505      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
4506      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4507      }      }
4508    else    else
# Line 4138  switch(type) Line 4516  switch(type)
4516      {      {
4517      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4518      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
4519  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
4520    #if defined COMPILE_PCRE8
4521      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4522      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
4523      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4524  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
4525      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
4526      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4527      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
4528      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4529      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4530      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4531  #endif /* COMPILE_PCRE16 */  #endif
 #endif /* COMPILE_PCRE8 */  
4532      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4533    #endif /* COMPILE_PCRE[8|16] */
4534      return cc;      return cc;
4535      }      }
4536  #endif  #endif
# Line 4183  switch(type) Line 4561  switch(type)
4561    read_char(common);    read_char(common);
4562    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
4563    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
4564      end_list = NULL;
4565    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4566      jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      add_jump(compiler, &end_list, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
4567    else    else
4568      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
4569    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4570    jump[2] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);    jump[1] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);
4571    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
4572    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
4573    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4574    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
4575      set_jumps(end_list, LABEL());
4576    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4577    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
4578    return cc;    return cc;
4579    
4580    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
# Line 4219  switch(type) Line 4598  switch(type)
4598    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4599    read_char(common);    read_char(common);
4600    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4601    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));
4602    /* Optimize register allocation: use a real register. */    /* Optimize register allocation: use a real register. */
4603    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4604    OP1(SLJIT_MOV_UB, STACK_TOP, 0, SLJIT_MEM2(TMP1, TMP2), 3);    OP1(SLJIT_MOV_UB, STACK_TOP, 0, SLJIT_MEM2(TMP1, TMP2), 3);
# Line 4229  switch(type) Line 4608  switch(type)
4608    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
4609    read_char(common);    read_char(common);
4610    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4611    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));
4612    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4613    
4614    OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);    OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);
4615    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), (sljit_w)PRIV(ucp_gbtable));    OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STACK_TOP), (sljit_sw)PRIV(ucp_gbtable));
4616    OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);    OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);
4617    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4618    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
# Line 4266  switch(type) Line 4645  switch(type)
4645        {        {
4646        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);
4647        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP2, 0, STR_END, 0);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP2, 0, STR_END, 0);
4648        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS);
4649        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
4650        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_NOT_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_NOT_EQUAL);
4651        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));
4652        check_partial(common, TRUE);        check_partial(common, TRUE);
4653        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
# Line 4448  switch(type) Line 4827  switch(type)
4827      }      }
4828    oc = char_othercase(common, c);    oc = char_othercase(common, c);
4829    bit = c ^ oc;    bit = c ^ oc;
4830    if (ispowerof2(bit))    if (is_powerof2(bit))
4831      {      {
4832      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4833      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));
4834      return cc + length;      return cc + length;
4835      }      }
4836    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c);
4837    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4838    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);
4839    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4840    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4841    return cc + length;    return cc + length;
4842    
# Line 4484  switch(type) Line 4863  switch(type)
4863        /* Skip the variable-length character. */        /* Skip the variable-length character. */
4864        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
4865        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4866        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
4867        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4868        JUMPHERE(jump[0]);        JUMPHERE(jump[0]);
4869        return cc + 1;        return cc + 1;
# Line 4509  switch(type) Line 4888  switch(type)
4888      {      {
4889      oc = char_othercase(common, c);      oc = char_othercase(common, c);
4890      bit = c ^ oc;      bit = c ^ oc;
4891      if (ispowerof2(bit))      if (is_powerof2(bit))
4892        {        {
4893        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4894        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));
# Line 4547  switch(type) Line 4926  switch(type)
4926  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4927    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4928    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4929    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4930    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4931    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4932    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 4557  switch(type) Line 4936  switch(type)
4936  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4937    return cc + 32 / sizeof(pcre_uchar);    return cc + 32 / sizeof(pcre_uchar);
4938    
4939  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4940    case OP_XCLASS:    case OP_XCLASS:
4941    compile_xclass_matchingpath(common, cc + LINK_SIZE, backtracks);    compile_xclass_matchingpath(common, cc + LINK_SIZE, backtracks);
4942    return cc + GET(cc, 0) - 1;    return cc + GET(cc, 0) - 1;
# Line 4671  if (!common->jscript_compat) Line 5050  if (!common->jscript_compat)
5050      {      {
5051      /* OVECTOR(1) contains the "string begin - 1" constant. */      /* OVECTOR(1) contains the "string begin - 1" constant. */
5052      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5053      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
5054      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5055      COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
5056      return JUMP(SLJIT_C_NOT_ZERO);      return JUMP(SLJIT_C_NOT_ZERO);
5057      }      }
5058    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
# Line 4729  if (withchecks && !common->jscript_compa Line 5108  if (withchecks && !common->jscript_compa
5108  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5109  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5110    {    {
5111    SLJIT_ASSERT(TMP1 == SLJIT_TEMPORARY_REG1 && STACK_TOP == SLJIT_TEMPORARY_REG2 && TMP2 == SLJIT_TEMPORARY_REG3);    SLJIT_ASSERT(TMP1 == SLJIT_SCRATCH_REG1 && STACK_TOP == SLJIT_SCRATCH_REG2 && TMP2 == SLJIT_SCRATCH_REG3);
5112    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5113    if (withchecks)    if (withchecks)
5114      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5115    
5116    /* Needed to save important temporary registers. */    /* Needed to save important temporary registers. */
5117    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5118    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
5119    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, uchar_ptr), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, uchar_ptr), STR_PTR, 0);
5120    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_utf_caselesscmp));    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_utf_caselesscmp));
5121    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5122    if (common->mode == JIT_COMPILE)    if (common->mode == JIT_COMPILE)
# Line 4850  if (!minimize) Line 5229  if (!minimize)
5229      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5230      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5231      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5232      OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));      OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5233      zerolength = compile_ref_checks(common, ccbegin, NULL);      zerolength = compile_ref_checks(common, ccbegin, NULL);
5234      /* Restore if not zero length. */      /* Restore if not zero length. */
5235      OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));      OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5236      }      }
5237    else    else
5238      {      {
# Line 4896  if (!minimize) Line 5275  if (!minimize)
5275    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5276    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5277    
5278    decrease_call_count(common);    count_match(common);
5279    return cc;    return cc;
5280    }    }
5281    
# Line 4935  if (jump != NULL) Line 5314  if (jump != NULL)
5314    JUMPHERE(jump);    JUMPHERE(jump);
5315  JUMPHERE(zerolength);  JUMPHERE(zerolength);
5316    
5317  decrease_call_count(common);  count_match(common);
5318  return cc;  return cc;
5319  }  }
5320    
# Line 4945  DEFINE_COMPILER; Line 5324  DEFINE_COMPILER;
5324  backtrack_common *backtrack;  backtrack_common *backtrack;
5325  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5326  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5327  int start = GET(cc, 1);  sljit_sw start = GET(cc, 1);
5328    pcre_uchar *start_cc;
5329    BOOL needs_control_head;
5330    
5331  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5332    
5333    /* Inlining simple patterns. */
5334    if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head) == no_stack)
5335      {
5336      start_cc = common->start + start;
5337      compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
5338      BACKTRACK_AS(recurse_backtrack)->inlined_pattern = TRUE;
5339      return cc + 1 + LINK_SIZE;
5340      }
5341    
5342  while (entry != NULL)  while (entry != NULL)
5343    {    {
5344    if (entry->start == start)    if (entry->start == start)
# Line 4996  add_jump(compiler, &backtrack->topbacktr Line 5387  add_jump(compiler, &backtrack->topbacktr
5387  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5388  }  }
5389    
5390    static int SLJIT_CALL do_callout(struct jit_arguments* arguments, PUBL(callout_block) *callout_block, pcre_uchar **jit_ovector)
5391    {
5392    const pcre_uchar *begin = arguments->begin;
5393    int *offset_vector = arguments->offsets;
5394    int offset_count = arguments->offset_count;
5395    int i;
5396    
5397    if (PUBL(callout) == NULL)
5398      return 0;
5399    
5400    callout_block->version = 2;
5401    callout_block->callout_data = arguments->callout_data;
5402    
5403    /* Offsets in subject. */
5404    callout_block->subject_length = arguments->end - arguments->begin;
5405    callout_block->start_match = (pcre_uchar*)callout_block->subject - arguments->begin;
5406    callout_block->current_position = (pcre_uchar*)callout_block->offset_vector - arguments->begin;
5407    #if defined COMPILE_PCRE8
5408    callout_block->subject = (PCRE_SPTR)begin;
5409    #elif defined COMPILE_PCRE16
5410    callout_block->subject = (PCRE_SPTR16)begin;
5411    #elif defined COMPILE_PCRE32
5412    callout_block->subject = (PCRE_SPTR32)begin;
5413    #endif
5414    
5415    /* Convert and copy the JIT offset vector to the offset_vector array. */
5416    callout_block->capture_top = 0;
5417    callout_block->offset_vector = offset_vector;
5418    for (i = 2; i < offset_count; i += 2)
5419      {
5420      offset_vector[i] = jit_ovector[i] - begin;
5421      offset_vector[i + 1] = jit_ovector[i + 1] - begin;
5422      if (jit_ovector[i] >= begin)
5423        callout_block->capture_top = i;
5424      }
5425    
5426    callout_block->capture_top = (callout_block->capture_top >> 1) + 1;
5427    if (offset_count > 0)
5428      offset_vector[0] = -1;
5429    if (offset_count > 1)
5430      offset_vector[1] = -1;
5431    return (*PUBL(callout))(callout_block);
5432    }
5433    
5434    /* Aligning to 8 byte. */
5435    #define CALLOUT_ARG_SIZE \
5436        (((int)sizeof(PUBL(callout_block)) + 7) & ~7)
5437    
5438    #define CALLOUT_ARG_OFFSET(arg) \
5439        (-CALLOUT_ARG_SIZE + SLJIT_OFFSETOF(PUBL(callout_block), arg))
5440    
5441    static SLJIT_INLINE pcre_uchar *compile_callout_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5442    {
5443    DEFINE_COMPILER;
5444    backtrack_common *backtrack;
5445    
5446    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
5447    
5448    allocate_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5449    
5450    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5451    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
5452    SLJIT_ASSERT(common->capture_last_ptr != 0);
5453    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
5454    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
5455    
5456    /* These pointer sized fields temporarly stores internal variables. */
5457    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
5458    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0);
5459    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(subject), TMP2, 0);
5460    
5461    if (common->mark_ptr != 0)
5462      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));
5463    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));
5464    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));
5465    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
5466    
5467    /* Needed to save important temporary registers. */
5468    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5469    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, STACK_TOP, 0, SLJIT_IMM, CALLOUT_ARG_SIZE);
5470    GET_LOCAL_BASE(SLJIT_SCRATCH_REG3, 0, OVECTOR_START);
5471    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout));
5472    OP1(SLJIT_MOV_SI, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0);
5473    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5474    free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5475    
5476    /* Check return value. */
5477    OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
5478    add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_C_SIG_GREATER));
5479    if (common->forced_quit_label == NULL)
5480      add_jump(compiler, &common->forced_quit, JUMP(SLJIT_C_SIG_LESS));
5481    else
5482      JUMPTO(SLJIT_C_SIG_LESS, common->forced_quit_label);
5483    return cc + 2 + 2 * LINK_SIZE;
5484    }
5485    
5486    #undef CALLOUT_ARG_SIZE
5487    #undef CALLOUT_ARG_OFFSET
5488    
5489  static pcre_uchar *compile_assert_matchingpath(compiler_common *common, pcre_uchar *cc, assert_backtrack *backtrack, BOOL conditional)  static pcre_uchar *compile_assert_matchingpath(compiler_common *common, pcre_uchar *cc, assert_backtrack *backtrack, BOOL conditional)
5490  {  {
5491  DEFINE_COMPILER;  DEFINE_COMPILER;
5492  int framesize;  int framesize;
5493    int extrasize;
5494    BOOL needs_control_head;
5495  int private_data_ptr;  int private_data_ptr;
5496  backtrack_common altbacktrack;  backtrack_common altbacktrack;
5497  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5009  jump_list *tmp = NULL; Line 5501  jump_list *tmp = NULL;
5501  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5502  jump_list **found;  jump_list **found;
5503  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5504  struct sljit_label *save_quitlabel = common->quitlabel;  BOOL save_local_exit = common->local_exit;
5505  struct sljit_label *save_acceptlabel = common->acceptlabel;  BOOL save_positive_assert = common->positive_assert;
5506    then_trap_backtrack *save_then_trap = common->then_trap;
5507    struct sljit_label *save_quit_label = common->quit_label;
5508    struct sljit_label *save_accept_label = common->accept_label;
5509  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5510    jump_list *save_positive_assert_quit = common->positive_assert_quit;
5511  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
5512  struct sljit_jump *jump;  struct sljit_jump *jump;
5513  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
5514    
5515    /* Assert captures then. */
5516    common->then_trap = NULL;
5517    
5518  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
5519    {    {
5520    SLJIT_ASSERT(!conditional);    SLJIT_ASSERT(!conditional);
# Line 5024  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5523  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5523    }    }
5524  private_data_ptr = PRIVATE_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
5525  SLJIT_ASSERT(private_data_ptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
5526  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
5527  backtrack->framesize = framesize;  backtrack->framesize = framesize;
5528  backtrack->private_data_ptr = private_data_ptr;  backtrack->private_data_ptr = private_data_ptr;
5529  opcode = *cc;  opcode = *cc;
# Line 5043  if (bra == OP_BRAMINZERO) Line 5542  if (bra == OP_BRAMINZERO)
5542    
5543  if (framesize < 0)  if (framesize < 0)
5544    {    {
5545    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    extrasize = needs_control_head ? 2 : 1;
5546    allocate_stack(common, 1);    if (framesize == no_frame)
5547        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5548      allocate_stack(common, extrasize);
5549      if (needs_control_head)
5550        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5551    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5552      if (needs_control_head)
5553        {
5554        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5555        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5556        }
5557    }    }
5558  else  else
5559    {    {
5560    allocate_stack(common, framesize + 2);    extrasize = needs_control_head ? 3 : 2;
5561      allocate_stack(common, framesize + extrasize);
5562    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5563    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(framesize + 1));    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
5564    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
5565      if (needs_control_head)
5566        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5567    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5568    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    if (needs_control_head)
5569    init_frame(common, ccbegin, framesize + 1, 2, FALSE);      {
5570        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
5571        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
5572        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5573        }
5574      else
5575        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5576      init_frame(common, ccbegin, NULL, framesize + extrasize - 1, extrasize, FALSE);
5577    }    }
5578    
5579  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5580  common->quitlabel = NULL;  if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5581  common->quit = NULL;    {
5582      /* Negative assert is stronger than positive assert. */
5583      common->local_exit = TRUE;
5584      common->quit_label = NULL;
5585      common->quit = NULL;
5586      common->positive_assert = FALSE;
5587      }
5588    else
5589      common->positive_assert = TRUE;
5590    common->positive_assert_quit = NULL;
5591    
5592  while (1)  while (1)
5593    {    {
5594    common->acceptlabel = NULL;    common->accept_label = NULL;
5595    common->accept = NULL;    common->accept = NULL;
5596    altbacktrack.top = NULL;    altbacktrack.top = NULL;
5597    altbacktrack.topbacktracks = NULL;    altbacktrack.topbacktracks = NULL;
# Line 5075  while (1) Line 5603  while (1)
5603    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5604    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5605      {      {
5606      common->quitlabel = save_quitlabel;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5607      common->acceptlabel = save_acceptlabel;        {
5608      common->quit = save_quit;        common->local_exit = save_local_exit;
5609          common->quit_label = save_quit_label;
5610          common->quit = save_quit;
5611          }
5612        common->positive_assert = save_positive_assert;
5613        common->then_trap = save_then_trap;
5614        common->accept_label = save_accept_label;
5615        common->positive_assert_quit = save_positive_assert_quit;
5616