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

Diff of /code/trunk/pcre_jit_compile.c

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

revision 1012 by zherczeg, Sat Aug 25 15:34:13 2012 UTC revision 1249 by zherczeg, Mon Feb 18 09:55:43 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    /* Defines for debugging purposes. */
69    
70    /* 1 - Use unoptimized capturing brackets.
71       2 - Enable capture_last_ptr (includes option 1). */
72    /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */
73    
74  /* Allocate memory for the regex stack on the real machine stack.  /* Allocate memory for the regex stack on the real machine stack.
75  Fast, but limited size. */  Fast, but limited size. */
76  #define MACHINE_STACK_SIZE 32768  #define MACHINE_STACK_SIZE 32768
# Line 157  typedef struct jit_arguments { Line 163  typedef struct jit_arguments {
163    int *offsets;    int *offsets;
164    pcre_uchar *uchar_ptr;    pcre_uchar *uchar_ptr;
165    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
166      void *callout_data;
167    /* Everything else after. */    /* Everything else after. */
168    int offsetcount;    int offset_count;
169    int calllimit;    int call_limit;
170    pcre_uint8 notbol;    pcre_uint8 notbol;
171    pcre_uint8 noteol;    pcre_uint8 noteol;
172    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 170  typedef struct executable_functions { Line 177  typedef struct executable_functions {
177    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
178    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
179    void *userdata;    void *userdata;
180      pcre_uint32 top_bracket;
181    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
182  } executable_functions;  } executable_functions;
183    
# Line 178  typedef struct jump_list { Line 186  typedef struct jump_list {
186    struct jump_list *next;    struct jump_list *next;
187  } jump_list;  } jump_list;
188    
 enum stub_types { stack_alloc };  
   
189  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
190    struct sljit_jump *start;    struct sljit_jump *start;
191    struct sljit_label *quit;    struct sljit_label *quit;
192    struct stub_list *next;    struct stub_list *next;
193  } stub_list;  } stub_list;
194    
195    enum frame_types { no_frame = -1, no_stack = -2 };
196    
197  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
198    
199  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
# Line 269  typedef struct recurse_entry { Line 275  typedef struct recurse_entry {
275    
276  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
277    backtrack_common common;    backtrack_common common;
278      BOOL inlined_pattern;
279  } recurse_backtrack;  } recurse_backtrack;
280    
281  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 6
# Line 288  typedef struct compiler_common { Line 295  typedef struct compiler_common {
295    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
296    int req_char_ptr;    int req_char_ptr;
297    /* Head of the last recursion. */    /* Head of the last recursion. */
298    int recursive_head;    int recursive_head_ptr;
299    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
300    int start_used_ptr;    int start_used_ptr;
301    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 297  typedef struct compiler_common { Line 304  typedef struct compiler_common {
304    int first_line_end;    int first_line_end;
305    /* Points to the marked string. */    /* Points to the marked string. */
306    int mark_ptr;    int mark_ptr;
307      /* Points to the last matched capture block index. */
308      int capture_last_ptr;
309    
310    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
311    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
312    sljit_w lcc;    sljit_sw lcc;
313    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
314    int mode;    int mode;
315    /* Newline control. */    /* Newline control. */
# Line 311  typedef struct compiler_common { Line 320  typedef struct compiler_common {
320    int endonly;    int endonly;
321    BOOL has_set_som;    BOOL has_set_som;
322    /* Tables. */    /* Tables. */
323    sljit_w ctypes;    sljit_sw ctypes;
324    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
325    /* Named capturing brackets. */    /* Named capturing brackets. */
326    sljit_uw name_table;    sljit_uw name_table;
327    sljit_w name_count;    sljit_sw name_count;
328    sljit_w name_entry_size;    sljit_sw name_entry_size;
329    
330    /* Labels and jump lists. */    /* Labels and jump lists. */
331    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
332    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
333    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
334      struct sljit_label *accept_label;
335    stub_list *stubs;    stub_list *stubs;
336    recurse_entry *entries;    recurse_entry *entries;
337    recurse_entry *currententry;    recurse_entry *currententry;
338    jump_list *partialmatch;    jump_list *partialmatch;
339    jump_list *quit;    jump_list *quit;
340      jump_list *forced_quit;
341    jump_list *accept;    jump_list *accept;
342    jump_list *calllimit;    jump_list *calllimit;
343    jump_list *stackalloc;    jump_list *stackalloc;
# Line 343  typedef struct compiler_common { Line 354  typedef struct compiler_common {
354  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
355    BOOL use_ucp;    BOOL use_ucp;
356  #endif  #endif
357    #ifndef COMPILE_PCRE32
358    jump_list *utfreadchar;    jump_list *utfreadchar;
359    #endif
360  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
361    jump_list *utfreadtype8;    jump_list *utfreadtype8;
362  #endif  #endif
# Line 361  typedef struct compare_context { Line 374  typedef struct compare_context {
374  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
375    int ucharptr;    int ucharptr;
376    union {    union {
377      sljit_i asint;      sljit_si asint;
378      sljit_uh asushort;      sljit_uh asushort;
379  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
380      sljit_ub asbyte;      sljit_ub asbyte;
381      sljit_ub asuchars[4];      sljit_ub asuchars[4];
382  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
383      sljit_uh asuchars[2];      sljit_uh asuchars[2];
384  #endif  #elif defined COMPILE_PCRE32
385        sljit_ui asuchars[1];
386  #endif  #endif
387    } c;    } c;
388    union {    union {
389      sljit_i asint;      sljit_si asint;
390      sljit_uh asushort;      sljit_uh asushort;
391  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
392      sljit_ub asbyte;      sljit_ub asbyte;
393      sljit_ub asuchars[4];      sljit_ub asuchars[4];
394  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
395      sljit_uh asuchars[2];      sljit_uh asuchars[2];
396  #endif  #elif defined COMPILE_PCRE32
397        sljit_ui asuchars[1];
398  #endif  #endif
399    } oc;    } oc;
400  #endif  #endif
401  } compare_context;  } compare_context;
402    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
403  /* Undefine sljit macros. */  /* Undefine sljit macros. */
404  #undef CMP  #undef CMP
405    
406  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
407  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
408    
409  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
410  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
411  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
412  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
413  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
414  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
415  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
416  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
417  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
# Line 412  enum { Line 419  enum {
419    
420  /* Local space layout. */  /* Local space layout. */
421  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
422  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
423  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
424  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
425  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
426  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
427  /* Max limit of recursions. */  /* Max limit of recursions. */
428  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
429  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
430  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
431  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
432  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. */
433  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
434  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
435  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_sw))
436  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
437    
438  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
439  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
440  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
441  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
442  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
443  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
444    #elif defined COMPILE_PCRE32
445    #define MOV_UCHAR  SLJIT_MOV_UI
446    #define MOVU_UCHAR SLJIT_MOVU_UI
447  #else  #else
448  #error Unsupported compiling mode  #error Unsupported compiling mode
449  #endif  #endif
 #endif  
450    
451  /* Shortcuts. */  /* Shortcuts. */
452  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 455  the start pointers when the end of the c Line 463  the start pointers when the end of the c
463    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
464  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
465    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
466    #define SET_LABEL(jump, label) \
467      sljit_set_label((jump), (label))
468  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
469    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
470  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
471    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))
472  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
473    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
474  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
475    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
476    
# Line 503  switch(*cc) Line 513  switch(*cc)
513    case OP_WORDCHAR:    case OP_WORDCHAR:
514    case OP_ANY:    case OP_ANY:
515    case OP_ALLANY:    case OP_ALLANY:
516      case OP_NOTPROP:
517      case OP_PROP:
518    case OP_ANYNL:    case OP_ANYNL:
519    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
520    case OP_HSPACE:    case OP_HSPACE:
# Line 515  switch(*cc) Line 527  switch(*cc)
527    case OP_CIRCM:    case OP_CIRCM:
528    case OP_DOLL:    case OP_DOLL:
529    case OP_DOLLM:    case OP_DOLLM:
   case OP_TYPESTAR:  
   case OP_TYPEMINSTAR:  
   case OP_TYPEPLUS:  
   case OP_TYPEMINPLUS:  
   case OP_TYPEQUERY:  
   case OP_TYPEMINQUERY:  
   case OP_TYPEPOSSTAR:  
   case OP_TYPEPOSPLUS:  
   case OP_TYPEPOSQUERY:  
530    case OP_CRSTAR:    case OP_CRSTAR:
531    case OP_CRMINSTAR:    case OP_CRMINSTAR:
532    case OP_CRPLUS:    case OP_CRPLUS:
533    case OP_CRMINPLUS:    case OP_CRMINPLUS:
534    case OP_CRQUERY:    case OP_CRQUERY:
535    case OP_CRMINQUERY:    case OP_CRMINQUERY:
536      case OP_CRRANGE:
537      case OP_CRMINRANGE:
538      case OP_CLASS:
539      case OP_NCLASS:
540      case OP_REF:
541      case OP_REFI:
542      case OP_RECURSE:
543      case OP_CALLOUT:
544      case OP_ALT:
545      case OP_KET:
546      case OP_KETRMAX:
547      case OP_KETRMIN:
548      case OP_KETRPOS:
549      case OP_REVERSE:
550      case OP_ASSERT:
551      case OP_ASSERT_NOT:
552      case OP_ASSERTBACK:
553      case OP_ASSERTBACK_NOT:
554      case OP_ONCE:
555      case OP_ONCE_NC:
556      case OP_BRA:
557      case OP_BRAPOS:
558      case OP_CBRA:
559      case OP_CBRAPOS:
560      case OP_COND:
561      case OP_SBRA:
562      case OP_SBRAPOS:
563      case OP_SCBRA:
564      case OP_SCBRAPOS:
565      case OP_SCOND:
566      case OP_CREF:
567      case OP_NCREF:
568      case OP_RREF:
569      case OP_NRREF:
570    case OP_DEF:    case OP_DEF:
571    case OP_BRAZERO:    case OP_BRAZERO:
572    case OP_BRAMINZERO:    case OP_BRAMINZERO:
# Line 538  switch(*cc) Line 575  switch(*cc)
575    case OP_FAIL:    case OP_FAIL:
576    case OP_ACCEPT:    case OP_ACCEPT:
577    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
578      case OP_CLOSE:
579    case OP_SKIPZERO:    case OP_SKIPZERO:
580    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
581    
582    case OP_CHAR:    case OP_CHAR:
583    case OP_CHARI:    case OP_CHARI:
# Line 557  switch(*cc) Line 589  switch(*cc)
589    case OP_MINPLUS:    case OP_MINPLUS:
590    case OP_QUERY:    case OP_QUERY:
591    case OP_MINQUERY:    case OP_MINQUERY:
592      case OP_UPTO:
593      case OP_MINUPTO:
594      case OP_EXACT:
595    case OP_POSSTAR:    case OP_POSSTAR:
596    case OP_POSPLUS:    case OP_POSPLUS:
597    case OP_POSQUERY:    case OP_POSQUERY:
598      case OP_POSUPTO:
599    case OP_STARI:    case OP_STARI:
600    case OP_MINSTARI:    case OP_MINSTARI:
601    case OP_PLUSI:    case OP_PLUSI:
602    case OP_MINPLUSI:    case OP_MINPLUSI:
603    case OP_QUERYI:    case OP_QUERYI:
604    case OP_MINQUERYI:    case OP_MINQUERYI:
605      case OP_UPTOI:
606      case OP_MINUPTOI:
607      case OP_EXACTI:
608    case OP_POSSTARI:    case OP_POSSTARI:
609    case OP_POSPLUSI:    case OP_POSPLUSI:
610    case OP_POSQUERYI:    case OP_POSQUERYI:
611      case OP_POSUPTOI:
612    case OP_NOTSTAR:    case OP_NOTSTAR:
613    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
614    case OP_NOTPLUS:    case OP_NOTPLUS:
615    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
616    case OP_NOTQUERY:    case OP_NOTQUERY:
617    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
618      case OP_NOTUPTO:
619      case OP_NOTMINUPTO:
620      case OP_NOTEXACT:
621    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
622    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
623    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
624      case OP_NOTPOSUPTO:
625    case OP_NOTSTARI:    case OP_NOTSTARI:
626    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
627    case OP_NOTPLUSI:    case OP_NOTPLUSI:
628    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
629    case OP_NOTQUERYI:    case OP_NOTQUERYI:
630    case OP_NOTMINQUERYI:    case OP_NOTMINQUERYI:
   case OP_NOTPOSSTARI:  
   case OP_NOTPOSPLUSI:  
   case OP_NOTPOSQUERYI:  
   cc += 2;  
 #ifdef SUPPORT_UTF  
   if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
   return cc;  
   
   case OP_UPTO:  
   case OP_MINUPTO:  
   case OP_EXACT:  
   case OP_POSUPTO:  
   case OP_UPTOI:  
   case OP_MINUPTOI:  
   case OP_EXACTI:  
   case OP_POSUPTOI:  
   case OP_NOTUPTO:  
   case OP_NOTMINUPTO:  
   case OP_NOTEXACT:  
   case OP_NOTPOSUPTO:  
631    case OP_NOTUPTOI:    case OP_NOTUPTOI:
632    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
633    case OP_NOTEXACTI:    case OP_NOTEXACTI:
634      case OP_NOTPOSSTARI:
635      case OP_NOTPOSPLUSI:
636      case OP_NOTPOSQUERYI:
637    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
638    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
639  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
640    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
641  #endif  #endif
642    return cc;    return cc;
643    
644    case OP_NOTPROP:    /* Special cases. */
645    case OP_PROP:    case OP_TYPESTAR:
646    return cc + 1 + 2;    case OP_TYPEMINSTAR:
647      case OP_TYPEPLUS:
648      case OP_TYPEMINPLUS:
649      case OP_TYPEQUERY:
650      case OP_TYPEMINQUERY:
651    case OP_TYPEUPTO:    case OP_TYPEUPTO:
652    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
653    case OP_TYPEEXACT:    case OP_TYPEEXACT:
654      case OP_TYPEPOSSTAR:
655      case OP_TYPEPOSPLUS:
656      case OP_TYPEPOSQUERY:
657    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
658    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_NCREF:  
   case OP_RREF:  
   case OP_NRREF:  
   case OP_CLOSE:  
   cc += 1 + IMM2_SIZE;  
   return cc;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   return cc + 1 + 2 * IMM2_SIZE;  
659    
660    case OP_CLASS:    case OP_ANYBYTE:
661    case OP_NCLASS:  #ifdef SUPPORT_UTF
662    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
663    #endif
664      return cc + 1;
665    
666  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
667    case OP_XCLASS:    case OP_XCLASS:
668    return cc + GET(cc, 1);    return cc + GET(cc, 1);
669  #endif  #endif
670    
   case OP_RECURSE:  
   case OP_ASSERT:  
   case OP_ASSERT_NOT:  
   case OP_ASSERTBACK:  
   case OP_ASSERTBACK_NOT:  
   case OP_REVERSE:  
   case OP_ONCE:  
   case OP_ONCE_NC:  
   case OP_BRA:  
   case OP_BRAPOS:  
   case OP_COND:  
   case OP_SBRA:  
   case OP_SBRAPOS:  
   case OP_SCOND:  
   case OP_ALT:  
   case OP_KET:  
   case OP_KETRMAX:  
   case OP_KETRMIN:  
   case OP_KETRPOS:  
   return cc + 1 + LINK_SIZE;  
   
   case OP_CBRA:  
   case OP_CBRAPOS:  
   case OP_SCBRA:  
   case OP_SCBRAPOS:  
   return cc + 1 + LINK_SIZE + IMM2_SIZE;  
   
671    case OP_MARK:    case OP_MARK:
672    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
673    
# Line 764  int private_data_length = 0; Line 759  int private_data_length = 0;
759  pcre_uchar *alternative;  pcre_uchar *alternative;
760  pcre_uchar *name;  pcre_uchar *name;
761  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
762  int space, size, bracketlen, i;  int space, size, i;
763    pcre_uint32 bracketlen;
764    
765  /* 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. */
766  while (cc < ccend)  while (cc < ccend)
# Line 794  while (cc < ccend) Line 790  while (cc < ccend)
790      case OP_BRAPOS:      case OP_BRAPOS:
791      case OP_SBRA:      case OP_SBRA:
792      case OP_SBRAPOS:      case OP_SBRAPOS:
793      private_data_length += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
794      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
795      break;      break;
796    
797      case OP_CBRAPOS:      case OP_CBRAPOS:
798      case OP_SCBRAPOS:      case OP_SCBRAPOS:
799      private_data_length += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
800      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
801      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
802      break;      break;
803    
804      case OP_COND:      case OP_COND:
805      case OP_SCOND:      case OP_SCOND:
806      bracketlen = cc[1 + LINK_SIZE];      /* Only AUTO_CALLOUT can insert this opcode. We do
807      if (bracketlen == OP_CREF)         not intend to support this case. */
808        {      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
809        bracketlen = GET2(cc, 1 + LINK_SIZE + 1);        return -1;
       common->optimized_cbracket[bracketlen] = 0;  
       }  
     else if (bracketlen == OP_NCREF)  
       {  
       bracketlen = GET2(cc, 1 + LINK_SIZE + 1);  
       name = (pcre_uchar *)common->name_table;  
       alternative = name;  
       for (i = 0; i < common->name_count; i++)  
         {  
         if (GET2(name, 0) == bracketlen) break;  
         name += common->name_entry_size;  
         }  
       SLJIT_ASSERT(i != common->name_count);  
   
       for (i = 0; i < common->name_count; i++)  
         {  
         if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)  
           common->optimized_cbracket[GET2(alternative, 0)] = 0;  
         alternative += common->name_entry_size;  
         }  
       }  
810    
811      if (*cc == OP_COND)      if (*cc == OP_COND)
812        {        {
813        /* Might be a hidden SCOND. */        /* Might be a hidden SCOND. */
814        alternative = cc + GET(cc, 1);        alternative = cc + GET(cc, 1);
815        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
816          private_data_length += sizeof(sljit_w);          private_data_length += sizeof(sljit_sw);
817        }        }
818      else      else
819        private_data_length += sizeof(sljit_w);        private_data_length += sizeof(sljit_sw);
820      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
821      break;      break;
822    
823        case OP_CREF:
824        i = GET2(cc, 1);
825        common->optimized_cbracket[i] = 0;
826        cc += 1 + IMM2_SIZE;
827        break;
828    
829        case OP_NCREF:
830        bracketlen = GET2(cc, 1);
831        name = (pcre_uchar *)common->name_table;
832        alternative = name;
833        for (i = 0; i < common->name_count; i++)
834          {
835          if (GET2(name, 0) == bracketlen) break;
836          name += common->name_entry_size;
837          }
838        SLJIT_ASSERT(i != common->name_count);
839    
840        for (i = 0; i < common->name_count; i++)
841          {
842          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
843            common->optimized_cbracket[GET2(alternative, 0)] = 0;
844          alternative += common->name_entry_size;
845          }
846        bracketlen = 0;
847        cc += 1 + IMM2_SIZE;
848        break;
849    
850      case OP_BRA:      case OP_BRA:
851      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
852      break;      break;
# Line 901  while (cc < ccend) Line 903  while (cc < ccend)
903    
904      case OP_RECURSE:      case OP_RECURSE:
905      /* Set its value only once. */      /* Set its value only once. */
906      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
907        {        {
908        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
909        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
910        }        }
911      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
912      break;      break;
913    
914        case OP_CALLOUT:
915        if (common->capture_last_ptr == 0)
916          {
917          common->capture_last_ptr = common->ovector_start;
918          common->ovector_start += sizeof(sljit_sw);
919          }
920        cc += 2 + 2 * LINK_SIZE;
921        break;
922    
923      case OP_MARK:      case OP_MARK:
924      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
925        {        {
926        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
927        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
928        }        }
929      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
930      break;      break;
# Line 926  while (cc < ccend) Line 937  while (cc < ccend)
937      }      }
938    
939    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
940      private_data_length += sizeof(sljit_w) * space;      private_data_length += sizeof(sljit_sw) * space;
941    
942    if (size != 0)    if (size != 0)
943      {      {
# Line 941  while (cc < ccend) Line 952  while (cc < ccend)
952        cc += size;        cc += size;
953      }      }
954    
955    if (bracketlen > 0)    if (bracketlen != 0)
956      {      {
957      if (cc >= end)      if (cc >= end)
958        {        {
# Line 980  while (cc < ccend) Line 991  while (cc < ccend)
991      case OP_SBRAPOS:      case OP_SBRAPOS:
992      case OP_SCOND:      case OP_SCOND:
993      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
994      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
995      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
996      break;      break;
997    
998      case OP_CBRAPOS:      case OP_CBRAPOS:
999      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1000      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1001      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1002      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1003      break;      break;
1004    
# Line 997  while (cc < ccend) Line 1008  while (cc < ccend)
1008      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1009        {        {
1010        common->private_data_ptrs[cc - common->start] = private_data_ptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1011        private_data_ptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1012        }        }
1013      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1014      break;      break;
# Line 1065  while (cc < ccend) Line 1076  while (cc < ccend)
1076    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1077      {      {
1078      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1079      private_data_ptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1080      }      }
1081    
1082    if (size != 0)    if (size != 0)
# Line 1094  while (cc < ccend) Line 1105  while (cc < ccend)
1105    }    }
1106  }  }
1107    
1108  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1109  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)
1110  {  {
1111  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1112  int length = 0;  int length = 0;
1113  BOOL possessive = FALSE;  int possessive = 0;
1114    BOOL stack_restore = FALSE;
1115  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1116  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1117    /* The last capture is a local variable even for recursions. */
1118    BOOL capture_last_found = FALSE;
1119    
1120  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1121    {    {
1122    length = 3;    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1123    possessive = TRUE;    /* This is correct regardless of common->capture_last_ptr. */
1124      capture_last_found = TRUE;
1125    }    }
1126    
1127  cc = next_opcode(common, cc);  cc = next_opcode(common, cc);
# Line 1116  while (cc < ccend) Line 1131  while (cc < ccend)
1131      {      {
1132      case OP_SET_SOM:      case OP_SET_SOM:
1133      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1134        stack_restore = TRUE;
1135      if (!setsom_found)      if (!setsom_found)
1136        {        {
1137        length += 2;        length += 2;
# Line 1126  while (cc < ccend) Line 1142  while (cc < ccend)
1142    
1143      case OP_MARK:      case OP_MARK:
1144      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1145        stack_restore = TRUE;
1146      if (!setmark_found)      if (!setmark_found)
1147        {        {
1148        length += 2;        length += 2;
# Line 1135  while (cc < ccend) Line 1152  while (cc < ccend)
1152      break;      break;
1153    
1154      case OP_RECURSE:      case OP_RECURSE:
1155        stack_restore = TRUE;
1156      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1157        {        {
1158        length += 2;        length += 2;
# Line 1145  while (cc < ccend) Line 1163  while (cc < ccend)
1163        length += 2;        length += 2;
1164        setmark_found = TRUE;        setmark_found = TRUE;
1165        }        }
1166        if (common->capture_last_ptr != 0 && !capture_last_found)
1167          {
1168          length += 2;
1169          capture_last_found = TRUE;
1170          }
1171      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1172      break;      break;
1173    
# Line 1152  while (cc < ccend) Line 1175  while (cc < ccend)
1175      case OP_CBRAPOS:      case OP_CBRAPOS:
1176      case OP_SCBRA:      case OP_SCBRA:
1177      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1178        stack_restore = TRUE;
1179        if (common->capture_last_ptr != 0 && !capture_last_found)
1180          {
1181          length += 2;
1182          capture_last_found = TRUE;
1183          }
1184      length += 3;      length += 3;
1185      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1186      break;      break;
1187    
1188      default:      default:
1189        stack_restore = TRUE;
1190        /* Fall through. */
1191    
1192        case OP_NOT_WORD_BOUNDARY:
1193        case OP_WORD_BOUNDARY:
1194        case OP_NOT_DIGIT:
1195        case OP_DIGIT:
1196        case OP_NOT_WHITESPACE:
1197        case OP_WHITESPACE:
1198        case OP_NOT_WORDCHAR:
1199        case OP_WORDCHAR:
1200        case OP_ANY:
1201        case OP_ALLANY:
1202        case OP_ANYBYTE:
1203        case OP_NOTPROP:
1204        case OP_PROP:
1205        case OP_ANYNL:
1206        case OP_NOT_HSPACE:
1207        case OP_HSPACE:
1208        case OP_NOT_VSPACE:
1209        case OP_VSPACE:
1210        case OP_EXTUNI:
1211        case OP_EODN:
1212        case OP_EOD:
1213        case OP_CIRC:
1214        case OP_CIRCM:
1215        case OP_DOLL:
1216        case OP_DOLLM:
1217        case OP_CHAR:
1218        case OP_CHARI:
1219        case OP_NOT:
1220        case OP_NOTI:
1221    
1222        case OP_EXACT:
1223        case OP_POSSTAR:
1224        case OP_POSPLUS:
1225        case OP_POSQUERY:
1226        case OP_POSUPTO:
1227    
1228        case OP_EXACTI:
1229        case OP_POSSTARI:
1230        case OP_POSPLUSI:
1231        case OP_POSQUERYI:
1232        case OP_POSUPTOI:
1233    
1234        case OP_NOTEXACT:
1235        case OP_NOTPOSSTAR:
1236        case OP_NOTPOSPLUS:
1237        case OP_NOTPOSQUERY:
1238        case OP_NOTPOSUPTO:
1239    
1240        case OP_NOTEXACTI:
1241        case OP_NOTPOSSTARI:
1242        case OP_NOTPOSPLUSI:
1243        case OP_NOTPOSQUERYI:
1244        case OP_NOTPOSUPTOI:
1245    
1246        case OP_TYPEEXACT:
1247        case OP_TYPEPOSSTAR:
1248        case OP_TYPEPOSPLUS:
1249        case OP_TYPEPOSQUERY:
1250        case OP_TYPEPOSUPTO:
1251    
1252        case OP_CLASS:
1253        case OP_NCLASS:
1254        case OP_XCLASS:
1255    
1256      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1257      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1258      break;      break;
1259      }      }
1260    
1261  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1262  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1263    return -1;    return stack_restore ? no_frame : no_stack;
1264    
1265  if (length > 0)  if (length > 0)
1266    return length + 1;    return length + 1;
1267  return -1;  return stack_restore ? no_frame : no_stack;
1268  }  }
1269    
1270  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)
1271  {  {
1272  DEFINE_COMPILER;  DEFINE_COMPILER;
1273  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1274  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1275  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1276    /* The last capture is a local variable even for recursions. */
1277    BOOL capture_last_found = FALSE;
1278  int offset;  int offset;
1279    
1280  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1195  while (cc < ccend) Line 1293  while (cc < ccend)
1293      if (!setsom_found)      if (!setsom_found)
1294        {        {
1295        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1296        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1297        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1298        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1299        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1300        setsom_found = TRUE;        setsom_found = TRUE;
1301        }        }
1302      cc += 1;      cc += 1;
# Line 1209  while (cc < ccend) Line 1307  while (cc < ccend)
1307      if (!setmark_found)      if (!setmark_found)
1308        {        {
1309        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);
1310        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);
1311        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1312        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1313        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1314        setmark_found = TRUE;        setmark_found = TRUE;
1315        }        }
1316      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1222  while (cc < ccend) Line 1320  while (cc < ccend)
1320      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1321        {        {
1322        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1323        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1324        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1325        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1326        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1327        setsom_found = TRUE;        setsom_found = TRUE;
1328        }        }
1329      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1330        {        {
1331        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);
1332        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);
1333        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1334        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1335        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1336        setmark_found = TRUE;        setmark_found = TRUE;
1337        }        }
1338        if (common->capture_last_ptr != 0 && !capture_last_found)
1339          {
1340          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1341          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1342          stackpos += (int)sizeof(sljit_sw);
1343          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1344          stackpos += (int)sizeof(sljit_sw);
1345          capture_last_found = TRUE;
1346          }
1347      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1348      break;      break;
1349    
# Line 1244  while (cc < ccend) Line 1351  while (cc < ccend)
1351      case OP_CBRAPOS:      case OP_CBRAPOS:
1352      case OP_SCBRA:      case OP_SCBRA:
1353      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1354        if (common->capture_last_ptr != 0 && !capture_last_found)
1355          {
1356          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1357          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1358          stackpos += (int)sizeof(sljit_sw);
1359          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1360          stackpos += (int)sizeof(sljit_sw);
1361          capture_last_found = TRUE;
1362          }
1363      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1364      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1365      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1366      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1367      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));
1368      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1369      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1370      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1371      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1372    
1373      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1374      break;      break;
# Line 1263  while (cc < ccend) Line 1379  while (cc < ccend)
1379      break;      break;
1380      }      }
1381    
1382  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1383  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1384  }  }
1385    
# Line 1403  stacktop = STACK(stacktop - 1); Line 1519  stacktop = STACK(stacktop - 1);
1519    
1520  if (!save)  if (!save)
1521    {    {
1522    stackptr += sizeof(sljit_w);    stackptr += sizeof(sljit_sw);
1523    if (stackptr < stacktop)    if (stackptr < stacktop)
1524      {      {
1525      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1526      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1527      tmp1empty = FALSE;      tmp1empty = FALSE;
1528      }      }
1529    if (stackptr < stacktop)    if (stackptr < stacktop)
1530      {      {
1531      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1532      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1533      tmp2empty = FALSE;      tmp2empty = FALSE;
1534      }      }
1535    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
# Line 1425  while (status != end) Line 1541  while (status != end)
1541    switch(status)    switch(status)
1542      {      {
1543      case start:      case start:
1544      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1545      count = 1;      count = 1;
1546      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1547      status = loop;      status = loop;
1548      break;      break;
1549    
# Line 1504  while (status != end) Line 1620  while (status != end)
1620          {          {
1621          count = 2;          count = 2;
1622          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1623          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1624          }          }
1625        cc += 2;        cc += 2;
1626  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1517  while (status != end) Line 1633  while (status != end)
1633          {          {
1634          count = 2;          count = 2;
1635          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1636          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1637          }          }
1638        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1639  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1539  while (status != end) Line 1655  while (status != end)
1655          {          {
1656          count = 2;          count = 2;
1657          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1658          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1659          }          }
1660        cc += 1;        cc += 1;
1661        break;        break;
# Line 1549  while (status != end) Line 1665  while (status != end)
1665          {          {
1666          count = 2;          count = 2;
1667          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1668          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1669          }          }
1670        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1671        break;        break;
# Line 1573  while (status != end) Line 1689  while (status != end)
1689            case 2:            case 2:
1690            count = 2;            count = 2;
1691            srcw[0] = PRIVATE_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1692            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1693            break;            break;
1694    
1695            default:            default:
# Line 1605  while (status != end) Line 1721  while (status != end)
1721          if (!tmp1empty)          if (!tmp1empty)
1722            {            {
1723            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1724            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1725            }            }
1726          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1727          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1616  while (status != end) Line 1732  while (status != end)
1732          if (!tmp2empty)          if (!tmp2empty)
1733            {            {
1734            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1735            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1736            }            }
1737          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1738          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1633  while (status != end) Line 1749  while (status != end)
1749          if (!tmp1empty)          if (!tmp1empty)
1750            {            {
1751            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1752            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1753            }            }
1754          tmp1next = FALSE;          tmp1next = FALSE;
1755          }          }
# Line 1645  while (status != end) Line 1761  while (status != end)
1761          if (!tmp2empty)          if (!tmp2empty)
1762            {            {
1763            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1764            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1765            }            }
1766          tmp1next = TRUE;          tmp1next = TRUE;
1767          }          }
# Line 1660  if (save) Line 1776  if (save)
1776      if (!tmp1empty)      if (!tmp1empty)
1777        {        {
1778        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1779        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1780        }        }
1781      if (!tmp2empty)      if (!tmp2empty)
1782        {        {
1783        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1784        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1785        }        }
1786      }      }
1787    else    else
# Line 1673  if (save) Line 1789  if (save)
1789      if (!tmp2empty)      if (!tmp2empty)
1790        {        {
1791        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1792        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1793        }        }
1794      if (!tmp1empty)      if (!tmp1empty)
1795        {        {
1796        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1797        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1798        }        }
1799      }      }
1800    }    }
# Line 1692  SLJIT_ASSERT(cc == ccend && stackptr == Line 1808  SLJIT_ASSERT(cc == ccend && stackptr ==
1808  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1809  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1810    
1811  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1812  {  {
1813  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1814  }  }
# Line 1703  while (list) Line 1819  while (list)
1819    {    {
1820    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1821    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1822    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1823    list = list->next;    list = list->next;
1824    }    }
1825  }  }
# Line 1719  if (list_item) Line 1835  if (list_item)
1835    }    }
1836  }  }
1837    
1838  static void add_stub(compiler_common *common, enum stub_types type, int data, struct sljit_jump *start)  static void add_stub(compiler_common *common, struct sljit_jump *start)
1839  {  {
1840  DEFINE_COMPILER;  DEFINE_COMPILER;
1841  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1842    
1843  if (list_item)  if (list_item)
1844    {    {
   list_item->type = type;  
   list_item->data = data;  
1845    list_item->start = start;    list_item->start = start;
1846    list_item->quit = LABEL();    list_item->quit = LABEL();
1847    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1743  stub_list* list_item = common->stubs; Line 1857  stub_list* list_item = common->stubs;
1857  while (list_item)  while (list_item)
1858    {    {
1859    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
1860    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
     {  
     case stack_alloc:  
     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));  
     break;  
     }  
1861    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
1862    list_item = list_item->next;    list_item = list_item->next;
1863    }    }
# Line 1768  static SLJIT_INLINE void allocate_stack( Line 1877  static SLJIT_INLINE void allocate_stack(
1877  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
1878  DEFINE_COMPILER;  DEFINE_COMPILER;
1879    
1880  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));
1881  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
1882  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
1883  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1776  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 1885  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
1885  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
1886  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
1887  #endif  #endif
1888  add_stub(common, stack_alloc, 0, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));  add_stub(common, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));
1889  }  }
1890    
1891  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
1892  {  {
1893  DEFINE_COMPILER;  DEFINE_COMPILER;
1894  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));
1895  }  }
1896    
1897  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1792  struct sljit_label *loop; Line 1901  struct sljit_label *loop;
1901  int i;  int i;
1902  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
1903  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
1904  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));
1905  if (length < 8)  if (length < 8)
1906    {    {
1907    for (i = 0; i < length; i++)    for (i = 0; i < length; i++)
1908      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);
1909    }    }
1910  else  else
1911    {    {
1912    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START - sizeof(sljit_sw));
1913    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length);
1914    loop = LABEL();    loop = LABEL();
1915    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);
1916    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);
1917    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
1918    }    }
1919  }  }
# Line 1813  static SLJIT_INLINE void copy_ovector(co Line 1922  static SLJIT_INLINE void copy_ovector(co
1922  {  {
1923  DEFINE_COMPILER;  DEFINE_COMPILER;
1924  struct sljit_label *loop;  struct sljit_label *loop;
1925  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
1926    
1927  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
1928  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));
1929  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);
1930    
1931  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
1932  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
1933    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);
1934  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));
1935  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
1936    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);
1937  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));
1938  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));
1939  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
1940  /* Unlikely, but possible */  /* Unlikely, but possible */
1941  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);
1942  loop = LABEL();  loop = LABEL();
1943  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);
1944  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));
1945  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
1946  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1947  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);
1948  #endif  #endif
1949  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);
1950  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);
1951  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
1952  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
1953    
1954  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
1955  if (topbracket > 1)  if (topbracket > 1)
1956    {    {
1957    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));
1958    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
1959    
1960    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
1961    loop = LABEL();    loop = LABEL();
1962    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)));
1963    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);
1964    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);
1965    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
1966    }    }
1967  else  else
1968    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1866  DEFINE_COMPILER; Line 1975  DEFINE_COMPILER;
1975  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);
1976  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));
1977    
1978  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
1979  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
1980  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));
1981  CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, quit);  CMPTO(SLJIT_C_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
1982    
1983  /* Store match begin and end. */  /* Store match begin and end. */
1984  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));
1985  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));
1986  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);
1987  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);
1988  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1989  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);
1990  #endif  #endif
1991  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);
1992    
1993  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);
1994  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1995  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);
1996  #endif  #endif
1997  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);
1998    
1999  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2000  }  }
# Line 1998  if (c <= 127 && bit == 0x20) Line 2107  if (c <= 127 && bit == 0x20)
2107    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2108    
2109  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2110  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2111    return 0;    return 0;
2112    
2113  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2114    
2115  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2116  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 2017  if (common->utf && c > 127) Line 2126  if (common->utf && c > 127)
2126  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2127  return (0 << 8) | bit;  return (0 << 8) | bit;
2128    
2129  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2130    
 #ifdef COMPILE_PCRE16  
2131  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2132  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2133    {    {
# Line 2030  if (common->utf && c > 65535) Line 2138  if (common->utf && c > 65535)
2138    }    }
2139  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2140  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2141    
2142  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2143  }  }
2144    
2145  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
# Line 2130  static void read_char(compiler_common *c Line 2237  static void read_char(compiler_common *c
2237  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2238  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2239  DEFINE_COMPILER;  DEFINE_COMPILER;
2240  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2241  struct sljit_jump *jump;  struct sljit_jump *jump;
2242  #endif  #endif
2243    
2244  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2245  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2246  if (common->utf)  if (common->utf)
2247    {    {
2248  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2249    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2250  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2251    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2252  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2253    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2254    JUMPHERE(jump);    JUMPHERE(jump);
2255    }    }
2256  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2257  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));
2258  }  }
2259    
# Line 2157  static void peek_char(compiler_common *c Line 2262  static void peek_char(compiler_common *c
2262  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2263  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2264  DEFINE_COMPILER;  DEFINE_COMPILER;
2265  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2266  struct sljit_jump *jump;  struct sljit_jump *jump;
2267  #endif  #endif
2268    
2269  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2270  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2271  if (common->utf)  if (common->utf)
2272    {    {
2273  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2274    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2275  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2276    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2277  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2278    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2279    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2280    JUMPHERE(jump);    JUMPHERE(jump);
2281    }    }
2282  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2283  }  }
2284    
2285  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2286  {  {
2287  /* 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. */
2288  DEFINE_COMPILER;  DEFINE_COMPILER;
2289  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2290  struct sljit_jump *jump;  struct sljit_jump *jump;
2291  #endif  #endif
2292    
# Line 2192  if (common->utf) Line 2295  if (common->utf)
2295    {    {
2296    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2297    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));
2298  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2299    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2300    it is needed in most cases. */    it is needed in most cases. */
2301    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2302    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2303    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2304    JUMPHERE(jump);    JUMPHERE(jump);
2305  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2306    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2307    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2308    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
# Line 2208  if (common->utf) Line 2310  if (common->utf)
2310    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2311    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2312    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);
2313    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2314    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2315    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2316  #endif  #elif defined COMPILE_PCRE32
2317  #endif /* COMPILE_PCRE8 */    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2318      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2319      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2320      JUMPHERE(jump);
2321    #endif /* COMPILE_PCRE[8|16|32] */
2322    return;    return;
2323    }    }
2324  #endif  #endif /* SUPPORT_UTF */
2325  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2326  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));
2327  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2328  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2329  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2330  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2331  #endif  #endif
2332  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2333  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2334  JUMPHERE(jump);  JUMPHERE(jump);
2335  #endif  #endif
2336  }  }
# Line 2233  static void skip_char_back(compiler_comm Line 2339  static void skip_char_back(compiler_comm
2339  {  {
2340  /* 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. */
2341  DEFINE_COMPILER;  DEFINE_COMPILER;
2342  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2343    #if defined COMPILE_PCRE8
2344  struct sljit_label *label;  struct sljit_label *label;
2345    
2346  if (common->utf)  if (common->utf)
# Line 2245  if (common->utf) Line 2352  if (common->utf)
2352    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2353    return;    return;
2354    }    }
2355  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2356  if (common->utf)  if (common->utf)
2357    {    {
2358    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
# Line 2254  if (common->utf) Line 2360  if (common->utf)
2360    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2361    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2362    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);
2363    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2364    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2365    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2366    return;    return;
2367    }    }
2368  #endif  #endif /* COMPILE_PCRE[8|16] */
2369    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2370  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));
2371  }  }
2372    
# Line 2276  if (nltype == NLTYPE_ANY) Line 2383  if (nltype == NLTYPE_ANY)
2383  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2384    {    {
2385    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);
2386    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2387    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);
2388    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);
2389    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));
2390    }    }
2391  else  else
# Line 2290  else Line 2397  else
2397    
2398  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2399    
2400  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2401  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2402  {  {
2403  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
# Line 2378  sljit_emit_fast_return(compiler, RETURN_ Line 2485  sljit_emit_fast_return(compiler, RETURN_
2485  JUMPHERE(jump);  JUMPHERE(jump);
2486    
2487  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2488  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);
2489  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2490  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2491  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2492  }  }
2493    
2494  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2495    
 #ifdef COMPILE_PCRE16  
2496  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2497  {  {
2498  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char
# Line 2411  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC Line 2517  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2517  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2518  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2519  }  }
 #endif /* COMPILE_PCRE16 */  
2520    
2521  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2522    
2523  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2524    
# Line 2433  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2538  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2538    
2539  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2540  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2541  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));
2542  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2543  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2544  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2545  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2546  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2547  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));
2548  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2549  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2550  }  }
# Line 2453  struct sljit_label *newlinelabel = NULL; Line 2558  struct sljit_label *newlinelabel = NULL;
2558  struct sljit_jump *start;  struct sljit_jump *start;
2559  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2560  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2561  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2562  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2563  #endif  #endif
2564  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2508  if (newlinecheck) Line 2613  if (newlinecheck)
2613    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2614    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2615    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);
2616    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2617  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2618    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2619  #endif  #endif
2620    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2621    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2531  if (newlinecheck) Line 2636  if (newlinecheck)
2636    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);
2637    
2638  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));
2639  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2640    #if defined COMPILE_PCRE8
2641  if (common->utf)  if (common->utf)
2642    {    {
2643    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2644    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);
2645    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2646    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2647    }    }
2648  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2649  if (common->utf)  if (common->utf)
2650    {    {
2651    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2652    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2653    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);
2654    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2655    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2656    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2657    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2658    }    }
2659  #endif  #endif /* COMPILE_PCRE[8|16] */
2660    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2661  JUMPHERE(start);  JUMPHERE(start);
2662    
2663  if (newlinecheck)  if (newlinecheck)
# Line 2563  if (newlinecheck) Line 2669  if (newlinecheck)
2669  return mainloop;  return mainloop;
2670  }  }
2671    
2672  static SLJIT_INLINE BOOL fast_forward_first_two_chars(compiler_common *common, BOOL firstline)  #define MAX_N_CHARS 3
2673    
2674    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2675  {  {
2676  DEFINE_COMPILER;  DEFINE_COMPILER;
2677  struct sljit_label *start;  struct sljit_label *start;
2678  struct sljit_jump *quit;  struct sljit_jump *quit;
2679  struct sljit_jump *found;  pcre_uint32 chars[MAX_N_CHARS * 2];
2680  pcre_int32 chars[4];  pcre_uchar *cc = common->start + 1 + LINK_SIZE;
 pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  
2681  int location = 0;  int location = 0;
2682  pcre_int32 len, c, bit, caseless;  pcre_int32 len, c, bit, caseless;
2683  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  
2684    
2685    /* We do not support alternatives now. */
2686  if (*(common->start + GET(common->start, 1)) == OP_ALT)  if (*(common->start + GET(common->start, 1)) == OP_ALT)
2687    return FALSE;    return FALSE;
2688    
2689  while (TRUE)  while (TRUE)
2690    {    {
2691    caseless = 0;    caseless = 0;
2692    must_end = TRUE;    must_stop = 1;
2693    switch(*cc)    switch(*cc)
2694      {      {
2695      case OP_CHAR:      case OP_CHAR:
2696      must_end = FALSE;      must_stop = 0;
2697      cc++;      cc++;
2698      break;      break;
2699    
2700      case OP_CHARI:      case OP_CHARI:
2701      caseless = 1;      caseless = 1;
2702      must_end = FALSE;      must_stop = 0;
2703      cc++;      cc++;
2704      break;      break;
2705    
# Line 2645  while (TRUE) Line 2741  while (TRUE)
2741      break;      break;
2742    
2743      default:      default:
2744      return FALSE;      must_stop = 2;
2745        break;
2746      }      }
2747    
2748      if (must_stop == 2)
2749          break;
2750    
2751    len = 1;    len = 1;
2752  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2753    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
# Line 2670  while (TRUE) Line 2770  while (TRUE)
2770    else    else
2771      caseless = 0;      caseless = 0;
2772    
2773    while (len > 0 && location < 2 * 2)    while (len > 0 && location < MAX_N_CHARS * 2)
2774      {      {
2775      c = *cc;      c = *cc;
2776      bit = 0;      bit = 0;
# Line 2688  while (TRUE) Line 2788  while (TRUE)
2788      cc++;      cc++;
2789      }      }
2790    
2791    if (location == 2 * 2)    if (location >= MAX_N_CHARS * 2 || must_stop != 0)
2792      break;      break;
   else if (must_end)  
     return FALSE;  
2793    }    }
2794    
2795    /* At least two characters are required. */
2796    if (location < 2 * 2)
2797        return FALSE;
2798    
2799  if (firstline)  if (firstline)
2800    {    {
2801    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
2802    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2803    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));
2804    }    }
2805  else  else
2806    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));
2807    
2808  start = LABEL();  start = LABEL();
2809  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  
2810    
2811  #else /* SLJIT_UNALIGNED */  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
   
 #if defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN  
 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 */  
2812  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2813  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2814  #endif /* SLJIT_BIG_ENDIAN */  if (chars[1] != 0)
2815      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
2816  #ifdef COMPILE_PCRE8  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
2817  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 8);  if (location > 2 * 2)
2818  #else /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2819  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 16);  if (chars[3] != 0)
2820  #endif    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
2821  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
2822    if (location > 2 * 2)
2823  #endif    {
2824      if (chars[5] != 0)
2825  if (chars[1] != 0 || chars[3] != 0)      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
2826    {    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);  
2827    }    }
2828    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2829    
 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);  
2830  JUMPHERE(quit);  JUMPHERE(quit);
2831    
2832  if (firstline)  if (firstline)
2833    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2834  else  else
2835    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));
2836  return TRUE;  return TRUE;
2837  }  }
2838    
2839    #undef MAX_N_CHARS
2840    
2841  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)
2842  {  {
2843  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2787  if (first_char == oc) Line 2871  if (first_char == oc)
2871  else  else
2872    {    {
2873    bit = first_char ^ oc;    bit = first_char ^ oc;
2874    if (ispowerof2(bit))    if (is_powerof2(bit))
2875      {      {
2876      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
2877      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
# Line 2795  else Line 2879  else
2879    else    else
2880      {      {
2881      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);
2882      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2883      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);
2884      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);
2885      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
2886      }      }
2887    }    }
# Line 2839  if (common->nltype == NLTYPE_FIXED && co Line 2923  if (common->nltype == NLTYPE_FIXED && co
2923    
2924    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
2925    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);
2926    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
2927  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2928    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
2929  #endif  #endif
2930    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2931    
# Line 2882  if (common->nltype == NLTYPE_ANY || comm Line 2966  if (common->nltype == NLTYPE_ANY || comm
2966    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2967    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2968    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);
2969    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2970  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2971    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2972  #endif  #endif
2973    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2974    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
# Line 2897  if (firstline) Line 2981  if (firstline)
2981    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2982  }  }
2983    
2984    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
2985    
2986  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)
2987  {  {
2988  DEFINE_COMPILER;  DEFINE_COMPILER;
2989  struct sljit_label *start;  struct sljit_label *start;
2990  struct sljit_jump *quit;  struct sljit_jump *quit;
2991  struct sljit_jump *found;  struct sljit_jump *found = NULL;
2992    jump_list *matches = NULL;
2993    pcre_uint8 inverted_start_bits[32];
2994    int i;
2995  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
2996  struct sljit_jump *jump;  struct sljit_jump *jump;
2997  #endif  #endif
2998    
2999    for (i = 0; i < 32; ++i)
3000      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3001    
3002  if (firstline)  if (firstline)
3003    {    {
3004    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
# Line 2921  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3013  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3013  if (common->utf)  if (common->utf)
3014    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3015  #endif  #endif
3016    
3017    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3018      {
3019  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3020  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3021  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3022  JUMPHERE(jump);    JUMPHERE(jump);
3023  #endif  #endif
3024  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3025  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3026  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3027  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3028  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);
3029  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3030      }
3031    
3032  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3033  if (common->utf)  if (common->utf)
3034    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3035  #endif  #endif
3036  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));
3037  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3038    #if defined COMPILE_PCRE8
3039  if (common->utf)  if (common->utf)
3040    {    {
3041    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3042    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);
3043    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3044    }    }
3045  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3046  if (common->utf)  if (common->utf)
3047    {    {
3048    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3049    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3050    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);
3051    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3052    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3053    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3054    }    }
3055  #endif  #endif /* COMPILE_PCRE[8|16] */
3056    #endif /* SUPPORT_UTF */
3057  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3058  JUMPHERE(found);  if (found != NULL)
3059      JUMPHERE(found);
3060    if (matches != NULL)
3061      set_jumps(matches, LABEL());
3062  JUMPHERE(quit);  JUMPHERE(quit);
3063    
3064  if (firstline)  if (firstline)
# Line 2974  struct sljit_jump *alreadyfound; Line 3074  struct sljit_jump *alreadyfound;
3074  struct sljit_jump *found;  struct sljit_jump *found;
3075  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3076  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3077  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3078    
3079  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3080  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
# Line 3005  if (req_char == oc) Line 3105  if (req_char == oc)
3105  else  else
3106    {    {
3107    bit = req_char ^ oc;    bit = req_char ^ oc;
3108    if (ispowerof2(bit))    if (is_powerof2(bit))
3109      {      {
3110      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3111      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
# Line 3041  GET_LOCAL_BASE(TMP3, 0, 0); Line 3141  GET_LOCAL_BASE(TMP3, 0, 0);
3141  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3142  mainloop = LABEL();  mainloop = LABEL();
3143  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3144  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);
3145    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3146    
3147  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3148  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));
3149  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));
3150  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));
3151  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3152    
3153  JUMPHERE(jump);  JUMPHERE(jump);
3154  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3155  /* End of dropping frames. */  /* End of dropping frames. */
3156  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3157    
3158  JUMPHERE(jump);  JUMPHERE(jump);
3159  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3160  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3161  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3162  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));  
3163  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3164  }  }
3165    
# Line 3107  if (common->use_ucp) Line 3192  if (common->use_ucp)
3192    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3193    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3194    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);
3195    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3196    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);
3197    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);
3198    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3199    JUMPHERE(jump);    JUMPHERE(jump);
3200    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3201    }    }
# Line 3151  if (common->use_ucp) Line 3236  if (common->use_ucp)
3236    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3237    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3238    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);
3239    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3240    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);
3241    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);
3242    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3243    JUMPHERE(jump);    JUMPHERE(jump);
3244    }    }
3245  else  else
# Line 3235  switch(ranges[0]) Line 3320  switch(ranges[0])
3320        }        }
3321      return TRUE;      return TRUE;
3322      }      }
3323    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]))
3324      {      {
3325      if (readch)      if (readch)
3326        read_char(common);        read_char(common);
# Line 3334  sljit_emit_fast_enter(compiler, RETURN_A Line 3419  sljit_emit_fast_enter(compiler, RETURN_A
3419    
3420  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3421  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);
3422  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3423  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);
3424  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3425  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3426  if (common->utf)  if (common->utf)
3427    {    {
3428  #endif  #endif
3429    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3430    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3431    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);
3432  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3433    }    }
3434  #endif  #endif
3435  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3436  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);
3437  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3438  }  }
3439    
# Line 3360  DEFINE_COMPILER; Line 3445  DEFINE_COMPILER;
3445  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3446    
3447  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);
3448  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3449  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);
3450  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3451  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);
3452  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3453  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3454  if (common->utf)  if (common->utf)
3455    {    {
3456  #endif  #endif
3457    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3458    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);
3459    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3460    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);
3461    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3462    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3463    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);
3464    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3465    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);
3466    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3467    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);
3468    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3469    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);
3470  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3471    }    }
3472  #endif  #endif
3473  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3474  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);
3475    
3476  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3477  }  }
# Line 3400  sljit_emit_fast_enter(compiler, RETURN_A Line 3485  sljit_emit_fast_enter(compiler, RETURN_A
3485    
3486  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3487  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);
3488  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3489  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);
3490  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3491  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3492  if (common->utf)  if (common->utf)
3493    {    {
3494  #endif  #endif
3495    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);
3496    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3497    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);
3498  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3499    }    }
3500  #endif  #endif
3501  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3502  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);
3503    
3504  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3505  }  }
# Line 3500  sljit_emit_fast_return(compiler, RETURN_ Line 3585  sljit_emit_fast_return(compiler, RETURN_
3585    
3586  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3587    
3588  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)
3589  {  {
3590  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3591  int c1, c2;  pcre_uint32 c1, c2;
3592  const pcre_uchar *src2 = args->uchar_ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3593  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
3594    const ucd_record *ur;
3595    const pcre_uint32 *pp;
3596    
3597  while (src1 < end1)  while (src1 < end1)
3598    {    {
# Line 3513  while (src1 < end1) Line 3600  while (src1 < end1)
3600      return (pcre_uchar*)1;      return (pcre_uchar*)1;
3601    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3602    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3603    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return NULL;    ur = GET_UCD(c2);
3604      if (c1 != c2 && c1 != c2 + ur->other_case)
3605        {
3606        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3607        for (;;)
3608          {
3609          if (c1 < *pp) return NULL;
3610          if (c1 == *pp++) break;
3611          }
3612        }
3613    }    }
3614  return src2;  return src2;
3615  }  }
# Line 3535  if (caseless && char_has_othercase(commo Line 3631  if (caseless && char_has_othercase(commo
3631    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3632    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3633    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3634  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3635    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3636    othercasebit &= 0xff;    othercasebit &= 0xff;
3637  #else  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3638  #ifdef COMPILE_PCRE16    /* Note that this code only handles characters in the BMP. If there
3639      ever are characters outside the BMP whose othercase differs in only one
3640      bit from itself (there currently are none), this code will need to be
3641      revised for COMPILE_PCRE32. */
3642    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3643    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3644      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
3645    else    else
3646      othercasebit &= 0xff;      othercasebit &= 0xff;
3647  #endif  #endif /* COMPILE_PCRE[8|16|32] */
 #endif  
3648    }    }
3649    
3650  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3651    {    {
3652  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3653  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3654    if (context->length >= 4)    if (context->length >= 4)
3655      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
# Line 3560  if (context->sourcereg == -1) Line 3658  if (context->sourcereg == -1)
3658    else    else
3659  #endif  #endif
3660      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3661  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
3662  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3663    if (context->length >= 4)    if (context->length >= 4)
3664      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3665    else    else
3666  #endif  #endif
3667      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3668  #endif  #elif defined COMPILE_PCRE32
3669  #endif /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3670    #endif /* COMPILE_PCRE[8|16|32] */
3671    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3672    }    }
3673    
# Line 3583  do Line 3681  do
3681  #endif  #endif
3682    
3683    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3684  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3685    
3686    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3687    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3598  do Line 3696  do
3696      }      }
3697    context->ucharptr++;    context->ucharptr++;
3698    
3699  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3700    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))
3701  #else  #else
3702    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
# Line 3606  do Line 3704  do
3704      {      {
3705      if (context->length >= 4)      if (context->length >= 4)
3706        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  
3707      else if (context->length >= 2)      else if (context->length >= 2)
3708        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);
3709    #if defined COMPILE_PCRE8
3710      else if (context->length >= 1)      else if (context->length >= 1)
3711        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);
3712  #else  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3713      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3714    
3715      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3648  do Line 3743  do
3743    
3744  #else  #else
3745    
3746    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3747  #ifdef COMPILE_PCRE8    if (context->length >= 1)
3748    if (context->length > 0)      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3749      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  
3750    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3751    
3752    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3705  static void compile_xclass_matchingpath( Line 3796  static void compile_xclass_matchingpath(
3796  DEFINE_COMPILER;  DEFINE_COMPILER;
3797  jump_list *found = NULL;  jump_list *found = NULL;
3798  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;
3799  unsigned int c;  pcre_int32 c, charoffset;
3800  int compares;  const pcre_uint32 *other_cases;
3801  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
3802  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
3803    int compares, invertcmp, numberofcmps;
3804  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3805  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
3806  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
3807  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
3808  unsigned int typeoffset;  pcre_int32 typeoffset;
3809  #endif  #endif
 int invertcmp, numberofcmps;  
 unsigned int charoffset;  
3810    
3811  /* Although SUPPORT_UTF must be defined, we are  /* Although SUPPORT_UTF must be defined, we are
3812     not necessary in utf mode even in 8 bit mode. */     not necessary in utf mode even in 8 bit mode. */
# Line 3737  if ((*cc++ & XCL_MAP) != 0) Line 3827  if ((*cc++ & XCL_MAP) != 0)
3827      {      {
3828      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3829      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3830      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
3831      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3832      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);
3833      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
# Line 3814  while (*cc != XCL_END) Line 3904  while (*cc != XCL_END)
3904        needschar = TRUE;        needschar = TRUE;
3905        break;        break;
3906    
3907          case PT_CLIST:
3908          needschar = TRUE;
3909          break;
3910    
3911        default:        default:
3912        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
3913        break;        break;
# Line 3850  if (needstype || needsscript) Line 3944  if (needstype || needsscript)
3944      {      {
3945      if (scriptreg == TMP1)      if (scriptreg == TMP1)
3946        {        {
3947        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));
3948        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
3949        }        }
3950      else      else
3951        {        {
3952        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
3953        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));
3954        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
3955        }        }
3956      }      }
# Line 3892  while (*cc != XCL_END) Line 3986  while (*cc != XCL_END)
3986      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
3987        {        {
3988        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);
3989        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);
3990        numberofcmps++;        numberofcmps++;
3991        }        }
3992      else if (numberofcmps > 0)      else if (numberofcmps > 0)
3993        {        {
3994        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);
3995        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);
3996        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
3997        numberofcmps = 0;        numberofcmps = 0;
3998        }        }
# Line 3931  while (*cc != XCL_END) Line 4025  while (*cc != XCL_END)
4025      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4026        {        {
4027        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);
4028        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);
4029        numberofcmps++;        numberofcmps++;
4030        }        }
4031      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4032        {        {
4033        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);
4034        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);
4035        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4036        numberofcmps = 0;        numberofcmps = 0;
4037        }        }
# Line 3968  while (*cc != XCL_END) Line 4062  while (*cc != XCL_END)
4062    
4063        case PT_LAMP:        case PT_LAMP:
4064        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);
4065        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4066        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);
4067        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4068        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);
4069        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);
4070        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4071        break;        break;
4072    
# Line 3999  while (*cc != XCL_END) Line 4093  while (*cc != XCL_END)
4093          }          }
4094        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4095        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);
4096        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4097        if (*cc == PT_SPACE)        if (*cc == PT_SPACE)
4098          JUMPHERE(jump);          JUMPHERE(jump);
4099    
4100        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4101        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);
4102        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);
4103        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4104        break;        break;
4105    
4106        case PT_WORD:        case PT_WORD:
4107        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);
4108        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4109        /* ... fall through */        /* Fall through. */
4110    
4111        case PT_ALNUM:        case PT_ALNUM:
4112        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
4113        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);
4114        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);
4115        SET_TYPE_OFFSET(ucp_Nd);        SET_TYPE_OFFSET(ucp_Nd);
4116        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);
4117        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);
4118          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4119          break;
4120    
4121          case PT_CLIST:
4122          other_cases = PRIV(ucd_caseless_sets) + cc[1];
4123    
4124          /* At least three characters are required.
4125             Otherwise this case would be handled by the normal code path. */
4126          SLJIT_ASSERT(other_cases[0] != NOTACHAR && other_cases[1] != NOTACHAR && other_cases[2] != NOTACHAR);
4127          SLJIT_ASSERT(other_cases[0] < other_cases[1] && other_cases[1] < other_cases[2]);
4128    
4129          /* Optimizing character pairs, if their difference is power of 2. */
4130          if (is_powerof2(other_cases[1] ^ other_cases[0]))
4131            {
4132            if (charoffset == 0)
4133              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4134            else
4135              {
4136              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4137              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4138              }
4139            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[1]);
4140            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4141            other_cases += 2;
4142            }
4143          else if (is_powerof2(other_cases[2] ^ other_cases[1]))
4144            {
4145            if (charoffset == 0)
4146              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[2] ^ other_cases[1]);
4147            else
4148              {
4149              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4150              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4151              }
4152            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[2]);
4153            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4154    
4155            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, other_cases[0] - charoffset);
4156            OP_FLAGS(SLJIT_OR | ((other_cases[3] == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4157    
4158            other_cases += 3;
4159            }
4160          else
4161            {
4162            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4163            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4164            }
4165    
4166          while (*other_cases != NOTACHAR)
4167            {
4168            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4169            OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4170            }
4171        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4172        break;        break;
4173        }        }
# Line 4138  switch(type) Line 4285  switch(type)
4285      {      {
4286      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4287      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));
4288  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
4289    #if defined COMPILE_PCRE8
4290      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4291      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);
4292      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4293  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
4294      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
4295      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4296      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);
4297      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4298      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4299      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4300  #endif /* COMPILE_PCRE16 */  #endif
 #endif /* COMPILE_PCRE8 */  
4301      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4302    #endif /* COMPILE_PCRE[8|16] */
4303      return cc;      return cc;
4304      }      }
4305  #endif  #endif
# Line 4219  switch(type) Line 4366  switch(type)
4366    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4367    read_char(common);    read_char(common);
4368    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4369    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));
4370    OP1(SLJIT_MOV_UB, TMP3, 0, SLJIT_MEM2(TMP1, TMP2), 3);    /* Optimize register allocation: use a real register. */
4371      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4372      OP1(SLJIT_MOV_UB, STACK_TOP, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4373    
4374    label = LABEL();    label = LABEL();
4375    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);
4376    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
4377    read_char(common);    read_char(common);
4378    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4379    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));
4380    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4381    
4382    OP2(SLJIT_MUL, TMP1, 0, TMP3, 0, SLJIT_IMM, ucp_gbCount);    OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);
4383    OP1(SLJIT_MOV, TMP3, 0, TMP2, 0);    OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STACK_TOP), (sljit_sw)PRIV(ucp_gbtable));
4384    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);    OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);
4385    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(ucp_gbtable));    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4386    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, label);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4387      JUMPTO(SLJIT_C_NOT_ZERO, label);
4388    
4389    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
4390    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4391      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
4392    
4393    if (common->mode == JIT_PARTIAL_HARD_COMPILE)    if (common->mode == JIT_PARTIAL_HARD_COMPILE)
4394      {      {
4395      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 4261  switch(type) Line 4413  switch(type)
4413        {        {
4414        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);
4415        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);
4416        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS);
4417        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);
4418        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);
4419        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));
4420        check_partial(common, TRUE);        check_partial(common, TRUE);
4421        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
# Line 4443  switch(type) Line 4595  switch(type)
4595      }      }
4596    oc = char_othercase(common, c);    oc = char_othercase(common, c);
4597    bit = c ^ oc;    bit = c ^ oc;
4598    if (ispowerof2(bit))    if (is_powerof2(bit))
4599      {      {
4600      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4601      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));
4602      return cc + length;      return cc + length;
4603      }      }
4604    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);
4605    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4606    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);
4607    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);
4608    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4609    return cc + length;    return cc + length;
4610    
# Line 4479  switch(type) Line 4631  switch(type)
4631        /* Skip the variable-length character. */        /* Skip the variable-length character. */
4632        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));
4633        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4634        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);
4635        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4636        JUMPHERE(jump[0]);        JUMPHERE(jump[0]);
4637        return cc + 1;        return cc + 1;
# Line 4504  switch(type) Line 4656  switch(type)
4656      {      {
4657      oc = char_othercase(common, c);      oc = char_othercase(common, c);
4658      bit = c ^ oc;      bit = c ^ oc;
4659      if (ispowerof2(bit))      if (is_powerof2(bit))
4660        {        {
4661        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4662        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 4542  switch(type) Line 4694  switch(type)
4694  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4695    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4696    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4697    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4698    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4699    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);
4700    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 4552  switch(type) Line 4704  switch(type)
4704  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4705    return cc + 32 / sizeof(pcre_uchar);    return cc + 32 / sizeof(pcre_uchar);
4706    
4707  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4708    case OP_XCLASS:    case OP_XCLASS:
4709    compile_xclass_matchingpath(common, cc + LINK_SIZE, backtracks);    compile_xclass_matchingpath(common, cc + LINK_SIZE, backtracks);
4710    return cc + GET(cc, 0) - 1;    return cc + GET(cc, 0) - 1;
# Line 4666  if (!common->jscript_compat) Line 4818  if (!common->jscript_compat)
4818      {      {
4819      /* OVECTOR(1) contains the "string begin - 1" constant. */      /* OVECTOR(1) contains the "string begin - 1" constant. */
4820      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));
4821      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4822      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));
4823      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);
4824      return JUMP(SLJIT_C_NOT_ZERO);      return JUMP(SLJIT_C_NOT_ZERO);
4825      }      }
4826    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 4724  if (withchecks && !common->jscript_compa Line 4876  if (withchecks && !common->jscript_compa
4876  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
4877  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
4878    {    {
4879    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);
4880    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));
4881    if (withchecks)    if (withchecks)
4882      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
4883    
4884    /* Needed to save important temporary registers. */    /* Needed to save important temporary registers. */
4885    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4886    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
4887    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);
4888    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));
4889    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
4890    if (common->mode == JIT_COMPILE)    if (common->mode == JIT_COMPILE)
# Line 4845  if (!minimize) Line 4997  if (!minimize)
4997      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
4998      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
4999      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5000      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));
5001      zerolength = compile_ref_checks(common, ccbegin, NULL);      zerolength = compile_ref_checks(common, ccbegin, NULL);
5002      /* Restore if not zero length. */      /* Restore if not zero length. */
5003      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));
5004      }      }
5005    else    else
5006      {      {
# Line 4941  backtrack_common *backtrack; Line 5093  backtrack_common *backtrack;
5093  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5094  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5095  int start = GET(cc, 1);  int start = GET(cc, 1);
5096    pcre_uchar *start_cc;
5097    
5098  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5099    
5100    /* Inlining simple patterns. */
5101    if (get_framesize(common, common->start + start, TRUE) == no_stack)
5102      {
5103      start_cc = common->start + start;
5104      compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
5105      BACKTRACK_AS(recurse_backtrack)->inlined_pattern = TRUE;
5106      return cc + 1 + LINK_SIZE;
5107      }
5108    
5109  while (entry != NULL)  while (entry != NULL)
5110    {    {
5111    if (entry->start == start)    if (entry->start == start)
# Line 4991  add_jump(compiler, &backtrack->topbacktr Line 5154  add_jump(compiler, &backtrack->topbacktr
5154  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5155  }  }
5156    
5157    static int SLJIT_CALL do_callout(struct jit_arguments* arguments, PUBL(callout_block) *callout_block, pcre_uchar **jit_ovector)
5158    {
5159    const pcre_uchar *begin = arguments->begin;
5160    int *offset_vector = arguments->offsets;
5161    int offset_count = arguments->offset_count;
5162    int i;
5163    
5164    if (PUBL(callout) == NULL)
5165      return 0;
5166    
5167    callout_block->version = 2;
5168    callout_block->callout_data = arguments->callout_data;
5169    
5170    /* Offsets in subject. */
5171    callout_block->subject_length = arguments->end - arguments->begin;
5172    callout_block->start_match = (pcre_uchar*)callout_block->subject - arguments->begin;
5173    callout_block->current_position = (pcre_uchar*)callout_block->offset_vector - arguments->begin;
5174    #if defined COMPILE_PCRE8
5175    callout_block->subject = (PCRE_SPTR)begin;
5176    #elif defined COMPILE_PCRE16
5177    callout_block->subject = (PCRE_SPTR16)begin;
5178    #elif defined COMPILE_PCRE32
5179    callout_block->subject = (PCRE_SPTR32)begin;
5180    #endif
5181    
5182    /* Convert and copy the JIT offset vector to the offset_vector array. */
5183    callout_block->capture_top = 0;
5184    callout_block->offset_vector = offset_vector;
5185    for (i = 2; i < offset_count; i += 2)
5186      {
5187      offset_vector[i] = jit_ovector[i] - begin;
5188      offset_vector[i + 1] = jit_ovector[i + 1] - begin;
5189      if (jit_ovector[i] >= begin)
5190        callout_block->capture_top = i;
5191      }
5192    
5193    callout_block->capture_top = (callout_block->capture_top >> 1) + 1;
5194    if (offset_count > 0)
5195      offset_vector[0] = -1;
5196    if (offset_count > 1)
5197      offset_vector[1] = -1;
5198    return (*PUBL(callout))(callout_block);
5199    }
5200    
5201    /* Aligning to 8 byte. */
5202    #define CALLOUT_ARG_SIZE \
5203        (((int)sizeof(PUBL(callout_block)) + 7) & ~7)
5204    
5205    #define CALLOUT_ARG_OFFSET(arg) \
5206        (-CALLOUT_ARG_SIZE + SLJIT_OFFSETOF(PUBL(callout_block), arg))
5207    
5208    static SLJIT_INLINE pcre_uchar *compile_callout_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5209    {
5210    DEFINE_COMPILER;
5211    backtrack_common *backtrack;
5212    
5213    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
5214    
5215    allocate_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5216    
5217    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5218    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
5219    SLJIT_ASSERT(common->capture_last_ptr != 0);
5220    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
5221    OP1(SLJIT_MOV_UI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
5222    
5223    /* These pointer sized fields temporarly stores internal variables. */
5224    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
5225    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0);
5226    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(subject), TMP2, 0);
5227    
5228    if (common->mark_ptr != 0)
5229      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));
5230    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));
5231    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));
5232    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
5233    
5234    /* Needed to save important temporary registers. */
5235    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5236    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, STACK_TOP, 0, SLJIT_IMM, CALLOUT_ARG_SIZE);
5237    GET_LOCAL_BASE(SLJIT_SCRATCH_REG3, 0, OVECTOR_START);
5238    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout));
5239    OP1(SLJIT_MOV_SI, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0);
5240    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5241    free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5242    
5243    /* Check return value. */
5244    OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
5245    add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_C_SIG_GREATER));
5246    if (common->forced_quit_label == NULL)
5247      add_jump(compiler, &common->forced_quit, JUMP(SLJIT_C_SIG_LESS));
5248    else
5249      JUMPTO(SLJIT_C_SIG_LESS, common->forced_quit_label);
5250    return cc + 2 + 2 * LINK_SIZE;
5251    }
5252    
5253    #undef CALLOUT_ARG_SIZE
5254    #undef CALLOUT_ARG_OFFSET
5255    
5256  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)
5257  {  {
5258  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 5004  jump_list *tmp = NULL; Line 5266  jump_list *tmp = NULL;
5266  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5267  jump_list **found;  jump_list **found;
5268  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5269  struct sljit_label *save_quitlabel = common->quitlabel;  struct sljit_label *save_quit_label = common->quit_label;
5270  struct sljit_label *save_acceptlabel = common->acceptlabel;  struct sljit_label *save_accept_label = common->accept_label;
5271  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5272  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
5273  struct sljit_jump *jump;  struct sljit_jump *jump;
# Line 5054  else Line 5316  else
5316    }    }
5317    
5318  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5319  common->quitlabel = NULL;  common->quit_label = NULL;
5320  common->quit = NULL;  common->quit = NULL;
5321  while (1)  while (1)
5322    {    {
5323    common->acceptlabel = NULL;    common->accept_label = NULL;
5324    common->accept = NULL;    common->accept = NULL;
5325    altbacktrack.top = NULL;    altbacktrack.top = NULL;
5326    altbacktrack.topbacktracks = NULL;    altbacktrack.topbacktracks = NULL;
# Line 5070  while (1) Line 5332  while (1)
5332    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5333    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5334      {      {
5335      common->quitlabel = save_quitlabel;      common->quit_label = save_quit_label;
5336      common->acceptlabel = save_acceptlabel;      common->accept_label = save_accept_label;
5337      common->quit = save_quit;      common->quit = save_quit;
5338      common->accept = save_accept;      common->accept = save_accept;
5339      return NULL;      return NULL;
5340      }      }
5341    common->acceptlabel = LABEL();    common->accept_label = LABEL();
5342    if (common->accept != NULL)    if (common->accept != NULL)
5343      set_jumps(common->accept, common->acceptlabel);      set_jumps(common->accept, common->accept_label);
5344    
5345    /* Reset stack. */    /* Reset stack. */
5346    if (framesize < 0)    if (framesize < 0)
# Line 5087  while (1) Line 5349  while (1)
5349      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
5350        {        {
5351        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
5352        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, 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));
5353        }        }
5354      else      else
5355        {        {
# Line 5107  while (1) Line 5369  while (1)
5369          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5370        else        else
5371          {          {
5372          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));
5373          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));
5374          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
5375          }          }
5376        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));
5377        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5378        }        }
5379      else if (framesize >= 0)      else if (framesize >= 0)
5380        {        {
5381        /* For OP_BRA and OP_BRAMINZERO. */        /* For OP_BRA and OP_BRAMINZERO. */
5382        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, 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));
5383        }        }
5384      }      }
5385    add_jump(compiler, found, JUMP(SLJIT_JUMP));    add_jump(compiler, found, JUMP(SLJIT_JUMP));
# Line 5125  while (1) Line 5387  while (1)
5387    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5388    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5389      {      {
5390      common->quitlabel = save_quitlabel;      common->quit_label = save_quit_label;
5391      common->acceptlabel = save_acceptlabel;      common->accept_label = save_accept_label;
5392      common->quit = save_quit;      common->quit = save_quit;
5393      common->accept = save_accept;      common->accept = save_accept;
5394      return NULL;      return NULL;
# Line 5182  if (opcode == OP_ASSERT || opcode == OP_ Line 5444  if (opcode == OP_ASSERT || opcode == OP_
5444      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5445      /* Keep the STR_PTR on the top of the stack. */      /* Keep the STR_PTR on the top of the stack. */
5446      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5447        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));
5448      else if (bra == OP_BRAMINZERO)      else if (bra == OP_BRAMINZERO)
5449        {        {
5450        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));
5451        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5452        }        }
5453      }      }
# Line 5194  if (opcode == OP_ASSERT || opcode == OP_ Line 5456  if (opcode == OP_ASSERT || opcode == OP_
5456      if (bra == OP_BRA)      if (bra == OP_BRA)
5457        {        {
5458        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
5459        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, 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));
5460        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5461        }        }
5462      else      else
5463        {        {
5464        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
5465        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, 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));
5466        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5467        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);
5468        }        }
# Line 5209  if (opcode == OP_ASSERT || opcode == OP_ Line 5471  if (opcode == OP_ASSERT || opcode == OP_
5471    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
5472      {      {
5473      backtrack->matchingpath = LABEL();      backtrack->matchingpath = LABEL();
5474      sljit_set_label(jump, backtrack->matchingpath);      SET_LABEL(jump, backtrack->matchingpath);
5475      }      }
5476    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
5477      {      {
# Line 5219  if (opcode == OP_ASSERT || opcode == OP_ Line 5481  if (opcode == OP_ASSERT || opcode == OP_
5481        {        {
5482        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5483        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5484        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, 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));
5485        }        }
5486      set_jumps(backtrack->common.topbacktracks, LABEL());      set_jumps(backtrack->common.topbacktracks, LABEL());
5487      }      }
# Line 5266  else Line 5528  else
5528      }      }
5529    }    }
5530    
5531  common->quitlabel = save_quitlabel;  common->quit_label = save_quit_label;
5532  common->acceptlabel = save_acceptlabel;  common->accept_label = save_accept_label;
5533  common->quit = save_quit;  common->quit = save_quit;
5534  common->accept = save_accept;  common->accept = save_accept;
5535  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5536  }  }
5537    
5538  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)
5539  {  {
5540  int condition = FALSE;  int condition = FALSE;
5541  pcre_uchar *slotA = name_table;  pcre_uchar *slotA = name_table;
5542  pcre_uchar *slotB;  pcre_uchar *slotB;
5543  sljit_w name_count = locals[LOCALS0 / sizeof(sljit_w)];  sljit_sw name_count = locals[LOCALS0 / sizeof(sljit_sw)];
5544  sljit_w name_entry_size = locals[LOCALS1 / sizeof(sljit_w)];  sljit_sw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];
5545  sljit_w no_capture;  sljit_sw no_capture;
5546  int i;  int i;
5547    
5548  locals += refno & 0xff;  locals += refno & 0xff;
# Line 5330  if (i < name_count) Line 5592  if (i < name_count)
5592  return condition;  return condition;
5593  }  }
5594    
5595  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)
5596  {  {
5597  int condition = FALSE;  int condition = FALSE;
5598  pcre_uchar *slotA = name_table;  pcre_uchar *slotA = name_table;
5599  pcre_uchar *slotB;  pcre_uchar *slotB;
5600  sljit_w name_count = locals[LOCALS0 / sizeof(sljit_w)];  sljit_uw name_count = locals[LOCALS0 / sizeof(sljit_sw)];
5601  sljit_w name_entry_size = locals[LOCALS1 / sizeof(sljit_w)];  sljit_uw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];
5602  sljit_w group_num = locals[POSSESSIVE0 / sizeof(sljit_w)];  sljit_uw group_num = locals[POSSESSIVE0 / sizeof(sljit_sw)];
5603  int i;  sljit_uw i;
5604    
5605  for (i = 0; i < name_count; i++)  for (i = 0; i < name_count; i++)
5606    {    {
# Line 5493  if (SLJIT_UNLIKELY(opcode == OP_COND) || Line 5755  if (SLJIT_UNLIKELY(opcode == OP_COND) ||
5755      else if (common->currententry->start == 0)      else if (common->currententry->start == 0)
5756        has_alternatives = stacksize != 0;        has_alternatives = stacksize != 0;
5757      else      else
5758        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);
5759      }      }
5760    }    }
5761    
# Line 5577  if (bra == OP_BRAMINZERO) Line 5839  if (bra == OP_BRAMINZERO)
5839          {          {
5840          /* Except when the whole stack frame must be saved. */          /* Except when the whole stack frame must be saved. */
5841          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5842          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));
5843          }          }
5844        JUMPHERE(skip);        JUMPHERE(skip);
5845        }        }
# Line 5612  if (opcode == OP_ONCE) Line 5874  if (opcode == OP_ONCE)
5874        allocate_stack(common, 2);        allocate_stack(common, 2);
5875        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5876        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
5877        OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, 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));
5878        }        }
5879      else if (ket == OP_KETRMAX || has_alternatives)      else if (ket == OP_KETRMAX || has_alternatives)
5880        {        {
# Line 5649  if (opcode == OP_ONCE) Line 5911  if (opcode == OP_ONCE)
5911  else if (opcode == OP_CBRA || opcode == OP_SCBRA)  else if (opcode == OP_CBRA || opcode == OP_SCBRA)
5912    {    {
5913    /* Saving the previous values. */    /* Saving the previous values. */
5914    if (common->optimized_cbracket[offset >> 1] == 0)    if (common->optimized_cbracket[offset >> 1] != 0)
     {  
     allocate_stack(common, 3);  
     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  
     OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);  
     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);  
     }  
   else  
5915      {      {
5916      SLJIT_ASSERT(private_data_ptr == OVECTOR(offset));      SLJIT_ASSERT(private_data_ptr == OVECTOR(offset));
5917      allocate_stack(common, 2);      allocate_stack(common, 2);
5918      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5919      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr + sizeof(sljit_w));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr + sizeof(sljit_sw));
5920      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);
5921      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
5922      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
5923      }      }
5924      else
5925        {
5926        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5927        allocate_stack(common, 1);
5928        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);
5929        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
5930        }
5931    }    }
5932  else if (opcode == OP_SBRA || opcode == OP_SCOND)  else if (opcode == OP_SBRA || opcode == OP_SCOND)
5933    {    {
# Line 5705  if (opcode == OP_COND || opcode == OP_SC Line 5963  if (opcode == OP_COND || opcode == OP_SC
5963      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);
5964      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);
5965      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);
5966      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)));
5967      GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, 0);      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);
5968      OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, common->name_table);      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);
5969      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));
5970      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5971      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));
5972    
5973      JUMPHERE(jump);      JUMPHERE(jump);
5974      matchingpath += 1 + IMM2_SIZE;      matchingpath += 1 + IMM2_SIZE;
# Line 5728  if (opcode == OP_COND || opcode == OP_SC Line 5986  if (opcode == OP_COND || opcode == OP_SC
5986      else if (common->currententry->start == 0)      else if (common->currententry->start == 0)
5987        stacksize = stacksize == 0;        stacksize = stacksize == 0;
5988      else      else
5989        stacksize = stacksize == GET2(common->start, common->currententry->start + 1 + LINK_SIZE);        stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
5990    
5991      if (*matchingpath == OP_RREF || stacksize || common->currententry == NULL)      if (*matchingpath == OP_RREF || stacksize || common->currententry == NULL)
5992        {        {
# Line 5755  if (opcode == OP_COND || opcode == OP_SC Line 6013  if (opcode == OP_COND || opcode == OP_SC
6013        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);
6014        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);
6015        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));
6016        OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, stacksize);        OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, stacksize);
6017        GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, 0);        GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);
6018        OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, common->name_table);        OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);
6019        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));
6020        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
6021        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));
6022        matchingpath += 1 + IMM2_SIZE;        matchingpath += 1 + IMM2_SIZE;
6023        }        }
6024      }      }
# Line 5799  if (opcode == OP_ONCE) Line 6057  if (opcode == OP_ONCE)
6057    else    else
6058      {      {
6059      stacksize = (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives) ? 2 : 1;      stacksize = (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives) ? 2 : 1;
6060      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_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));
6061      if (ket == OP_KETRMAX)      if (ket == OP_KETRMAX)
6062        {        {
6063        /* TMP2 which is set here used by OP_KETRMAX below. */        /* TMP2 which is set here used by OP_KETRMAX below. */
# Line 5811  if (opcode == OP_ONCE) Line 6069  if (opcode == OP_ONCE)
6069  stacksize = 0;  stacksize = 0;
6070  if (ket != OP_KET || bra != OP_BRA)  if (ket != OP_KET || bra != OP_BRA)
6071    stacksize++;    stacksize++;
6072    if (offset != 0)
6073      {
6074      if (common->capture_last_ptr != 0)
6075        stacksize++;
6076      if (common->optimized_cbracket[offset >> 1] == 0)
6077        stacksize += 2;
6078      }
6079  if (has_alternatives && opcode != OP_ONCE)  if (has_alternatives && opcode != OP_ONCE)
6080    stacksize++;    stacksize++;
6081    
# Line 5818  if (stacksize > 0) Line 6083  if (stacksize > 0)
6083    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6084    
6085  stacksize = 0;  stacksize = 0;
6086  if (ket != OP_KET)  if (ket != OP_KET || bra != OP_BRA)
6087    {    {
6088    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);    if (ket != OP_KET)
6089        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6090      else
6091        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
6092    stacksize++;    stacksize++;
6093    }    }
6094  else if (bra != OP_BRA)  
6095    if (offset != 0)
6096    {    {
6097    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);    if (common->capture_last_ptr != 0)
6098    stacksize++;      {
6099        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6100        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6101        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP2, 0);
6102        stacksize++;
6103        }
6104      if (common->optimized_cbracket[offset >> 1] == 0)
6105        {
6106        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6107        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
6108        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6109        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6110        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6111        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6112        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6113        stacksize += 2;
6114        }
6115    }    }
6116    
6117  if (has_alternatives)  if (has_alternatives)
# Line 5838  if (has_alternatives) Line 6123  if (has_alternatives)
6123    }    }
6124    
6125  /* Must be after the matchingpath label. */  /* Must be after the matchingpath label. */
6126  if (offset != 0)  if (offset != 0 && common->optimized_cbracket[offset >> 1] != 0)
6127    {    {
6128    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0));
6129    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);  
6130    }    }
6131    
6132  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
# Line 5956  framesize = get_framesize(common, cc, FA Line 6240  framesize = get_framesize(common, cc, FA
6240  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;
6241  if (framesize < 0)  if (framesize < 0)
6242    {    {
6243    stacksize = (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS) ? 2 : 1;    if (offset != 0)
6244        {
6245        stacksize = 2;
6246        if (common->capture_last_ptr != 0)
6247          stacksize++;
6248        }
6249      else
6250        stacksize = 1;
6251    
6252    if (!zero)    if (!zero)
6253      stacksize++;      stacksize++;
6254    
6255    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
6256    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6257    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    if (framesize == no_frame)
6258        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6259    
6260    if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)    if (offset != 0)
6261      {      {
6262      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6263      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));
6264      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
6265        if (common->capture_last_ptr != 0)
6266          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6267      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6268        if (common->capture_last_ptr != 0)
6269          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
6270      }      }
6271    else    else
6272      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 5984  else Line 6282  else
6282    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)
6283      stacksize++;      stacksize++;
6284    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
   allocate_stack(common, stacksize);  
6285    
6286      allocate_stack(common, stacksize);
6287    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6288    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));
6289    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
6290    
6291    stack = 0;    stack = 0;
6292    if (!zero)    if (!zero)
6293      {      {
# Line 6004  else Line 6303  else
6303    init_frame(common, cc, stacksize - 1, stacksize - framesize, FALSE);    init_frame(common, cc, stacksize - 1, stacksize - framesize, FALSE);
6304    }    }
6305    
6306  if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)  if (offset != 0)
6307    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6308    
6309  loop = LABEL();  loop = LABEL();
# Line 6020  while (*cc != OP_KETRPOS) Line 6319  while (*cc != OP_KETRPOS)
6319    
6320    if (framesize < 0)    if (framesize < 0)
6321      {      {
6322      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      if (framesize == no_frame)
6323          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6324    
6325      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6326        {        {
6327        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6328        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);
6329        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6330          if (common->capture_last_ptr != 0)
6331            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6332        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6333        }        }
6334      else      else
# Line 6044  while (*cc != OP_KETRPOS) Line 6346  while (*cc != OP_KETRPOS)
6346      }      }
6347    else    else
6348      {      {
6349      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6350        {        {
6351        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, 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));
6352        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6353        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);
6354        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6355          if (common->capture_last_ptr != 0)
6356            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6357        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6358        }        }
6359      else      else
6360        {        {
6361        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6362        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));
6363        if (opcode == OP_SBRAPOS)        if (opcode == OP_SBRAPOS)
6364          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));
6365        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);
6366        }        }
6367    
6368      if (opcode == OP_SBRAPOS || opcode == OP_SCBRAPOS)      if (opcode == OP_SBRAPOS || opcode == OP_SCBRAPOS)
# Line 6082  while (*cc != OP_KETRPOS) Line 6386  while (*cc != OP_KETRPOS)
6386    
6387    if (framesize < 0)    if (framesize < 0)
6388      {      {
6389      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6390        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6391      else      else
6392        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6393      }      }
6394    else    else
6395      {      {
6396      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6397        {        {
6398        /* Last alternative. */        /* Last alternative. */
6399        if (*cc == OP_KETRPOS)        if (*cc == OP_KETRPOS)
# Line 6099  while (*cc != OP_KETRPOS) Line 6403  while (*cc != OP_KETRPOS)
6403      else      else
6404        {        {
6405        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6406        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));
6407        }        }
6408      }      }
6409    
# Line 6114  if (!zero) Line 6418  if (!zero)
6418    if (framesize < 0)    if (framesize < 0)
6419      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));
6420    else /* TMP2 is set to [private_data_ptr] above. */    else /* TMP2 is set to [private_data_ptr] above. */
6421      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));
6422    }    }
6423    
6424  /* None of them matched. */  /* None of them matched. */
# Line 6229  struct sljit_label *label; Line 6533  struct sljit_label *label;
6533  int private_data_ptr = PRIVATE_DATA(cc);  int private_data_ptr = PRIVATE_DATA(cc);
6534  int base = (private_data_ptr == 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);
6535  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;
6536  int offset1 = (private_data_ptr == 0) ? STACK(1) : private_data_ptr + (int)sizeof(sljit_w);  int offset1 = (private_data_ptr == 0) ? STACK(1) : private_data_ptr + (int)sizeof(sljit_sw);
6537  int tmp_base, tmp_offset;  int tmp_base, tmp_offset;
6538    
6539  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
6540    
6541  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);
6542    
6543  switch (type)  switch(type)
6544    {    {
6545    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
6546    case OP_DIGIT:    case OP_DIGIT:
# Line 6438  static SLJIT_INLINE pcre_uchar *compile_ Line 6742  static SLJIT_INLINE pcre_uchar *compile_
6742  DEFINE_COMPILER;  DEFINE_COMPILER;
6743  backtrack_common *backtrack;  backtrack_common *backtrack;
6744    
6745  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
6746    
6747  if (*cc == OP_FAIL)  if (*cc == OP_FAIL)
6748    {    {
# Line 6449  if (*cc == OP_FAIL) Line 6753  if (*cc == OP_FAIL)
6753  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)
6754    {    {
6755    /* No need to check notempty conditions. */    /* No need to check notempty conditions. */
6756    if (common->acceptlabel == NULL)    if (common->accept_label == NULL)
6757      add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));
6758    else    else
6759      JUMPTO(SLJIT_JUMP, common->acceptlabel);      JUMPTO(SLJIT_JUMP, common->accept_label);
6760    return cc + 1;    return cc + 1;
6761    }    }
6762    
6763  if (common->acceptlabel == NULL)  if (common->accept_label == NULL)
6764    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)));
6765  else  else
6766    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);
6767  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
6768  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));
6769  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));
6770  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));
6771  if (common->acceptlabel == NULL)  if (common->accept_label == NULL)
6772    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));
6773  else  else
6774    CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, common->acceptlabel);    CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, common->accept_label);
6775  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));
6776  if (common->acceptlabel == NULL)  if (common->accept_label == NULL)
6777    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));
6778  else  else
6779    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);
6780  add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_JUMP));  add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_JUMP));
6781  return cc + 1;  return cc + 1;
6782  }  }
# Line 6631  while (cc < ccend) Line 6935  while (cc < ccend)
6935        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);
6936      break;      break;
6937    
6938  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
6939      case OP_XCLASS:      case OP_XCLASS:
6940      if (*(cc + GET(cc, 1)) >= OP_CRSTAR && *(cc + GET(cc, 1)) <= OP_CRMINRANGE)      if (*(cc + GET(cc, 1)) >= OP_CRSTAR && *(cc + GET(cc, 1)) <= OP_CRMINRANGE)
6941        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
# Line 6652  while (cc < ccend) Line 6956  while (cc < ccend)
6956      cc = compile_recurse_matchingpath(common, cc, parent);      cc = compile_recurse_matchingpath(common, cc, parent);
6957      break;      break;
6958    
6959        case OP_CALLOUT:
6960        cc = compile_callout_matchingpath(common, cc, parent);
6961        break;
6962    
6963      case OP_ASSERT:      case OP_ASSERT:
6964      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
6965      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 6715  while (cc < ccend) Line 7023  while (cc < ccend)
7023      allocate_stack(common, 1);      allocate_stack(common, 1);
7024      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
7025      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
7026      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)(cc + 2));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));
7027      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);
7028      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);
7029      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 6778  jump_list *jumplist = NULL; Line 7086  jump_list *jumplist = NULL;
7086  int private_data_ptr = PRIVATE_DATA(cc);  int private_data_ptr = PRIVATE_DATA(cc);
7087  int base = (private_data_ptr == 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);
7088  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;
7089  int offset1 = (private_data_ptr == 0) ? STACK(1) : private_data_ptr + (int)sizeof(sljit_w);  int offset1 = (private_data_ptr == 0) ? STACK(1) : private_data_ptr + (int)sizeof(sljit_sw);
7090    
7091  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, NULL);  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, NULL);
7092    
# Line 6934  static void compile_recurse_backtracking Line 7242  static void compile_recurse_backtracking
7242  {  {
7243  DEFINE_COMPILER;  DEFINE_COMPILER;
7244    
7245    if (CURRENT_AS(recurse_backtrack)->inlined_pattern)
7246      compile_backtrackingpath(common, current->top);
7247  set_jumps(current->topbacktracks, LABEL());  set_jumps(current->topbacktracks, LABEL());
7248    if (CURRENT_AS(recurse_backtrack)->inlined_pattern)
7249      return;
7250    
7251  if (common->has_set_som && common->mark_ptr != 0)  if (common->has_set_som && common->mark_ptr != 0)
7252    {    {
# Line 7002  if (*cc == OP_ASSERT || *cc == OP_ASSERT Line 7314  if (*cc == OP_ASSERT || *cc == OP_ASSERT
7314    {    {
7315    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(assert_backtrack)->private_data_ptr);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(assert_backtrack)->private_data_ptr);
7316    add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
7317    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(assert_backtrack)->private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(assert_backtrack)->framesize * sizeof(sljit_w));    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(assert_backtrack)->private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(assert_backtrack)->framesize * sizeof(sljit_sw));
7318    
7319    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
7320    }    }
# Line 7012  else Line 7324  else
7324  if (bra == OP_BRAZERO)  if (bra == OP_BRAZERO)
7325    {    {
7326    /* We know there is enough place on the stack. */    /* We know there is enough place on the stack. */
7327    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));
7328    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
7329    JUMPTO(SLJIT_JUMP, CURRENT_AS(assert_backtrack)->matchingpath);    JUMPTO(SLJIT_JUMP, CURRENT_AS(assert_backtrack)->matchingpath);
7330    JUMPHERE(brajump);    JUMPHERE(brajump);
# Line 7083  else if (ket == OP_KETRMIN) Line 7395  else if (ket == OP_KETRMIN)
7395        else        else
7396          {          {
7397          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
7398          CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (CURRENT_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_w), CURRENT_AS(bracket_backtrack)->recursive_matchingpath);          CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (CURRENT_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw), CURRENT_AS(bracket_backtrack)->recursive_matchingpath);
7399          }          }
7400        if (opcode != OP_ONCE)        if (opcode != OP_ONCE)
7401          free_stack(common, 1);          free_stack(common, 1);
# Line 7100  else if (bra == OP_BRAZERO) Line 7412  else if (bra == OP_BRAZERO)
7412    brazero = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0);    brazero = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0);
7413    }    }
7414    
7415    if (offset != 0)
7416      {
7417      if (common->capture_last_ptr != 0)
7418        {
7419        SLJIT_ASSERT(common->optimized_cbracket[offset >> 1] == 0);
7420        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7421        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
7422        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, TMP1, 0);
7423        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
7424        free_stack(common, 3);
7425        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP2, 0);
7426        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
7427        }
7428      else if (common->optimized_cbracket[offset >> 1] == 0)
7429        {
7430        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7431        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
7432        free_stack(common, 2);
7433        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
7434        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);
7435        }
7436      }
7437    
7438  if (SLJIT_UNLIKELY(opcode == OP_ONCE))  if (SLJIT_UNLIKELY(opcode == OP_ONCE))
7439    {    {
7440    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
# Line 7172  if (SLJIT_UNLIKELY(opcode == OP_COND) || Line 7507  if (SLJIT_UNLIKELY(opcode == OP_COND) ||
7507        {        {
7508        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->private_data_ptr);
7509        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
7510        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->private_data_ptr, SLJIT_MEM1(STACK_TOP), assert->framesize * sizeof(sljit_w));        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->private_data_ptr, SLJIT_MEM1(STACK_TOP), assert->framesize * sizeof(sljit_sw));
7511        }        }
7512      cond = JUMP(SLJIT_JUMP);      cond = JUMP(SLJIT_JUMP);
7513      set_jumps(CURRENT_AS(bracket_backtrack)->u.assert->condfailed, LABEL());      set_jumps(CURRENT_AS(bracket_backtrack)->u.assert->condfailed, LABEL());
# Line 7229  if (has_alternatives) Line 7564  if (has_alternatives)
7564          }          }
7565        else        else
7566          {          {
7567          OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (CURRENT_AS(bracket_backtrack)->u.framesize + 2) * sizeof(sljit_w));          OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (CURRENT_AS(bracket_backtrack)->u.framesize + 2) * sizeof(sljit_sw));
7568          if (ket == OP_KETRMAX)          if (ket == OP_KETRMAX)
7569            {            {
7570            /* TMP2 which is set here used by OP_KETRMAX below. */            /* TMP2 which is set here used by OP_KETRMAX below. */
# Line 7239  if (has_alternatives) Line 7574  if (has_alternatives)
7574        }        }
7575    
7576      stacksize = 0;      stacksize = 0;
     if (opcode != OP_ONCE)  
       stacksize++;  
7577      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
7578        stacksize++;        stacksize++;
7579        if (offset != 0)
7580          {
7581          if (common->capture_last_ptr != 0)
7582            stacksize++;
7583          if (common->optimized_cbracket[offset >> 1] == 0)
7584            stacksize += 2;
7585          }
7586        if (opcode != OP_ONCE)
7587          stacksize++;
7588    
7589      if (stacksize > 0) {      if (stacksize > 0) {
7590        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize >= 0)        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
# Line 7251  if (has_alternatives) Line 7593  if (has_alternatives)
7593          {          {
7594          /* We know we have place at least for one item on the top of the stack. */          /* We know we have place at least for one item on the top of the stack. */
7595          SLJIT_ASSERT(stacksize == 1);          SLJIT_ASSERT(stacksize == 1);
7596          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));
7597          }          }
7598      }      }
7599    
# Line 7265  if (has_alternatives) Line 7607  if (has_alternatives)
7607        stacksize++;        stacksize++;
7608        }        }
7609    
7610        if (offset != 0)
7611          {
7612          if (common->capture_last_ptr != 0)
7613            {
7614            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
7615            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
7616            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
7617            stacksize++;
7618            }
7619          if (common->optimized_cbracket[offset >> 1] == 0)
7620            {
7621            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
7622            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
7623            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
7624            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
7625            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
7626            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
7627            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
7628            stacksize += 2;
7629            }
7630          }
7631    
7632      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
7633        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, count++);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, count++);
7634    
7635      if (offset != 0)      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)
7636        {        {
7637        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        /* If ket is not OP_KETRMAX, this code path is executed after the jump to alternative_matchingpath. */
7638          SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0));
7639        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);  
7640        }        }
7641    
7642      JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->alternative_matchingpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->alternative_matchingpath);
# Line 7301  if (has_alternatives) Line 7665  if (has_alternatives)
7665        {        {
7666        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->private_data_ptr);
7667        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
7668        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->private_data_ptr, SLJIT_MEM1(STACK_TOP), assert->framesize * sizeof(sljit_w));        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->private_data_ptr, SLJIT_MEM1(STACK_TOP), assert->framesize * sizeof(sljit_sw));
7669        }        }
7670      JUMPHERE(cond);      JUMPHERE(cond);
7671      }      }
# Line 7314  if (has_alternatives) Line 7678  if (has_alternatives)
7678  if (offset != 0)  if (offset != 0)
7679    {    {
7680    /* Using both tmp register is better for instruction scheduling. */    /* Using both tmp register is better for instruction scheduling. */
7681    if (common->optimized_cbracket[offset >> 1] == 0)    if (common->optimized_cbracket[offset >> 1] != 0)
7682      {      {
7683      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7684      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
7685        free_stack(common, 2);
7686      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2));  
     free_stack(common, 3);  
7687      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);  
7688      }      }
7689    else    else
7690      {      {
7691      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7692      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      free_stack(common, 1);
7693      free_stack(common, 2);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);  
7694      }      }
7695    }    }
7696  else if (opcode == OP_SBRA || opcode == OP_SCOND)  else if (opcode == OP_SBRA || opcode == OP_SCOND)
# Line 7356  else if (opcode == OP_ONCE) Line 7716  else if (opcode == OP_ONCE)
7716    JUMPHERE(once);    JUMPHERE(once);
7717    /* Restore previous private_data_ptr */    /* Restore previous private_data_ptr */
7718    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
7719      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracket_backtrack)->u.framesize * sizeof(sljit_w));      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracket_backtrack)->u.framesize * sizeof(sljit_sw));
7720    else if (ket == OP_KETRMIN)    else if (ket == OP_KETRMIN)
7721      {      {
7722      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
# Line 7417  if (CURRENT_AS(bracketpos_backtrack)->fr Line 7777  if (CURRENT_AS(bracketpos_backtrack)->fr
7777      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7778      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
7779      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
7780        if (common->capture_last_ptr != 0)
7781          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
7782      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);
7783        if (common->capture_last_ptr != 0)
7784          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, TMP1, 0);
7785      }      }
7786    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
7787    free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize);    free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize);
# Line 7435  if (current->topbacktracks) Line 7799  if (current->topbacktracks)
7799    free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize);    free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize);
7800    JUMPHERE(jump);    JUMPHERE(jump);
7801    }    }
7802  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(bracketpos_backtrack)->private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracketpos_backtrack)->framesize * sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(bracketpos_backtrack)->private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracketpos_backtrack)->framesize * sizeof(sljit_sw));
7803  }  }
7804    
7805  static void compile_braminzero_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_braminzero_backtrackingpath(compiler_common *common, struct backtrack_common *current)
# Line 7605  while (current) Line 7969  while (current)
7969    
7970      case OP_COMMIT:      case OP_COMMIT:
7971      OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);      OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);
7972      if (common->quitlabel == NULL)      if (common->quit_label == NULL)
7973        add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));        add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));
7974      else      else
7975        JUMPTO(SLJIT_JUMP, common->quitlabel);        JUMPTO(SLJIT_JUMP, common->quit_label);
7976      break;      break;
7977    
7978        case OP_CALLOUT:
7979      case OP_FAIL:      case OP_FAIL:
7980      case OP_ACCEPT:      case OP_ACCEPT:
7981      case OP_ASSERT_ACCEPT:      case OP_ASSERT_ACCEPT:
# Line 7636  int framesize = get_framesize(common, cc Line 8001  int framesize = get_framesize(common, cc
8001  int alternativesize;  int alternativesize;
8002  BOOL needsframe;  BOOL needsframe;
8003  backtrack_common altbacktrack;  backtrack_common altbacktrack;
8004  struct sljit_label *save_quitlabel = common->quitlabel;  struct sljit_label *save_quit_label = common->quit_label;
8005  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
8006  struct sljit_jump *jump;  struct sljit_jump *jump;
8007    
# Line 7646  if (!needsframe) Line 8011  if (!needsframe)
8011    framesize = 0;    framesize = 0;
8012  alternativesize = *(cc + GET(cc, 1)) == OP_ALT ? 1 : 0;  alternativesize = *(cc + GET(cc, 1)) == OP_ALT ? 1 : 0;
8013    
8014  SLJIT_ASSERT(common->currententry->entry == NULL && common->recursive_head != 0);  SLJIT_ASSERT(common->currententry->entry == NULL && common->recursive_head_ptr != 0);
8015  common->currententry->entry = LABEL();  common->currententry->entry = LABEL();
8016  set_jumps(common->currententry->calls, common->currententry->entry);  set_jumps(common->currententry->calls, common->currententry->entry);
8017    
# Line 7654  sljit_emit_fast_enter(compiler, TMP2, 0) Line 8019  sljit_emit_fast_enter(compiler, TMP2, 0)
8019  allocate_stack(common, private_data_size + framesize + alternativesize);  allocate_stack(common, private_data_size + framesize + alternativesize);
8020  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(private_data_size + framesize + alternativesize - 1), TMP2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(private_data_size + framesize + alternativesize - 1), TMP2, 0);
8021  copy_private_data(common, ccbegin, ccend, TRUE, private_data_size + framesize + alternativesize, framesize + alternativesize);  copy_private_data(common, ccbegin, ccend, TRUE, private_data_size + framesize + alternativesize, framesize + alternativesize);
8022  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head, STACK_TOP, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, STACK_TOP, 0);
8023  if (needsframe)  if (needsframe)
8024    init_frame(common, cc, framesize + alternativesize - 1, alternativesize, TRUE);    init_frame(common, cc, framesize + alternativesize - 1, alternativesize, TRUE);
8025    
# Line 7662  if (alternativesize > 0) Line 8027  if (alternativesize > 0)
8027    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
8028    
8029  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
8030  common->quitlabel = NULL;  common->quit_label = NULL;
8031  common->acceptlabel = NULL;  common->accept_label = NULL;
8032  common->quit = NULL;  common->quit = NULL;
8033  common->accept = NULL;  common->accept = NULL;
8034  altbacktrack.cc = ccbegin;  altbacktrack.cc = ccbegin;
# Line 7679  while (1) Line 8044  while (1)
8044    compile_matchingpath(common, altbacktrack.cc, cc, &altbacktrack);    compile_matchingpath(common, altbacktrack.cc, cc, &altbacktrack);
8045    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
8046      {      {
8047      common->quitlabel = save_quitlabel;      common->quit_label = save_quit_label;
8048      common->quit = save_quit;      common->quit = save_quit;
8049      return;      return;
8050      }      }
# Line 7689  while (1) Line 8054  while (1)
8054    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
8055    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
8056     &nb