/[pcre]/code/tags/pcre-8.37/pcre_jit_compile.c
ViewVC logotype

Diff of /code/tags/pcre-8.37/pcre_jit_compile.c

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

revision 999 by zherczeg, Mon Aug 6 07:36:49 2012 UTC revision 1246 by zherczeg, Sun Feb 10 08:44:53 2013 UTC
# 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  /* Allocate memory on the stack. Fast, but limited size. */  /* Allocate memory for the regex stack on the real machine stack.
69  #define LOCAL_SPACE_SIZE 32768  Fast, but limited size. */
70    #define MACHINE_STACK_SIZE 32768
71    
72    /* Growth rate for stack allocated by the OS. Should be the multiply
73    of page size. */
74  #define STACK_GROWTH_RATE 8192  #define STACK_GROWTH_RATE 8192
75    
76  /* Enable to check that the allocation could destroy temporaries. */  /* Enable to check that the allocation could destroy temporaries. */
# Line 134  The generated code will be the following Line 137  The generated code will be the following
137  /*  /*
138  Saved stack frames:  Saved stack frames:
139    
140  Atomic blocks and asserts require reloading the values of local variables  Atomic blocks and asserts require reloading the values of private data
141  when the backtrack mechanism performed. Because of OP_RECURSE, the locals  when the backtrack mechanism performed. Because of OP_RECURSE, the data
142  are not necessarly known in compile time, thus we need a dynamic restore  are not necessarly known in compile time, thus we need a dynamic restore
143  mechanism.  mechanism.
144    
145  The stack frames are stored in a chain list, and have the following format:  The stack frames are stored in a chain list, and have the following format:
146  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]
147    
148  Thus we can restore the locals to a particular point in the stack.  Thus we can restore the private data to a particular point in the stack.
149  */  */
150    
151  typedef struct jit_arguments {  typedef struct jit_arguments {
# Line 154  typedef struct jit_arguments { Line 157  typedef struct jit_arguments {
157    int *offsets;    int *offsets;
158    pcre_uchar *uchar_ptr;    pcre_uchar *uchar_ptr;
159    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
160      void *callout_data;
161    /* Everything else after. */    /* Everything else after. */
162    int offsetcount;    int offset_count;
163    int calllimit;    int call_limit;
164    pcre_uint8 notbol;    pcre_uint8 notbol;
165    pcre_uint8 noteol;    pcre_uint8 noteol;
166    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 167  typedef struct executable_functions { Line 171  typedef struct executable_functions {
171    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
172    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
173    void *userdata;    void *userdata;
174      pcre_uint32 top_bracket;
175    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
176  } executable_functions;  } executable_functions;
177    
# Line 208  typedef struct assert_backtrack { Line 213  typedef struct assert_backtrack {
213    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 (-1) if a frame is not needed. */
214    int framesize;    int framesize;
215    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
216    int localptr;    int private_data_ptr;
217    /* For iterators. */    /* For iterators. */
218    struct sljit_label *matchingpath;    struct sljit_label *matchingpath;
219  } assert_backtrack;  } assert_backtrack;
# Line 230  typedef struct bracket_backtrack { Line 235  typedef struct bracket_backtrack {
235      int framesize;      int framesize;
236    } u;    } u;
237    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
238    int localptr;    int private_data_ptr;
239  } bracket_backtrack;  } bracket_backtrack;
240    
241  typedef struct bracketpos_backtrack {  typedef struct bracketpos_backtrack {
242    backtrack_common common;    backtrack_common common;
243    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
244    int localptr;    int private_data_ptr;
245    /* Reverting stack is needed. */    /* Reverting stack is needed. */
246    int framesize;    int framesize;
247    /* Allocated stack size. */    /* Allocated stack size. */
# Line 274  typedef struct compiler_common { Line 279  typedef struct compiler_common {
279    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
280    pcre_uchar *start;    pcre_uchar *start;
281    
282    /* Opcode local area direct map. */    /* Maps private data offset to each opcode. */
283    int *localptrs;    int *private_data_ptrs;
284      /* Tells whether the capturing bracket is optimized. */
285      pcre_uint8 *optimized_cbracket;
286      /* Starting offset of private data for capturing brackets. */
287    int cbraptr;    int cbraptr;
288    /* OVector starting point. Must be divisible by 2. */    /* OVector starting point. Must be divisible by 2. */
289    int ovector_start;    int ovector_start;
290    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
291    int req_char_ptr;    int req_char_ptr;
292    /* Head of the last recursion. */    /* Head of the last recursion. */
293    int recursive_head;    int recursive_head_ptr;
294    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
295    int start_used_ptr;    int start_used_ptr;
296    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 291  typedef struct compiler_common { Line 299  typedef struct compiler_common {
299    int first_line_end;    int first_line_end;
300    /* Points to the marked string. */    /* Points to the marked string. */
301    int mark_ptr;    int mark_ptr;
302      /* Points to the last matched capture block index. */
303      int capture_last_ptr;
304    
305    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
306    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
307    sljit_w lcc;    sljit_sw lcc;
308    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
309    int mode;    int mode;
310    /* Newline control. */    /* Newline control. */
# Line 305  typedef struct compiler_common { Line 315  typedef struct compiler_common {
315    int endonly;    int endonly;
316    BOOL has_set_som;    BOOL has_set_som;
317    /* Tables. */    /* Tables. */
318    sljit_w ctypes;    sljit_sw ctypes;
319    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
320    /* Named capturing brackets. */    /* Named capturing brackets. */
321    sljit_uw name_table;    sljit_uw name_table;
322    sljit_w name_count;    sljit_sw name_count;
323    sljit_w name_entry_size;    sljit_sw name_entry_size;
324    
325    /* Labels and jump lists. */    /* Labels and jump lists. */
326    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
327    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
328    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
329      struct sljit_label *accept_label;
330    stub_list *stubs;    stub_list *stubs;
331    recurse_entry *entries;    recurse_entry *entries;
332    recurse_entry *currententry;    recurse_entry *currententry;
333    jump_list *partialmatch;    jump_list *partialmatch;
334    jump_list *quit;    jump_list *quit;
335      jump_list *forced_quit;
336    jump_list *accept;    jump_list *accept;
337    jump_list *calllimit;    jump_list *calllimit;
338    jump_list *stackalloc;    jump_list *stackalloc;
# Line 337  typedef struct compiler_common { Line 349  typedef struct compiler_common {
349  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
350    BOOL use_ucp;    BOOL use_ucp;
351  #endif  #endif
352    #ifndef COMPILE_PCRE32
353    jump_list *utfreadchar;    jump_list *utfreadchar;
354    #endif
355  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
356    jump_list *utfreadtype8;    jump_list *utfreadtype8;
357  #endif  #endif
# Line 355  typedef struct compare_context { Line 369  typedef struct compare_context {
369  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
370    int ucharptr;    int ucharptr;
371    union {    union {
372      sljit_i asint;      sljit_si asint;
373      sljit_uh asushort;      sljit_uh asushort;
374  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
375      sljit_ub asbyte;      sljit_ub asbyte;
376      sljit_ub asuchars[4];      sljit_ub asuchars[4];
377  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
378      sljit_uh asuchars[2];      sljit_uh asuchars[2];
379  #endif  #elif defined COMPILE_PCRE32
380        sljit_ui asuchars[1];
381  #endif  #endif
382    } c;    } c;
383    union {    union {
384      sljit_i asint;      sljit_si asint;
385      sljit_uh asushort;      sljit_uh asushort;
386  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
387      sljit_ub asbyte;      sljit_ub asbyte;
388      sljit_ub asuchars[4];      sljit_ub asuchars[4];
389  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
390      sljit_uh asuchars[2];      sljit_uh asuchars[2];
391  #endif  #elif defined COMPILE_PCRE32
392        sljit_ui asuchars[1];
393  #endif  #endif
394    } oc;    } oc;
395  #endif  #endif
396  } compare_context;  } compare_context;
397    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
398  /* Undefine sljit macros. */  /* Undefine sljit macros. */
399  #undef CMP  #undef CMP
400    
401  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
402  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
403    
404  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
405  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
406  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
407  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
408  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
409  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
410  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
411  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
412  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
413  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
414    
415  /* Locals layout. */  /* Local space layout. */
416  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
417  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
418  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
419  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
420  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
421  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
422  /* Max limit of recursions. */  /* Max limit of recursions. */
423  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
424  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
425  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
426  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
427  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. */
428  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
429  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
430  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_sw))
431  #define PRIV_DATA(cc)    (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
432    
433  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
434  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
435  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
436  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
437  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
438  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
439    #elif defined COMPILE_PCRE32
440    #define MOV_UCHAR  SLJIT_MOV_UI
441    #define MOVU_UCHAR SLJIT_MOVU_UI
442  #else  #else
443  #error Unsupported compiling mode  #error Unsupported compiling mode
444  #endif  #endif
 #endif  
445    
446  /* Shortcuts. */  /* Shortcuts. */
447  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 449  the start pointers when the end of the c Line 458  the start pointers when the end of the c
458    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
459  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
460    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
461    #define SET_LABEL(jump, label) \
462      sljit_set_label((jump), (label))
463  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
464    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
465  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
466    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))
467  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
468    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
469  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
470    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
471    
# Line 469  return cc; Line 480  return cc;
480    
481  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
482   next_opcode   next_opcode
483   get_localspace   get_private_data_length
484   set_localptrs   set_private_data_ptrs
485   get_framesize   get_framesize
486   init_frame   init_frame
487   get_localsize   get_private_data_length_for_copy
488   copy_locals   copy_private_data
489   compile_matchingpath   compile_matchingpath
490   compile_backtrackingpath   compile_backtrackingpath
491  */  */
# Line 670  switch(*cc) Line 681  switch(*cc)
681    case OP_MARK:    case OP_MARK:
682    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
683    
684      case OP_CALLOUT:
685      return cc + 2 + 2 * LINK_SIZE;
686    
687    default:    default:
688    return NULL;    return NULL;
689    }    }
690  }  }
691    
692  #define CASE_ITERATOR_LOCAL1 \  #define CASE_ITERATOR_PRIVATE_DATA_1 \
693      case OP_MINSTAR: \      case OP_MINSTAR: \
694      case OP_MINPLUS: \      case OP_MINPLUS: \
695      case OP_QUERY: \      case OP_QUERY: \
# Line 693  switch(*cc) Line 707  switch(*cc)
707      case OP_NOTQUERYI: \      case OP_NOTQUERYI: \
708      case OP_NOTMINQUERYI:      case OP_NOTMINQUERYI:
709    
710  #define CASE_ITERATOR_LOCAL2A \  #define CASE_ITERATOR_PRIVATE_DATA_2A \
711      case OP_STAR: \      case OP_STAR: \
712      case OP_PLUS: \      case OP_PLUS: \
713      case OP_STARI: \      case OP_STARI: \
# Line 703  switch(*cc) Line 717  switch(*cc)
717      case OP_NOTSTARI: \      case OP_NOTSTARI: \
718      case OP_NOTPLUSI:      case OP_NOTPLUSI:
719    
720  #define CASE_ITERATOR_LOCAL2B \  #define CASE_ITERATOR_PRIVATE_DATA_2B \
721      case OP_UPTO: \      case OP_UPTO: \
722      case OP_MINUPTO: \      case OP_MINUPTO: \
723      case OP_UPTOI: \      case OP_UPTOI: \
# Line 713  switch(*cc) Line 727  switch(*cc)
727      case OP_NOTUPTOI: \      case OP_NOTUPTOI: \
728      case OP_NOTMINUPTOI:      case OP_NOTMINUPTOI:
729    
730  #define CASE_ITERATOR_TYPE_LOCAL1 \  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
731      case OP_TYPEMINSTAR: \      case OP_TYPEMINSTAR: \
732      case OP_TYPEMINPLUS: \      case OP_TYPEMINPLUS: \
733      case OP_TYPEQUERY: \      case OP_TYPEQUERY: \
734      case OP_TYPEMINQUERY:      case OP_TYPEMINQUERY:
735    
736  #define CASE_ITERATOR_TYPE_LOCAL2A \  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
737      case OP_TYPESTAR: \      case OP_TYPESTAR: \
738      case OP_TYPEPLUS:      case OP_TYPEPLUS:
739    
740  #define CASE_ITERATOR_TYPE_LOCAL2B \  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
741      case OP_TYPEUPTO: \      case OP_TYPEUPTO: \
742      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
743    
# Line 752  switch(*cc) Line 766  switch(*cc)
766    }    }
767  }  }
768    
769  static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
770  {  {
771  int localspace = 0;  int private_data_length = 0;
772  pcre_uchar *alternative;  pcre_uchar *alternative;
773    pcre_uchar *name;
774  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
775  int space, size, bracketlen;  int space, size, i;
776    pcre_uint32 bracketlen;
777    
778  /* 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. */
779  while (cc < ccend)  while (cc < ccend)
# Line 772  while (cc < ccend) Line 788  while (cc < ccend)
788      cc += 1;      cc += 1;
789      break;      break;
790    
791        case OP_REF:
792        case OP_REFI:
793        common->optimized_cbracket[GET2(cc, 1)] = 0;
794        cc += 1 + IMM2_SIZE;
795        break;
796    
797      case OP_ASSERT:      case OP_ASSERT:
798      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
799      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 781  while (cc < ccend) Line 803  while (cc < ccend)
803      case OP_BRAPOS:      case OP_BRAPOS:
804      case OP_SBRA:      case OP_SBRA:
805      case OP_SBRAPOS:      case OP_SBRAPOS:
806      case OP_SCOND:      private_data_length += sizeof(sljit_sw);
     localspace += sizeof(sljit_w);  
807      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
808      break;      break;
809    
810      case OP_CBRAPOS:      case OP_CBRAPOS:
811      case OP_SCBRAPOS:      case OP_SCBRAPOS:
812      localspace += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
813        common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
814      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
815      break;      break;
816    
817      case OP_COND:      case OP_COND:
818      /* Might be a hidden SCOND. */      case OP_SCOND:
819      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
820      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
821        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
822          return -1;
823    
824        if (*cc == OP_COND)
825          {
826          /* Might be a hidden SCOND. */
827          alternative = cc + GET(cc, 1);
828          if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
829            private_data_length += sizeof(sljit_sw);
830          }
831        else
832          private_data_length += sizeof(sljit_sw);
833      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
834      break;      break;
835    
836        case OP_CREF:
837        i = GET2(cc, 1);
838        common->optimized_cbracket[i] = 0;
839        cc += 1 + IMM2_SIZE;
840        break;
841    
842        case OP_NCREF:
843        bracketlen = GET2(cc, 1);
844        name = (pcre_uchar *)common->name_table;
845        alternative = name;
846        for (i = 0; i < common->name_count; i++)
847          {
848          if (GET2(name, 0) == bracketlen) break;
849          name += common->name_entry_size;
850          }
851        SLJIT_ASSERT(i != common->name_count);
852    
853        for (i = 0; i < common->name_count; i++)
854          {
855          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
856            common->optimized_cbracket[GET2(alternative, 0)] = 0;
857          alternative += common->name_entry_size;
858          }
859        bracketlen = 0;
860        cc += 1 + IMM2_SIZE;
861        break;
862    
863      case OP_BRA:      case OP_BRA:
864      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
865      break;      break;
# Line 809  while (cc < ccend) Line 869  while (cc < ccend)
869      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
870      break;      break;
871    
872      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
873      space = 1;      space = 1;
874      size = -2;      size = -2;
875      break;      break;
876    
877      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
878      space = 2;      space = 2;
879      size = -2;      size = -2;
880      break;      break;
881    
882      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
883      space = 2;      space = 2;
884      size = -(2 + IMM2_SIZE);      size = -(2 + IMM2_SIZE);
885      break;      break;
886    
887      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
888      space = 1;      space = 1;
889      size = 1;      size = 1;
890      break;      break;
891    
892      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
893      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
894        space = 2;        space = 2;
895      size = 1;      size = 1;
896      break;      break;
897    
898      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
899      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
900        space = 2;        space = 2;
901      size = 1 + IMM2_SIZE;      size = 1 + IMM2_SIZE;
# Line 856  while (cc < ccend) Line 916  while (cc < ccend)
916    
917      case OP_RECURSE:      case OP_RECURSE:
918      /* Set its value only once. */      /* Set its value only once. */
919      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
920        {        {
921        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
922        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
923        }        }
924      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
925      break;      break;
926    
927        case OP_CALLOUT:
928        if (common->capture_last_ptr == 0)
929          {
930          common->capture_last_ptr = common->ovector_start;
931          common->ovector_start += sizeof(sljit_sw);
932          }
933        cc += 2 + 2 * LINK_SIZE;
934        break;
935    
936      case OP_MARK:      case OP_MARK:
937      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
938        {        {
939        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
940        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
941        }        }
942      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
943      break;      break;
# Line 881  while (cc < ccend) Line 950  while (cc < ccend)
950      }      }
951    
952    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
953      localspace += sizeof(sljit_w) * space;      private_data_length += sizeof(sljit_sw) * space;
954    
955    if (size != 0)    if (size != 0)
956      {      {
# Line 896  while (cc < ccend) Line 965  while (cc < ccend)
965        cc += size;        cc += size;
966      }      }
967    
968    if (bracketlen > 0)    if (bracketlen != 0)
969      {      {
970      if (cc >= end)      if (cc >= end)
971        {        {
# Line 907  while (cc < ccend) Line 976  while (cc < ccend)
976      cc += bracketlen;      cc += bracketlen;
977      }      }
978    }    }
979  return localspace;  return private_data_length;
980  }  }
981    
982  static void set_localptrs(compiler_common *common, int localptr, pcre_uchar *ccend)  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)
983  {  {
984  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
985  pcre_uchar *alternative;  pcre_uchar *alternative;
# Line 934  while (cc < ccend) Line 1003  while (cc < ccend)
1003      case OP_SBRA:      case OP_SBRA:
1004      case OP_SBRAPOS:      case OP_SBRAPOS:
1005      case OP_SCOND:      case OP_SCOND:
1006      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1007      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1008      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1009      break;      break;
1010    
1011      case OP_CBRAPOS:      case OP_CBRAPOS:
1012      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1013      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1014      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1015      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1016      break;      break;
1017    
# Line 951  while (cc < ccend) Line 1020  while (cc < ccend)
1020      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1021      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1022        {        {
1023        common->localptrs[cc - common->start] = localptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1024        localptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1025        }        }
1026      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1027      break;      break;
# Line 966  while (cc < ccend) Line 1035  while (cc < ccend)
1035      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1036      break;      break;
1037    
1038      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
1039      space = 1;      space = 1;
1040      size = -2;      size = -2;
1041      break;      break;
1042    
1043      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
1044      space = 2;      space = 2;
1045      size = -2;      size = -2;
1046      break;      break;
1047    
1048      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
1049      space = 2;      space = 2;
1050      size = -(2 + IMM2_SIZE);      size = -(2 + IMM2_SIZE);
1051      break;      break;
1052    
1053      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1054      space = 1;      space = 1;
1055      size = 1;      size = 1;
1056      break;      break;
1057    
1058      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1059      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1060        space = 2;        space = 2;
1061      size = 1;      size = 1;
1062      break;      break;
1063    
1064      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1065      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1066        space = 2;        space = 2;
1067      size = 1 + IMM2_SIZE;      size = 1 + IMM2_SIZE;
# Line 1019  while (cc < ccend) Line 1088  while (cc < ccend)
1088    
1089    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1090      {      {
1091      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1092      localptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1093      }      }
1094    
1095    if (size != 0)    if (size != 0)
# Line 1054  static int get_framesize(compiler_common Line 1123  static int get_framesize(compiler_common
1123  {  {
1124  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc);
1125  int length = 0;  int length = 0;
1126  BOOL possessive = FALSE;  int possessive = 0;
1127  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1128  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1129    BOOL capture_last_found = recursive;
1130    
1131  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1132    {    {
1133    length = 3;    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1134    possessive = TRUE;    /* This is correct regardless of common->capture_last_ptr. */
1135      capture_last_found = TRUE;
1136    }    }
1137    
1138  cc = next_opcode(common, cc);  cc = next_opcode(common, cc);
# Line 1100  while (cc < ccend) Line 1171  while (cc < ccend)
1171        length += 2;        length += 2;
1172        setmark_found = TRUE;        setmark_found = TRUE;
1173        }        }
1174        if (common->capture_last_ptr != 0 && !capture_last_found)
1175          {
1176          length += 2;
1177          capture_last_found = TRUE;
1178          }
1179      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1180      break;      break;
1181    
# Line 1107  while (cc < ccend) Line 1183  while (cc < ccend)
1183      case OP_CBRAPOS:      case OP_CBRAPOS:
1184      case OP_SCBRA:      case OP_SCBRA:
1185      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1186        if (common->capture_last_ptr != 0 && !capture_last_found)
1187          {
1188          length += 2;
1189          capture_last_found = TRUE;
1190          }
1191      length += 3;      length += 3;
1192      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1193      break;      break;
# Line 1118  while (cc < ccend) Line 1199  while (cc < ccend)
1199      }      }
1200    
1201  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1202  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1203    return -1;    return -1;
1204    
1205  if (length > 0)  if (length > 0)
# Line 1132  DEFINE_COMPILER; Line 1213  DEFINE_COMPILER;
1213  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc);
1214  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1215  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1216    BOOL capture_last_found = recursive;
1217  int offset;  int offset;
1218    
1219  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1150  while (cc < ccend) Line 1232  while (cc < ccend)
1232      if (!setsom_found)      if (!setsom_found)
1233        {        {
1234        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1235        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1236        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1237        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1238        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1239        setsom_found = TRUE;        setsom_found = TRUE;
1240        }        }
1241      cc += 1;      cc += 1;
# Line 1164  while (cc < ccend) Line 1246  while (cc < ccend)
1246      if (!setmark_found)      if (!setmark_found)
1247        {        {
1248        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);
1249        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);
1250        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1251        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1252        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1253        setmark_found = TRUE;        setmark_found = TRUE;
1254        }        }
1255      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1177  while (cc < ccend) Line 1259  while (cc < ccend)
1259      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1260        {        {
1261        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1262        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1263        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1264        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1265        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1266        setsom_found = TRUE;        setsom_found = TRUE;
1267        }        }
1268      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1269        {        {
1270        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);
1271        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);
1272        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1273        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1274        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1275        setmark_found = TRUE;        setmark_found = TRUE;
1276        }        }
1277        if (common->capture_last_ptr != 0 && !capture_last_found)
1278          {
1279          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1280          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1281          stackpos += (int)sizeof(sljit_sw);
1282          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1283          stackpos += (int)sizeof(sljit_sw);
1284          capture_last_found = TRUE;
1285          }
1286      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1287      break;      break;
1288    
# Line 1199  while (cc < ccend) Line 1290  while (cc < ccend)
1290      case OP_CBRAPOS:      case OP_CBRAPOS:
1291      case OP_SCBRA:      case OP_SCBRA:
1292      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1293        if (common->capture_last_ptr != 0 && !capture_last_found)
1294          {
1295          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1296          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1297          stackpos += (int)sizeof(sljit_sw);
1298          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1299          stackpos += (int)sizeof(sljit_sw);
1300          capture_last_found = TRUE;
1301          }
1302      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1303      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1304      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1305      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1306      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));
1307      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1308      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1309      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1310      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1311    
1312      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1313      break;      break;
# Line 1218  while (cc < ccend) Line 1318  while (cc < ccend)
1318      break;      break;
1319      }      }
1320    
1321  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1322  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1323  }  }
1324    
1325  static SLJIT_INLINE int get_localsize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static SLJIT_INLINE int get_private_data_length_for_copy(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
1326  {  {
1327  int localsize = 2;  int private_data_length = 2;
1328  int size;  int size;
1329  pcre_uchar *alternative;  pcre_uchar *alternative;
1330  /* Calculate the sum of the local variables. */  /* Calculate the sum of the private machine words. */
1331  while (cc < ccend)  while (cc < ccend)
1332    {    {
1333    size = 0;    size = 0;
# Line 1243  while (cc < ccend) Line 1343  while (cc < ccend)
1343      case OP_SBRA:      case OP_SBRA:
1344      case OP_SBRAPOS:      case OP_SBRAPOS:
1345      case OP_SCOND:      case OP_SCOND:
1346      localsize++;      private_data_length++;
1347      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1348      break;      break;
1349    
1350      case OP_CBRA:      case OP_CBRA:
1351      case OP_SCBRA:      case OP_SCBRA:
1352      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1353          private_data_length++;
1354      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1355      break;      break;
1356    
1357      case OP_CBRAPOS:      case OP_CBRAPOS:
1358      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1359      localsize += 2;      private_data_length += 2;
1360      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1361      break;      break;
1362    
# Line 1263  while (cc < ccend) Line 1364  while (cc < ccend)
1364      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1365      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1366      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1367        localsize++;        private_data_length++;
1368      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1369      break;      break;
1370    
1371      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
1372      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1373        localsize++;        private_data_length++;
1374      cc += 2;      cc += 2;
1375  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1376      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1377  #endif  #endif
1378      break;      break;
1379    
1380      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
1381      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1382        localsize += 2;        private_data_length += 2;
1383      cc += 2;      cc += 2;
1384  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1385      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1386  #endif  #endif
1387      break;      break;
1388    
1389      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
1390      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1391        localsize += 2;        private_data_length += 2;
1392      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1393  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1394      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1395  #endif  #endif
1396      break;      break;
1397    
1398      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1399      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1400        localsize++;        private_data_length++;
1401      cc += 1;      cc += 1;
1402      break;      break;
1403    
1404      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1405      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1406        localsize += 2;        private_data_length += 2;
1407      cc += 1;      cc += 1;
1408      break;      break;
1409    
1410      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1411      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1412        localsize += 2;        private_data_length += 2;
1413      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
1414      break;      break;
1415    
# Line 1320  while (cc < ccend) Line 1421  while (cc < ccend)
1421  #else  #else
1422      size = 1 + 32 / (int)sizeof(pcre_uchar);      size = 1 + 32 / (int)sizeof(pcre_uchar);
1423  #endif  #endif
1424      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1425        localsize += get_class_iterator_size(cc + size);        private_data_length += get_class_iterator_size(cc + size);
1426      cc += size;      cc += size;
1427      break;      break;
1428    
# Line 1332  while (cc < ccend) Line 1433  while (cc < ccend)
1433      }      }
1434    }    }
1435  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1436  return localsize;  return private_data_length;
1437  }  }
1438    
1439  static void copy_locals(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,
1440    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop)
1441  {  {
1442  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1357  stacktop = STACK(stacktop - 1); Line 1458  stacktop = STACK(stacktop - 1);
1458    
1459  if (!save)  if (!save)
1460    {    {
1461    stackptr += sizeof(sljit_w);    stackptr += sizeof(sljit_sw);
1462    if (stackptr < stacktop)    if (stackptr < stacktop)
1463      {      {
1464      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1465      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1466      tmp1empty = FALSE;      tmp1empty = FALSE;
1467      }      }
1468    if (stackptr < stacktop)    if (stackptr < stacktop)
1469      {      {
1470      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1471      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1472      tmp2empty = FALSE;      tmp2empty = FALSE;
1473      }      }
1474    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
# Line 1379  while (status != end) Line 1480  while (status != end)
1480    switch(status)    switch(status)
1481      {      {
1482      case start:      case start:
1483      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1484      count = 1;      count = 1;
1485      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1486      status = loop;      status = loop;
1487      break;      break;
1488    
# Line 1405  while (status != end) Line 1506  while (status != end)
1506        case OP_SBRAPOS:        case OP_SBRAPOS:
1507        case OP_SCOND:        case OP_SCOND:
1508        count = 1;        count = 1;
1509        srcw[0] = PRIV_DATA(cc);        srcw[0] = PRIVATE_DATA(cc);
1510        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1511        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1512        break;        break;
1513    
1514        case OP_CBRA:        case OP_CBRA:
1515        case OP_SCBRA:        case OP_SCBRA:
1516        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1517        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1518            count = 1;
1519            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1520            }
1521        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1522        break;        break;
1523    
1524        case OP_CBRAPOS:        case OP_CBRAPOS:
1525        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1526        count = 2;        count = 2;
1527        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[0] = PRIVATE_DATA(cc);
1528        srcw[1] = PRIV_DATA(cc);        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1529        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
1530        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1531        break;        break;
1532    
# Line 1432  while (status != end) Line 1536  while (status != end)
1536        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1537          {          {
1538          count = 1;          count = 1;
1539          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1540          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1541          }          }
1542        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1543        break;        break;
1544    
1545        CASE_ITERATOR_LOCAL1        CASE_ITERATOR_PRIVATE_DATA_1
1546        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1547          {          {
1548          count = 1;          count = 1;
1549          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1550          }          }
1551        cc += 2;        cc += 2;
1552  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1450  while (status != end) Line 1554  while (status != end)
1554  #endif  #endif
1555        break;        break;
1556    
1557        CASE_ITERATOR_LOCAL2A        CASE_ITERATOR_PRIVATE_DATA_2A
1558        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1559          {          {
1560          count = 2;          count = 2;
1561          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1562          srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1563          }          }
1564        cc += 2;        cc += 2;
1565  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1463  while (status != end) Line 1567  while (status != end)
1567  #endif  #endif
1568        break;        break;
1569    
1570        CASE_ITERATOR_LOCAL2B        CASE_ITERATOR_PRIVATE_DATA_2B
1571        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1572          {          {
1573          count = 2;          count = 2;
1574          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1575          srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1576          }          }
1577        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1578  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1476  while (status != end) Line 1580  while (status != end)
1580  #endif  #endif
1581        break;        break;
1582    
1583        CASE_ITERATOR_TYPE_LOCAL1        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1584        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1585          {          {
1586          count = 1;          count = 1;
1587          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1588          }          }
1589        cc += 1;        cc += 1;
1590        break;        break;
1591    
1592        CASE_ITERATOR_TYPE_LOCAL2A        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1593        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1594          {          {
1595          count = 2;          count = 2;
1596          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1597          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1598          }          }
1599        cc += 1;        cc += 1;
1600        break;        break;
1601    
1602        CASE_ITERATOR_TYPE_LOCAL2B        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1603        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1604          {          {
1605          count = 2;          count = 2;
1606          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1607          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1608          }          }
1609        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1610        break;        break;
# Line 1513  while (status != end) Line 1617  while (status != end)
1617  #else  #else
1618        size = 1 + 32 / (int)sizeof(pcre_uchar);        size = 1 + 32 / (int)sizeof(pcre_uchar);
1619  #endif  #endif
1620        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1621          switch(get_class_iterator_size(cc + size))          switch(get_class_iterator_size(cc + size))
1622            {            {
1623            case 1:            case 1:
1624            count = 1;            count = 1;
1625            srcw[0] = PRIV_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1626            break;            break;
1627    
1628            case 2:            case 2:
1629            count = 2;            count = 2;
1630            srcw[0] = PRIV_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1631            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1632            break;            break;
1633    
1634            default:            default:
# Line 1556  while (status != end) Line 1660  while (status != end)
1660          if (!tmp1empty)          if (!tmp1empty)
1661            {            {
1662            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1663            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1664            }            }
1665          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1666          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1567  while (status != end) Line 1671  while (status != end)
1671          if (!tmp2empty)          if (!tmp2empty)
1672            {            {
1673            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1674            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1675            }            }
1676          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1677          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1584  while (status != end) Line 1688  while (status != end)
1688          if (!tmp1empty)          if (!tmp1empty)
1689            {            {
1690            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1691            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1692            }            }
1693          tmp1next = FALSE;          tmp1next = FALSE;
1694          }          }
# Line 1596  while (status != end) Line 1700  while (status != end)
1700          if (!tmp2empty)          if (!tmp2empty)
1701            {            {
1702            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1703            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1704            }            }
1705          tmp1next = TRUE;          tmp1next = TRUE;
1706          }          }
# Line 1611  if (save) Line 1715  if (save)
1715      if (!tmp1empty)      if (!tmp1empty)
1716        {        {
1717        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1718        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1719        }        }
1720      if (!tmp2empty)      if (!tmp2empty)
1721        {        {
1722        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1723        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1724        }        }
1725      }      }
1726    else    else
# Line 1624  if (save) Line 1728  if (save)
1728      if (!tmp2empty)      if (!tmp2empty)
1729        {        {
1730        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1731        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1732        }        }
1733      if (!tmp1empty)      if (!tmp1empty)
1734        {        {
1735        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1736        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1737        }        }
1738      }      }
1739    }    }
1740  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1741  }  }
1742    
1743  #undef CASE_ITERATOR_LOCAL1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1744  #undef CASE_ITERATOR_LOCAL2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1745  #undef CASE_ITERATOR_LOCAL2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
1746  #undef CASE_ITERATOR_TYPE_LOCAL1  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1747  #undef CASE_ITERATOR_TYPE_LOCAL2A  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1748  #undef CASE_ITERATOR_TYPE_LOCAL2B  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1749    
1750  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1751  {  {
1752  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1753  }  }
# Line 1654  while (list) Line 1758  while (list)
1758    {    {
1759    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1760    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1761    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1762    list = list->next;    list = list->next;
1763    }    }
1764  }  }
# Line 1719  static SLJIT_INLINE void allocate_stack( Line 1823  static SLJIT_INLINE void allocate_stack(
1823  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
1824  DEFINE_COMPILER;  DEFINE_COMPILER;
1825    
1826  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));
1827  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
1828  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
1829  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1733  add_stub(common, stack_alloc, 0, CMP(SLJ Line 1837  add_stub(common, stack_alloc, 0, CMP(SLJ
1837  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
1838  {  {
1839  DEFINE_COMPILER;  DEFINE_COMPILER;
1840  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));
1841  }  }
1842    
1843  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1743  struct sljit_label *loop; Line 1847  struct sljit_label *loop;
1847  int i;  int i;
1848  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
1849  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
1850  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));
1851  if (length < 8)  if (length < 8)
1852    {    {
1853    for (i = 0; i < length; i++)    for (i = 0; i < length; i++)
1854      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);
1855    }    }
1856  else  else
1857    {    {
1858    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START - sizeof(sljit_sw));
1859    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length);
1860    loop = LABEL();    loop = LABEL();
1861    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);
1862    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);
1863    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
1864    }    }
1865  }  }
# Line 1764  static SLJIT_INLINE void copy_ovector(co Line 1868  static SLJIT_INLINE void copy_ovector(co
1868  {  {
1869  DEFINE_COMPILER;  DEFINE_COMPILER;
1870  struct sljit_label *loop;  struct sljit_label *loop;
1871  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
1872    
1873  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
1874  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));
1875  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);
1876    
1877  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
1878  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
1879    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);
1880  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));
1881  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
1882    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);
1883  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));
1884  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));
1885  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
1886  /* Unlikely, but possible */  /* Unlikely, but possible */
1887  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);
1888  loop = LABEL();  loop = LABEL();
1889  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);
1890  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));
1891  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
1892  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1893  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);
1894  #endif  #endif
1895  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);
1896  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);
1897  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
1898  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
1899    
1900  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
1901  if (topbracket > 1)  if (topbracket > 1)
1902    {    {
1903    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));
1904    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
1905    
1906    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
1907    loop = LABEL();    loop = LABEL();
1908    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)));
1909    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);
1910    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);
1911    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
1912    }    }
1913  else  else
1914    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1817  DEFINE_COMPILER; Line 1921  DEFINE_COMPILER;
1921  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);
1922  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->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
1923    
1924  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
1925  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
1926  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, offset_count));
1927  CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, quit);  CMPTO(SLJIT_C_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
1928    
1929  /* Store match begin and end. */  /* Store match begin and end. */
1930  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));
1931  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));
1932  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);  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);
1933  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);
1934  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1935  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);
1936  #endif  #endif
1937  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);
1938    
1939  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);
1940  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1941  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);
1942  #endif  #endif
1943  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);
1944    
1945  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
1946  }  }
# Line 1949  if (c <= 127 && bit == 0x20) Line 2053  if (c <= 127 && bit == 0x20)
2053    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2054    
2055  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2056  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2057    return 0;    return 0;
2058    
2059  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2060    
2061  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2062  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 1968  if (common->utf && c > 127) Line 2072  if (common->utf && c > 127)
2072  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2073  return (0 << 8) | bit;  return (0 << 8) | bit;
2074    
2075  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2076    
 #ifdef COMPILE_PCRE16  
2077  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2078  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2079    {    {
# Line 1981  if (common->utf && c > 65535) Line 2084  if (common->utf && c > 65535)
2084    }    }
2085  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2086  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2087    
2088  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2089  }  }
2090    
2091  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
# Line 2081  static void read_char(compiler_common *c Line 2183  static void read_char(compiler_common *c
2183  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2184  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2185  DEFINE_COMPILER;  DEFINE_COMPILER;
2186  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2187  struct sljit_jump *jump;  struct sljit_jump *jump;
2188  #endif  #endif
2189    
2190  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2191  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2192  if (common->utf)  if (common->utf)
2193    {    {
2194  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2195    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2196  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2197    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2198  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2199    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2200    JUMPHERE(jump);    JUMPHERE(jump);
2201    }    }
2202  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2203  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));
2204  }  }
2205    
# Line 2108  static void peek_char(compiler_common *c Line 2208  static void peek_char(compiler_common *c
2208  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2209  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2210  DEFINE_COMPILER;  DEFINE_COMPILER;
2211  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2212  struct sljit_jump *jump;  struct sljit_jump *jump;
2213  #endif  #endif
2214    
2215  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2216  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2217  if (common->utf)  if (common->utf)
2218    {    {
2219  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2220    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2221  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2222    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2223  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2224    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2225    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2226    JUMPHERE(jump);    JUMPHERE(jump);
2227    }    }
2228  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2229  }  }
2230    
2231  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2232  {  {
2233  /* 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. */
2234  DEFINE_COMPILER;  DEFINE_COMPILER;
2235  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2236  struct sljit_jump *jump;  struct sljit_jump *jump;
2237  #endif  #endif
2238    
# Line 2143  if (common->utf) Line 2241  if (common->utf)
2241    {    {
2242    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2243    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));
2244  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2245    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2246    it is needed in most cases. */    it is needed in most cases. */
2247    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2248    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2249    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2250    JUMPHERE(jump);    JUMPHERE(jump);
2251  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2252    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2253    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2254    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
# Line 2159  if (common->utf) Line 2256  if (common->utf)
2256    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2257    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2258    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);
2259    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2260    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2261    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2262  #endif  #elif defined COMPILE_PCRE32
2263  #endif /* COMPILE_PCRE8 */    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2264      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2265      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2266      JUMPHERE(jump);
2267    #endif /* COMPILE_PCRE[8|16|32] */
2268    return;    return;
2269    }    }
2270  #endif  #endif /* SUPPORT_UTF */
2271  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2272  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));
2273  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2274  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2275  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2276  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2277  #endif  #endif
2278  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2279  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2280  JUMPHERE(jump);  JUMPHERE(jump);
2281  #endif  #endif
2282  }  }
# Line 2184  static void skip_char_back(compiler_comm Line 2285  static void skip_char_back(compiler_comm
2285  {  {
2286  /* 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. */
2287  DEFINE_COMPILER;  DEFINE_COMPILER;
2288  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2289    #if defined COMPILE_PCRE8
2290  struct sljit_label *label;  struct sljit_label *label;
2291    
2292  if (common->utf)  if (common->utf)
# Line 2196  if (common->utf) Line 2298  if (common->utf)
2298    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2299    return;    return;
2300    }    }
2301  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2302  if (common->utf)  if (common->utf)
2303    {    {
2304    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 2205  if (common->utf) Line 2306  if (common->utf)
2306    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2307    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2308    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);
2309    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2310    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2311    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2312    return;    return;
2313    }    }
2314  #endif  #endif /* COMPILE_PCRE[8|16] */
2315    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2316  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));
2317  }  }
2318    
# Line 2227  if (nltype == NLTYPE_ANY) Line 2329  if (nltype == NLTYPE_ANY)
2329  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2330    {    {
2331    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);
2332    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2333    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);
2334    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);
2335    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));
2336    }    }
2337  else  else
# Line 2241  else Line 2343  else
2343    
2344  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2345    
2346  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2347  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2348  {  {
2349  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
# Line 2329  sljit_emit_fast_return(compiler, RETURN_ Line 2431  sljit_emit_fast_return(compiler, RETURN_
2431  JUMPHERE(jump);  JUMPHERE(jump);
2432    
2433  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2434  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);
2435  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2436  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2437  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2438  }  }
2439    
2440  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2441    
 #ifdef COMPILE_PCRE16  
2442  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2443  {  {
2444  /* 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 2362  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC Line 2463  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2463  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2464  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2465  }  }
 #endif /* COMPILE_PCRE16 */  
2466    
2467  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2468    
2469  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2470    
# Line 2384  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2484  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2484    
2485  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2486  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2487  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));
2488  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2489  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2490  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2491  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2492  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2493  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));
2494  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2495  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2496  }  }
# Line 2404  struct sljit_label *newlinelabel = NULL; Line 2504  struct sljit_label *newlinelabel = NULL;
2504  struct sljit_jump *start;  struct sljit_jump *start;
2505  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2506  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2507  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2508  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2509  #endif  #endif
2510  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2459  if (newlinecheck) Line 2559  if (newlinecheck)
2559    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2560    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2561    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);
2562    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2563  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2564    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2565  #endif  #endif
2566    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2567    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2482  if (newlinecheck) Line 2582  if (newlinecheck)
2582    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);
2583    
2584  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));
2585  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2586    #if defined COMPILE_PCRE8
2587  if (common->utf)  if (common->utf)
2588    {    {
2589    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2590    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);
2591    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2592    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2593    }    }
2594  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2595  if (common->utf)  if (common->utf)
2596    {    {
2597    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2598    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2599    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);
2600    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2601    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2602    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2603    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2604    }    }
2605  #endif  #endif /* COMPILE_PCRE[8|16] */
2606    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2607  JUMPHERE(start);  JUMPHERE(start);
2608    
2609  if (newlinecheck)  if (newlinecheck)
# Line 2514  if (newlinecheck) Line 2615  if (newlinecheck)
2615  return mainloop;  return mainloop;
2616  }  }
2617    
2618  static SLJIT_INLINE BOOL fast_forward_first_two_chars(compiler_common *common, BOOL firstline)  #define MAX_N_CHARS 3
2619    
2620    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2621  {  {
2622  DEFINE_COMPILER;  DEFINE_COMPILER;
2623  struct sljit_label *start;  struct sljit_label *start;
2624  struct sljit_jump *quit;  struct sljit_jump *quit;
2625  struct sljit_jump *found;  pcre_uint32 chars[MAX_N_CHARS * 2];
2626  pcre_int32 chars[4];  pcre_uchar *cc = common->start + 1 + LINK_SIZE;
 pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  
2627  int location = 0;  int location = 0;
2628  pcre_int32 len, c, bit, caseless;  pcre_int32 len, c, bit, caseless;
2629  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  
2630    
2631    /* We do not support alternatives now. */
2632  if (*(common->start + GET(common->start, 1)) == OP_ALT)  if (*(common->start + GET(common->start, 1)) == OP_ALT)
2633    return FALSE;    return FALSE;
2634    
2635  while (TRUE)  while (TRUE)
2636    {    {
2637    caseless = 0;    caseless = 0;
2638    must_end = TRUE;    must_stop = 1;
2639    switch(*cc)    switch(*cc)
2640      {      {
2641      case OP_CHAR:      case OP_CHAR:
2642      must_end = FALSE;      must_stop = 0;
2643      cc++;      cc++;
2644      break;      break;
2645    
2646      case OP_CHARI:      case OP_CHARI:
2647      caseless = 1;      caseless = 1;
2648      must_end = FALSE;      must_stop = 0;
2649      cc++;      cc++;
2650      break;      break;
2651    
# Line 2596  while (TRUE) Line 2687  while (TRUE)
2687      break;      break;
2688    
2689      default:      default:
2690      return FALSE;      must_stop = 2;
2691        break;
2692      }      }
2693    
2694      if (must_stop == 2)
2695          break;
2696    
2697    len = 1;    len = 1;
2698  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2699    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 2621  while (TRUE) Line 2716  while (TRUE)
2716    else    else
2717      caseless = 0;      caseless = 0;
2718    
2719    while (len > 0 && location < 2 * 2)    while (len > 0 && location < MAX_N_CHARS * 2)
2720      {      {
2721      c = *cc;      c = *cc;
2722      bit = 0;      bit = 0;
# Line 2639  while (TRUE) Line 2734  while (TRUE)
2734      cc++;      cc++;
2735      }      }
2736    
2737    if (location == 2 * 2)    if (location >= MAX_N_CHARS * 2 || must_stop != 0)
2738      break;      break;
   else if (must_end)  
     return FALSE;  
2739    }    }
2740    
2741    /* At least two characters are required. */
2742    if (location < 2 * 2)
2743        return FALSE;
2744    
2745  if (firstline)  if (firstline)
2746    {    {
2747    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
2748    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2749    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));
2750    }    }
2751  else  else
2752    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));
2753    
2754  start = LABEL();  start = LABEL();
2755  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 */  
2756    
2757  #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 */  
2758  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2759  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2760  #endif /* SLJIT_BIG_ENDIAN */  if (chars[1] != 0)
2761      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
2762  #ifdef COMPILE_PCRE8  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
2763  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 8);  if (location > 2 * 2)
2764  #else /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2765  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 16);  if (chars[3] != 0)
2766  #endif    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
2767  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
2768    if (location > 2 * 2)
2769  #endif    {
2770      if (chars[5] != 0)
2771  if (chars[1] != 0 || chars[3] != 0)      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
2772    {    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);  
2773    }    }
2774    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2775    
 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);  
2776  JUMPHERE(quit);  JUMPHERE(quit);
2777    
2778  if (firstline)  if (firstline)
2779    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2780  else  else
2781    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));
2782  return TRUE;  return TRUE;
2783  }  }
2784    
2785    #undef MAX_N_CHARS
2786    
2787  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)
2788  {  {
2789  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2738  if (first_char == oc) Line 2817  if (first_char == oc)
2817  else  else
2818    {    {
2819    bit = first_char ^ oc;    bit = first_char ^ oc;
2820    if (ispowerof2(bit))    if (is_powerof2(bit))
2821      {      {
2822      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
2823      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 2746  else Line 2825  else
2825    else    else
2826      {      {
2827      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);
2828      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2829      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);
2830      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);
2831      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
2832      }      }
2833    }    }
# Line 2790  if (common->nltype == NLTYPE_FIXED && co Line 2869  if (common->nltype == NLTYPE_FIXED && co
2869    
2870    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
2871    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);
2872    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
2873  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2874    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
2875  #endif  #endif
2876    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2877    
# Line 2833  if (common->nltype == NLTYPE_ANY || comm Line 2912  if (common->nltype == NLTYPE_ANY || comm
2912    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2913    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2914    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);
2915    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2916  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2917    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2918  #endif  #endif
2919    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2920    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
# Line 2848  if (firstline) Line 2927  if (firstline)
2927    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2928  }  }
2929    
2930    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
2931    
2932  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)
2933  {  {
2934  DEFINE_COMPILER;  DEFINE_COMPILER;
2935  struct sljit_label *start;  struct sljit_label *start;
2936  struct sljit_jump *quit;  struct sljit_jump *quit;
2937  struct sljit_jump *found;  struct sljit_jump *found = NULL;
2938    jump_list *matches = NULL;
2939    pcre_uint8 inverted_start_bits[32];
2940    int i;
2941  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
2942  struct sljit_jump *jump;  struct sljit_jump *jump;
2943  #endif  #endif
2944    
2945    for (i = 0; i < 32; ++i)
2946      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
2947    
2948  if (firstline)  if (firstline)
2949    {    {
2950    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
# Line 2872  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 2959  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
2959  if (common->utf)  if (common->utf)
2960    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
2961  #endif  #endif
2962    
2963    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
2964      {
2965  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
2966  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
2967  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
2968  JUMPHERE(jump);    JUMPHERE(jump);
2969  #endif  #endif
2970  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
2971  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
2972  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
2973  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
2974  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);
2975  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
2976      }
2977    
2978  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2979  if (common->utf)  if (common->utf)
2980    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
2981  #endif  #endif
2982  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));
2983  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
2984    #if defined COMPILE_PCRE8
2985  if (common->utf)  if (common->utf)
2986    {    {
2987    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
2988    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);
2989    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2990    }    }
2991  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2992  if (common->utf)  if (common->utf)
2993    {    {
2994    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
2995    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2996    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);
2997    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2998    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2999    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3000    }    }
3001  #endif  #endif /* COMPILE_PCRE[8|16] */
3002    #endif /* SUPPORT_UTF */
3003  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3004  JUMPHERE(found);  if (found != NULL)
3005      JUMPHERE(found);
3006    if (matches != NULL)
3007      set_jumps(matches, LABEL());
3008  JUMPHERE(quit);  JUMPHERE(quit);
3009    
3010  if (firstline)  if (firstline)
# Line 2925  struct sljit_jump *alreadyfound; Line 3020  struct sljit_jump *alreadyfound;
3020  struct sljit_jump *found;  struct sljit_jump *found;
3021  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3022  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3023  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3024    
3025  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3026  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 2956  if (req_char == oc) Line 3051  if (req_char == oc)
3051  else  else
3052    {    {
3053    bit = req_char ^ oc;    bit = req_char ^ oc;
3054    if (ispowerof2(bit))    if (is_powerof2(bit))
3055      {      {
3056      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3057      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 2992  GET_LOCAL_BASE(TMP3, 0, 0); Line 3087  GET_LOCAL_BASE(TMP3, 0, 0);
3087  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3088  mainloop = LABEL();  mainloop = LABEL();
3089  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3090  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);
3091    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3092    
3093  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3094  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));
3095  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));
3096  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));
3097  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3098    
3099  JUMPHERE(jump);  JUMPHERE(jump);
3100  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3101  /* End of dropping frames. */  /* End of dropping frames. */
3102  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3103    
3104  JUMPHERE(jump);  JUMPHERE(jump);
3105  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3106  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3107  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3108  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));  
3109  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3110  }  }
3111    
# Line 3058  if (common->use_ucp) Line 3138  if (common->use_ucp)
3138    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3139    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3140    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);
3141    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3142    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);
3143    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);
3144    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3145    JUMPHERE(jump);    JUMPHERE(jump);
3146    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3147    }    }
# Line 3102  if (common->use_ucp) Line 3182  if (common->use_ucp)
3182    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3183    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3184    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);
3185    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3186    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);
3187    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);
3188    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3189    JUMPHERE(jump);    JUMPHERE(jump);
3190    }    }
3191  else  else
# Line 3186  switch(ranges[0]) Line 3266  switch(ranges[0])
3266        }        }
3267      return TRUE;      return TRUE;
3268      }      }
3269    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]))
3270      {      {
3271      if (readch)      if (readch)
3272        read_char(common);        read_char(common);
# Line 3285  sljit_emit_fast_enter(compiler, RETURN_A Line 3365  sljit_emit_fast_enter(compiler, RETURN_A
3365    
3366  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3367  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);
3368  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3369  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);
3370  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3371  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3372  if (common->utf)  if (common->utf)
3373    {    {
3374  #endif  #endif
3375    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3376    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3377    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);
3378  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3379    }    }
3380  #endif  #endif
3381  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3382  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);
3383  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3384  }  }
3385    
# Line 3311  DEFINE_COMPILER; Line 3391  DEFINE_COMPILER;
3391  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3392    
3393  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);
3394  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3395  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);
3396  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3397  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);
3398  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3399  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3400  if (common->utf)  if (common->utf)
3401    {    {
3402  #endif  #endif
3403    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3404    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);
3405    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3406    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);
3407    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3408    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3409    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);
3410    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3411    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);
3412    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3413    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);
3414    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3415    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);
3416  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3417    }    }
3418  #endif  #endif
3419  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3420  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);
3421    
3422  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3423  }  }
# Line 3351  sljit_emit_fast_enter(compiler, RETURN_A Line 3431  sljit_emit_fast_enter(compiler, RETURN_A
3431    
3432  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3433  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);
3434  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3435  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);
3436  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3437  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3438  if (common->utf)  if (common->utf)
3439    {    {
3440  #endif  #endif
3441    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);
3442    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3443    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);
3444  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3445    }    }
3446  #endif  #endif
3447  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3448  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);
3449    
3450  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3451  }  }
# Line 3451  sljit_emit_fast_return(compiler, RETURN_ Line 3531  sljit_emit_fast_return(compiler, RETURN_
3531    
3532  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3533    
3534  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)
3535  {  {
3536  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3537  int c1, c2;  pcre_uint32 c1, c2;
3538  const pcre_uchar *src2 = args->uchar_ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3539  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
3540    const ucd_record *ur;
3541    const pcre_uint32 *pp;
3542    
3543  while (src1 < end1)  while (src1 < end1)
3544    {    {
# Line 3464  while (src1 < end1) Line 3546  while (src1 < end1)
3546      return (pcre_uchar*)1;      return (pcre_uchar*)1;
3547    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3548    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3549    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return NULL;    ur = GET_UCD(c2);
3550      if (c1 != c2 && c1 != c2 + ur->other_case)
3551        {
3552        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3553        for (;;)
3554          {
3555          if (c1 < *pp) return NULL;
3556          if (c1 == *pp++) break;
3557          }
3558        }
3559    }    }
3560  return src2;  return src2;
3561  }  }
# Line 3486  if (caseless && char_has_othercase(commo Line 3577  if (caseless && char_has_othercase(commo
3577    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3578    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3579    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3580  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3581    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3582    othercasebit &= 0xff;    othercasebit &= 0xff;
3583  #else  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3584  #ifdef COMPILE_PCRE16    /* Note that this code only handles characters in the BMP. If there
3585      ever are characters outside the BMP whose othercase differs in only one
3586      bit from itself (there currently are none), this code will need to be
3587      revised for COMPILE_PCRE32. */
3588    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3589    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3590      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
3591    else    else
3592      othercasebit &= 0xff;      othercasebit &= 0xff;
3593  #endif  #endif /* COMPILE_PCRE[8|16|32] */
 #endif  
3594    }    }
3595    
3596  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3597    {    {
3598  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3599  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3600    if (context->length >= 4)    if (context->length >= 4)
3601      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 3511  if (context->sourcereg == -1) Line 3604  if (context->sourcereg == -1)
3604    else    else
3605  #endif  #endif
3606      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3607  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
3608  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3609    if (context->length >= 4)    if (context->length >= 4)
3610      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3611    else    else
3612  #endif  #endif
3613      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3614  #endif  #elif defined COMPILE_PCRE32
3615  #endif /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3616    #endif /* COMPILE_PCRE[8|16|32] */
3617    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3618    }    }
3619    
# Line 3534  do Line 3627  do
3627  #endif  #endif
3628    
3629    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3630  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3631    
3632    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3633    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3549  do Line 3642  do
3642      }      }
3643    context->ucharptr++;    context->ucharptr++;
3644    
3645  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3646    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))
3647  #else  #else
3648    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
# Line 3557  do Line 3650  do
3650      {      {
3651      if (context->length >= 4)      if (context->length >= 4)
3652        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  
3653      else if (context->length >= 2)      else if (context->length >= 2)
3654        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);
3655    #if defined COMPILE_PCRE8
3656      else if (context->length >= 1)      else if (context->length >= 1)
3657        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);
3658  #else  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3659      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3660    
3661      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3599  do Line 3689  do
3689    
3690  #else  #else
3691    
3692    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3693  #ifdef COMPILE_PCRE8    if (context->length >= 1)
3694    if (context->length > 0)      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3695      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  
3696    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3697    
3698    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3656  static void compile_xclass_matchingpath( Line 3742  static void compile_xclass_matchingpath(
3742  DEFINE_COMPILER;  DEFINE_COMPILER;
3743  jump_list *found = NULL;  jump_list *found = NULL;
3744  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;
3745  unsigned int c;  pcre_int32 c, charoffset;
3746  int compares;  const pcre_uint32 *other_cases;
3747  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
3748  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
3749    int compares, invertcmp, numberofcmps;
3750  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3751  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
3752  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
3753  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
3754  unsigned int typeoffset;  pcre_int32 typeoffset;
3755  #endif  #endif
 int invertcmp, numberofcmps;  
 unsigned int charoffset;  
3756    
3757  /* Although SUPPORT_UTF must be defined, we are  /* Although SUPPORT_UTF must be defined, we are
3758     not necessary in utf mode even in 8 bit mode. */     not necessary in utf mode even in 8 bit mode. */
# Line 3688  if ((*cc++ & XCL_MAP) != 0) Line 3773  if ((*cc++ & XCL_MAP) != 0)
3773      {      {
3774      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3775      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3776      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
3777      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3778      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);
3779      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
# Line 3765  while (*cc != XCL_END) Line 3850  while (*cc != XCL_END)
3850        needschar = TRUE;        needschar = TRUE;
3851        break;        break;
3852    
3853          case PT_CLIST:
3854          needschar = TRUE;
3855          break;
3856    
3857        default:        default:
3858        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
3859        break;        break;
# Line 3801  if (needstype || needsscript) Line 3890  if (needstype || needsscript)
3890      {      {
3891      if (scriptreg == TMP1)      if (scriptreg == TMP1)
3892        {        {
3893        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));
3894        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
3895        }        }
3896      else      else
3897        {        {
3898        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
3899        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));
3900        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
3901        }        }
3902      }      }
# Line 3843  while (*cc != XCL_END) Line 3932  while (*cc != XCL_END)
3932      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
3933        {        {
3934        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);
3935        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);
3936        numberofcmps++;        numberofcmps++;
3937        }        }
3938      else if (numberofcmps > 0)      else if (numberofcmps > 0)
3939        {        {
3940        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);
3941        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);
3942        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
3943        numberofcmps = 0;        numberofcmps = 0;
3944        }        }
# Line 3882  while (*cc != XCL_END) Line 3971  while (*cc != XCL_END)
3971      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
3972        {        {
3973        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);
3974        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);
3975        numberofcmps++;        numberofcmps++;
3976        }        }
3977      else if (numberofcmps > 0)      else if (numberofcmps > 0)
3978        {        {
3979        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);
3980        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);
3981        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
3982        numberofcmps = 0;        numberofcmps = 0;
3983        }        }
# Line 3919  while (*cc != XCL_END) Line 4008  while (*cc != XCL_END)
4008    
4009        case PT_LAMP:        case PT_LAMP:
4010        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);
4011        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4012        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);
4013        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4014        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);
4015        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);
4016        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4017        break;        break;
4018    
# Line 3950  while (*cc != XCL_END) Line 4039  while (*cc != XCL_END)
4039          }          }
4040        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4041        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);
4042        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4043        if (*cc == PT_SPACE)        if (*cc == PT_SPACE)
4044          JUMPHERE(jump);          JUMPHERE(jump);
4045    
4046        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4047        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);
4048        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);
4049        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4050        break;        break;
4051    
4052        case PT_WORD:        case PT_WORD:
4053        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);
4054        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4055        /* ... fall through */        /* ... fall through */
4056    
4057        case PT_ALNUM:        case PT_ALNUM:
4058        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
4059        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);
4060        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);
4061        SET_TYPE_OFFSET(ucp_Nd);        SET_TYPE_OFFSET(ucp_Nd);
4062        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);
4063        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);
4064          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4065          break;
4066    
4067          case PT_CLIST:
4068          other_cases = PRIV(ucd_caseless_sets) + cc[1];
4069    
4070          /* At least three characters are required.
4071             Otherwise this case would be handled by the normal code path. */
4072          SLJIT_ASSERT(other_cases[0] != NOTACHAR && other_cases[1] != NOTACHAR && other_cases[2] != NOTACHAR);
4073          SLJIT_ASSERT(other_cases[0] < other_cases[1] && other_cases[1] < other_cases[2]);
4074    
4075          /* Optimizing character pairs, if their difference is power of 2. */
4076          if (is_powerof2(other_cases[1] ^ other_cases[0]))
4077            {
4078            if (charoffset == 0)
4079              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4080            else
4081              {
4082              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4083              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4084              }
4085            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[1]);
4086            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4087            other_cases += 2;
4088            }
4089          else if (is_powerof2(other_cases[2] ^ other_cases[1]))
4090            {
4091            if (charoffset == 0)
4092              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[2] ^ other_cases[1]);
4093            else
4094              {
4095              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4096              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4097              }
4098            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[2]);
4099            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4100    
4101            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, other_cases[0] - charoffset);
4102            OP_FLAGS(SLJIT_OR | ((other_cases[3] == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4103    
4104            other_cases += 3;
4105            }
4106          else
4107            {
4108            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4109            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4110            }
4111    
4112          while (*other_cases != NOTACHAR)
4113            {
4114            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4115            OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4116            }
4117        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4118        break;        break;
4119        }        }
# Line 4089  switch(type) Line 4231  switch(type)
4231      {      {
4232      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4233      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));
4234  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
4235    #if defined COMPILE_PCRE8
4236      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4237      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);
4238      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4239  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
4240      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
4241      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4242      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);
4243      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4244      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4245      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4246  #endif /* COMPILE_PCRE16 */  #endif
 #endif /* COMPILE_PCRE8 */  
4247      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4248    #endif /* COMPILE_PCRE[8|16] */
4249      return cc;      return cc;
4250      }      }
4251  #endif  #endif
# Line 4170  switch(type) Line 4312  switch(type)
4312    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4313    read_char(common);    read_char(common);
4314    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4315    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Mc);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));
4316    add_jump(compiler, backtracks, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, ucp_Mn - ucp_Mc));    /* Optimize register allocation: use a real register. */
4317      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4318      OP1(SLJIT_MOV_UB, STACK_TOP, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4319    
4320    label = LABEL();    label = LABEL();
4321    jump[0] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    jump[0] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
4322    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
4323    read_char(common);    read_char(common);
4324    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4325    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Mc);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));
4326    CMPTO(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, ucp_Mn - ucp_Mc, label);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4327    
4328      OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);
4329      OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STACK_TOP), (sljit_sw)PRIV(ucp_gbtable));
4330      OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);
4331      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4332      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4333      JUMPTO(SLJIT_C_NOT_ZERO, label);
4334    
4335    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
4336    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4337      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
4338    
4339    if (common->mode == JIT_PARTIAL_HARD_COMPILE)    if (common->mode == JIT_PARTIAL_HARD_COMPILE)
4340      {      {
4341      jump[0] = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);      jump[0] = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
# Line 4206  switch(type) Line 4359  switch(type)
4359        {        {
4360        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);
4361        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);
4362        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS);
4363        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);
4364        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);
4365        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));
4366        check_partial(common, TRUE);        check_partial(common, TRUE);
4367        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
# Line 4388  switch(type) Line 4541  switch(type)
4541      }      }
4542    oc = char_othercase(common, c);    oc = char_othercase(common, c);
4543    bit = c ^ oc;    bit = c ^ oc;
4544    if (ispowerof2(bit))    if (is_powerof2(bit))
4545      {      {
4546      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4547      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));
4548      return cc + length;      return cc + length;
4549      }      }
4550    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);
4551    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4552    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);
4553    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);
4554    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4555    return cc + length;    return cc + length;
4556    
# Line 4424  switch(type) Line 4577  switch(type)
4577        /* Skip the variable-length character. */        /* Skip the variable-length character. */
4578        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));
4579        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4580        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);
4581        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4582        JUMPHERE(jump[0]);        JUMPHERE(jump[0]);
4583        return cc + 1;        return cc + 1;
# Line 4449  switch(type) Line 4602  switch(type)
4602      {      {
4603      oc = char_othercase(common, c);      oc = char_othercase(common, c);
4604      bit = c ^ oc;      bit = c ^ oc;
4605      if (ispowerof2(bit))      if (is_powerof2(bit))
4606        {        {
4607        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4608        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 4487  switch(type) Line 4640  switch(type)
4640  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4641    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4642    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4643    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4644    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4645    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);
4646    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 4497  switch(type) Line 4650  switch(type)
4650  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4651    return cc + 32 / sizeof(pcre_uchar);    return cc + 32 / sizeof(pcre_uchar);
4652    
4653  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4654    case OP_XCLASS:    case OP_XCLASS:
4655    compile_xclass_matchingpath(common, cc + LINK_SIZE, backtracks);    compile_xclass_matchingpath(common, cc + LINK_SIZE, backtracks);
4656    return cc + GET(cc, 0) - 1;    return cc + GET(cc, 0) - 1;
# Line 4611  if (!common->jscript_compat) Line 4764  if (!common->jscript_compat)
4764      {      {
4765      /* OVECTOR(1) contains the "string begin - 1" constant. */      /* OVECTOR(1) contains the "string begin - 1" constant. */
4766      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));
4767      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4768      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));
4769      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);
4770      return JUMP(SLJIT_C_NOT_ZERO);      return JUMP(SLJIT_C_NOT_ZERO);
4771      }      }
4772    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 4669  if (withchecks && !common->jscript_compa Line 4822  if (withchecks && !common->jscript_compa
4822  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
4823  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
4824    {    {
4825    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);
4826    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));
4827    if (withchecks)    if (withchecks)
4828      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
4829    
4830    /* Needed to save important temporary registers. */    /* Needed to save important temporary registers. */
4831    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4832    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
4833    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);
4834    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));
4835    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
4836    if (common->mode == JIT_COMPILE)    if (common->mode == JIT_COMPILE)
# Line 4790  if (!minimize) Line 4943  if (!minimize)
4943      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
4944      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
4945      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
4946      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));
4947      zerolength = compile_ref_checks(common, ccbegin, NULL);      zerolength = compile_ref_checks(common, ccbegin, NULL);
4948      /* Restore if not zero length. */      /* Restore if not zero length. */
4949      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));
4950      }      }
4951    else    else
4952      {      {
# Line 4936  add_jump(compiler, &backtrack->topbacktr Line 5089  add_jump(compiler, &backtrack->topbacktr
5089  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5090  }  }
5091    
5092    static int SLJIT_CALL do_callout(struct jit_arguments* arguments, PUBL(callout_block) *callout_block, pcre_uchar **jit_ovector)
5093    {
5094    const pcre_uchar *begin = arguments->begin;
5095    int *offset_vector = arguments->offsets;
5096    int offset_count = arguments->offset_count;
5097    int i;
5098    
5099    if (PUBL(callout) == NULL)
5100      return 0;
5101    
5102    callout_block->version = 2;
5103    callout_block->callout_data = arguments->callout_data;
5104    
5105    /* Offsets in subject. */
5106    callout_block->subject_length = arguments->end - arguments->begin;
5107    callout_block->start_match = (pcre_uchar*)callout_block->subject - arguments->begin;
5108    callout_block->current_position = (pcre_uchar*)callout_block->offset_vector - arguments->begin;
5109    #if defined COMPILE_PCRE8
5110    callout_block->subject = (PCRE_SPTR)begin;
5111    #elif defined COMPILE_PCRE16
5112    callout_block->subject = (PCRE_SPTR16)begin;
5113    #elif defined COMPILE_PCRE32
5114    callout_block->subject = (PCRE_SPTR32)begin;
5115    #endif
5116    
5117    /* Convert and copy the JIT offset vector to the offset_vector array. */
5118    callout_block->capture_top = 0;
5119    callout_block->offset_vector = offset_vector;
5120    for (i = 2; i < offset_count; i += 2)
5121      {
5122      offset_vector[i] = jit_ovector[i] - begin;
5123      offset_vector[i + 1] = jit_ovector[i + 1] - begin;
5124      if (jit_ovector[i] >= begin)
5125        callout_block->capture_top = i;
5126      }
5127    
5128    callout_block->capture_top = (callout_block->capture_top >> 1) + 1;
5129    if (offset_count > 0)
5130      offset_vector[0] = -1;
5131    if (offset_count > 1)
5132      offset_vector[1] = -1;
5133    return (*PUBL(callout))(callout_block);
5134    }
5135    
5136    /* Aligning to 8 byte. */
5137    #define CALLOUT_ARG_SIZE \
5138        (((int)sizeof(PUBL(callout_block)) + 7) & ~7)
5139    
5140    #define CALLOUT_ARG_OFFSET(arg) \
5141        (-CALLOUT_ARG_SIZE + SLJIT_OFFSETOF(PUBL(callout_block), arg))
5142    
5143    static SLJIT_INLINE pcre_uchar *compile_callout_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5144    {
5145    DEFINE_COMPILER;
5146    backtrack_common *backtrack;
5147    
5148    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
5149    
5150    allocate_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5151    
5152    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5153    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
5154    SLJIT_ASSERT(common->capture_last_ptr != 0);
5155    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
5156    OP1(SLJIT_MOV_UI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
5157    
5158    /* These pointer sized fields temporarly stores internal variables. */
5159    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
5160    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0);
5161    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(subject), TMP2, 0);
5162    
5163    if (common->mark_ptr != 0)
5164      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));
5165    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));
5166    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));
5167    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
5168    
5169    /* Needed to save important temporary registers. */
5170    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5171    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, STACK_TOP, 0, SLJIT_IMM, CALLOUT_ARG_SIZE);
5172    GET_LOCAL_BASE(SLJIT_SCRATCH_REG3, 0, OVECTOR_START);
5173    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout));
5174    OP1(SLJIT_MOV_SI, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0);
5175    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5176    free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5177    
5178    /* Check return value. */
5179    OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
5180    add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_C_SIG_GREATER));
5181    if (common->forced_quit_label == NULL)
5182      add_jump(compiler, &common->forced_quit, JUMP(SLJIT_C_SIG_LESS));
5183    else
5184      JUMPTO(SLJIT_C_SIG_LESS, common->forced_quit_label);
5185    return cc + 2 + 2 * LINK_SIZE;
5186    }
5187    
5188    #undef CALLOUT_ARG_SIZE
5189    #undef CALLOUT_ARG_OFFSET
5190    
5191  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)
5192  {  {
5193  DEFINE_COMPILER;  DEFINE_COMPILER;
5194  int framesize;  int framesize;
5195  int localptr;  int private_data_ptr;
5196  backtrack_common altbacktrack;  backtrack_common altbacktrack;
5197  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
5198  pcre_uchar opcode;  pcre_uchar opcode;
# Line 4949  jump_list *tmp = NULL; Line 5201  jump_list *tmp = NULL;
5201  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5202  jump_list **found;  jump_list **found;
5203  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5204  struct sljit_label *save_quitlabel = common->quitlabel;  struct sljit_label *save_quit_label = common->quit_label;
5205  struct sljit_label *save_acceptlabel = common->acceptlabel;  struct sljit_label *save_accept_label = common->accept_label;
5206  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5207  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
5208  struct sljit_jump *jump;  struct sljit_jump *jump;
# Line 4962  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5214  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5214    bra = *cc;    bra = *cc;
5215    cc++;    cc++;
5216    }    }
5217  localptr = PRIV_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
5218  SLJIT_ASSERT(localptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
5219  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, FALSE);
5220  backtrack->framesize = framesize;  backtrack->framesize = framesize;
5221  backtrack->localptr = localptr;  backtrack->private_data_ptr = private_data_ptr;
5222  opcode = *cc;  opcode = *cc;
5223  SLJIT_ASSERT(opcode >= OP_ASSERT && opcode <= OP_ASSERTBACK_NOT);  SLJIT_ASSERT(opcode >= OP_ASSERT && opcode <= OP_ASSERTBACK_NOT);
5224  found = (opcode == OP_ASSERT || opcode == OP_ASSERTBACK) ? &tmp : target;  found = (opcode == OP_ASSERT || opcode == OP_ASSERTBACK) ? &tmp : target;
# Line 4983  if (bra == OP_BRAMINZERO) Line 5235  if (bra == OP_BRAMINZERO)
5235    
5236  if (framesize < 0)  if (framesize < 0)
5237    {    {
5238    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5239    allocate_stack(common, 1);    allocate_stack(common, 1);
5240    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5241    }    }
5242  else  else
5243    {    {
5244    allocate_stack(common, framesize + 2);    allocate_stack(common, framesize + 2);
5245    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5246    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(framesize + 1));    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(framesize + 1));
5247    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
5248    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5249    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5250    init_frame(common, ccbegin, framesize + 1, 2, FALSE);    init_frame(common, ccbegin, framesize + 1, 2, FALSE);
5251    }    }
5252    
5253  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5254  common->quitlabel = NULL;  common->quit_label = NULL;
5255  common->quit = NULL;  common->quit = NULL;
5256  while (1)  while (1)
5257    {    {
5258    common->acceptlabel = NULL;    common->accept_label = NULL;
5259    common->accept = NULL;    common->accept = NULL;
5260    altbacktrack.top = NULL;    altbacktrack.top = NULL;
5261    altbacktrack.topbacktracks = NULL;    altbacktrack.topbacktracks = NULL;
# Line 5015  while (1) Line 5267  while (1)
5267    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5268    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5269      {      {
5270      common->quitlabel = save_quitlabel;      common->quit_label = save_quit_label;
5271      common->acceptlabel = save_acceptlabel;      common->accept_label = save_accept_label;
5272      common->quit = save_quit;      common->quit = save_quit;
5273      common->accept = save_accept;      common->accept = save_accept;
5274      return NULL;      return NULL;
5275      }      }
5276    common->acceptlabel = LABEL();    common->accept_label = LABEL();
5277    if (common->accept != NULL)    if (common->accept != NULL)
5278      set_jumps(common->accept, common->acceptlabel);      set_jumps(common->accept, common->accept_label);
5279    
5280    /* Reset stack. */    /* Reset stack. */
5281    if (framesize < 0)    if (framesize < 0)
5282      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5283    else {    else {
5284      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
5285        {        {
5286        /* We don't need to keep the STR_PTR, only the previous localptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
5287        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));
5288        }        }
5289      else      else
5290        {        {
5291        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5292        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5293        }        }
5294    }    }
# Line 5052  while (1) Line 5304  while (1)
5304          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5305        else        else
5306          {          {
5307          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_w));          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));
5308          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_w));          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));
5309          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP1, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
5310          }          }
5311        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));
5312        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5313        }        }
5314      else if (framesize >= 0)      else if (framesize >= 0)
5315        {        {
5316        /* For OP_BRA and OP_BRAMINZERO. */        /* For OP_BRA and OP_BRAMINZERO. */
5317        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_w));        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));
5318        }        }
5319      }      }
5320    add_jump(compiler, found, JUMP(SLJIT_JUMP));    add_jump(compiler, found, JUMP(SLJIT_JUMP));
# Line 5070  while (1) Line 5322  while (1)
5322    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5323    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5324      {      {
5325      common->quitlabel = save_quitlabel;      common->quit_label = save_quit_label;
5326      common->acceptlabel = save_acceptlabel;      common->accept_label = save_accept_label;
5327      common->quit = save_quit;      common->quit = save_quit;
5328      common->accept = save_accept;      common->accept = save_accept;
5329      return NULL;      return NULL;
# Line 5113  if (opcode == OP_ASSERT || opcode == OP_ Line 5365  if (opcode == OP_ASSERT || opcode == OP_
5365        }        }
5366      else      else
5367        free_stack(common, framesize + 2);        free_stack(common, framesize + 2);
5368      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
5369      }      }
5370    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5371    if (bra != OP_BRAZERO)    if (bra != OP_BRAZERO)
# Line 5127  if (opcode == OP_ASSERT || opcode == OP_ Line 5379  if (opcode == OP_ASSERT || opcode == OP_
5379      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5380      /* Keep the STR_PTR on the top of the stack. */      /* Keep the STR_PTR on the top of the stack. */
5381      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5382        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));
5383      else if (bra == OP_BRAMINZERO)      else if (bra == OP_BRAMINZERO)
5384        {        {
5385        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));
5386        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5387        }        }
5388      }      }
# Line 5138  if (opcode == OP_ASSERT || opcode == OP_ Line 5390  if (opcode == OP_ASSERT || opcode == OP_
5390      {      {
5391      if (bra == OP_BRA)      if (bra == OP_BRA)
5392        {        {
5393        /* We don't need to keep the STR_PTR, only the previous localptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
5394        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));
5395        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5396        }        }
5397      else      else
5398        {        {
5399        /* We don't need to keep the STR_PTR, only the previous localptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
5400        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_sw));
5401        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5402        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);
5403        }        }
# Line 5154  if (opcode == OP_ASSERT || opcode == OP_ Line 5406  if (opcode == OP_ASSERT || opcode == OP_
5406    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
5407      {      {
5408      backtrack->matchingpath = LABEL();      backtrack->matchingpath = LABEL();
5409      sljit_set_label(jump, backtrack->matchingpath);      SET_LABEL(jump, backtrack->matchingpath);
5410      }      }
5411    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
5412      {      {
# Line 5162  if (opcode == OP_ASSERT || opcode == OP_ Line 5414  if (opcode == OP_ASSERT || opcode == OP_
5414      JUMPHERE(brajump);      JUMPHERE(brajump);
5415      if (framesize >= 0)      if (framesize >= 0)
5416        {        {
5417        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5418        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5419        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_w));        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));
5420        }        }
5421      set_jumps(backtrack->common.topbacktracks, LABEL());      set_jumps(backtrack->common.topbacktracks, LABEL());
5422      }      }
# Line 5192  else Line 5444  else
5444        }        }
5445      else      else
5446        free_stack(common, framesize + 2);        free_stack(common, framesize + 2);
5447      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
5448      }      }
5449    
5450    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
# Line 5211  else Line 5463  else
5463      }      }
5464    }    }
5465    
5466  common->quitlabel = save_quitlabel;  common->quit_label = save_quit_label;
5467  common->acceptlabel = save_acceptlabel;  common->accept_label = save_accept_label;
5468  common->quit = save_quit;  common->quit = save_quit;
5469  common->accept = save_accept;  common->accept = save_accept;
5470  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5471  }  }
5472    
5473  static sljit_w SLJIT_CALL do_searchovector(sljit_w refno, sljit_w* locals, pcre_uchar *name_table)  static sljit_sw SLJIT_CALL do_searchovector(sljit_uw refno, sljit_sw* locals, pcre_uchar *name_table)
5474  {  {
5475  int condition = FALSE;  int condition = FALSE;
5476  pcre_uchar *slotA = name_table;  pcre_uchar *slotA = name_table;
5477  pcre_uchar *slotB;  pcre_uchar *slotB;
5478  sljit_w name_count = locals[LOCALS0 / sizeof(sljit_w)];  sljit_sw name_count = locals[LOCALS0 / sizeof(sljit_sw)];
5479  sljit_w name_entry_size = locals[LOCALS1 / sizeof(sljit_w)];  sljit_sw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];
5480  sljit_w no_capture;  sljit_sw no_capture;
5481  int i;  int i;
5482    
5483  locals += refno & 0xff;  locals += refno & 0xff;
# Line 5275  if (i < name_count) Line 5527  if (i < name_count)
5527  return condition;  return condition;
5528  }  }
5529    
5530  static sljit_w SLJIT_CALL do_searchgroups(sljit_w recno, sljit_w* locals, pcre_uchar *name_table)  static sljit_sw SLJIT_CALL do_searchgroups(sljit_uw recno, sljit_uw* locals, pcre_uchar *name_table)
5531  {  {
5532  int condition = FALSE;  int condition = FALSE;
5533  pcre_uchar *slotA = name_table;  pcre_uchar *slotA = name_table;
5534  pcre_uchar *slotB;  pcre_uchar *slotB;
5535  sljit_w name_count = locals[LOCALS0 / sizeof(sljit_w)];  sljit_uw name_count = locals[LOCALS0 / sizeof(sljit_sw)];
5536  sljit_w name_entry_size = locals[LOCALS1 / sizeof(sljit_w)];  sljit_uw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];
5537  sljit_w group_num = locals[POSSESSIVE0 / sizeof(sljit_w)];  sljit_uw group_num = locals[POSSESSIVE0 / sizeof(sljit_sw)];
5538  int i;  sljit_uw i;
5539    
5540  for (i = 0; i < name_count; i++)  for (i = 0; i < name_count; i++)
5541    {    {
# Line 5387  static pcre_uchar *compile_bracket_match Line 5639  static pcre_uchar *compile_bracket_match
5639  DEFINE_COMPILER;  DEFINE_COMPILER;
5640  backtrack_common *backtrack;  backtrack_common *backtrack;
5641  pcre_uchar opcode;  pcre_uchar opcode;
5642  int localptr = 0;  int private_data_ptr = 0;
5643  int offset = 0;  int offset = 0;
5644  int stacksize;  int stacksize;
5645  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5438  if (SLJIT_UNLIKELY(opcode == OP_COND) || Line 5690  if (SLJIT_UNLIKELY(opcode == OP_COND) ||
5690      else if (common->currententry->start == 0)      else if (common->currententry->start == 0)
5691        has_alternatives = stacksize != 0;        has_alternatives = stacksize != 0;
5692      else      else
5693        has_alternatives = stacksize != GET2(common->start, common->currententry->start + 1 + LINK_SIZE);        has_alternatives = stacksize != (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
5694      }      }
5695    }    }
5696    
# Line 5451  if (opcode == OP_CBRA || opcode == OP_SC Line 5703  if (opcode == OP_CBRA || opcode == OP_SC
5703    {    {
5704    /* Capturing brackets has a pre-allocated space. */    /* Capturing brackets has a pre-allocated space. */
5705    offset = GET2(ccbegin, 1 + LINK_SIZE);    offset = GET2(ccbegin, 1 + LINK_SIZE);
5706    localptr = OVECTOR_PRIV(offset);    if (common->optimized_cbracket[offset] == 0)
5707    offset <<= 1;      {
5708    BACKTRACK_AS(bracket_backtrack)->localptr = localptr;      private_data_ptr = OVECTOR_PRIV(offset);
5709        offset <<= 1;
5710        }
5711      else
5712        {
5713        offset <<= 1;
5714        private_data_ptr = OVECTOR(offset);
5715        }
5716      BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;
5717    matchingpath += IMM2_SIZE;    matchingpath += IMM2_SIZE;
5718    }    }
5719  else if (opcode == OP_ONCE || opcode == OP_SBRA || opcode == OP_SCOND)  else if (opcode == OP_ONCE || opcode == OP_SBRA || opcode == OP_SCOND)
5720    {    {
5721    /* Other brackets simply allocate the next entry. */    /* Other brackets simply allocate the next entry. */
5722    localptr = PRIV_DATA(ccbegin);    private_data_ptr = PRIVATE_DATA(ccbegin);
5723    SLJIT_ASSERT(localptr != 0);    SLJIT_ASSERT(private_data_ptr != 0);
5724    BACKTRACK_AS(bracket_backtrack)->localptr = localptr;    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;
5725    if (opcode == OP_ONCE)    if (opcode == OP_ONCE)
5726      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, FALSE);      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, FALSE);
5727    }    }
# Line 5507  if (bra == OP_BRAMINZERO) Line 5767  if (bra == OP_BRAMINZERO)
5767        /* Checking zero-length iteration. */        /* Checking zero-length iteration. */
5768        if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)        if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
5769          {          {
5770          /* When we come from outside, localptr contains the previous STR_PTR. */          /* When we come from outside, private_data_ptr contains the previous STR_PTR. */
5771          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5772          }          }
5773        else        else
5774          {          {
5775          /* Except when the whole stack frame must be saved. */          /* Except when the whole stack frame must be saved. */
5776          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5777          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (BACKTRACK_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_w));          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (BACKTRACK_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw));
5778          }          }
5779        JUMPHERE(skip);        JUMPHERE(skip);
5780        }        }
# Line 5545  if (opcode == OP_ONCE) Line 5805  if (opcode == OP_ONCE)
5805      /* Neither capturing brackets nor recursions are not found in the block. */      /* Neither capturing brackets nor recursions are not found in the block. */
5806      if (ket == OP_KETRMIN)      if (ket == OP_KETRMIN)
5807        {        {
5808        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5809        allocate_stack(common, 2);        allocate_stack(common, 2);
5810        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5811        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
5812        OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));        OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5813        }        }
5814      else if (ket == OP_KETRMAX || has_alternatives)      else if (ket == OP_KETRMAX || has_alternatives)
5815        {        {
5816        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STACK_TOP, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5817        allocate_stack(common, 1);        allocate_stack(common, 1);
5818        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5819        }        }
5820      else      else
5821        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STACK_TOP, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5822      }      }
5823    else    else
5824      {      {
5825      if (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives)      if (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives)
5826        {        {
5827        allocate_stack(common, BACKTRACK_AS(bracket_backtrack)->u.framesize + 2);        allocate_stack(common, BACKTRACK_AS(bracket_backtrack)->u.framesize + 2);
5828        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5829        OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(BACKTRACK_AS(bracket_backtrack)->u.framesize + 1));        OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(BACKTRACK_AS(bracket_backtrack)->u.framesize + 1));
5830        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5831        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
5832        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5833        init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1, 2, FALSE);        init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1, 2, FALSE);
5834        }        }
5835      else      else
5836        {        {
5837        allocate_stack(common, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1);        allocate_stack(common, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1);
5838        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5839        OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(BACKTRACK_AS(bracket_backtrack)->u.framesize));        OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(BACKTRACK_AS(bracket_backtrack)->u.framesize));
5840        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
5841        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
5842        init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize, 1, FALSE);        init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize, 1, FALSE);
5843        }        }
# Line 5586  if (opcode == OP_ONCE) Line 5846  if (opcode == OP_ONCE)
5846  else if (opcode == OP_CBRA || opcode == OP_SCBRA)  else if (opcode == OP_CBRA || opcode == OP_SCBRA)
5847    {    {
5848    /* Saving the previous values. */    /* Saving the previous values. */
5849    allocate_stack(common, 3);    if (common->optimized_cbracket[offset >> 1] != 0)
5850    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      {
5851    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      SLJIT_ASSERT(private_data_ptr == OVECTOR(offset));
5852    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      allocate_stack(common, 2);
5853    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5854    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr + sizeof(sljit_sw));
5855    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);
5856    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
5857        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
5858        }
5859      else
5860        {
5861        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5862        allocate_stack(common, 1);
5863        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);
5864        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
5865        }
5866    }    }
5867  else if (opcode == OP_SBRA || opcode == OP_SCOND)  else if (opcode == OP_SBRA || opcode == OP_SCOND)
5868    {    {
5869    /* Saving the previous value. */    /* Saving the previous value. */
5870    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5871    allocate_stack(common, 1);    allocate_stack(common, 1);
5872    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);
5873    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
5874    }    }
5875  else if (has_alternatives)  else if (has_alternatives)
# Line 5629  if (opcode == OP_COND || opcode == OP_SC Line 5898  if (opcode == OP_COND || opcode == OP_SC
5898      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);
5899      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);
5900      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);
5901      OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, (stacksize << 8) | (common->ovector_start / sizeof(sljit_w)));      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (stacksize << 8) | (common->ovector_start / sizeof(sljit_sw)));
5902      GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, 0);      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);
5903      OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, common->name_table);      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);
5904      sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchovector));      sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchovector));
5905      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5906      add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0));      add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0));
5907    
5908      JUMPHERE(jump);      JUMPHERE(jump);
5909      matchingpath += 1 + IMM2_SIZE;      matchingpath += 1 + IMM2_SIZE;
# Line 5652  if (opcode == OP_COND || opcode == OP_SC Line 5921  if (opcode == OP_COND || opcode == OP_SC
5921      else if (common->currententry->start == 0)      else if (common->currententry->start == 0)
5922        stacksize = stacksize == 0;        stacksize = stacksize == 0;
5923      else      else
5924        stacksize = stacksize == GET2(common->start, common->currententry->start + 1 + LINK_SIZE);        stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
5925    
5926      if (*matchingpath == OP_RREF || stacksize || common->currententry == NULL)      if (*matchingpath == OP_RREF || stacksize || common->currententry == NULL)
5927        {        {
# Line 5679  if (opcode == OP_COND || opcode == OP_SC Line 5948  if (opcode == OP_COND || opcode == OP_SC
5948        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);
5949        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);
5950        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, GET2(common->start, common->currententry->start + 1 + LINK_SIZE));        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, GET2(common->start, common->currententry->start + 1 + LINK_SIZE));
5951        OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, stacksize);        OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, stacksize);
5952        GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, 0);        GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);
5953        OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, common->name_table);        OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);
5954        sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchgroups));        sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchgroups));
5955        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5956        add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0));        add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0));
5957        matchingpath += 1 + IMM2_SIZE;        matchingpath += 1 + IMM2_SIZE;
5958        }        }
5959      }      }
# Line 5710  if (opcode == OP_ONCE) Line 5979  if (opcode == OP_ONCE)
5979    {    {
5980    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
5981      {      {
5982      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5983      /* TMP2 which is set here used by OP_KETRMAX below. */      /* TMP2 which is set here used by OP_KETRMAX below. */
5984      if (ket == OP_KETRMAX)      if (ket == OP_KETRMAX)
5985        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);
5986      else if (ket == OP_KETRMIN)      else if (ket == OP_KETRMIN)
5987        {        {
5988        /* Move the STR_PTR to the localptr. */        /* Move the STR_PTR to the private_data_ptr. */
5989        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);
5990        }        }
5991      }      }
5992    else    else
5993      {      {
5994      stacksize = (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives) ? 2 : 1;      stacksize = (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives) ? 2 : 1;
5995      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_IMM, (BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize) * sizeof(sljit_w));      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize) * sizeof(sljit_sw));
5996      if (ket == OP_KETRMAX)      if (ket == OP_KETRMAX)
5997        {        {
5998        /* TMP2 which is set here used by OP_KETRMAX below. */        /* TMP2 which is set here used by OP_KETRMAX below. */
# Line 5735  if (opcode == OP_ONCE) Line 6004  if (opcode == OP_ONCE)
6004  stacksize = 0;  stacksize = 0;
6005  if (ket != OP_KET || bra != OP_BRA)  if (ket != OP_KET || bra != OP_BRA)
6006    stacksize++;    stacksize++;
6007    if (offset != 0)
6008      {
6009      if (common->capture_last_ptr != 0)
6010        stacksize++;
6011      if (common->optimized_cbracket[offset >> 1] == 0)
6012        stacksize += 2;
6013      }
6014  if (has_alternatives && opcode != OP_ONCE)  if (has_alternatives && opcode != OP_ONCE)
6015    stacksize++;    stacksize++;
6016    
# Line 5742  if (stacksize > 0) Line 6018  if (stacksize > 0)
6018    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6019    
6020  stacksize = 0;  stacksize = 0;
6021  if (ket != OP_KET)  if (ket != OP_KET || bra != OP_BRA)
6022    {    {
6023    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);    if (ket != OP_KET)
6024        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6025      else
6026        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
6027    stacksize++;    stacksize++;
6028    }    }
6029  else if (bra != OP_BRA)  
6030    if (offset != 0)
6031    {    {
6032    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);    if (common->capture_last_ptr != 0)
6033    stacksize++;      {
6034        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6035        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6036        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP2, 0);
6037        stacksize++;
6038        }
6039      if (common->optimized_cbracket[offset >> 1] == 0)
6040        {
6041        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6042        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
6043        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6044        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6045        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6046        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6047        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6048        stacksize += 2;
6049        }
6050    }    }
6051    
6052  if (has_alternatives)  if (has_alternatives)
# Line 5762  if (has_alternatives) Line 6058  if (has_alternatives)
6058    }    }
6059    
6060  /* Must be after the matchingpath label. */  /* Must be after the matchingpath label. */
6061  if (offset != 0)  if (offset != 0 && common->optimized_cbracket[offset >> 1] != 0)
6062    {    {
6063    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);    SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0));
6064    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 0), TMP1, 0);  
6065    }    }
6066    
6067  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
# Line 5778  if (ket == OP_KETRMAX) Line 6073  if (ket == OP_KETRMAX)
6073      /* Checking zero-length iteration. */      /* Checking zero-length iteration. */
6074      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
6075        {        {
6076        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STR_PTR, 0, rmaxlabel);        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0, rmaxlabel);
6077        /* Drop STR_PTR for greedy plus quantifier. */        /* Drop STR_PTR for greedy plus quantifier. */
6078        if (bra != OP_BRAZERO)        if (bra != OP_BRAZERO)
6079          free_stack(common, 1);          free_stack(common, 1);
# Line 5807  if (bra == OP_BRAMINZERO) Line 6102  if (bra == OP_BRAMINZERO)
6102      framesize is < 0, OP_ONCE will do the release itself. */      framesize is < 0, OP_ONCE will do the release itself. */
6103      if (opcode == OP_ONCE && BACKTRACK_AS(bracket_backtrack)->u.framesize >= 0)      if (opcode == OP_ONCE && BACKTRACK_AS(bracket_backtrack)->u.framesize >= 0)
6104        {        {
6105        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6106        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
6107        }        }
6108      else if (ket == OP_KETRMIN && opcode != OP_ONCE)      else if (ket == OP_KETRMIN && opcode != OP_ONCE)
# Line 5831  static pcre_uchar *compile_bracketpos_ma Line 6126  static pcre_uchar *compile_bracketpos_ma
6126  DEFINE_COMPILER;  DEFINE_COMPILER;
6127  backtrack_common *backtrack;  backtrack_common *backtrack;
6128  pcre_uchar opcode;  pcre_uchar opcode;
6129  int localptr;  int private_data_ptr;
6130  int cbraprivptr = 0;  int cbraprivptr = 0;
6131  int framesize;  int framesize;
6132  int stacksize;  int stacksize;
# Line 5850  if (*cc == OP_BRAPOSZERO) Line 6145  if (*cc == OP_BRAPOSZERO)
6145    }    }
6146    
6147  opcode = *cc;  opcode = *cc;
6148  localptr = PRIV_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
6149  SLJIT_ASSERT(localptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
6150  BACKTRACK_AS(bracketpos_backtrack)->localptr = localptr;  BACKTRACK_AS(bracketpos_backtrack)->private_data_ptr = private_data_ptr;
6151  switch(opcode)  switch(opcode)
6152    {    {
6153    case OP_BRAPOS:    case OP_BRAPOS:
# Line 5863  switch(opcode) Line 6158  switch(opcode)
6158    case OP_CBRAPOS:    case OP_CBRAPOS:
6159    case OP_SCBRAPOS:    case OP_SCBRAPOS:
6160    offset = GET2(cc, 1 + LINK_SIZE);    offset = GET2(cc, 1 + LINK_SIZE);
6161      /* This case cannot be optimized in the same was as
6162      normal capturing brackets. */
6163      SLJIT_ASSERT(common->optimized_cbracket[offset] == 0);
6164    cbraprivptr = OVECTOR_PRIV(offset);    cbraprivptr = OVECTOR_PRIV(offset);
6165    offset <<= 1;    offset <<= 1;
6166    ccbegin = cc + 1 + LINK_SIZE + IMM2_SIZE;    ccbegin = cc + 1 + LINK_SIZE + IMM2_SIZE;
# Line 5877  framesize = get_framesize(common, cc, FA Line 6175  framesize = get_framesize(common, cc, FA
6175  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;
6176  if (framesize < 0)  if (framesize < 0)
6177    {    {
6178    stacksize = (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS) ? 2 : 1;    if (offset != 0)
6179        {
6180        stacksize = 2;
6181        if (common->capture_last_ptr != 0)
6182          stacksize++;
6183        }
6184      else
6185        stacksize = 1;
6186    
6187    if (!zero)    if (!zero)
6188      stacksize++;      stacksize++;
6189    
6190    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
6191    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6192    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6193    
6194    if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)    if (offset != 0)
6195      {      {
6196      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6197      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));
6198      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
6199        if (common->capture_last_ptr != 0)
6200          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6201      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6202        if (common->capture_last_ptr != 0)
6203          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
6204      }      }
6205    else    else
6206      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
# Line 5905  else Line 6216  else
6216    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)
6217      stacksize++;      stacksize++;
6218    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
   allocate_stack(common, stacksize);  
6219    
6220    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);    allocate_stack(common, stacksize);
6221      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6222    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));
6223    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
6224    
6225    stack = 0;    stack = 0;
6226    if (!zero)    if (!zero)
6227      {      {
# Line 5925  else Line 6237  else
6237    init_frame(common, cc, stacksize - 1, stacksize - framesize, FALSE);    init_frame(common, cc, stacksize - 1, stacksize - framesize, FALSE);
6238    }    }
6239    
6240  if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)  if (offset != 0)
6241    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6242    
6243  loop = LABEL();  loop = LABEL();
# Line 5941  while (*cc != OP_KETRPOS) Line 6253  while (*cc != OP_KETRPOS)
6253    
6254    if (framesize < 0)    if (framesize < 0)
6255      {      {
6256      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6257    
6258      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6259        {        {
6260        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6261        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6262        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6263          if (common->capture_last_ptr != 0)
6264            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6265        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6266        }        }
6267      else      else
# Line 5965  while (*cc != OP_KETRPOS) Line 6279  while (*cc != OP_KETRPOS)
6279      }      }
6280    else    else
6281      {      {
6282      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6283        {        {
6284        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_IMM, stacksize * sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, stacksize * sizeof(sljit_sw));
6285        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6286        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6287        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6288          if (common->capture_last_ptr != 0)
6289            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6290        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6291        }        }
6292      else      else
6293        {        {
6294        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6295        OP2(SLJIT_ADD, STACK_TOP, 0, TMP2, 0, SLJIT_IMM, stacksize * sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, TMP2, 0, SLJIT_IMM, stacksize * sizeof(sljit_sw));
6296        if (opcode == OP_SBRAPOS)        if (opcode == OP_SBRAPOS)
6297          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), (framesize + 1) * sizeof(sljit_w));          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), (framesize + 1) * sizeof(sljit_sw));
6298        OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), (framesize + 1) * sizeof(sljit_w), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), (framesize + 1) * sizeof(sljit_sw), STR_PTR, 0);
6299        }        }
6300    
6301      if (opcode == OP_SBRAPOS || opcode == OP_SCBRAPOS)      if (opcode == OP_SBRAPOS || opcode == OP_SCBRAPOS)
# Line 6003  while (*cc != OP_KETRPOS) Line 6319  while (*cc != OP_KETRPOS)
6319    
6320    if (framesize < 0)    if (framesize < 0)
6321      {      {
6322      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6323        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6324      else      else
6325        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6326      }      }
6327    else    else
6328      {      {
6329      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6330        {        {
6331        /* Last alternative. */        /* Last alternative. */
6332        if (*cc == OP_KETRPOS)        if (*cc == OP_KETRPOS)
6333          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6334        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6335        }        }
6336      else      else
6337        {        {
6338        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6339        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP2), (framesize + 1) * sizeof(sljit_w));        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP2), (framesize + 1) * sizeof(sljit_sw));
6340        }        }
6341      }      }
6342    
# Line 6034  if (!zero) Line 6350  if (!zero)
6350    {    {
6351    if (framesize < 0)    if (framesize < 0)
6352      add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(stacksize - 1), SLJIT_IMM, 0));      add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(stacksize - 1), SLJIT_IMM, 0));
6353    else /* TMP2 is set to [localptr] above. */    else /* TMP2 is set to [private_data_ptr] above. */
6354      add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(TMP2), (stacksize - 1) * sizeof(sljit_w), SLJIT_IMM, 0));      add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(TMP2), (stacksize - 1) * sizeof(sljit_sw), SLJIT_IMM, 0));
6355    }    }
6356    
6357  /* None of them matched. */  /* None of them matched. */
# Line 6147  pcre_uchar* end; Line 6463  pcre_uchar* end;
6463  jump_list *nomatch = NULL;  jump_list *nomatch = NULL;
6464  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
6465  struct sljit_label *label;  struct sljit_label *label;
6466  int localptr = PRIV_DATA(cc);  int private_data_ptr = PRIVATE_DATA(cc);
6467  int base = (localptr == 0) ? SLJIT_MEM1(STACK_TOP) : SLJIT_MEM1(SLJIT_LOCALS_REG);  int base = (private_data_ptr == 0) ? SLJIT_MEM1(STACK_TOP) : SLJIT_MEM1(SLJIT_LOCALS_REG);
6468  int offset0 = (localptr == 0) ? STACK(0) : localptr;  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;
6469  int offset1 = (localptr == 0) ? STACK(1) : localptr + (int)sizeof(sljit_w);  int offset1 = (private_data_ptr == 0) ? STACK(1) : private_data_ptr + (int)sizeof(sljit_sw);
6470  int tmp_base, tmp_offset;  int tmp_base, tmp_offset;
6471    
6472  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
6473    
6474  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);
6475    
6476  switch (type)  switch(type)
6477    {    {
6478    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
6479    case OP_DIGIT:    case OP_DIGIT:
# Line 6204  switch(opcode) Line 6520  switch(opcode)
6520    case OP_CRRANGE:    case OP_CRRANGE:
6521    if (type == OP_ANYNL || type == OP_EXTUNI)    if (type == OP_ANYNL || type == OP_EXTUNI)
6522      {      {
6523      SLJIT_ASSERT(localptr == 0);      SLJIT_ASSERT(private_data_ptr == 0);
6524      if (opcode == OP_STAR || opcode == OP_UPTO)      if (opcode == OP_STAR || opcode == OP_UPTO)
6525        {        {
6526        allocate_stack(common, 2);        allocate_stack(common, 2);
# Line 6244  switch(opcode) Line 6560  switch(opcode)
6560      {      {
6561      if (opcode == OP_PLUS)      if (opcode == OP_PLUS)
6562        compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);        compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
6563      if (localptr == 0)      if (private_data_ptr == 0)
6564        allocate_stack(common, 2);        allocate_stack(common, 2);
6565      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
6566      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
# Line 6280  switch(opcode) Line 6596  switch(opcode)
6596    case OP_MINPLUS:    case OP_MINPLUS:
6597    if (opcode == OP_MINPLUS)    if (opcode == OP_MINPLUS)
6598      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
6599    if (localptr == 0)    if (private_data_ptr == 0)
6600      allocate_stack(common, 1);      allocate_stack(common, 1);
6601    OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);    OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
6602    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
# Line 6288  switch(opcode) Line 6604  switch(opcode)
6604    
6605    case OP_MINUPTO:    case OP_MINUPTO:
6606    case OP_CRMINRANGE:    case OP_CRMINRANGE:
6607    if (localptr == 0)    if (private_data_ptr == 0)
6608      allocate_stack(common, 2);      allocate_stack(common, 2);
6609    OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);    OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
6610    OP1(SLJIT_MOV, base, offset1, SLJIT_IMM, 1);    OP1(SLJIT_MOV, base, offset1, SLJIT_IMM, 1);
# Line 6299  switch(opcode) Line 6615  switch(opcode)
6615    
6616    case OP_QUERY:    case OP_QUERY:
6617    case OP_MINQUERY:    case OP_MINQUERY:
6618    if (localptr == 0)    if (private_data_ptr == 0)
6619      allocate_stack(common, 1);      allocate_stack(common, 1);
6620    OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);    OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
6621    if (opcode == OP_QUERY)    if (opcode == OP_QUERY)
# Line 6359  static SLJIT_INLINE pcre_uchar *compile_ Line 6675  static SLJIT_INLINE pcre_uchar *compile_
6675  DEFINE_COMPILER;  DEFINE_COMPILER;
6676  backtrack_common *backtrack;  backtrack_common *backtrack;
6677    
6678  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
6679    
6680  if (*cc == OP_FAIL)  if (*cc == OP_FAIL)
6681    {    {
# Line 6370  if (*cc == OP_FAIL) Line 6686  if (*cc == OP_FAIL)
6686  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)
6687    {    {
6688    /* No need to check notempty conditions. */    /* No need to check notempty conditions. */
6689    if (common->acceptlabel == NULL)    if (common->accept_label == NULL)
6690      add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));
6691    else    else
6692      JUMPTO(SLJIT_JUMP, common->acceptlabel);      JUMPTO(SLJIT_JUMP, common->accept_label);
6693    return cc + 1;    return cc + 1;
6694    }    }
6695    
6696  if (common->acceptlabel == NULL)  if (common->accept_label == NULL)
6697    add_jump(compiler, &common->accept, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0)));    add_jump(compiler, &common->accept, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0)));
6698  else  else
6699    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), common->acceptlabel);    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), common->accept_label);
6700  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
6701  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));
6702  add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));  add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
6703  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));
6704  if (common->acceptlabel == NULL)  if (common->accept_label == NULL)
6705    add_jump(compiler, &common->accept, CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0));    add_jump(compiler, &common->accept, CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0));
6706  else  else
6707    CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, common->acceptlabel);    CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, common->accept_label);
6708  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
6709  if (common->acceptlabel == NULL)  if (common->accept_label == NULL)
6710    add_jump(compiler, &common->accept, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0));    add_jump(compiler, &common->accept, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0));
6711  else  else
6712    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, common->acceptlabel);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, common->accept_label);
6713  add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_JUMP));  add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_JUMP));
6714  return cc + 1;  return cc + 1;
6715  }  }
# Line 6402  static SLJIT_INLINE pcre_uchar *compile_ Line 6718  static SLJIT_INLINE pcre_uchar *compile_
6718  {  {
6719  DEFINE_COMPILER;  DEFINE_COMPILER;
6720  int offset = GET2(cc, 1);  int offset = GET2(cc, 1);
6721    BOOL optimized_cbracket = common->optimized_cbracket[offset] != 0;
6722    
6723  /* Data will be discarded anyway... */  /* Data will be discarded anyway... */
6724  if (common->currententry != NULL)  if (common->currententry != NULL)
6725    return cc + 1 + IMM2_SIZE;    return cc + 1 + IMM2_SIZE;
6726    
6727  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR_PRIV(offset));  if (!optimized_cbracket)
6728      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR_PRIV(offset));
6729  offset <<= 1;  offset <<= 1;
6730  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6731  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);  if (!optimized_cbracket)
6732      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6733  return cc + 1 + IMM2_SIZE;  return cc + 1 + IMM2_SIZE;
6734  }  }
6735    
# Line 6549  while (cc < ccend) Line 6868  while (cc < ccend)
6868        cc = compile_char1_matchingpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);        cc = compile_char1_matchingpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
6869      break;      break;
6870