/[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 1275 by zherczeg, Sun Mar 10 05:32:10 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11    The machine code generator part (this module) was written by Zoltan Herczeg    The machine code generator part (this module) was written by Zoltan Herczeg
12                        Copyright (c) 2010-2012                        Copyright (c) 2010-2013
13    
14  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
15  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 46  POSSIBILITY OF SUCH DAMAGE. Line 46  POSSIBILITY OF SUCH DAMAGE.
46    
47  #include "pcre_internal.h"  #include "pcre_internal.h"
48    
49  #ifdef SUPPORT_JIT  #if defined SUPPORT_JIT
50    
51  /* All-in-one: Since we use the JIT compiler only from here,  /* All-in-one: Since we use the JIT compiler only from here,
52  we just include it. This way we don't need to touch the build  we just include it. This way we don't need to touch the build
# Line 65  system files. */ Line 65  system files. */
65  #error Unsupported architecture  #error Unsupported architecture
66  #endif  #endif
67    
68    /* Defines for debugging purposes. */
69    
70    /* 1 - Use unoptimized capturing brackets.
71       2 - Enable capture_last_ptr (includes option 1). */
72    /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */
73    
74    /* 1 - Always have a control head. */
75    /* #define DEBUG_FORCE_CONTROL_HEAD 1 */
76    
77  /* Allocate memory for the regex stack on the real machine stack.  /* Allocate memory for the regex stack on the real machine stack.
78  Fast, but limited size. */  Fast, but limited size. */
79  #define MACHINE_STACK_SIZE 32768  #define MACHINE_STACK_SIZE 32768
# Line 157  typedef struct jit_arguments { Line 166  typedef struct jit_arguments {
166    int *offsets;    int *offsets;
167    pcre_uchar *uchar_ptr;    pcre_uchar *uchar_ptr;
168    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
169      void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171    int offsetcount;    int real_offset_count;
172    int calllimit;    int offset_count;
173      int call_limit;
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 170  typedef struct executable_functions { Line 181  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184      pcre_uint32 top_bracket;
185    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
186  } executable_functions;  } executable_functions;
187    
# Line 178  typedef struct jump_list { Line 190  typedef struct jump_list {
190    struct jump_list *next;    struct jump_list *next;
191  } jump_list;  } jump_list;
192    
 enum stub_types { stack_alloc };  
   
193  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
194    struct sljit_jump *start;    struct sljit_jump *start;
195    struct sljit_label *quit;    struct sljit_label *quit;
196    struct stub_list *next;    struct stub_list *next;
197  } stub_list;  } stub_list;
198    
199    enum frame_types {
200      no_frame = -1,
201      no_stack = -2
202    };
203    
204    enum control_types {
205      type_commit = 0,
206      type_prune = 1,
207      type_skip = 2
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
# Line 269  typedef struct recurse_entry { Line 288  typedef struct recurse_entry {
288    
289  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
290    backtrack_common common;    backtrack_common common;
291      BOOL inlined_pattern;
292  } recurse_backtrack;  } recurse_backtrack;
293    
294  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 6
295    
296  typedef struct compiler_common {  typedef struct compiler_common {
297      /* The sljit ceneric compiler. */
298    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
299      /* First byte code. */
300    pcre_uchar *start;    pcre_uchar *start;
   
301    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
302    int *private_data_ptrs;    int *private_data_ptrs;
303    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
304    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
305    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
306    int cbraptr;    int cbra_ptr;
307    /* OVector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
308    int ovector_start;    int ovector_start;
309    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
310    int req_char_ptr;    int req_char_ptr;
311    /* Head of the last recursion. */    /* Head of the last recursion. */
312    int recursive_head;    int recursive_head_ptr;
313    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
314    int start_used_ptr;    int start_used_ptr;
315    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 297  typedef struct compiler_common { Line 318  typedef struct compiler_common {
318    int first_line_end;    int first_line_end;
319    /* Points to the marked string. */    /* Points to the marked string. */
320    int mark_ptr;    int mark_ptr;
321      /* Recursive control verb management chain. */
322      int control_head_ptr;
323      /* Points to the last matched capture block index. */
324      int capture_last_ptr;
325      /* Points to the starting position of the current match. */
326      int start_ptr;
327    
328    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
329    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
330    sljit_w lcc;    sljit_sw lcc;
331    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
332    int mode;    int mode;
333      /* \K is in the pattern. */
334      BOOL has_set_som;
335      /* Needs to know the start position anytime. */
336      BOOL needs_start_ptr;
337      /* Currently in recurse or assert. */
338      BOOL local_exit;
339    /* Newline control. */    /* Newline control. */
340    int nltype;    int nltype;
341    int newline;    int newline;
342    int bsr_nltype;    int bsr_nltype;
343    /* Dollar endonly. */    /* Dollar endonly. */
344    int endonly;    int endonly;
   BOOL has_set_som;  
345    /* Tables. */    /* Tables. */
346    sljit_w ctypes;    sljit_sw ctypes;
347    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
348    /* Named capturing brackets. */    /* Named capturing brackets. */
349    sljit_uw name_table;    sljit_uw name_table;
350    sljit_w name_count;    sljit_sw name_count;
351    sljit_w name_entry_size;    sljit_sw name_entry_size;
352    
353    /* Labels and jump lists. */    /* Labels and jump lists. */
354    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
355    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
356    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
357      struct sljit_label *accept_label;
358    stub_list *stubs;    stub_list *stubs;
359    recurse_entry *entries;    recurse_entry *entries;
360    recurse_entry *currententry;    recurse_entry *currententry;
361    jump_list *partialmatch;    jump_list *partialmatch;
362    jump_list *quit;    jump_list *quit;
363      jump_list *forced_quit;
364    jump_list *accept;    jump_list *accept;
365    jump_list *calllimit;    jump_list *calllimit;
366    jump_list *stackalloc;    jump_list *stackalloc;
# Line 337  typedef struct compiler_common { Line 371  typedef struct compiler_common {
371    jump_list *vspace;    jump_list *vspace;
372    jump_list *casefulcmp;    jump_list *casefulcmp;
373    jump_list *caselesscmp;    jump_list *caselesscmp;
374      jump_list *reset_match;
375    BOOL jscript_compat;    BOOL jscript_compat;
376  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
377    BOOL utf;    BOOL utf;
378  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
379    BOOL use_ucp;    BOOL use_ucp;
380  #endif  #endif
381    #ifndef COMPILE_PCRE32
382    jump_list *utfreadchar;    jump_list *utfreadchar;
383    #endif
384  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
385    jump_list *utfreadtype8;    jump_list *utfreadtype8;
386  #endif  #endif
# Line 361  typedef struct compare_context { Line 398  typedef struct compare_context {
398  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
399    int ucharptr;    int ucharptr;
400    union {    union {
401      sljit_i asint;      sljit_si asint;
402      sljit_uh asushort;      sljit_uh asushort;
403  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
404      sljit_ub asbyte;      sljit_ub asbyte;
405      sljit_ub asuchars[4];      sljit_ub asuchars[4];
406  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
407      sljit_uh asuchars[2];      sljit_uh asuchars[2];
408  #endif  #elif defined COMPILE_PCRE32
409        sljit_ui asuchars[1];
410  #endif  #endif
411    } c;    } c;
412    union {    union {
413      sljit_i asint;      sljit_si asint;
414      sljit_uh asushort;      sljit_uh asushort;
415  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
416      sljit_ub asbyte;      sljit_ub asbyte;
417      sljit_ub asuchars[4];      sljit_ub asuchars[4];
418  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
419      sljit_uh asuchars[2];      sljit_uh asuchars[2];
420  #endif  #elif defined COMPILE_PCRE32
421        sljit_ui asuchars[1];
422  #endif  #endif
423    } oc;    } oc;
424  #endif  #endif
425  } compare_context;  } compare_context;
426    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
427  /* Undefine sljit macros. */  /* Undefine sljit macros. */
428  #undef CMP  #undef CMP
429    
430  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
431  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
432    
433  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
434  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
435  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
436  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
437  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
438  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
439  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
440  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
441  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
# Line 412  enum { Line 443  enum {
443    
444  /* Local space layout. */  /* Local space layout. */
445  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
446  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
447  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
448  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
449  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
450  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
451  /* Max limit of recursions. */  /* Max limit of recursions. */
452  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
453  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
454  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
455  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
456  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. */
457  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
458  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
459  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))
460  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
461    
462  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
463  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
464  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
465  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
466  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
467  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
468    #elif defined COMPILE_PCRE32
469    #define MOV_UCHAR  SLJIT_MOV_UI
470    #define MOVU_UCHAR SLJIT_MOVU_UI
471  #else  #else
472  #error Unsupported compiling mode  #error Unsupported compiling mode
473  #endif  #endif
 #endif  
474    
475  /* Shortcuts. */  /* Shortcuts. */
476  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 455  the start pointers when the end of the c Line 487  the start pointers when the end of the c
487    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
488  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
489    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
490    #define SET_LABEL(jump, label) \
491      sljit_set_label((jump), (label))
492  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
493    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
494  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
495    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))
496  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
497    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
498  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
499    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
500    
# Line 503  switch(*cc) Line 537  switch(*cc)
537    case OP_WORDCHAR:    case OP_WORDCHAR:
538    case OP_ANY:    case OP_ANY:
539    case OP_ALLANY:    case OP_ALLANY:
540      case OP_NOTPROP:
541      case OP_PROP:
542    case OP_ANYNL:    case OP_ANYNL:
543    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
544    case OP_HSPACE:    case OP_HSPACE:
# Line 515  switch(*cc) Line 551  switch(*cc)
551    case OP_CIRCM:    case OP_CIRCM:
552    case OP_DOLL:    case OP_DOLL:
553    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:  
554    case OP_CRSTAR:    case OP_CRSTAR:
555    case OP_CRMINSTAR:    case OP_CRMINSTAR:
556    case OP_CRPLUS:    case OP_CRPLUS:
557    case OP_CRMINPLUS:    case OP_CRMINPLUS:
558    case OP_CRQUERY:    case OP_CRQUERY:
559    case OP_CRMINQUERY:    case OP_CRMINQUERY:
560      case OP_CRRANGE:
561      case OP_CRMINRANGE:
562      case OP_CLASS:
563      case OP_NCLASS:
564      case OP_REF:
565      case OP_REFI:
566      case OP_RECURSE:
567      case OP_CALLOUT:
568      case OP_ALT:
569      case OP_KET:
570      case OP_KETRMAX:
571      case OP_KETRMIN:
572      case OP_KETRPOS:
573      case OP_REVERSE:
574      case OP_ASSERT:
575      case OP_ASSERT_NOT:
576      case OP_ASSERTBACK:
577      case OP_ASSERTBACK_NOT:
578      case OP_ONCE:
579      case OP_ONCE_NC:
580      case OP_BRA:
581      case OP_BRAPOS:
582      case OP_CBRA:
583      case OP_CBRAPOS:
584      case OP_COND:
585      case OP_SBRA:
586      case OP_SBRAPOS:
587      case OP_SCBRA:
588      case OP_SCBRAPOS:
589      case OP_SCOND:
590      case OP_CREF:
591      case OP_NCREF:
592      case OP_RREF:
593      case OP_NRREF:
594    case OP_DEF:    case OP_DEF:
595    case OP_BRAZERO:    case OP_BRAZERO:
596    case OP_BRAMINZERO:    case OP_BRAMINZERO:
597    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
598      case OP_PRUNE:
599      case OP_SKIP:
600    case OP_COMMIT:    case OP_COMMIT:
601    case OP_FAIL:    case OP_FAIL:
602    case OP_ACCEPT:    case OP_ACCEPT:
603    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
604      case OP_CLOSE:
605    case OP_SKIPZERO:    case OP_SKIPZERO:
606    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
607    
608    case OP_CHAR:    case OP_CHAR:
609    case OP_CHARI:    case OP_CHARI:
# Line 557  switch(*cc) Line 615  switch(*cc)
615    case OP_MINPLUS:    case OP_MINPLUS:
616    case OP_QUERY:    case OP_QUERY:
617    case OP_MINQUERY:    case OP_MINQUERY:
618      case OP_UPTO:
619      case OP_MINUPTO:
620      case OP_EXACT:
621    case OP_POSSTAR:    case OP_POSSTAR:
622    case OP_POSPLUS:    case OP_POSPLUS:
623    case OP_POSQUERY:    case OP_POSQUERY:
624      case OP_POSUPTO:
625    case OP_STARI:    case OP_STARI:
626    case OP_MINSTARI:    case OP_MINSTARI:
627    case OP_PLUSI:    case OP_PLUSI:
628    case OP_MINPLUSI:    case OP_MINPLUSI:
629    case OP_QUERYI:    case OP_QUERYI:
630    case OP_MINQUERYI:    case OP_MINQUERYI:
631      case OP_UPTOI:
632      case OP_MINUPTOI:
633      case OP_EXACTI:
634    case OP_POSSTARI:    case OP_POSSTARI:
635    case OP_POSPLUSI:    case OP_POSPLUSI:
636    case OP_POSQUERYI:    case OP_POSQUERYI:
637      case OP_POSUPTOI:
638    case OP_NOTSTAR:    case OP_NOTSTAR:
639    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
640    case OP_NOTPLUS:    case OP_NOTPLUS:
641    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
642    case OP_NOTQUERY:    case OP_NOTQUERY:
643    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
644      case OP_NOTUPTO:
645      case OP_NOTMINUPTO:
646      case OP_NOTEXACT:
647    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
648    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
649    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
650      case OP_NOTPOSUPTO:
651    case OP_NOTSTARI:    case OP_NOTSTARI:
652    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
653    case OP_NOTPLUSI:    case OP_NOTPLUSI:
654    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
655    case OP_NOTQUERYI:    case OP_NOTQUERYI:
656    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:  
657    case OP_NOTUPTOI:    case OP_NOTUPTOI:
658    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
659    case OP_NOTEXACTI:    case OP_NOTEXACTI:
660      case OP_NOTPOSSTARI:
661      case OP_NOTPOSPLUSI:
662      case OP_NOTPOSQUERYI:
663    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
664    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
665  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
666    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
667  #endif  #endif
668    return cc;    return cc;
669    
670    case OP_NOTPROP:    /* Special cases. */
671    case OP_PROP:    case OP_TYPESTAR:
672    return cc + 1 + 2;    case OP_TYPEMINSTAR:
673      case OP_TYPEPLUS:
674      case OP_TYPEMINPLUS:
675      case OP_TYPEQUERY:
676      case OP_TYPEMINQUERY:
677    case OP_TYPEUPTO:    case OP_TYPEUPTO:
678    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
679    case OP_TYPEEXACT:    case OP_TYPEEXACT:
680      case OP_TYPEPOSSTAR:
681      case OP_TYPEPOSPLUS:
682      case OP_TYPEPOSQUERY:
683    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
684    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;  
685    
686    case OP_CRRANGE:    case OP_ANYBYTE:
687    case OP_CRMINRANGE:  #ifdef SUPPORT_UTF
688    return cc + 1 + 2 * IMM2_SIZE;    if (common->utf) return NULL;
689    #endif
690    case OP_CLASS:    return cc + 1;
   case OP_NCLASS:  
   return cc + 1 + 32 / sizeof(pcre_uchar);  
691    
692  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
693    case OP_XCLASS:    case OP_XCLASS:
694    return cc + GET(cc, 1);    return cc + GET(cc, 1);
695  #endif  #endif
696    
   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;  
   
697    case OP_MARK:    case OP_MARK:
698      case OP_PRUNE_ARG:
699    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
700    
701    default:    default:
# Line 764  int private_data_length = 0; Line 786  int private_data_length = 0;
786  pcre_uchar *alternative;  pcre_uchar *alternative;
787  pcre_uchar *name;  pcre_uchar *name;
788  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
789  int space, size, bracketlen, i;  int space, size, i;
790    pcre_uint32 bracketlen;
791    
792  /* 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. */
793  while (cc < ccend)  while (cc < ccend)
# Line 794  while (cc < ccend) Line 817  while (cc < ccend)
817      case OP_BRAPOS:      case OP_BRAPOS:
818      case OP_SBRA:      case OP_SBRA:
819      case OP_SBRAPOS:      case OP_SBRAPOS:
820      private_data_length += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
821      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
822      break;      break;
823    
824      case OP_CBRAPOS:      case OP_CBRAPOS:
825      case OP_SCBRAPOS:      case OP_SCBRAPOS:
826      private_data_length += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
827      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
828      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
829      break;      break;
830    
831      case OP_COND:      case OP_COND:
832      case OP_SCOND:      case OP_SCOND:
833      bracketlen = cc[1 + LINK_SIZE];      /* Only AUTO_CALLOUT can insert this opcode. We do
834      if (bracketlen == OP_CREF)         not intend to support this case. */
835        {      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
836        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;  
         }  
       }  
837    
838      if (*cc == OP_COND)      if (*cc == OP_COND)
839        {        {
840        /* Might be a hidden SCOND. */        /* Might be a hidden SCOND. */
841        alternative = cc + GET(cc, 1);        alternative = cc + GET(cc, 1);
842        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
843          private_data_length += sizeof(sljit_w);          private_data_length += sizeof(sljit_sw);
844        }        }
845      else      else
846        private_data_length += sizeof(sljit_w);        private_data_length += sizeof(sljit_sw);
847      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
848      break;      break;
849    
850        case OP_CREF:
851        i = GET2(cc, 1);
852        common->optimized_cbracket[i] = 0;
853        cc += 1 + IMM2_SIZE;
854        break;
855    
856        case OP_NCREF:
857        bracketlen = GET2(cc, 1);
858        name = (pcre_uchar *)common->name_table;
859        alternative = name;
860        for (i = 0; i < common->name_count; i++)
861          {
862          if (GET2(name, 0) == bracketlen) break;
863          name += common->name_entry_size;
864          }
865        SLJIT_ASSERT(i != common->name_count);
866    
867        for (i = 0; i < common->name_count; i++)
868          {
869          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
870            common->optimized_cbracket[GET2(alternative, 0)] = 0;
871          alternative += common->name_entry_size;
872          }
873        bracketlen = 0;
874        cc += 1 + IMM2_SIZE;
875        break;
876    
877      case OP_BRA:      case OP_BRA:
878      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
879      break;      break;
# Line 901  while (cc < ccend) Line 930  while (cc < ccend)
930    
931      case OP_RECURSE:      case OP_RECURSE:
932      /* Set its value only once. */      /* Set its value only once. */
933      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
934        {        {
935        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
936        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
937        }        }
938      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
939      break;      break;
940    
941        case OP_CALLOUT:
942        if (common->capture_last_ptr == 0)
943          {
944          common->capture_last_ptr = common->ovector_start;
945          common->ovector_start += sizeof(sljit_sw);
946          }
947        cc += 2 + 2 * LINK_SIZE;
948        break;
949    
950        case OP_PRUNE_ARG:
951        common->needs_start_ptr = TRUE;
952        common->control_head_ptr = 1;
953        /* Fall through. */
954    
955      case OP_MARK:      case OP_MARK:
956      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
957        {        {
958        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
959        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
960        }        }
961      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
962      break;      break;
963    
964        case OP_PRUNE:
965        case OP_SKIP:
966        common->needs_start_ptr = TRUE;
967        /* Fall through. */
968    
969        case OP_COMMIT:
970        common->control_head_ptr = 1;
971        cc += 1;
972        break;
973    
974      default:      default:
975      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
976      if (cc == NULL)      if (cc == NULL)
# Line 926  while (cc < ccend) Line 979  while (cc < ccend)
979      }      }
980    
981    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
982      private_data_length += sizeof(sljit_w) * space;      private_data_length += sizeof(sljit_sw) * space;
983    
984    if (size != 0)    if (size != 0)
985      {      {
# Line 941  while (cc < ccend) Line 994  while (cc < ccend)
994        cc += size;        cc += size;
995      }      }
996    
997    if (bracketlen > 0)    if (bracketlen != 0)
998      {      {
999      if (cc >= end)      if (cc >= end)
1000        {        {
# Line 980  while (cc < ccend) Line 1033  while (cc < ccend)
1033      case OP_SBRAPOS:      case OP_SBRAPOS:
1034      case OP_SCOND:      case OP_SCOND:
1035      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1036      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1037      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1038      break;      break;
1039    
1040      case OP_CBRAPOS:      case OP_CBRAPOS:
1041      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1042      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1043      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1044      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1045      break;      break;
1046    
# Line 997  while (cc < ccend) Line 1050  while (cc < ccend)
1050      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1051        {        {
1052        common->private_data_ptrs[cc - common->start] = private_data_ptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1053        private_data_ptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1054        }        }
1055      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1056      break;      break;
# Line 1065  while (cc < ccend) Line 1118  while (cc < ccend)
1118    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1119      {      {
1120      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1121      private_data_ptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1122      }      }
1123    
1124    if (size != 0)    if (size != 0)
# Line 1094  while (cc < ccend) Line 1147  while (cc < ccend)
1147    }    }
1148  }  }
1149    
1150  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1151  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)
1152  {  {
1153  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1154  int length = 0;  int length = 0;
1155  BOOL possessive = FALSE;  int possessive = 0;
1156    BOOL stack_restore = FALSE;
1157  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1158  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1159    /* The last capture is a local variable even for recursions. */
1160    BOOL capture_last_found = FALSE;
1161    
1162  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1163    {    {
1164    length = 3;    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1165    possessive = TRUE;    /* This is correct regardless of common->capture_last_ptr. */
1166      capture_last_found = TRUE;
1167    }    }
1168    
1169  cc = next_opcode(common, cc);  cc = next_opcode(common, cc);
# Line 1116  while (cc < ccend) Line 1173  while (cc < ccend)
1173      {      {
1174      case OP_SET_SOM:      case OP_SET_SOM:
1175      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1176        stack_restore = TRUE;
1177      if (!setsom_found)      if (!setsom_found)
1178        {        {
1179        length += 2;        length += 2;
# Line 1125  while (cc < ccend) Line 1183  while (cc < ccend)
1183      break;      break;
1184    
1185      case OP_MARK:      case OP_MARK:
1186        case OP_PRUNE_ARG:
1187      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1188        stack_restore = TRUE;
1189      if (!setmark_found)      if (!setmark_found)
1190        {        {
1191        length += 2;        length += 2;
# Line 1135  while (cc < ccend) Line 1195  while (cc < ccend)
1195      break;      break;
1196    
1197      case OP_RECURSE:      case OP_RECURSE:
1198        stack_restore = TRUE;
1199      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1200        {        {
1201        length += 2;        length += 2;
# Line 1145  while (cc < ccend) Line 1206  while (cc < ccend)
1206        length += 2;        length += 2;
1207        setmark_found = TRUE;        setmark_found = TRUE;
1208        }        }
1209        if (common->capture_last_ptr != 0 && !capture_last_found)
1210          {
1211          length += 2;
1212          capture_last_found = TRUE;
1213          }
1214      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1215      break;      break;
1216    
# Line 1152  while (cc < ccend) Line 1218  while (cc < ccend)
1218      case OP_CBRAPOS:      case OP_CBRAPOS:
1219      case OP_SCBRA:      case OP_SCBRA:
1220      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1221        stack_restore = TRUE;
1222        if (common->capture_last_ptr != 0 && !capture_last_found)
1223          {
1224          length += 2;
1225          capture_last_found = TRUE;
1226          }
1227      length += 3;      length += 3;
1228      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1229      break;      break;
1230    
1231      default:      default:
1232        stack_restore = TRUE;
1233        /* Fall through. */
1234    
1235        case OP_NOT_WORD_BOUNDARY:
1236        case OP_WORD_BOUNDARY:
1237        case OP_NOT_DIGIT:
1238        case OP_DIGIT:
1239        case OP_NOT_WHITESPACE:
1240        case OP_WHITESPACE:
1241        case OP_NOT_WORDCHAR:
1242        case OP_WORDCHAR:
1243        case OP_ANY:
1244        case OP_ALLANY:
1245        case OP_ANYBYTE:
1246        case OP_NOTPROP:
1247        case OP_PROP:
1248        case OP_ANYNL:
1249        case OP_NOT_HSPACE:
1250        case OP_HSPACE:
1251        case OP_NOT_VSPACE:
1252        case OP_VSPACE:
1253        case OP_EXTUNI:
1254        case OP_EODN:
1255        case OP_EOD:
1256        case OP_CIRC:
1257        case OP_CIRCM:
1258        case OP_DOLL:
1259        case OP_DOLLM:
1260        case OP_CHAR:
1261        case OP_CHARI:
1262        case OP_NOT:
1263        case OP_NOTI:
1264    
1265        case OP_EXACT:
1266        case OP_POSSTAR:
1267        case OP_POSPLUS:
1268        case OP_POSQUERY:
1269        case OP_POSUPTO:
1270    
1271        case OP_EXACTI:
1272        case OP_POSSTARI:
1273        case OP_POSPLUSI:
1274        case OP_POSQUERYI:
1275        case OP_POSUPTOI:
1276    
1277        case OP_NOTEXACT:
1278        case OP_NOTPOSSTAR:
1279        case OP_NOTPOSPLUS:
1280        case OP_NOTPOSQUERY:
1281        case OP_NOTPOSUPTO:
1282    
1283        case OP_NOTEXACTI:
1284        case OP_NOTPOSSTARI:
1285        case OP_NOTPOSPLUSI:
1286        case OP_NOTPOSQUERYI:
1287        case OP_NOTPOSUPTOI:
1288    
1289        case OP_TYPEEXACT:
1290        case OP_TYPEPOSSTAR:
1291        case OP_TYPEPOSPLUS:
1292        case OP_TYPEPOSQUERY:
1293        case OP_TYPEPOSUPTO:
1294    
1295        case OP_CLASS:
1296        case OP_NCLASS:
1297        case OP_XCLASS:
1298    
1299      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1300      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1301      break;      break;
1302      }      }
1303    
1304  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1305  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1306    return -1;    return stack_restore ? no_frame : no_stack;
1307    
1308  if (length > 0)  if (length > 0)
1309    return length + 1;    return length + 1;
1310  return -1;  return stack_restore ? no_frame : no_stack;
1311  }  }
1312    
1313  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)
1314  {  {
1315  DEFINE_COMPILER;  DEFINE_COMPILER;
1316  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1317  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1318  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1319    /* The last capture is a local variable even for recursions. */
1320    BOOL capture_last_found = FALSE;
1321  int offset;  int offset;
1322    
1323  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1195  while (cc < ccend) Line 1336  while (cc < ccend)
1336      if (!setsom_found)      if (!setsom_found)
1337        {        {
1338        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1339        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1340        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1341        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1342        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1343        setsom_found = TRUE;        setsom_found = TRUE;
1344        }        }
1345      cc += 1;      cc += 1;
1346      break;      break;
1347    
1348      case OP_MARK:      case OP_MARK:
1349        case OP_PRUNE_ARG:
1350      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1351      if (!setmark_found)      if (!setmark_found)
1352        {        {
1353        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);
1354        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);
1355        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1356        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1357        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1358        setmark_found = TRUE;        setmark_found = TRUE;
1359        }        }
1360      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1222  while (cc < ccend) Line 1364  while (cc < ccend)
1364      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1365        {        {
1366        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1367        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1368        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1369        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1370        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1371        setsom_found = TRUE;        setsom_found = TRUE;
1372        }        }
1373      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1374        {        {
1375        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);
1376        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);
1377        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1378        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1379        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1380        setmark_found = TRUE;        setmark_found = TRUE;
1381        }        }
1382        if (common->capture_last_ptr != 0 && !capture_last_found)
1383          {
1384          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1385          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1386          stackpos += (int)sizeof(sljit_sw);
1387          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1388          stackpos += (int)sizeof(sljit_sw);
1389          capture_last_found = TRUE;
1390          }
1391      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1392      break;      break;
1393    
# Line 1244  while (cc < ccend) Line 1395  while (cc < ccend)
1395      case OP_CBRAPOS:      case OP_CBRAPOS:
1396      case OP_SCBRA:      case OP_SCBRA:
1397      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1398        if (common->capture_last_ptr != 0 && !capture_last_found)
1399          {
1400          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1401          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1402          stackpos += (int)sizeof(sljit_sw);
1403          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1404          stackpos += (int)sizeof(sljit_sw);
1405          capture_last_found = TRUE;
1406          }
1407      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1408      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1409      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1410      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1411      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));
1412      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1413      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1414      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1415      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1416    
1417      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1418      break;      break;
# Line 1263  while (cc < ccend) Line 1423  while (cc < ccend)
1423      break;      break;
1424      }      }
1425    
1426  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1427  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1428  }  }
1429    
1430  static SLJIT_INLINE int get_private_data_length_for_copy(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static SLJIT_INLINE int get_private_data_length_for_copy(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
1431  {  {
1432  int private_data_length = 2;  int private_data_length = common->control_head_ptr ? 3 : 2;
1433  int size;  int size;
1434  pcre_uchar *alternative;  pcre_uchar *alternative;
1435  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1403  stacktop = STACK(stacktop - 1); Line 1563  stacktop = STACK(stacktop - 1);
1563    
1564  if (!save)  if (!save)
1565    {    {
1566    stackptr += sizeof(sljit_w);    stackptr += (common->control_head_ptr ? 2 : 1) * sizeof(sljit_sw);
1567    if (stackptr < stacktop)    if (stackptr < stacktop)
1568      {      {
1569      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1570      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1571      tmp1empty = FALSE;      tmp1empty = FALSE;
1572      }      }
1573    if (stackptr < stacktop)    if (stackptr < stacktop)
1574      {      {
1575      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1576      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1577      tmp2empty = FALSE;      tmp2empty = FALSE;
1578      }      }
1579    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1580    }    }
1581    
1582  while (status != end)  do
1583    {    {
1584    count = 0;    count = 0;
1585    switch(status)    switch(status)
1586      {      {
1587      case start:      case start:
1588      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1589      count = 1;      count = 1;
1590      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1591        if (common->control_head_ptr != 0)
1592          {
1593          count = 2;
1594          srcw[1] = common->control_head_ptr;
1595          }
1596      status = loop;      status = loop;
1597      break;      break;
1598    
# Line 1504  while (status != end) Line 1669  while (status != end)
1669          {          {
1670          count = 2;          count = 2;
1671          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1672          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1673          }          }
1674        cc += 2;        cc += 2;
1675  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1517  while (status != end) Line 1682  while (status != end)
1682          {          {
1683          count = 2;          count = 2;
1684          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1685          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1686          }          }
1687        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1688  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1539  while (status != end) Line 1704  while (status != end)
1704          {          {
1705          count = 2;          count = 2;
1706          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1707          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1708          }          }
1709        cc += 1;        cc += 1;
1710        break;        break;
# Line 1549  while (status != end) Line 1714  while (status != end)
1714          {          {
1715          count = 2;          count = 2;
1716          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1717          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1718          }          }
1719        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1720        break;        break;
# Line 1573  while (status != end) Line 1738  while (status != end)
1738            case 2:            case 2:
1739            count = 2;            count = 2;
1740            srcw[0] = PRIVATE_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1741            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1742            break;            break;
1743    
1744            default:            default:
# Line 1605  while (status != end) Line 1770  while (status != end)
1770          if (!tmp1empty)          if (!tmp1empty)
1771            {            {
1772            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1773            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1774            }            }
1775          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1776          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1616  while (status != end) Line 1781  while (status != end)
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          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1787          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1633  while (status != end) Line 1798  while (status != end)
1798          if (!tmp1empty)          if (!tmp1empty)
1799            {            {
1800            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1801            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1802            }            }
1803          tmp1next = FALSE;          tmp1next = FALSE;
1804          }          }
# Line 1645  while (status != end) Line 1810  while (status != end)
1810          if (!tmp2empty)          if (!tmp2empty)
1811            {            {
1812            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1813            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1814            }            }
1815          tmp1next = TRUE;          tmp1next = TRUE;
1816          }          }
1817        }        }
1818      }      }
1819    }    }
1820    while (status != end);
1821    
1822  if (save)  if (save)
1823    {    {
# Line 1660  if (save) Line 1826  if (save)
1826      if (!tmp1empty)      if (!tmp1empty)
1827        {        {
1828        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1829        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1830        }        }
1831      if (!tmp2empty)      if (!tmp2empty)
1832        {        {
1833        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1834        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1835        }        }
1836      }      }
1837    else    else
# Line 1673  if (save) Line 1839  if (save)
1839      if (!tmp2empty)      if (!tmp2empty)
1840        {        {
1841        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1842        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1843        }        }
1844      if (!tmp1empty)      if (!tmp1empty)
1845        {        {
1846        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1847        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1848        }        }
1849      }      }
1850    }    }
# Line 1692  SLJIT_ASSERT(cc == ccend && stackptr == Line 1858  SLJIT_ASSERT(cc == ccend && stackptr ==
1858  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1859  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1860    
1861  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1862  {  {
1863  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1864  }  }
# Line 1703  while (list) Line 1869  while (list)
1869    {    {
1870    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1871    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1872    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1873    list = list->next;    list = list->next;
1874    }    }
1875  }  }
# Line 1719  if (list_item) Line 1885  if (list_item)
1885    }    }
1886  }  }
1887    
1888  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)
1889  {  {
1890  DEFINE_COMPILER;  DEFINE_COMPILER;
1891  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1892    
1893  if (list_item)  if (list_item)
1894    {    {
   list_item->type = type;  
   list_item->data = data;  
1895    list_item->start = start;    list_item->start = start;
1896    list_item->quit = LABEL();    list_item->quit = LABEL();
1897    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1743  stub_list* list_item = common->stubs; Line 1907  stub_list* list_item = common->stubs;
1907  while (list_item)  while (list_item)
1908    {    {
1909    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
1910    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;  
     }  
1911    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
1912    list_item = list_item->next;    list_item = list_item->next;
1913    }    }
# Line 1768  static SLJIT_INLINE void allocate_stack( Line 1927  static SLJIT_INLINE void allocate_stack(
1927  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
1928  DEFINE_COMPILER;  DEFINE_COMPILER;
1929    
1930  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));
1931  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
1932  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
1933  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 1935  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
1935  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
1936  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
1937  #endif  #endif
1938  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));
1939  }  }
1940    
1941  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
1942  {  {
1943  DEFINE_COMPILER;  DEFINE_COMPILER;
1944  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));
1945  }  }
1946    
1947  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1790  static SLJIT_INLINE void reset_ovector(c Line 1949  static SLJIT_INLINE void reset_ovector(c
1949  DEFINE_COMPILER;  DEFINE_COMPILER;
1950  struct sljit_label *loop;  struct sljit_label *loop;
1951  int i;  int i;
1952    
1953  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
1954    SLJIT_ASSERT(length > 1);
1955  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
1956  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));
1957    if (length < 8)
1958      {
1959      for (i = 1; i < length; i++)
1960        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
1961      }
1962    else
1963      {
1964      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
1965      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
1966      loop = LABEL();
1967      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
1968      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
1969      JUMPTO(SLJIT_C_NOT_ZERO, loop);
1970      }
1971    }
1972    
1973    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
1974    {
1975    DEFINE_COMPILER;
1976    struct sljit_label *loop;
1977    int i;
1978    
1979    SLJIT_ASSERT(length > 1);
1980    /* OVECTOR(1) contains the "string begin - 1" constant. */
1981    if (length > 2)
1982      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
1983  if (length < 8)  if (length < 8)
1984    {    {
1985    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
1986      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_TEMPORARY_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
1987    }    }
1988  else  else
1989    {    {
1990    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
1991    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
1992    loop = LABEL();    loop = LABEL();
1993    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
1994    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
1995    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
1996    }    }
1997    
1998    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
1999    if (common->mark_ptr != 0)
2000      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2001    SLJIT_ASSERT(common->control_head_ptr != 0);
2002    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2003    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2004    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2005    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2006    }
2007    
2008    static sljit_sw do_check_control_chain(sljit_sw *current)
2009    {
2010    sljit_sw return_value = 0;
2011    
2012    SLJIT_ASSERT(current != NULL);
2013    do
2014      {
2015      switch (current[-2])
2016        {
2017        case type_commit:
2018        /* Commit overwrites all. */
2019        return -1;
2020    
2021        case type_prune:
2022        break;
2023    
2024        case type_skip:
2025        /* Overwrites prune, but not other skips. */
2026        if (return_value == 0)
2027          return_value = current[-3];
2028        break;
2029    
2030        default:
2031        SLJIT_ASSERT_STOP();
2032        break;
2033        }
2034      current = (sljit_sw*)current[-1];
2035      }
2036    while (current != NULL);
2037    return return_value;
2038  }  }
2039    
2040  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2041  {  {
2042  DEFINE_COMPILER;  DEFINE_COMPILER;
2043  struct sljit_label *loop;  struct sljit_label *loop;
2044  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2045    
2046  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2047  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));
2048  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);
2049    
2050  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2051  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2052    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);
2053  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));
2054  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2055    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);
2056  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));
2057  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));
2058  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2059  /* Unlikely, but possible */  /* Unlikely, but possible */
2060  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);
2061  loop = LABEL();  loop = LABEL();
2062  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);
2063  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));
2064  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2065  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2066  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);
2067  #endif  #endif
2068  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);
2069  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);
2070  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2071  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2072    
2073  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2074  if (topbracket > 1)  if (topbracket > 1)
2075    {    {
2076    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));
2077    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2078    
2079    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2080    loop = LABEL();    loop = LABEL();
2081    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)));
2082    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);
2083    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);
2084    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2085    }    }
2086  else  else
2087    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1862  else Line 2090  else
2090  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2091  {  {
2092  DEFINE_COMPILER;  DEFINE_COMPILER;
2093    struct sljit_jump *jump;
2094    
2095  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);
2096  SLJIT_ASSERT(common->start_used_ptr != 0 && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));  SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0
2097      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2098    
2099  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2100  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2101  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
2102  CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, quit);  CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2103    
2104  /* Store match begin and end. */  /* Store match begin and end. */
2105  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));
2106  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));
2107  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);  
2108    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2109    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);
2110    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2111    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2112    #endif
2113    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2114    JUMPHERE(jump);
2115    
2116    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);
2117  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);
2118  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2119  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);
2120  #endif  #endif
2121  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);
2122    
2123  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);
2124  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2125  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);
2126  #endif  #endif
2127  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);
2128    
2129  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2130  }  }
# Line 1998  if (c <= 127 && bit == 0x20) Line 2237  if (c <= 127 && bit == 0x20)
2237    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2238    
2239  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2240  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2241    return 0;    return 0;
2242    
2243  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2244    
2245  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2246  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 2017  if (common->utf && c > 127) Line 2256  if (common->utf && c > 127)
2256  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2257  return (0 << 8) | bit;  return (0 << 8) | bit;
2258    
2259  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2260    
 #ifdef COMPILE_PCRE16  
2261  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2262  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2263    {    {
# Line 2030  if (common->utf && c > 65535) Line 2268  if (common->utf && c > 65535)
2268    }    }
2269  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2270  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2271    
2272  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2273  }  }
2274    
2275  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
# Line 2052  else if (common->mode == JIT_PARTIAL_SOF Line 2289  else if (common->mode == JIT_PARTIAL_SOF
2289    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2290    
2291  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2292    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2293  else  else
2294    {    {
2295    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2065  if (jump != NULL) Line 2302  if (jump != NULL)
2302    JUMPHERE(jump);    JUMPHERE(jump);
2303  }  }
2304    
2305  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2306  {  {
2307  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2308  DEFINE_COMPILER;  DEFINE_COMPILER;
2309  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2310    
2311  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2312    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2313      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2314      return;
2315      }
2316    
2317  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2318  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2319    {    {
2320    nohit = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2321    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2322    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2323    }    }
2324  else  else
2325    {    {
2326    return_value = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2327    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2328      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2329    else    else
2330      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2331    }    }
2332  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2333  }  }
2334    
2335  static void detect_partial_match(compiler_common *common, jump_list **backtracks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
# Line 2112  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR Line 2348  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2348  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2349  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2350    {    {
2351    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2352    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2353    }    }
2354  else  else
# Line 2130  static void read_char(compiler_common *c Line 2366  static void read_char(compiler_common *c
2366  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2367  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2368  DEFINE_COMPILER;  DEFINE_COMPILER;
2369  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2370  struct sljit_jump *jump;  struct sljit_jump *jump;
2371  #endif  #endif
2372    
2373  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2374  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2375  if (common->utf)  if (common->utf)
2376    {    {
2377  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2378    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2379  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2380    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2381  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2382    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2383    JUMPHERE(jump);    JUMPHERE(jump);
2384    }    }
2385  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2386  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));
2387  }  }
2388    
# Line 2157  static void peek_char(compiler_common *c Line 2391  static void peek_char(compiler_common *c
2391  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2392  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2393  DEFINE_COMPILER;  DEFINE_COMPILER;
2394  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2395  struct sljit_jump *jump;  struct sljit_jump *jump;
2396  #endif  #endif
2397    
2398  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2399  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2400  if (common->utf)  if (common->utf)
2401    {    {
2402  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2403    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2404  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2405    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2406  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2407    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2408    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2409    JUMPHERE(jump);    JUMPHERE(jump);
2410    }    }
2411  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2412  }  }
2413    
2414  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2415  {  {
2416  /* 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. */
2417  DEFINE_COMPILER;  DEFINE_COMPILER;
2418  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2419  struct sljit_jump *jump;  struct sljit_jump *jump;
2420  #endif  #endif
2421    
# Line 2192  if (common->utf) Line 2424  if (common->utf)
2424    {    {
2425    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2426    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));
2427  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2428    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2429    it is needed in most cases. */    it is needed in most cases. */
2430    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2431    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2432    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2433    JUMPHERE(jump);    JUMPHERE(jump);
2434  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2435    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2436    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2437    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 2439  if (common->utf)
2439    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2440    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2441    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);
2442    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2443    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2444    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2445  #endif  #elif defined COMPILE_PCRE32
2446  #endif /* COMPILE_PCRE8 */    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2447      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2448      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2449      JUMPHERE(jump);
2450    #endif /* COMPILE_PCRE[8|16|32] */
2451    return;    return;
2452    }    }
2453  #endif  #endif /* SUPPORT_UTF */
2454  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2455  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));
2456  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2457  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2458  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2459  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2460  #endif  #endif
2461  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2462  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2463  JUMPHERE(jump);  JUMPHERE(jump);
2464  #endif  #endif
2465  }  }
# Line 2233  static void skip_char_back(compiler_comm Line 2468  static void skip_char_back(compiler_comm
2468  {  {
2469  /* 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. */
2470  DEFINE_COMPILER;  DEFINE_COMPILER;
2471  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2472    #if defined COMPILE_PCRE8
2473  struct sljit_label *label;  struct sljit_label *label;
2474    
2475  if (common->utf)  if (common->utf)
# Line 2245  if (common->utf) Line 2481  if (common->utf)
2481    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2482    return;    return;
2483    }    }
2484  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2485  if (common->utf)  if (common->utf)
2486    {    {
2487    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 2489  if (common->utf)
2489    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2490    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2491    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);
2492    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2493    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2494    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2495    return;    return;
2496    }    }
2497  #endif  #endif /* COMPILE_PCRE[8|16] */
2498    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2499  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));
2500  }  }
2501    
# Line 2276  if (nltype == NLTYPE_ANY) Line 2512  if (nltype == NLTYPE_ANY)
2512  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2513    {    {
2514    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);
2515    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2516    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);
2517    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);
2518    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));
2519    }    }
2520  else  else
# Line 2290  else Line 2526  else
2526    
2527  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2528    
2529  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2530  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2531  {  {
2532  /* 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 2614  sljit_emit_fast_return(compiler, RETURN_
2614  JUMPHERE(jump);  JUMPHERE(jump);
2615    
2616  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2617  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);
2618  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2619  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2620  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2621  }  }
2622    
2623  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2624    
 #ifdef COMPILE_PCRE16  
2625  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2626  {  {
2627  /* 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 2646  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2646  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2647  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2648  }  }
 #endif /* COMPILE_PCRE16 */  
2649    
2650  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2651    
2652  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2653    
# Line 2433  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2667  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2667    
2668  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2669  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2670  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));
2671  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2672  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2673  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2674  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2675  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2676  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));
2677  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2678  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2679  }  }
# Line 2453  struct sljit_label *newlinelabel = NULL; Line 2687  struct sljit_label *newlinelabel = NULL;
2687  struct sljit_jump *start;  struct sljit_jump *start;
2688  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2689  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2690  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2691  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2692  #endif  #endif
2693  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2508  if (newlinecheck) Line 2742  if (newlinecheck)
2742    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2743    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2744    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);
2745    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2746  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2747    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2748  #endif  #endif
2749    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2750    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2531  if (newlinecheck) Line 2765  if (newlinecheck)
2765    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);
2766    
2767  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));
2768  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2769    #if defined COMPILE_PCRE8
2770  if (common->utf)  if (common->utf)
2771    {    {
2772    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2773    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);
2774    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2775    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2776    }    }
2777  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2778  if (common->utf)  if (common->utf)
2779    {    {
2780    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2781    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2782    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);
2783    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2784    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2785    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2786    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2787    }    }
2788  #endif  #endif /* COMPILE_PCRE[8|16] */
2789    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2790  JUMPHERE(start);  JUMPHERE(start);
2791    
2792  if (newlinecheck)  if (newlinecheck)
# Line 2563  if (newlinecheck) Line 2798  if (newlinecheck)
2798  return mainloop;  return mainloop;
2799  }  }
2800    
2801  static SLJIT_INLINE BOOL fast_forward_first_two_chars(compiler_common *common, BOOL firstline)  #define MAX_N_CHARS 3
2802    
2803    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2804  {  {
2805  DEFINE_COMPILER;  DEFINE_COMPILER;
2806  struct sljit_label *start;  struct sljit_label *start;
2807  struct sljit_jump *quit;  struct sljit_jump *quit;
2808  struct sljit_jump *found;  pcre_uint32 chars[MAX_N_CHARS * 2];
2809  pcre_int32 chars[4];  pcre_uchar *cc = common->start + 1 + LINK_SIZE;
 pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  
2810  int location = 0;  int location = 0;
2811  pcre_int32 len, c, bit, caseless;  pcre_int32 len, c, bit, caseless;
2812  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  
2813    
2814    /* We do not support alternatives now. */
2815  if (*(common->start + GET(common->start, 1)) == OP_ALT)  if (*(common->start + GET(common->start, 1)) == OP_ALT)
2816    return FALSE;    return FALSE;
2817    
2818  while (TRUE)  while (TRUE)
2819    {    {
2820    caseless = 0;    caseless = 0;
2821    must_end = TRUE;    must_stop = 1;
2822    switch(*cc)    switch(*cc)
2823      {      {
2824      case OP_CHAR:      case OP_CHAR:
2825      must_end = FALSE;      must_stop = 0;
2826      cc++;      cc++;
2827      break;      break;
2828    
2829      case OP_CHARI:      case OP_CHARI:
2830      caseless = 1;      caseless = 1;
2831      must_end = FALSE;      must_stop = 0;
2832      cc++;      cc++;
2833      break;      break;
2834    
# Line 2645  while (TRUE) Line 2870  while (TRUE)
2870      break;      break;
2871    
2872      default:      default:
2873      return FALSE;      must_stop = 2;
2874        break;
2875      }      }
2876    
2877      if (must_stop == 2)
2878          break;
2879    
2880    len = 1;    len = 1;
2881  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2882    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 2899  while (TRUE)
2899    else    else
2900      caseless = 0;      caseless = 0;
2901    
2902    while (len > 0 && location < 2 * 2)    while (len > 0 && location < MAX_N_CHARS * 2)
2903      {      {
2904      c = *cc;      c = *cc;
2905      bit = 0;      bit = 0;
# Line 2688  while (TRUE) Line 2917  while (TRUE)
2917      cc++;      cc++;
2918      }      }
2919    
2920    if (location == 2 * 2)    if (location >= MAX_N_CHARS * 2 || must_stop != 0)
2921      break;      break;
   else if (must_end)  
     return FALSE;  
2922    }    }
2923    
2924    /* At least two characters are required. */
2925    if (location < 2 * 2)
2926        return FALSE;
2927    
2928  if (firstline)  if (firstline)
2929    {    {
2930    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
2931    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2932    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));
2933    }    }
2934  else  else
2935    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));
2936    
2937  start = LABEL();  start = LABEL();
2938  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  
 #ifdef COMPILE_PCRE8  
 OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #else /* COMPILE_PCRE8 */  
 OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #endif  
   
 #else /* SLJIT_UNALIGNED */  
2939    
2940  #if defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 #else /* SLJIT_BIG_ENDIAN */  
2941  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2942  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2943  #endif /* SLJIT_BIG_ENDIAN */  if (chars[1] != 0)
2944      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
2945  #ifdef COMPILE_PCRE8  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
2946  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 8);  if (location > 2 * 2)
2947  #else /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2948  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 16);  if (chars[3] != 0)
2949  #endif    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
2950  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
2951    if (location > 2 * 2)
2952  #endif    {
2953      if (chars[5] != 0)
2954  if (chars[1] != 0 || chars[3] != 0)      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
2955    {    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);  
2956    }    }
2957    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2958    
 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);  
2959  JUMPHERE(quit);  JUMPHERE(quit);
2960    
2961  if (firstline)  if (firstline)
2962    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2963  else  else
2964    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));
2965  return TRUE;  return TRUE;
2966  }  }
2967    
2968    #undef MAX_N_CHARS
2969    
2970  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)
2971  {  {
2972  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2787  if (first_char == oc) Line 3000  if (first_char == oc)
3000  else  else
3001    {    {
3002    bit = first_char ^ oc;    bit = first_char ^ oc;
3003    if (ispowerof2(bit))    if (is_powerof2(bit))
3004      {      {
3005      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3006      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 3008  else
3008    else    else
3009      {      {
3010      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);
3011      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3012      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);
3013      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);
3014      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3015      }      }
3016    }    }
# Line 2839  if (common->nltype == NLTYPE_FIXED && co Line 3052  if (common->nltype == NLTYPE_FIXED && co
3052    
3053    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3054    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);
3055    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3056  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3057    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3058  #endif  #endif
3059    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3060    
# Line 2882  if (common->nltype == NLTYPE_ANY || comm Line 3095  if (common->nltype == NLTYPE_ANY || comm
3095    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3096    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3097    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);
3098    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3099  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3100    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3101  #endif  #endif
3102    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3103    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
# Line 2897  if (firstline) Line 3110  if (firstline)
3110    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3111  }  }
3112    
3113    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3114    
3115  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)
3116  {  {
3117  DEFINE_COMPILER;  DEFINE_COMPILER;
3118  struct sljit_label *start;  struct sljit_label *start;
3119  struct sljit_jump *quit;  struct sljit_jump *quit;
3120  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3121    jump_list *matches = NULL;
3122    pcre_uint8 inverted_start_bits[32];
3123    int i;
3124  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3125  struct sljit_jump *jump;  struct sljit_jump *jump;
3126  #endif  #endif
3127    
3128    for (i = 0; i < 32; ++i)
3129      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3130    
3131  if (firstline)  if (firstline)
3132    {    {
3133    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 3142  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3142  if (common->utf)  if (common->utf)
3143    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3144  #endif  #endif
3145    
3146    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3147      {
3148  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3149  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3150  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3151  JUMPHERE(jump);    JUMPHERE(jump);
3152  #endif  #endif
3153  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3154  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3155  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3156  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3157  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);
3158  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3159      }
3160    
3161  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3162  if (common->utf)  if (common->utf)
3163    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3164  #endif  #endif
3165  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));
3166  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3167    #if defined COMPILE_PCRE8
3168  if (common->utf)  if (common->utf)
3169    {    {
3170    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3171    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);
3172    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3173    }    }
3174  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3175  if (common->utf)  if (common->utf)
3176    {    {
3177    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3178    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3179    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);
3180    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3181    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3182    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3183    }    }
3184  #endif  #endif /* COMPILE_PCRE[8|16] */
3185    #endif /* SUPPORT_UTF */
3186  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3187  JUMPHERE(found);  if (found != NULL)
3188      JUMPHERE(found);
3189    if (matches != NULL)
3190      set_jumps(matches, LABEL());
3191  JUMPHERE(quit);  JUMPHERE(quit);
3192    
3193  if (firstline)  if (firstline)
# Line 2974  struct sljit_jump *alreadyfound; Line 3203  struct sljit_jump *alreadyfound;
3203  struct sljit_jump *found;  struct sljit_jump *found;
3204  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3205  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3206  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3207    
3208  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3209  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 3234  if (req_char == oc)
3234  else  else
3235    {    {
3236    bit = req_char ^ oc;    bit = req_char ^ oc;
3237    if (ispowerof2(bit))    if (is_powerof2(bit))
3238      {      {
3239      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3240      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 3270  GET_LOCAL_BASE(TMP3, 0, 0);
3270  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3271  mainloop = LABEL();  mainloop = LABEL();
3272  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3273  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);
3274    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3275    
3276  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3277  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));
3278  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));
3279  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));
3280  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3281    
3282  JUMPHERE(jump);  JUMPHERE(jump);
3283  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3284  /* End of dropping frames. */  /* End of dropping frames. */
3285  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3286    
3287  JUMPHERE(jump);  JUMPHERE(jump);
3288  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3289  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3290  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3291  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));  
3292  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3293  }  }
3294    
# Line 3082  static void check_wordboundary(compiler_ Line 3296  static void check_wordboundary(compiler_
3296  {  {
3297  DEFINE_COMPILER;  DEFINE_COMPILER;
3298  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3299    jump_list *skipread_list = NULL;
3300  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3301  struct sljit_jump *jump;  struct sljit_jump *jump;
3302  #endif  #endif
# Line 3107  if (common->use_ucp) Line 3322  if (common->use_ucp)
3322    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3323    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3324    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);
3325    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3326    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);
3327    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);
3328    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3329    JUMPHERE(jump);    JUMPHERE(jump);
3330    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3331    }    }
# Line 3139  else Line 3354  else
3354  JUMPHERE(skipread);  JUMPHERE(skipread);
3355    
3356  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3357  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3358  peek_char(common);  peek_char(common);
3359    
3360  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3151  if (common->use_ucp) Line 3366  if (common->use_ucp)
3366    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3367    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3368    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);
3369    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3370    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);
3371    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);
3372    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3373    JUMPHERE(jump);    JUMPHERE(jump);
3374    }    }
3375  else  else
# Line 3180  else Line 3395  else
3395      JUMPHERE(jump);      JUMPHERE(jump);
3396  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3397    }    }
3398  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3399    
3400  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3401  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
# Line 3235  switch(ranges[0]) Line 3450  switch(ranges[0])
3450        }        }
3451      return TRUE;      return TRUE;
3452      }      }
3453    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]))
3454      {      {
3455      if (readch)      if (readch)
3456        read_char(common);        read_char(common);
# Line 3334  sljit_emit_fast_enter(compiler, RETURN_A Line 3549  sljit_emit_fast_enter(compiler, RETURN_A
3549    
3550  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3551  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);
3552  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3553  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);
3554  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3555  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3556  if (common->utf)  if (common->utf)
3557    {    {
3558  #endif  #endif
3559    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3560    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3561    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);
3562  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3563    }    }
3564  #endif  #endif
3565  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3566  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);
3567  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3568  }  }
3569    
# Line 3360  DEFINE_COMPILER; Line 3575  DEFINE_COMPILER;
3575  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3576    
3577  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);
3578  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3579  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);
3580  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3581  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);
3582  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3583  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3584  if (common->utf)  if (common->utf)
3585    {    {
3586  #endif  #endif
3587    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3588    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);
3589    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3590    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);
3591    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3592    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3593    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);
3594    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3595    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);
3596    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3597    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);
3598    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3599    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);
3600  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3601    }    }
3602  #endif  #endif
3603  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3604  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);
3605    
3606  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3607  }  }
# Line 3400  sljit_emit_fast_enter(compiler, RETURN_A Line 3615  sljit_emit_fast_enter(compiler, RETURN_A
3615    
3616  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3617  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);
3618  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3619  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);
3620  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3621  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3622  if (common->utf)  if (common->utf)
3623    {    {
3624  #endif  #endif
3625    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);
3626    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3627    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);
3628  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3629    }    }
3630  #endif  #endif
3631  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3632  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);
3633    
3634  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3635  }  }
# Line 3500  sljit_emit_fast_return(compiler, RETURN_ Line 3715  sljit_emit_fast_return(compiler, RETURN_
3715    
3716  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3717    
3718  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)
3719  {  {
3720  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3721  int c1, c2;  pcre_uint32 c1, c2;
3722  const pcre_uchar *src2 = args->uchar_ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3723  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
3724    const ucd_record *ur;
3725    const pcre_uint32 *pp;
3726    
3727  while (src1 < end1)  while (src1 < end1)
3728    {    {
# Line 3513  while (src1 < end1) Line 3730  while (src1 < end1)
3730      return (pcre_uchar*)1;      return (pcre_uchar*)1;
3731    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3732    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3733    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return NULL;    ur = GET_UCD(c2);
3734      if (c1 != c2 && c1 != c2 + ur->other_case)
3735        {
3736        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3737        for (;;)
3738          {
3739          if (c1 < *pp) return NULL;
3740          if (c1 == *pp++) break;
3741          }
3742        }
3743    }    }
3744  return src2;  return src2;
3745  }  }
# Line 3535  if (caseless && char_has_othercase(commo Line 3761  if (caseless && char_has_othercase(commo
3761    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3762    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3763    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3764  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3765    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3766    othercasebit &= 0xff;    othercasebit &= 0xff;
3767  #else  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3768  #ifdef COMPILE_PCRE16    /* Note that this code only handles characters in the BMP. If there
3769      ever are characters outside the BMP whose othercase differs in only one
3770      bit from itself (there currently are none), this code will need to be
3771      revised for COMPILE_PCRE32. */
3772    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3773    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3774      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
3775    else    else
3776      othercasebit &= 0xff;      othercasebit &= 0xff;
3777  #endif  #endif /* COMPILE_PCRE[8|16|32] */
 #endif  
3778    }    }
3779    
3780  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3781    {    {
3782  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3783  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3784    if (context->length >= 4)    if (context->length >= 4)
3785      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 3788  if (context->sourcereg == -1)
3788    else    else
3789  #endif  #endif
3790      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3791  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
3792  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3793    if (context->length >= 4)    if (context->length >= 4)
3794      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3795    else    else
3796  #endif  #endif
3797      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3798  #endif  #elif defined COMPILE_PCRE32
3799  #endif /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3800    #endif /* COMPILE_PCRE[8|16|32] */
3801    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3802    }    }
3803    
# Line 3583  do Line 3811  do
3811  #endif  #endif
3812    
3813    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3814  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3815    
3816    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3817    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3598  do Line 3826  do
3826      }      }
3827    context->ucharptr++;    context->ucharptr++;
3828    
3829  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3830    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))
3831  #else  #else
3832    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
# Line 3606  do Line 3834  do
3834      {      {
3835      if (context->length >= 4)      if (context->length >= 4)
3836        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  
3837      else if (context->length >= 2)      else if (context->length >= 2)
3838        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);
3839    #if defined COMPILE_PCRE8
3840      else if (context->length >= 1)      else if (context->length >= 1)
3841        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);
3842  #else  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3843      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3844    
3845      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3648  do Line 3873  do
3873    
3874  #else  #else
3875    
3876    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3877  #ifdef COMPILE_PCRE8    if (context->length >= 1)
3878    if (context->length > 0)      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3879      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  
3880    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3881    
3882    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3705  static void compile_xclass_matchingpath( Line 3926  static void compile_xclass_matchingpath(
3926  DEFINE_COMPILER;  DEFINE_COMPILER;
3927  jump_list *found = NULL;  jump_list *found = NULL;
3928  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;
3929  unsigned int c;  pcre_int32 c, charoffset;
3930  int compares;  const pcre_uint32 *other_cases;
3931  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
3932  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
3933    int compares, invertcmp, numberofcmps;
3934  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3935  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
3936  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
3937  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
3938  unsigned int typeoffset;  pcre_int32 typeoffset;
3939  #endif  #endif
 int invertcmp, numberofcmps;  
 unsigned int charoffset;  
3940    
3941  /* Although SUPPORT_UTF must be defined, we are  /* Although SUPPORT_UTF must be defined, we are
3942     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 3957  if ((*cc++ & XCL_MAP) != 0)
3957      {      {
3958      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3959      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3960      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
3961      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3962      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);
3963      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 4034  while (*cc != XCL_END)
4034        needschar = TRUE;        needschar = TRUE;
4035        break;        break;
4036    
4037          case PT_CLIST:
4038          case PT_UCNC:
4039          needschar = TRUE;
4040          break;
4041    
4042        default:        default:
4043        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
4044        break;        break;
# Line 3850  if (needstype || needsscript) Line 4075  if (needstype || needsscript)
4075      {      {
4076      if (scriptreg == TMP1)      if (scriptreg == TMP1)
4077        {        {
4078        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));
4079        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
4080        }        }
4081      else      else
4082        {        {
4083        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
4084        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));
4085        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
4086        }        }
4087      }      }
# Line 3892  while (*cc != XCL_END) Line 4117  while (*cc != XCL_END)
4117      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4118        {        {
4119        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);
4120        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);
4121        numberofcmps++;        numberofcmps++;
4122        }        }
4123      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4124        {        {
4125        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);
4126        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);
4127        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4128        numberofcmps = 0;        numberofcmps = 0;
4129        }        }
# Line 3931  while (*cc != XCL_END) Line 4156  while (*cc != XCL_END)
4156      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4157        {        {
4158        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);
4159        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);
4160        numberofcmps++;        numberofcmps++;
4161        }        }
4162      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4163        {        {
4164        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);
4165        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);
4166        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4167        numberofcmps = 0;        numberofcmps = 0;
4168        }        }
# Line 3968  while (*cc != XCL_END) Line 4193  while (*cc != XCL_END)
4193    
4194        case PT_LAMP:        case PT_LAMP:
4195        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);
4196        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4197        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);
4198        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4199        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);
4200        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);
4201        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4202        break;        break;
4203    
# Line 3999  while (*cc != XCL_END) Line 4224  while (*cc != XCL_END)
4224          }          }
4225        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4226        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);
4227        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4228        if (*cc == PT_SPACE)        if (*cc == PT_SPACE)
4229          JUMPHERE(jump);          JUMPHERE(jump);
4230    
4231        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4232        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);
4233        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);
4234        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4235        break;        break;
4236    
4237        case PT_WORD:        case PT_WORD:
4238        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);
4239        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4240        /* ... fall through */        /* Fall through. */
4241    
4242        case PT_ALNUM:        case PT_ALNUM:
4243        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
4244        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);
4245        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);
4246        SET_TYPE_OFFSET(ucp_Nd);        SET_TYPE_OFFSET(ucp_Nd);
4247        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);
4248        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);
4249          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4250          break;
4251    
4252          case PT_CLIST:
4253          other_cases = PRIV(ucd_caseless_sets) + cc[1];
4254    
4255          /* At least three characters are required.
4256             Otherwise this case would be handled by the normal code path. */
4257          SLJIT_ASSERT(other_cases[0] != NOTACHAR && other_cases[1] != NOTACHAR && other_cases[2] != NOTACHAR);
4258          SLJIT_ASSERT(other_cases[0] < other_cases[1] && other_cases[1] < other_cases[2]);
4259    
4260          /* Optimizing character pairs, if their difference is power of 2. */
4261          if (is_powerof2(other_cases[1] ^ other_cases[0]))
4262            {
4263            if (charoffset == 0)
4264              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4265            else
4266              {
4267              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4268              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4269              }
4270            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[1]);
4271            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4272            other_cases += 2;
4273            }
4274          else if (is_powerof2(other_cases[2] ^ other_cases[1]))
4275            {
4276            if (charoffset == 0)
4277              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[2] ^ other_cases[1]);
4278            else
4279              {
4280              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4281              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4282              }
4283            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[2]);
4284            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4285    
4286            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, other_cases[0] - charoffset);
4287            OP_FLAGS(SLJIT_OR | ((other_cases[3] == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4288    
4289            other_cases += 3;
4290            }
4291          else
4292            {
4293            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4294            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4295            }
4296    
4297          while (*other_cases != NOTACHAR)
4298            {
4299            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4300            OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4301            }
4302          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4303          break;
4304    
4305          case PT_UCNC:
4306          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);
4307          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4308          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);
4309          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4310          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);
4311          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4312    
4313          SET_CHAR_OFFSET(0xa0);
4314          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);
4315          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4316          SET_CHAR_OFFSET(0);
4317          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4318          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4319        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4320        break;        break;
4321        }        }
# Line 4048  int length; Line 4343  int length;
4343  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4344  compare_context context;  compare_context context;
4345  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4346    jump_list *end_list;
4347  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4348  struct sljit_label *label;  struct sljit_label *label;
4349  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4116  switch(type) Line 4412  switch(type)
4412    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4413      {      {
4414      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
4415        end_list = NULL;
4416      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4417        jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);        add_jump(compiler, &end_list, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
4418      else      else
4419        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
4420    
4421      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4422      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));
4423      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
4424      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4425      }      }
4426    else    else
# Line 4138  switch(type) Line 4434  switch(type)
4434      {      {
4435      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4436      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));
4437  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
4438    #if defined COMPILE_PCRE8
4439      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4440      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);
4441      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4442  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
4443      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
4444      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4445      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);
4446      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4447      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4448      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4449  #endif /* COMPILE_PCRE16 */  #endif
 #endif /* COMPILE_PCRE8 */  
4450      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4451    #endif /* COMPILE_PCRE[8|16] */
4452      return cc;      return cc;
4453      }      }
4454  #endif  #endif
# Line 4183  switch(type) Line 4479  switch(type)
4479    read_char(common);    read_char(common);
4480    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
4481    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
4482      end_list = NULL;
4483    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4484      jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      add_jump(compiler, &end_list, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
4485    else    else
4486      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
4487    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4488    jump[2] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);    jump[1] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);
4489    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));
4490    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
4491    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4492    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
4493      set_jumps(end_list, LABEL());
4494    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4495    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
4496    return cc;    return cc;
4497    
4498    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
# Line 4219  switch(type) Line 4516  switch(type)
4516    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4517    read_char(common);    read_char(common);
4518    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4519    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));
4520    OP1(SLJIT_MOV_UB, TMP3, 0, SLJIT_MEM2(TMP1, TMP2), 3);    /* Optimize register allocation: use a real register. */
4521      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4522      OP1(SLJIT_MOV_UB, STACK_TOP, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4523    
4524    label = LABEL();    label = LABEL();
4525    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);
4526    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
4527    read_char(common);    read_char(common);
4528    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4529    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));
4530    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4531    
4532    OP2(SLJIT_MUL, TMP1, 0, TMP3, 0, SLJIT_IMM, ucp_gbCount);    OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);
4533    OP1(SLJIT_MOV, TMP3, 0, TMP2, 0);    OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STACK_TOP), (sljit_sw)PRIV(ucp_gbtable));
4534    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);    OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);
4535    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(ucp_gbtable));    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4536    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, label);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4537      JUMPTO(SLJIT_C_NOT_ZERO, label);
4538    
4539    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
4540    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4541      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
4542    
4543    if (common->mode == JIT_PARTIAL_HARD_COMPILE)    if (common->mode == JIT_PARTIAL_HARD_COMPILE)
4544      {      {
4545      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 4563  switch(type)
4563        {        {
4564        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);
4565        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);
4566        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS);
4567        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);
4568        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);
4569        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));
4570        check_partial(common, TRUE);        check_partial(common, TRUE);
4571        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
# Line 4443  switch(type) Line 4745  switch(type)
4745      }      }
4746    oc = char_othercase(common, c);    oc = char_othercase(common, c);
4747    bit = c ^ oc;    bit = c ^ oc;
4748    if (ispowerof2(bit))    if (is_powerof2(bit))
4749      {      {
4750      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4751      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));
4752      return cc + length;      return cc + length;
4753      }      }
4754    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);
4755    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4756    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);
4757    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);
4758    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4759    return cc + length;    return cc + length;
4760    
# Line 4479  switch(type) Line 4781  switch(type)
4781        /* Skip the variable-length character. */        /* Skip the variable-length character. */
4782        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));
4783        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4784        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);
4785        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4786        JUMPHERE(jump[0]);        JUMPHERE(jump[0]);
4787        return cc + 1;        return cc + 1;
# Line 4504  switch(type) Line 4806  switch(type)
4806      {      {
4807      oc = char_othercase(common, c);      oc = char_othercase(common, c);
4808      bit = c ^ oc;      bit = c ^ oc;
4809      if (ispowerof2(bit))      if (is_powerof2(bit))
4810        {        {
4811        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4812        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 4844  switch(type)
4844  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4845    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4846    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4847    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4848    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4849    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);
4850    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 4552  switch(type) Line 4854  switch(type)
4854  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4855    return cc + 32 / sizeof(pcre_uchar);    return cc + 32 / sizeof(pcre_uchar);
4856    
4857  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4858    case OP_XCLASS:    case OP_XCLASS:
4859    compile_xclass_matchingpath(common, cc + LINK_SIZE, backtracks);    compile_xclass_matchingpath(common, cc + LINK_SIZE, backtracks);
4860    return cc + GET(cc, 0) - 1;    return cc + GET(cc, 0) - 1;
# Line 4666  if (!common->jscript_compat) Line 4968  if (!common->jscript_compat)
4968      {      {
4969      /* OVECTOR(1) contains the "string begin - 1" constant. */      /* OVECTOR(1) contains the "string begin - 1" constant. */
4970      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));
4971      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4972      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));
4973      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);
4974      return JUMP(SLJIT_C_NOT_ZERO);      return JUMP(SLJIT_C_NOT_ZERO);
4975      }      }
4976    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 5026  if (withchecks && !common->jscript_compa
5026  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5027  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5028    {    {
5029    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);
5030    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));
5031    if (withchecks)    if (withchecks)
5032      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5033    
5034    /* Needed to save important temporary registers. */    /* Needed to save important temporary registers. */
5035    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5036    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
5037    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);
5038    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));
5039    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5040    if (common->mode == JIT_COMPILE)    if (common->mode == JIT_COMPILE)
# Line 4845  if (!minimize) Line 5147  if (!minimize)
5147      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5148      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5149      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5150      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));
5151      zerolength = compile_ref_checks(common, ccbegin, NULL);      zerolength = compile_ref_checks(common, ccbegin, NULL);
5152      /* Restore if not zero length. */      /* Restore if not zero length. */
5153      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));
5154      }      }
5155    else    else
5156      {      {
# Line 4941  backtrack_common *backtrack; Line 5243  backtrack_common *backtrack;
5243  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5244  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5245  int start = GET(cc, 1);  int start = GET(cc, 1);
5246    pcre_uchar *start_cc;
5247    
5248  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5249    
5250    /* Inlining simple patterns. */
5251    if (get_framesize(common, common->start + start, TRUE) == no_stack)
5252      {
5253      start_cc = common->start + start;
5254      compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
5255      BACKTRACK_AS(recurse_backtrack)->inlined_pattern = TRUE;
5256      return cc + 1 + LINK_SIZE;
5257      }
5258    
5259  while (entry != NULL)  while (entry != NULL)
5260    {    {
5261    if (entry->start == start)    if (entry->start == start)
# Line 4991  add_jump(compiler, &backtrack->topbacktr Line 5304  add_jump(compiler, &backtrack->topbacktr
5304  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5305  }  }
5306    
5307    static int SLJIT_CALL do_callout(struct jit_arguments* arguments, PUBL(callout_block) *callout_block, pcre_uchar **jit_ovector)
5308    {
5309    const pcre_uchar *begin = arguments->begin;
5310    int *offset_vector = arguments->offsets;
5311    int offset_count = arguments->offset_count;
5312    int i;
5313    
5314    if (PUBL(callout) == NULL)
5315      return 0;
5316    
5317    callout_block->version = 2;
5318    callout_block->callout_data = arguments->callout_data;
5319    
5320    /* Offsets in subject. */
5321    callout_block->subject_length = arguments->end - arguments->begin;
5322    callout_block->start_match = (pcre_uchar*)callout_block->subject - arguments->begin;
5323    callout_block->current_position = (pcre_uchar*)callout_block->offset_vector - arguments->begin;
5324    #if defined COMPILE_PCRE8
5325    callout_block->subject = (PCRE_SPTR)begin;
5326    #elif defined COMPILE_PCRE16
5327    callout_block->subject = (PCRE_SPTR16)begin;
5328    #elif defined COMPILE_PCRE32
5329    callout_block->subject = (PCRE_SPTR32)begin;
5330    #endif
5331    
5332    /* Convert and copy the JIT offset vector to the offset_vector array. */
5333    callout_block->capture_top = 0;
5334    callout_block->offset_vector = offset_vector;
5335    for (i = 2; i < offset_count; i += 2)
5336      {
5337      offset_vector[i] = jit_ovector[i] - begin;
5338      offset_vector[i + 1] = jit_ovector[i + 1] - begin;
5339      if (jit_ovector[i] >= begin)
5340        callout_block->capture_top = i;
5341      }
5342    
5343    callout_block->capture_top = (callout_block->capture_top >> 1) + 1;
5344    if (offset_count > 0)
5345      offset_vector[0] = -1;
5346    if (offset_count > 1)
5347      offset_vector[1] = -1;
5348    return (*PUBL(callout))(callout_block);
5349    }
5350    
5351    /* Aligning to 8 byte. */
5352    #define CALLOUT_ARG_SIZE \
5353        (((int)sizeof(PUBL(callout_block)) + 7) & ~7)
5354    
5355    #define CALLOUT_ARG_OFFSET(arg) \
5356        (-CALLOUT_ARG_SIZE + SLJIT_OFFSETOF(PUBL(callout_block), arg))
5357    
5358    static SLJIT_INLINE pcre_uchar *compile_callout_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5359    {
5360    DEFINE_COMPILER;
5361    backtrack_common *backtrack;
5362    
5363    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
5364    
5365    allocate_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5366    
5367    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5368    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
5369    SLJIT_ASSERT(common->capture_last_ptr != 0);
5370    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
5371    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
5372    
5373    /* These pointer sized fields temporarly stores internal variables. */
5374    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
5375    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0);
5376    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(subject), TMP2, 0);
5377    
5378    if (common->mark_ptr != 0)
5379      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));
5380    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));
5381    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));
5382    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
5383    
5384    /* Needed to save important temporary registers. */
5385    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5386    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, STACK_TOP, 0, SLJIT_IMM, CALLOUT_ARG_SIZE);
5387    GET_LOCAL_BASE(SLJIT_SCRATCH_REG3, 0, OVECTOR_START);
5388    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout));
5389    OP1(SLJIT_MOV_SI, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0);
5390    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5391    free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5392    
5393    /* Check return value. */
5394    OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
5395    add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_C_SIG_GREATER));
5396    if (common->forced_quit_label == NULL)
5397      add_jump(compiler, &common->forced_quit, JUMP(SLJIT_C_SIG_LESS));
5398    else
5399      JUMPTO(SLJIT_C_SIG_LESS, common->forced_quit_label);
5400    return cc + 2 + 2 * LINK_SIZE;
5401    }
5402    
5403    #undef CALLOUT_ARG_SIZE
5404    #undef CALLOUT_ARG_OFFSET
5405    
5406  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)
5407  {  {
5408  DEFINE_COMPILER;  DEFINE_COMPILER;
5409  int framesize;  int framesize;
5410    int extrasize;
5411    BOOL needs_control_head = common->control_head_ptr != 0;
5412  int private_data_ptr;  int private_data_ptr;
5413  backtrack_common altbacktrack;  backtrack_common altbacktrack;
5414  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5004  jump_list *tmp = NULL; Line 5418  jump_list *tmp = NULL;
5418  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5419  jump_list **found;  jump_list **found;
5420  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5421  struct sljit_label *save_quitlabel = common->quitlabel;  struct sljit_label *save_quit_label = common->quit_label;
5422  struct sljit_label *save_acceptlabel = common->acceptlabel;  struct sljit_label *save_accept_label = common->accept_label;
5423  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5424  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
5425    BOOL save_local_exit = common->local_exit;
5426  struct sljit_jump *jump;  struct sljit_jump *jump;
5427  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
5428    
# Line 5038  if (bra == OP_BRAMINZERO) Line 5453  if (bra == OP_BRAMINZERO)
5453    
5454  if (framesize < 0)  if (framesize < 0)
5455    {    {
5456    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    extrasize = needs_control_head ? 2 : 1;
5457    allocate_stack(common, 1);    if (framesize != no_stack)
5458        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5459      allocate_stack(common, extrasize);
5460      if (needs_control_head)
5461        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5462    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5463      if (needs_control_head)
5464        {
5465        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5466        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5467        }
5468    }    }
5469  else  else
5470    {    {
5471    allocate_stack(common, framesize + 2);    extrasize = needs_control_head ? 3 : 2;
5472      allocate_stack(common, framesize + extrasize);
5473    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);
5474    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(framesize + 1));    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
5475    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);
5476      if (needs_control_head)
5477        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5478    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5479    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    if (needs_control_head)
5480    init_frame(common, ccbegin, framesize + 1, 2, FALSE);      {
5481        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
5482        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
5483        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5484        }
5485      else
5486        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5487      init_frame(common, ccbegin, framesize + extrasize - 1, extrasize, FALSE);
5488    }    }
5489    
5490  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5491  common->quitlabel = NULL;  common->local_exit = TRUE;
5492    common->quit_label = NULL;
5493  common->quit = NULL;  common->quit = NULL;
5494  while (1)  while (1)
5495    {    {
5496    common->acceptlabel = NULL;    common->accept_label = NULL;
5497    common->accept = NULL;    common->accept = NULL;
5498    altbacktrack.top = NULL;    altbacktrack.top = NULL;
5499    altbacktrack.topbacktracks = NULL;    altbacktrack.topbacktracks = NULL;
# Line 5070  while (1) Line 5505  while (1)
5505    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5506    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5507      {      {
5508      common->quitlabel = save_quitlabel;      common->local_exit = save_local_exit;
5509      common->acceptlabel = save_acceptlabel;      common->quit_label = save_quit_label;
5510        common->accept_label = save_accept_label;
5511      common->quit = save_quit;      common->quit = save_quit;
5512      common->accept = save_accept;      common->accept = save_accept;
5513      return NULL;      return NULL;
5514      }      }
5515    common->acceptlabel = LABEL();    common->accept_label = LABEL();
5516    if (common->accept != NULL)    if (common->accept != NULL)
5517      set_jumps(common->accept, common->acceptlabel);      set_jumps(common->accept, common->accept_label);
5518    
5519    /* Reset stack. */    /* Reset stack. */
5520    if (framesize < 0)    if (framesize < 0)
5521      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      {
5522    else {      if (framesize != no_stack)
5523          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5524        else
5525          free_stack(common, extrasize);
5526        if (needs_control_head)
5527          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5528        }
5529      else
5530        {
5531      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
5532        {        {
5533        /* 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. */
5534        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));
5535          if (needs_control_head)
5536            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5537        }        }
5538      else      else
5539        {        {
5540        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);
5541          if (needs_control_head)
5542            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));
5543        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5544        }        }
5545    }      }
5546    
5547    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5548      {      {
5549      /* We know that STR_PTR was stored on the top of the stack. */      /* We know that STR_PTR was stored on the top of the stack. */
5550      if (conditional)      if (conditional)
5551        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), needs_control_head ? sizeof(sljit_sw) : 0);
5552      else if (bra == OP_BRAZERO)      else if (bra == OP_BRAZERO)
5553        {        {
5554        if (framesize < 0)        if (framesize < 0)
5555          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 1) * sizeof(sljit_sw));
5556        else        else
5557          {          {
5558          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));
5559          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 + extrasize - 1) * sizeof(sljit_sw));
5560          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);
5561          }          }
5562        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));
5563        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5564        }        }
5565      else if (framesize >= 0)      else if (framesize >= 0)
5566        {        {
5567        /* For OP_BRA and OP_BRAMINZERO. */        /* For OP_BRA and OP_BRAMINZERO. */
5568        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));
5569        }        }
5570      }      }
5571    add_jump(compiler, found, JUMP(SLJIT_JUMP));    add_jump(compiler, found, JUMP(SLJIT_JUMP));
# Line 5125  while (1) Line 5573  while (1)
5573    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5574    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5575      {      {
5576      common->quitlabel = save_quitlabel;      common->local_exit = save_local_exit;
5577      common->acceptlabel = save_acceptlabel;      common->quit_label = save_quit_label;
5578        common->accept_label = save_accept_label;
5579      common->quit = save_quit;      common->quit = save_quit;
5580      common->accept = save_accept;      common->accept = save_accept;
5581      return NULL;      return NULL;
# Line 5139  while (1) Line 5588  while (1)
5588    ccbegin = cc;    ccbegin = cc;
5589    cc += GET(cc, 1);    cc += GET(cc, 1);
5590    }    }
5591    
5592  /* None of them matched. */  /* None of them matched. */
5593  if (common->quit != NULL)  if (common->quit != NULL)
5594      {
5595      jump = JUMP(SLJIT_JUMP);
5596    set_jumps(common->quit, LABEL());    set_jumps(common->quit, LABEL());
5597      SLJIT_ASSERT(framesize != no_stack);
5598      if (framesize < 0)
5599        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
5600      else
5601        {
5602        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5603        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5604        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
5605        }
5606      JUMPHERE(jump);
5607      }
5608    
5609    if (needs_control_head)
5610      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(1));
5611    
5612  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)
5613    {    {
# Line 5153  if (opcode == OP_ASSERT || opcode == OP_ Line 5619  if (opcode == OP_ASSERT || opcode == OP_
5619      {      {
5620      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5621      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5622          {
5623          if (extrasize == 2)
5624            free_stack(common, 1);
5625        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5626          }
5627      else      else
5628        free_stack(common, 1);        free_stack(common, extrasize);
5629      }      }
5630    else    else
5631      {      {
5632      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5633      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5634      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5635        {        {
5636        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
5637        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5638        }        }
5639      else      else
5640        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
5641      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);
5642      }      }
5643    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
# Line 5179  if (opcode == OP_ASSERT || opcode == OP_ Line 5649  if (opcode == OP_ASSERT || opcode == OP_
5649    if (framesize < 0)    if (framesize < 0)
5650      {      {
5651      /* We know that STR_PTR was stored on the top of the stack. */      /* We know that STR_PTR was stored on the top of the stack. */
5652      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 1) * sizeof(sljit_sw));
5653      /* Keep the STR_PTR on the top of the stack. */      /* Keep the STR_PTR on the top of the stack. */
5654      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5655        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));        {
5656          OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5657          if (extrasize == 2)
5658            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5659          }
5660      else if (bra == OP_BRAMINZERO)      else if (bra == OP_BRAMINZERO)
5661        {        {
5662        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));
5663        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5664        }        }
5665      }      }
# Line 5194  if (opcode == OP_ASSERT || opcode == OP_ Line 5668  if (opcode == OP_ASSERT || opcode == OP_
5668      if (bra == OP_BRA)      if (bra == OP_BRA)
5669        {        {
5670        /* 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. */
5671        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));
5672        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 2) * sizeof(sljit_sw));
5673        }        }
5674      else      else
5675        {        {
5676        /* 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. */
5677        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));
5678        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        if (extrasize == 2)
5679        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);          {
5680            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5681            if (bra == OP_BRAMINZERO)
5682              OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5683            }
5684          else
5685            {
5686            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5687            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);
5688            }
5689        }        }
5690      }      }
5691    
5692    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
5693      {      {
5694      backtrack->matchingpath = LABEL();      backtrack->matchingpath = LABEL();
5695      sljit_set_label(jump, backtrack->matchingpath);      SET_LABEL(jump, backtrack->matchingpath);
5696      }      }
5697    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
5698      {      {
# Line 5219  if (opcode == OP_ASSERT || opcode == OP_ Line 5702  if (opcode == OP_ASSERT || opcode == OP_
5702        {        {
5703        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);
5704        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5705        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));
5706        }        }
5707      set_jumps(backtrack->common.topbacktracks, LABEL());      set_jumps(backtrack->common.topbacktracks, LABEL());
5708      }      }
# Line 5231  else Line 5714  else
5714      {      {
5715      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5716      if (bra != OP_BRA)      if (bra != OP_BRA)
5717          {
5718          if (extrasize == 2)
5719            free_stack(common, 1);
5720        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5721          }
5722      else      else
5723        free_stack(common, 1);        free_stack(common, extrasize);
5724      }      }
5725    else    else
5726      {      {
5727      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5728      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5729      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5730      if (bra != OP_BRA)      if (bra != OP_BRA)
5731        {        {
5732        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
5733        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5734        }        }
5735      else      else
5736        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
5737      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);
5738      }      }
5739    
# Line 5266  else Line 5753  else
5753      }      }
5754    }    }
5755    
5756  common->quitlabel = save_quitlabel;  common->local_exit = save_local_exit;
5757  common->acceptlabel = save_acceptlabel;  common->quit_label = save_quit_label;
5758    common->accept_label = save_accept_label;
5759  common->quit = save_quit;  common->quit = save_quit;
5760  common->accept = save_accept;  common->accept = save_accept;
5761  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5762  }  }
5763    
5764  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)
5765  {  {
5766  int condition = FALSE;  int condition = FALSE;
5767  pcre_uchar *slotA = name_table;  pcre_uchar *slotA = name_table;
5768  pcre_uchar *slotB;  pcre_uchar *slotB;
5769  sljit_w name_count = locals[LOCALS0 / sizeof(sljit_w)];  sljit_sw name_count = locals[LOCALS0 / sizeof(sljit_sw)];
5770  sljit_w name_entry_size = locals[LOCALS1 / sizeof(sljit_w)];  sljit_sw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];
5771  sljit_w no_capture;  sljit_sw no_capture;
5772  int i;  int i;
5773    
5774  locals += refno & 0xff;  locals += refno & 0xff;
# Line 5330  if (i < name_count) Line 5818  if (i < name_count)
5818  return condition;  return condition;
5819  }  }
5820    
5821  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)
5822  {  {
5823  int condition = FALSE;  int condition = FALSE;
5824  pcre_uchar *slotA = name_table;  pcre_uchar *slotA = name_table;
5825  pcre_uchar *slotB;  pcre_uchar *slotB;
5826  sljit_w name_count = locals[LOCALS0 / sizeof(sljit_w)];  sljit_uw name_count = locals[LOCALS0 / sizeof(sljit_sw)];
5827  sljit_w name_entry_size = locals[LOCALS1 / sizeof(sljit_w)];  sljit_uw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];
5828  sljit_w group_num = locals[POSSESSIVE0 / sizeof(sljit_w)];  sljit_uw group_num = locals[POSSESSIVE0 / sizeof(sljit_sw)];
5829  int i;  sljit_uw i;
5830    
5831  for (i = 0; i < name_count; i++)  for (i = 0; i < name_count; i++)
5832    {    {
# Line 5493  if (SLJIT_UNLIKELY(opcode == OP_COND) || Line 5981  if (SLJIT_UNLIKELY(opcode == OP_COND) ||
5981      else if (common->currententry->start == 0)      else if (common->currententry->start == 0)
5982        has_alternatives = stacksize != 0;        has_alternatives = stacksize != 0;
5983      else      else
5984        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);
5985      }      }
5986    }    }
5987    
# Line 5577  if (bra == OP_BRAMINZERO) Line 6065  if (bra == OP_BRAMINZERO)
6065          {          {
6066          /* Except when the whole stack frame must be saved. */          /* Except when the whole stack frame must be saved. */
6067          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);
6068          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));
6069          }          }
6070        JUMPHERE(skip);        JUMPHERE(skip);
6071        }        }
# Line 5612  if (opcode == OP_ONCE) Line 6100  if (opcode == OP_ONCE)
6100        allocate_stack(common, 2);        allocate_stack(common, 2);
6101        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6102        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6103        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));
6104        }        }
6105      else if (ket == OP_KETRMAX || has_alternatives)      else if (ket == OP_KETRMAX || has_alternatives)
6106        {        {
# Line 5649  if (opcode == OP_ONCE) Line 6137  if (opcode == OP_ONCE)
6137  else if (opcode == OP_CBRA || opcode == OP_SCBRA)  else if (opcode == OP_CBRA || opcode == OP_SCBRA)
6138    {    {
6139    /* Saving the previous values. */    /* Saving the previous values. */
6140    if (common->optimized_cbracket[offset >> 1] == 0)    if (common->optimized_cbracket[offset >> 1] != 0)
6141      {      {
6142      allocate_stack(common, 3);      SLJIT_ASSERT(private_data_ptr == OVECTOR(offset));
6143      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      allocate_stack(common, 2);
     OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);  
6144      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);
6145      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr + sizeof(sljit_sw));
6146      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);
6147      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
6148        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6149      }      }
6150    else    else
6151      {      {
6152      SLJIT_ASSERT(private_data_ptr == OVECTOR(offset));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6153      allocate_stack(common, 2);      allocate_stack(common, 1);
     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
     OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr + sizeof(sljit_w));  
6154      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);
6155      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);  
6156      }      }
6157    }    }
6158  else if (opcode == OP_SBRA || opcode == OP_SCOND)  else if (opcode == OP_SBRA || opcode == OP_SCOND)
# Line 5705  if (opcode == OP_COND || opcode == OP_SC Line 6189  if (opcode == OP_COND || opcode == OP_SC
6189      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);
6190      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);
6191      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);
6192      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)));
6193      GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, 0);      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);
6194      OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, common->name_table);      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);
6195      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));
6196      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
6197      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));
6198    
6199      JUMPHERE(jump);      JUMPHERE(jump);
6200      matchingpath += 1 + IMM2_SIZE;      matchingpath += 1 + IMM2_SIZE;
# Line 5728  if (opcode == OP_COND || opcode == OP_SC Line 6212  if (opcode == OP_COND || opcode == OP_SC
6212      else if (common->currententry->start == 0)      else if (common->currententry->start == 0)
6213        stacksize = stacksize == 0;        stacksize = stacksize == 0;
6214      else      else
6215        stacksize = stacksize == GET2(common->start, common->currententry->start + 1 + LINK_SIZE);        stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6216    
6217      if (*matchingpath == OP_RREF || stacksize || common->currententry == NULL)      if (*matchingpath == OP_RREF || stacksize || common->currententry == NULL)
6218        {        {
# Line 5755  if (opcode == OP_COND || opcode == OP_SC Line 6239  if (opcode == OP_COND || opcode == OP_SC
6239        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);
6240        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);
6241        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));
6242        OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, stacksize);        OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, stacksize);
6243        GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, 0);        GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);
6244        OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, common->name_table);        OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);
6245        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));
6246        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
6247        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));
6248        matchingpath += 1 + IMM2_SIZE;        matchingpath += 1 + IMM2_SIZE;
6249        }        }
6250      }      }
# Line 5799  if (opcode == OP_ONCE) Line 6283  if (opcode == OP_ONCE)
6283    else    else
6284      {      {
6285      stacksize = (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives) ? 2 : 1;      stacksize = (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives) ? 2 : 1;
6286      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));
6287      if (ket == OP_KETRMAX)      if (ket == OP_KETRMAX)
6288        {        {
6289        /* 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 6295  if (opcode == OP_ONCE)
6295  stacksize = 0;  stacksize = 0;
6296  if (ket != OP_KET || bra != OP_BRA)  if (ket != OP_KET || bra != OP_BRA)
6297    stacksize++;    stacksize++;
6298    if (offset != 0)
6299      {
6300      if (common->capture_last_ptr != 0)
6301        stacksize++;
6302      if (common->optimized_cbracket[offset >> 1] == 0)
6303        stacksize += 2;
6304      }
6305  if (has_alternatives && opcode != OP_ONCE)  if (has_alternatives && opcode != OP_ONCE)
6306    stacksize++;    stacksize++;
6307    
# Line 5818  if (stacksize > 0) Line 6309  if (stacksize > 0)
6309    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6310    
6311  stacksize = 0;  stacksize = 0;
6312  if (ket != OP_KET)  if (ket != OP_KET || bra != OP_BRA)
6313    {    {
6314    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);    if (ket != OP_KET)
6315        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6316      else
6317        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
6318    stacksize++;    stacksize++;
6319    }    }
6320  else if (bra != OP_BRA)  
6321    if (offset != 0)
6322    {    {
6323    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);    if (common->capture_last_ptr != 0)
6324    stacksize++;      {
6325        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6326        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6327        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP2, 0);
6328        stacksize++;
6329        }
6330      if (common->optimized_cbracket[offset >> 1] == 0)
6331        {
6332        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6333        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
6334        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6335        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6336        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6337        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6338        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6339        stacksize += 2;
6340        }
6341    }    }
6342    
6343  if (has_alternatives)  if (has_alternatives)
# Line 5838  if (has_alternatives) Line 6349  if (has_alternatives)
6349    }    }
6350    
6351  /* Must be after the matchingpath label. */  /* Must be after the matchingpath label. */
6352  if (offset != 0)  if (offset != 0 && common->optimized_cbracket[offset >> 1] != 0)
6353    {    {
6354    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0));
6355    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);  
6356    }    }
6357    
6358  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
# Line 5956  framesize = get_framesize(common, cc, FA Line 6466  framesize = get_framesize(common, cc, FA
6466  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;
6467  if (framesize < 0)  if (framesize < 0)
6468    {    {
6469    stacksize = (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS) ? 2 : 1;    if (offset != 0)
6470        {