/[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 1291 by zherczeg, Sun Mar 17 05:27:48 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_mark = 0,
206      type_then_trap = 1
207    };
208    
209  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
210    
211  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
# Line 208  typedef struct backtrack_common { Line 226  typedef struct backtrack_common {
226  typedef struct assert_backtrack {  typedef struct assert_backtrack {
227    backtrack_common common;    backtrack_common common;
228    jump_list *condfailed;    jump_list *condfailed;
229    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
230    int framesize;    int framesize;
231    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
232    int private_data_ptr;    int private_data_ptr;
# Line 229  typedef struct bracket_backtrack { Line 247  typedef struct bracket_backtrack {
247      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
248      jump_list *condfailed;      jump_list *condfailed;
249      assert_backtrack *assert;      assert_backtrack *assert;
250      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
251      int framesize;      int framesize;
252    } u;    } u;
253    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
# Line 264  typedef struct recurse_entry { Line 282  typedef struct recurse_entry {
282    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
283    jump_list *calls;    jump_list *calls;
284    /* Points to the starting opcode. */    /* Points to the starting opcode. */
285    int start;    sljit_sw start;
286  } recurse_entry;  } recurse_entry;
287    
288  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
289    backtrack_common common;    backtrack_common common;
290      BOOL inlined_pattern;
291  } recurse_backtrack;  } recurse_backtrack;
292    
293    #define OP_THEN_TRAP OP_TABLE_LENGTH
294    
295    typedef struct then_trap_backtrack {
296      backtrack_common common;
297      /* If then_trap is not NULL, this structure contains the real
298      then_trap for the backtracking path. */
299      struct then_trap_backtrack *then_trap;
300      /* Points to the starting opcode. */
301      sljit_sw start;
302      /* Exit point for the then opcodes of this alternative. */
303      jump_list *quit;
304      /* Frame size of the current alternative. */
305      int framesize;
306    } then_trap_backtrack;
307    
308  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 6
309    
310  typedef struct compiler_common {  typedef struct compiler_common {
311      /* The sljit ceneric compiler. */
312    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
313      /* First byte code. */
314    pcre_uchar *start;    pcre_uchar *start;
   
315    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
316    int *private_data_ptrs;    int *private_data_ptrs;
317    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
318    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
319      /* Tells whether the starting offset is a target of then. */
320      pcre_uint8 *then_offsets;
321      /* Current position where a THEN must jump. */
322      then_trap_backtrack *then_trap;
323    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
324    int cbraptr;    int cbra_ptr;
325    /* OVector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
326    int ovector_start;    int ovector_start;
327    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
328    int req_char_ptr;    int req_char_ptr;
329    /* Head of the last recursion. */    /* Head of the last recursion. */
330    int recursive_head;    int recursive_head_ptr;
331    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
332    int start_used_ptr;    int start_used_ptr;
333    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 297  typedef struct compiler_common { Line 336  typedef struct compiler_common {
336    int first_line_end;    int first_line_end;
337    /* Points to the marked string. */    /* Points to the marked string. */
338    int mark_ptr;    int mark_ptr;
339      /* Recursive control verb management chain. */
340      int control_head_ptr;
341      /* Points to the last matched capture block index. */
342      int capture_last_ptr;
343      /* Points to the starting position of the current match. */
344      int start_ptr;
345    
346    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
347    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
348    sljit_w lcc;    sljit_sw lcc;
349    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
350    int mode;    int mode;
351      /* \K is found in the pattern. */
352      BOOL has_set_som;
353      /* (*SKIP:arg) is found in the pattern. */
354      BOOL has_skip_arg;
355      /* (*THEN) is found in the pattern. */
356      BOOL has_then;
357      /* Needs to know the start position anytime. */
358      BOOL needs_start_ptr;
359      /* Currently in recurse or assert. */
360      BOOL local_exit;
361    /* Newline control. */    /* Newline control. */
362    int nltype;    int nltype;
363    int newline;    int newline;
364    int bsr_nltype;    int bsr_nltype;
365    /* Dollar endonly. */    /* Dollar endonly. */
366    int endonly;    int endonly;
   BOOL has_set_som;  
367    /* Tables. */    /* Tables. */
368    sljit_w ctypes;    sljit_sw ctypes;
369    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
370    /* Named capturing brackets. */    /* Named capturing brackets. */
371    sljit_uw name_table;    sljit_uw name_table;
372    sljit_w name_count;    sljit_sw name_count;
373    sljit_w name_entry_size;    sljit_sw name_entry_size;
374    
375    /* Labels and jump lists. */    /* Labels and jump lists. */
376    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
377    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
378    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
379      struct sljit_label *accept_label;
380    stub_list *stubs;    stub_list *stubs;
381    recurse_entry *entries;    recurse_entry *entries;
382    recurse_entry *currententry;    recurse_entry *currententry;
383    jump_list *partialmatch;    jump_list *partialmatch;
384    jump_list *quit;    jump_list *quit;
385      jump_list *forced_quit;
386    jump_list *accept;    jump_list *accept;
387    jump_list *calllimit;    jump_list *calllimit;
388    jump_list *stackalloc;    jump_list *stackalloc;
# Line 337  typedef struct compiler_common { Line 393  typedef struct compiler_common {
393    jump_list *vspace;    jump_list *vspace;
394    jump_list *casefulcmp;    jump_list *casefulcmp;
395    jump_list *caselesscmp;    jump_list *caselesscmp;
396      jump_list *reset_match;
397    BOOL jscript_compat;    BOOL jscript_compat;
398  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
399    BOOL utf;    BOOL utf;
400  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
401    BOOL use_ucp;    BOOL use_ucp;
402  #endif  #endif
403    #ifndef COMPILE_PCRE32
404    jump_list *utfreadchar;    jump_list *utfreadchar;
405    #endif
406  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
407    jump_list *utfreadtype8;    jump_list *utfreadtype8;
408  #endif  #endif
# Line 361  typedef struct compare_context { Line 420  typedef struct compare_context {
420  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
421    int ucharptr;    int ucharptr;
422    union {    union {
423      sljit_i asint;      sljit_si asint;
424      sljit_uh asushort;      sljit_uh asushort;
425  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
426      sljit_ub asbyte;      sljit_ub asbyte;
427      sljit_ub asuchars[4];      sljit_ub asuchars[4];
428  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
429      sljit_uh asuchars[2];      sljit_uh asuchars[2];
430  #endif  #elif defined COMPILE_PCRE32
431        sljit_ui asuchars[1];
432  #endif  #endif
433    } c;    } c;
434    union {    union {
435      sljit_i asint;      sljit_si asint;
436      sljit_uh asushort;      sljit_uh asushort;
437  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
438      sljit_ub asbyte;      sljit_ub asbyte;
439      sljit_ub asuchars[4];      sljit_ub asuchars[4];
440  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
441      sljit_uh asuchars[2];      sljit_uh asuchars[2];
442  #endif  #elif defined COMPILE_PCRE32
443        sljit_ui asuchars[1];
444  #endif  #endif
445    } oc;    } oc;
446  #endif  #endif
447  } compare_context;  } compare_context;
448    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
449  /* Undefine sljit macros. */  /* Undefine sljit macros. */
450  #undef CMP  #undef CMP
451    
452  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
453  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
454    
455  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
456  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
457  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
458  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
459  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
460  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
461  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
462  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
463  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
# Line 412  enum { Line 465  enum {
465    
466  /* Local space layout. */  /* Local space layout. */
467  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
468  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
469  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
470  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
471  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
472  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
473  /* Max limit of recursions. */  /* Max limit of recursions. */
474  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
475  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
476  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
477  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
478  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. */
479  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
480  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
481  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))
482  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
483    
484  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
485  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
486  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
487  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
488  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
489  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
490    #elif defined COMPILE_PCRE32
491    #define MOV_UCHAR  SLJIT_MOV_UI
492    #define MOVU_UCHAR SLJIT_MOVU_UI
493  #else  #else
494  #error Unsupported compiling mode  #error Unsupported compiling mode
495  #endif  #endif
 #endif  
496    
497  /* Shortcuts. */  /* Shortcuts. */
498  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 455  the start pointers when the end of the c Line 509  the start pointers when the end of the c
509    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
510  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
511    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
512    #define SET_LABEL(jump, label) \
513      sljit_set_label((jump), (label))
514  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
515    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
516  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
517    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))
518  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
519    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
520  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
521    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
522    
# Line 479  return cc; Line 535  return cc;
535   set_private_data_ptrs   set_private_data_ptrs
536   get_framesize   get_framesize
537   init_frame   init_frame
538   get_private_data_length_for_copy   get_private_data_copy_length
539   copy_private_data   copy_private_data
540   compile_matchingpath   compile_matchingpath
541   compile_backtrackingpath   compile_backtrackingpath
# Line 503  switch(*cc) Line 559  switch(*cc)
559    case OP_WORDCHAR:    case OP_WORDCHAR:
560    case OP_ANY:    case OP_ANY:
561    case OP_ALLANY:    case OP_ALLANY:
562      case OP_NOTPROP:
563      case OP_PROP:
564    case OP_ANYNL:    case OP_ANYNL:
565    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
566    case OP_HSPACE:    case OP_HSPACE:
# Line 515  switch(*cc) Line 573  switch(*cc)
573    case OP_CIRCM:    case OP_CIRCM:
574    case OP_DOLL:    case OP_DOLL:
575    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:  
576    case OP_CRSTAR:    case OP_CRSTAR:
577    case OP_CRMINSTAR:    case OP_CRMINSTAR:
578    case OP_CRPLUS:    case OP_CRPLUS:
579    case OP_CRMINPLUS:    case OP_CRMINPLUS:
580    case OP_CRQUERY:    case OP_CRQUERY:
581    case OP_CRMINQUERY:    case OP_CRMINQUERY:
582      case OP_CRRANGE:
583      case OP_CRMINRANGE:
584      case OP_CLASS:
585      case OP_NCLASS:
586      case OP_REF:
587      case OP_REFI:
588      case OP_RECURSE:
589      case OP_CALLOUT:
590      case OP_ALT:
591      case OP_KET:
592      case OP_KETRMAX:
593      case OP_KETRMIN:
594      case OP_KETRPOS:
595      case OP_REVERSE:
596      case OP_ASSERT:
597      case OP_ASSERT_NOT:
598      case OP_ASSERTBACK:
599      case OP_ASSERTBACK_NOT:
600      case OP_ONCE:
601      case OP_ONCE_NC:
602      case OP_BRA:
603      case OP_BRAPOS:
604      case OP_CBRA:
605      case OP_CBRAPOS:
606      case OP_COND:
607      case OP_SBRA:
608      case OP_SBRAPOS:
609      case OP_SCBRA:
610      case OP_SCBRAPOS:
611      case OP_SCOND:
612      case OP_CREF:
613      case OP_NCREF:
614      case OP_RREF:
615      case OP_NRREF:
616    case OP_DEF:    case OP_DEF:
617    case OP_BRAZERO:    case OP_BRAZERO:
618    case OP_BRAMINZERO:    case OP_BRAMINZERO:
619    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
620      case OP_PRUNE:
621      case OP_SKIP:
622      case OP_THEN:
623    case OP_COMMIT:    case OP_COMMIT:
624    case OP_FAIL:    case OP_FAIL:
625    case OP_ACCEPT:    case OP_ACCEPT:
626    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
627      case OP_CLOSE:
628    case OP_SKIPZERO:    case OP_SKIPZERO:
629    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
630    
631    case OP_CHAR:    case OP_CHAR:
632    case OP_CHARI:    case OP_CHARI:
# Line 557  switch(*cc) Line 638  switch(*cc)
638    case OP_MINPLUS:    case OP_MINPLUS:
639    case OP_QUERY:    case OP_QUERY:
640    case OP_MINQUERY:    case OP_MINQUERY:
641      case OP_UPTO:
642      case OP_MINUPTO:
643      case OP_EXACT:
644    case OP_POSSTAR:    case OP_POSSTAR:
645    case OP_POSPLUS:    case OP_POSPLUS:
646    case OP_POSQUERY:    case OP_POSQUERY:
647      case OP_POSUPTO:
648    case OP_STARI:    case OP_STARI:
649    case OP_MINSTARI:    case OP_MINSTARI:
650    case OP_PLUSI:    case OP_PLUSI:
651    case OP_MINPLUSI:    case OP_MINPLUSI:
652    case OP_QUERYI:    case OP_QUERYI:
653    case OP_MINQUERYI:    case OP_MINQUERYI:
654      case OP_UPTOI:
655      case OP_MINUPTOI:
656      case OP_EXACTI:
657    case OP_POSSTARI:    case OP_POSSTARI:
658    case OP_POSPLUSI:    case OP_POSPLUSI:
659    case OP_POSQUERYI:    case OP_POSQUERYI:
660      case OP_POSUPTOI:
661    case OP_NOTSTAR:    case OP_NOTSTAR:
662    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
663    case OP_NOTPLUS:    case OP_NOTPLUS:
664    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
665    case OP_NOTQUERY:    case OP_NOTQUERY:
666    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
667      case OP_NOTUPTO:
668      case OP_NOTMINUPTO:
669      case OP_NOTEXACT:
670    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
671    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
672    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
673      case OP_NOTPOSUPTO:
674    case OP_NOTSTARI:    case OP_NOTSTARI:
675    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
676    case OP_NOTPLUSI:    case OP_NOTPLUSI:
677    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
678    case OP_NOTQUERYI:    case OP_NOTQUERYI:
679    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:  
680    case OP_NOTUPTOI:    case OP_NOTUPTOI:
681    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
682    case OP_NOTEXACTI:    case OP_NOTEXACTI:
683      case OP_NOTPOSSTARI:
684      case OP_NOTPOSPLUSI:
685      case OP_NOTPOSQUERYI:
686    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
687    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
688  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
689    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
690  #endif  #endif
691    return cc;    return cc;
692    
693    case OP_NOTPROP:    /* Special cases. */
694    case OP_PROP:    case OP_TYPESTAR:
695    return cc + 1 + 2;    case OP_TYPEMINSTAR:
696      case OP_TYPEPLUS:
697      case OP_TYPEMINPLUS:
698      case OP_TYPEQUERY:
699      case OP_TYPEMINQUERY:
700    case OP_TYPEUPTO:    case OP_TYPEUPTO:
701    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
702    case OP_TYPEEXACT:    case OP_TYPEEXACT:
703      case OP_TYPEPOSSTAR:
704      case OP_TYPEPOSPLUS:
705      case OP_TYPEPOSQUERY:
706    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
707    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;  
708    
709    case OP_CRRANGE:    case OP_ANYBYTE:
710    case OP_CRMINRANGE:  #ifdef SUPPORT_UTF
711    return cc + 1 + 2 * IMM2_SIZE;    if (common->utf) return NULL;
712    #endif
713    case OP_CLASS:    return cc + 1;
   case OP_NCLASS:  
   return cc + 1 + 32 / sizeof(pcre_uchar);  
714    
715  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
716    case OP_XCLASS:    case OP_XCLASS:
717    return cc + GET(cc, 1);    return cc + GET(cc, 1);
718  #endif  #endif
719    
   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;  
   
720    case OP_MARK:    case OP_MARK:
721      case OP_PRUNE_ARG:
722      case OP_SKIP_ARG:
723      case OP_THEN_ARG:
724    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
725    
726    default:    default:
727      /* All opcodes are supported now! */
728      SLJIT_ASSERT_STOP();
729    return NULL;    return NULL;
730    }    }
731  }  }
# Line 764  int private_data_length = 0; Line 813  int private_data_length = 0;
813  pcre_uchar *alternative;  pcre_uchar *alternative;
814  pcre_uchar *name;  pcre_uchar *name;
815  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
816  int space, size, bracketlen, i;  int space, size, i;
817    pcre_uint32 bracketlen;
818    
819  /* 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. */
820  while (cc < ccend)  while (cc < ccend)
# Line 794  while (cc < ccend) Line 844  while (cc < ccend)
844      case OP_BRAPOS:      case OP_BRAPOS:
845      case OP_SBRA:      case OP_SBRA:
846      case OP_SBRAPOS:      case OP_SBRAPOS:
847      private_data_length += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
848      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
849      break;      break;
850    
851      case OP_CBRAPOS:      case OP_CBRAPOS:
852      case OP_SCBRAPOS:      case OP_SCBRAPOS:
853      private_data_length += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
854      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
855      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
856      break;      break;
857    
858      case OP_COND:      case OP_COND:
859      case OP_SCOND:      case OP_SCOND:
860      bracketlen = cc[1 + LINK_SIZE];      /* Only AUTO_CALLOUT can insert this opcode. We do
861      if (bracketlen == OP_CREF)         not intend to support this case. */
862        {      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
863        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;  
         }  
       }  
864    
865      if (*cc == OP_COND)      if (*cc == OP_COND)
866        {        {
867        /* Might be a hidden SCOND. */        /* Might be a hidden SCOND. */
868        alternative = cc + GET(cc, 1);        alternative = cc + GET(cc, 1);
869        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
870          private_data_length += sizeof(sljit_w);          private_data_length += sizeof(sljit_sw);
871        }        }
872      else      else
873        private_data_length += sizeof(sljit_w);        private_data_length += sizeof(sljit_sw);
874      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
875      break;      break;
876    
877        case OP_CREF:
878        i = GET2(cc, 1);
879        common->optimized_cbracket[i] = 0;
880        cc += 1 + IMM2_SIZE;
881        break;
882    
883        case OP_NCREF:
884        bracketlen = GET2(cc, 1);
885        name = (pcre_uchar *)common->name_table;
886        alternative = name;
887        for (i = 0; i < common->name_count; i++)
888          {
889          if (GET2(name, 0) == bracketlen) break;
890          name += common->name_entry_size;
891          }
892        SLJIT_ASSERT(i != common->name_count);
893    
894        for (i = 0; i < common->name_count; i++)
895          {
896          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
897            common->optimized_cbracket[GET2(alternative, 0)] = 0;
898          alternative += common->name_entry_size;
899          }
900        bracketlen = 0;
901        cc += 1 + IMM2_SIZE;
902        break;
903    
904      case OP_BRA:      case OP_BRA:
905      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
906      break;      break;
# Line 901  while (cc < ccend) Line 957  while (cc < ccend)
957    
958      case OP_RECURSE:      case OP_RECURSE:
959      /* Set its value only once. */      /* Set its value only once. */
960      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
961        {        {
962        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
963        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
964        }        }
965      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
966      break;      break;
967    
968        case OP_CALLOUT:
969        if (common->capture_last_ptr == 0)
970          {
971          common->capture_last_ptr = common->ovector_start;
972          common->ovector_start += sizeof(sljit_sw);
973          }
974        cc += 2 + 2 * LINK_SIZE;
975        break;
976    
977        case OP_THEN_ARG:
978        common->has_then = TRUE;
979        common->control_head_ptr = 1;
980        /* Fall through. */
981    
982        case OP_PRUNE_ARG:
983        common->needs_start_ptr = TRUE;
984        /* Fall through. */
985    
986      case OP_MARK:      case OP_MARK:
987      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
988        {        {
989        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
990        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
991        }        }
992      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
993      break;      break;
994    
995        case OP_THEN:
996        common->has_then = TRUE;
997        common->control_head_ptr = 1;
998        /* Fall through. */
999    
1000        case OP_PRUNE:
1001        case OP_SKIP:
1002        common->needs_start_ptr = TRUE;
1003        cc += 1;
1004        break;
1005    
1006        case OP_SKIP_ARG:
1007        common->control_head_ptr = 1;
1008        common->has_skip_arg = TRUE;
1009        cc += 1 + 2 + cc[1];
1010        break;
1011    
1012      default:      default:
1013      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1014      if (cc == NULL)      if (cc == NULL)
# Line 926  while (cc < ccend) Line 1017  while (cc < ccend)
1017      }      }
1018    
1019    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1020      private_data_length += sizeof(sljit_w) * space;      private_data_length += sizeof(sljit_sw) * space;
1021    
1022    if (size != 0)    if (size != 0)
1023      {      {
# Line 941  while (cc < ccend) Line 1032  while (cc < ccend)
1032        cc += size;        cc += size;
1033      }      }
1034    
1035    if (bracketlen > 0)    if (bracketlen != 0)
1036      {      {
1037      if (cc >= end)      if (cc >= end)
1038        {        {
# Line 980  while (cc < ccend) Line 1071  while (cc < ccend)
1071      case OP_SBRAPOS:      case OP_SBRAPOS:
1072      case OP_SCOND:      case OP_SCOND:
1073      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1074      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1075      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1076      break;      break;
1077    
1078      case OP_CBRAPOS:      case OP_CBRAPOS:
1079      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1080      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1081      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1082      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1083      break;      break;
1084    
# Line 997  while (cc < ccend) Line 1088  while (cc < ccend)
1088      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1089        {        {
1090        common->private_data_ptrs[cc - common->start] = private_data_ptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1091        private_data_ptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1092        }        }
1093      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1094      break;      break;
# Line 1065  while (cc < ccend) Line 1156  while (cc < ccend)
1156    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1157      {      {
1158      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1159      private_data_ptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1160      }      }
1161    
1162    if (size != 0)    if (size != 0)
# Line 1094  while (cc < ccend) Line 1185  while (cc < ccend)
1185    }    }
1186  }  }
1187    
1188  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1189  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head)
1190  {  {
 pcre_uchar *ccend = bracketend(cc);  
1191  int length = 0;  int length = 0;
1192  BOOL possessive = FALSE;  int possessive = 0;
1193    BOOL stack_restore = FALSE;
1194  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1195  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1196    /* The last capture is a local variable even for recursions. */
1197    BOOL capture_last_found = FALSE;
1198    
1199    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1200    SLJIT_ASSERT(common->control_head_ptr != 0);
1201    *needs_control_head = TRUE;
1202    #else
1203    *needs_control_head = FALSE;
1204    #endif
1205    
1206  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (ccend == NULL)
1207    {    {
1208    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1209    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1210        {
1211        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1212        /* This is correct regardless of common->capture_last_ptr. */
1213        capture_last_found = TRUE;
1214        }
1215      cc = next_opcode(common, cc);
1216    }    }
1217    
 cc = next_opcode(common, cc);  
1218  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1219  while (cc < ccend)  while (cc < ccend)
1220    switch(*cc)    switch(*cc)
1221      {      {
1222      case OP_SET_SOM:      case OP_SET_SOM:
1223      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1224        stack_restore = TRUE;
1225      if (!setsom_found)      if (!setsom_found)
1226        {        {
1227        length += 2;        length += 2;
# Line 1125  while (cc < ccend) Line 1231  while (cc < ccend)
1231      break;      break;
1232    
1233      case OP_MARK:      case OP_MARK:
1234        case OP_PRUNE_ARG:
1235        case OP_THEN_ARG:
1236      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1237        stack_restore = TRUE;
1238      if (!setmark_found)      if (!setmark_found)
1239        {        {
1240        length += 2;        length += 2;
1241        setmark_found = TRUE;        setmark_found = TRUE;
1242        }        }
1243        if (common->control_head_ptr != 0)
1244          *needs_control_head = TRUE;
1245      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1246      break;      break;
1247    
1248      case OP_RECURSE:      case OP_RECURSE:
1249        stack_restore = TRUE;
1250      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1251        {        {
1252        length += 2;        length += 2;
# Line 1145  while (cc < ccend) Line 1257  while (cc < ccend)
1257        length += 2;        length += 2;
1258        setmark_found = TRUE;        setmark_found = TRUE;
1259        }        }
1260        if (common->capture_last_ptr != 0 && !capture_last_found)
1261          {
1262          length += 2;
1263          capture_last_found = TRUE;
1264          }
1265      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1266      break;      break;
1267    
# Line 1152  while (cc < ccend) Line 1269  while (cc < ccend)
1269      case OP_CBRAPOS:      case OP_CBRAPOS:
1270      case OP_SCBRA:      case OP_SCBRA:
1271      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1272        stack_restore = TRUE;
1273        if (common->capture_last_ptr != 0 && !capture_last_found)
1274          {
1275          length += 2;
1276          capture_last_found = TRUE;
1277          }
1278      length += 3;      length += 3;
1279      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1280      break;      break;
1281    
1282      default:      default:
1283        stack_restore = TRUE;
1284        /* Fall through. */
1285    
1286        case OP_NOT_WORD_BOUNDARY:
1287        case OP_WORD_BOUNDARY:
1288        case OP_NOT_DIGIT:
1289        case OP_DIGIT:
1290        case OP_NOT_WHITESPACE:
1291        case OP_WHITESPACE:
1292        case OP_NOT_WORDCHAR:
1293        case OP_WORDCHAR:
1294        case OP_ANY:
1295        case OP_ALLANY:
1296        case OP_ANYBYTE:
1297        case OP_NOTPROP:
1298        case OP_PROP:
1299        case OP_ANYNL:
1300        case OP_NOT_HSPACE:
1301        case OP_HSPACE:
1302        case OP_NOT_VSPACE:
1303        case OP_VSPACE:
1304        case OP_EXTUNI:
1305        case OP_EODN:
1306        case OP_EOD:
1307        case OP_CIRC:
1308        case OP_CIRCM:
1309        case OP_DOLL:
1310        case OP_DOLLM:
1311        case OP_CHAR:
1312        case OP_CHARI:
1313        case OP_NOT:
1314        case OP_NOTI:
1315    
1316        case OP_EXACT:
1317        case OP_POSSTAR:
1318        case OP_POSPLUS:
1319        case OP_POSQUERY:
1320        case OP_POSUPTO:
1321    
1322        case OP_EXACTI:
1323        case OP_POSSTARI:
1324        case OP_POSPLUSI:
1325        case OP_POSQUERYI:
1326        case OP_POSUPTOI:
1327    
1328        case OP_NOTEXACT:
1329        case OP_NOTPOSSTAR:
1330        case OP_NOTPOSPLUS:
1331        case OP_NOTPOSQUERY:
1332        case OP_NOTPOSUPTO:
1333    
1334        case OP_NOTEXACTI:
1335        case OP_NOTPOSSTARI:
1336        case OP_NOTPOSPLUSI:
1337        case OP_NOTPOSQUERYI:
1338        case OP_NOTPOSUPTOI:
1339    
1340        case OP_TYPEEXACT:
1341        case OP_TYPEPOSSTAR:
1342        case OP_TYPEPOSPLUS:
1343        case OP_TYPEPOSQUERY:
1344        case OP_TYPEPOSUPTO:
1345    
1346        case OP_CLASS:
1347        case OP_NCLASS:
1348        case OP_XCLASS:
1349    
1350      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1351      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1352      break;      break;
1353      }      }
1354    
1355  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1356  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1357    return -1;    return stack_restore ? no_frame : no_stack;
1358    
1359  if (length > 0)  if (length > 0)
1360    return length + 1;    return length + 1;
1361  return -1;  return stack_restore ? no_frame : no_stack;
1362  }  }
1363    
1364  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)  static void init_frame(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, int stackpos, int stacktop, BOOL recursive)
1365  {  {
1366  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1367  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1368  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1369    /* The last capture is a local variable even for recursions. */
1370    BOOL capture_last_found = FALSE;
1371  int offset;  int offset;
1372    
1373  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1184  SLJIT_UNUSED_ARG(stacktop); Line 1375  SLJIT_UNUSED_ARG(stacktop);
1375  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1376    
1377  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1378  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1379    cc = next_opcode(common, cc);    {
1380      ccend = bracketend(cc) - (1 + LINK_SIZE);
1381      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1382        cc = next_opcode(common, cc);
1383      }
1384    
1385  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1386  while (cc < ccend)  while (cc < ccend)
1387    switch(*cc)    switch(*cc)
# Line 1195  while (cc < ccend) Line 1391  while (cc < ccend)
1391      if (!setsom_found)      if (!setsom_found)
1392        {        {
1393        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1394        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1395        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1396        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1397        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1398        setsom_found = TRUE;        setsom_found = TRUE;
1399        }        }
1400      cc += 1;      cc += 1;
1401      break;      break;
1402    
1403      case OP_MARK:      case OP_MARK:
1404        case OP_PRUNE_ARG:
1405        case OP_THEN_ARG:
1406      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1407      if (!setmark_found)      if (!setmark_found)
1408        {        {
1409        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);
1410        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);
1411        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
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        setmark_found = TRUE;        setmark_found = TRUE;
1415        }        }
1416      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1222  while (cc < ccend) Line 1420  while (cc < ccend)
1420      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1421        {        {
1422        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1423        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1424        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1425        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1426        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1427        setsom_found = TRUE;        setsom_found = TRUE;
1428        }        }
1429      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1430        {        {
1431        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);
1432        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);
1433        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1434        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1435        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1436        setmark_found = TRUE;        setmark_found = TRUE;
1437        }        }
1438        if (common->capture_last_ptr != 0 && !capture_last_found)
1439          {
1440          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1441          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1442          stackpos += (int)sizeof(sljit_sw);
1443          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1444          stackpos += (int)sizeof(sljit_sw);
1445          capture_last_found = TRUE;
1446          }
1447      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1448      break;      break;
1449    
# Line 1244  while (cc < ccend) Line 1451  while (cc < ccend)
1451      case OP_CBRAPOS:      case OP_CBRAPOS:
1452      case OP_SCBRA:      case OP_SCBRA:
1453      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1454        if (common->capture_last_ptr != 0 && !capture_last_found)
1455          {
1456          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1457          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1458          stackpos += (int)sizeof(sljit_sw);
1459          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1460          stackpos += (int)sizeof(sljit_sw);
1461          capture_last_found = TRUE;
1462          }
1463      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1464      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1465      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1466      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1467      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));
1468      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1469      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1470      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1471      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1472    
1473      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1474      break;      break;
# Line 1263  while (cc < ccend) Line 1479  while (cc < ccend)
1479      break;      break;
1480      }      }
1481    
1482  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1483  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1484  }  }
1485    
1486  static SLJIT_INLINE int get_private_data_length_for_copy(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static SLJIT_INLINE int get_private_data_copy_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL needs_control_head)
1487  {  {
1488  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1489  int size;  int size;
1490  pcre_uchar *alternative;  pcre_uchar *alternative;
1491  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1382  return private_data_length; Line 1598  return private_data_length;
1598  }  }
1599    
1600  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,
1601    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1602  {  {
1603  DEFINE_COMPILER;  DEFINE_COMPILER;
1604  int srcw[2];  int srcw[2];
# Line 1403  stacktop = STACK(stacktop - 1); Line 1619  stacktop = STACK(stacktop - 1);
1619    
1620  if (!save)  if (!save)
1621    {    {
1622    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1623    if (stackptr < stacktop)    if (stackptr < stacktop)
1624      {      {
1625      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1626      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1627      tmp1empty = FALSE;      tmp1empty = FALSE;
1628      }      }
1629    if (stackptr < stacktop)    if (stackptr < stacktop)
1630      {      {
1631      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1632      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1633      tmp2empty = FALSE;      tmp2empty = FALSE;
1634      }      }
1635    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1636    }    }
1637    
1638  while (status != end)  do
1639    {    {
1640    count = 0;    count = 0;
1641    switch(status)    switch(status)
1642      {      {
1643      case start:      case start:
1644      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1645      count = 1;      count = 1;
1646      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1647        if (needs_control_head)
1648          {
1649          SLJIT_ASSERT(common->control_head_ptr != 0);
1650          count = 2;
1651          srcw[1] = common->control_head_ptr;
1652          }
1653      status = loop;      status = loop;
1654      break;      break;
1655    
# Line 1504  while (status != end) Line 1726  while (status != end)
1726          {          {
1727          count = 2;          count = 2;
1728          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1729          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1730          }          }
1731        cc += 2;        cc += 2;
1732  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1517  while (status != end) Line 1739  while (status != end)
1739          {          {
1740          count = 2;          count = 2;
1741          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1742          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1743          }          }
1744        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1745  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1539  while (status != end) Line 1761  while (status != end)
1761          {          {
1762          count = 2;          count = 2;
1763          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1764          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1765          }          }
1766        cc += 1;        cc += 1;
1767        break;        break;
# Line 1549  while (status != end) Line 1771  while (status != end)
1771          {          {
1772          count = 2;          count = 2;
1773          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1774          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1775          }          }
1776        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1777        break;        break;
# Line 1573  while (status != end) Line 1795  while (status != end)
1795            case 2:            case 2:
1796            count = 2;            count = 2;
1797            srcw[0] = PRIVATE_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1798            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1799            break;            break;
1800    
1801            default:            default:
# Line 1605  while (status != end) Line 1827  while (status != end)
1827          if (!tmp1empty)          if (!tmp1empty)
1828            {            {
1829            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1830            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1831            }            }
1832          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1833          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1616  while (status != end) Line 1838  while (status != end)
1838          if (!tmp2empty)          if (!tmp2empty)
1839            {            {
1840            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1841            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1842            }            }
1843          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1844          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1633  while (status != end) Line 1855  while (status != end)
1855          if (!tmp1empty)          if (!tmp1empty)
1856            {            {
1857            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1858            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1859            }            }
1860          tmp1next = FALSE;          tmp1next = FALSE;
1861          }          }
# Line 1645  while (status != end) Line 1867  while (status != end)
1867          if (!tmp2empty)          if (!tmp2empty)
1868            {            {
1869            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1870            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1871            }            }
1872          tmp1next = TRUE;          tmp1next = TRUE;
1873          }          }
1874        }        }
1875      }      }
1876    }    }
1877    while (status != end);
1878    
1879  if (save)  if (save)
1880    {    {
# Line 1660  if (save) Line 1883  if (save)
1883      if (!tmp1empty)      if (!tmp1empty)
1884        {        {
1885        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1886        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1887        }        }
1888      if (!tmp2empty)      if (!tmp2empty)
1889        {        {
1890        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1891        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1892        }        }
1893      }      }
1894    else    else
# Line 1673  if (save) Line 1896  if (save)
1896      if (!tmp2empty)      if (!tmp2empty)
1897        {        {
1898        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1899        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1900        }        }
1901      if (!tmp1empty)      if (!tmp1empty)
1902        {        {
1903        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1904        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1905        }        }
1906      }      }
1907    }    }
1908  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1909  }  }
1910    
1911    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1912    {
1913    pcre_uchar *end = bracketend(cc);
1914    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1915    
1916    /* Assert captures then. */
1917    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1918      current_offset = NULL;
1919    /* Conditional block does not. */
1920    if (*cc == OP_COND || *cc == OP_SCOND)
1921      has_alternatives = FALSE;
1922    
1923    cc = next_opcode(common, cc);
1924    if (has_alternatives)
1925      current_offset = common->then_offsets + (cc - common->start);
1926    
1927    while (cc < end)
1928      {
1929      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1930        cc = set_then_offsets(common, cc, current_offset);
1931      else
1932        {
1933        if (*cc == OP_ALT && has_alternatives)
1934          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1935        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1936          *current_offset = 1;
1937        cc = next_opcode(common, cc);
1938        }
1939      }
1940    
1941    return end;
1942    }
1943    
1944  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1945  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1946  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1692  SLJIT_ASSERT(cc == ccend && stackptr == Line 1948  SLJIT_ASSERT(cc == ccend && stackptr ==
1948  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1949  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1950    
1951  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1952  {  {
1953  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1954  }  }
# Line 1703  while (list) Line 1959  while (list)
1959    {    {
1960    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1961    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1962    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1963    list = list->next;    list = list->next;
1964    }    }
1965  }  }
# Line 1719  if (list_item) Line 1975  if (list_item)
1975    }    }
1976  }  }
1977    
1978  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)
1979  {  {
1980  DEFINE_COMPILER;  DEFINE_COMPILER;
1981  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1982    
1983  if (list_item)  if (list_item)
1984    {    {
   list_item->type = type;  
   list_item->data = data;  
1985    list_item->start = start;    list_item->start = start;
1986    list_item->quit = LABEL();    list_item->quit = LABEL();
1987    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1743  stub_list* list_item = common->stubs; Line 1997  stub_list* list_item = common->stubs;
1997  while (list_item)  while (list_item)
1998    {    {
1999    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2000    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;  
     }  
2001    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2002    list_item = list_item->next;    list_item = list_item->next;
2003    }    }
# Line 1768  static SLJIT_INLINE void allocate_stack( Line 2017  static SLJIT_INLINE void allocate_stack(
2017  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2018  DEFINE_COMPILER;  DEFINE_COMPILER;
2019    
2020  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));
2021  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2022  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2023  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 2025  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2025  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2026  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2027  #endif  #endif
2028  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));
2029  }  }
2030    
2031  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2032  {  {
2033  DEFINE_COMPILER;  DEFINE_COMPILER;
2034  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));
2035  }  }
2036    
2037  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 2039  static SLJIT_INLINE void reset_ovector(c
2039  DEFINE_COMPILER;  DEFINE_COMPILER;
2040  struct sljit_label *loop;  struct sljit_label *loop;
2041  int i;  int i;
2042    
2043  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2044    SLJIT_ASSERT(length > 1);
2045  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2046  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));
2047  if (length < 8)  if (length < 8)
2048    {    {
2049    for (i = 0; i < length; i++)    for (i = 1; i < length; i++)
2050      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_TEMPORARY_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2051    }    }
2052  else  else
2053    {    {
2054    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2055    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2056    loop = LABEL();    loop = LABEL();
2057    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2058    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2059    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2060    }    }
2061  }  }
2062    
2063    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2064    {
2065    DEFINE_COMPILER;
2066    struct sljit_label *loop;
2067    int i;
2068    
2069    SLJIT_ASSERT(length > 1);
2070    /* OVECTOR(1) contains the "string begin - 1" constant. */
2071    if (length > 2)
2072      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2073    if (length < 8)
2074      {
2075      for (i = 2; i < length; i++)
2076        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
2077      }
2078    else
2079      {
2080      GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2081      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2082      loop = LABEL();
2083      OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2084      OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2085      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2086      }
2087    
2088    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2089    if (common->mark_ptr != 0)
2090      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2091    if (common->control_head_ptr != 0)
2092      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2093    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2094    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2095    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2096    }
2097    
2098    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2099    {
2100    while (current != NULL)
2101      {
2102      switch (current[-2])
2103        {
2104        case type_then_trap:
2105        break;
2106    
2107        case type_mark:
2108        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2109          return current[-4];
2110        break;
2111    
2112        default:
2113        SLJIT_ASSERT_STOP();
2114        break;
2115        }
2116      current = (sljit_sw*)current[-1];
2117      }
2118    return -1;
2119    }
2120    
2121  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2122  {  {
2123  DEFINE_COMPILER;  DEFINE_COMPILER;
2124  struct sljit_label *loop;  struct sljit_label *loop;
2125  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2126    
2127  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2128  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));
2129  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);
2130    
2131  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2132  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2133    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);
2134  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));
2135  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2136    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);
2137  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));
2138  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));
2139  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2140  /* Unlikely, but possible */  /* Unlikely, but possible */
2141  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);
2142  loop = LABEL();  loop = LABEL();
2143  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);
2144  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));
2145  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2146  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2147  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);
2148  #endif  #endif
2149  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);
2150  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);
2151  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2152  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2153    
2154  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2155  if (topbracket > 1)  if (topbracket > 1)
2156    {    {
2157    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));
2158    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2159    
2160    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2161    loop = LABEL();    loop = LABEL();
2162    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)));
2163    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);
2164    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);
2165    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2166    }    }
2167  else  else
2168    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1862  else Line 2171  else
2171  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)
2172  {  {
2173  DEFINE_COMPILER;  DEFINE_COMPILER;
2174    struct sljit_jump *jump;
2175    
2176  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);
2177  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
2178      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2179    
2180  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2181  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2182  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));
2183  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);
2184    
2185  /* Store match begin and end. */  /* Store match begin and end. */
2186  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));
2187  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));
2188  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);  
2189    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2190    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);
2191    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2192    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2193    #endif
2194    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2195    JUMPHERE(jump);
2196    
2197    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);
2198  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);
2199  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2200  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);
2201  #endif  #endif
2202  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);
2203    
2204  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);
2205  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2206  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);
2207  #endif  #endif
2208  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);
2209    
2210  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2211  }  }
# Line 1998  if (c <= 127 && bit == 0x20) Line 2318  if (c <= 127 && bit == 0x20)
2318    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2319    
2320  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2321  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2322    return 0;    return 0;
2323    
2324  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2325    
2326  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2327  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 2017  if (common->utf && c > 127) Line 2337  if (common->utf && c > 127)
2337  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2338  return (0 << 8) | bit;  return (0 << 8) | bit;
2339    
2340  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2341    
 #ifdef COMPILE_PCRE16  
2342  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2343  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2344    {    {
# Line 2030  if (common->utf && c > 65535) Line 2349  if (common->utf && c > 65535)
2349    }    }
2350  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2351  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2352    
2353  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2354  }  }
2355    
2356  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 2370  else if (common->mode == JIT_PARTIAL_SOF
2370    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);
2371    
2372  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2373    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);
2374  else  else
2375    {    {
2376    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2065  if (jump != NULL) Line 2383  if (jump != NULL)
2383    JUMPHERE(jump);    JUMPHERE(jump);
2384  }  }
2385    
2386  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2387  {  {
2388  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2389  DEFINE_COMPILER;  DEFINE_COMPILER;
2390  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2391    
2392  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2393    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2394      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2395      return;
2396      }
2397    
2398  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2399  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2400    {    {
2401    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));
2402    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);
2403    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2404    }    }
2405  else  else
2406    {    {
2407    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));
2408    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2409      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2410    else    else
2411      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2412    }    }
2413  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2414  }  }
2415    
2416  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 2429  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2429  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));
2430  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2431    {    {
2432    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);
2433    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2434    }    }
2435  else  else
# Line 2130  static void read_char(compiler_common *c Line 2447  static void read_char(compiler_common *c
2447  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2448  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2449  DEFINE_COMPILER;  DEFINE_COMPILER;
2450  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2451  struct sljit_jump *jump;  struct sljit_jump *jump;
2452  #endif  #endif
2453    
2454  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2455  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2456  if (common->utf)  if (common->utf)
2457    {    {
2458  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2459    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2460  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2461    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2462  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2463    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2464    JUMPHERE(jump);    JUMPHERE(jump);
2465    }    }
2466  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2467  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));
2468  }  }
2469    
# Line 2157  static void peek_char(compiler_common *c Line 2472  static void peek_char(compiler_common *c
2472  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2473  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2474  DEFINE_COMPILER;  DEFINE_COMPILER;
2475  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2476  struct sljit_jump *jump;  struct sljit_jump *jump;
2477  #endif  #endif
2478    
2479  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2480  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2481  if (common->utf)  if (common->utf)
2482    {    {
2483  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2484    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2485  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2486    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2487  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2488    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2489    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2490    JUMPHERE(jump);    JUMPHERE(jump);
2491    }    }
2492  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2493  }  }
2494    
2495  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2496  {  {
2497  /* 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. */
2498  DEFINE_COMPILER;  DEFINE_COMPILER;
2499  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2500  struct sljit_jump *jump;  struct sljit_jump *jump;
2501  #endif  #endif
2502    
# Line 2192  if (common->utf) Line 2505  if (common->utf)
2505    {    {
2506    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2507    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));
2508  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2509    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2510    it is needed in most cases. */    it is needed in most cases. */
2511    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2512    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2513    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2514    JUMPHERE(jump);    JUMPHERE(jump);
2515  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2516    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2517    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2518    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 2520  if (common->utf)
2520    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2521    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2522    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);
2523    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2524    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2525    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2526  #endif  #elif defined COMPILE_PCRE32
2527  #endif /* COMPILE_PCRE8 */    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2528      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2529      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2530      JUMPHERE(jump);
2531    #endif /* COMPILE_PCRE[8|16|32] */
2532    return;    return;
2533    }    }
2534  #endif  #endif /* SUPPORT_UTF */
2535  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2536  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));
2537  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2538  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2539  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2540  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2541  #endif  #endif
2542  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2543  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2544  JUMPHERE(jump);  JUMPHERE(jump);
2545  #endif  #endif
2546  }  }
# Line 2233  static void skip_char_back(compiler_comm Line 2549  static void skip_char_back(compiler_comm
2549  {  {
2550  /* 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. */
2551  DEFINE_COMPILER;  DEFINE_COMPILER;
2552  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2553    #if defined COMPILE_PCRE8
2554  struct sljit_label *label;  struct sljit_label *label;
2555    
2556  if (common->utf)  if (common->utf)
# Line 2245  if (common->utf) Line 2562  if (common->utf)
2562    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2563    return;    return;
2564    }    }
2565  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2566  if (common->utf)  if (common->utf)
2567    {    {
2568    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 2570  if (common->utf)
2570    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2571    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2572    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);
2573    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2574    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2575    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2576    return;    return;
2577    }    }
2578  #endif  #endif /* COMPILE_PCRE[8|16] */
2579    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2580  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));
2581  }  }
2582    
# Line 2276  if (nltype == NLTYPE_ANY) Line 2593  if (nltype == NLTYPE_ANY)
2593  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2594    {    {
2595    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);
2596    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2597    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);
2598    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);
2599    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));
2600    }    }
2601  else  else
# Line 2290  else Line 2607  else
2607    
2608  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2609    
2610  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2611  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2612  {  {
2613  /* 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 2695  sljit_emit_fast_return(compiler, RETURN_
2695  JUMPHERE(jump);  JUMPHERE(jump);
2696    
2697  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2698  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);
2699  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2700  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2701  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2702  }  }
2703    
2704  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2705    
 #ifdef COMPILE_PCRE16  
2706  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2707  {  {
2708  /* 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 2727  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2727  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2728  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2729  }  }
 #endif /* COMPILE_PCRE16 */  
2730    
2731  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2732    
2733  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2734    
# Line 2433  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2748  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2748    
2749  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2750  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2751  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));
2752  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2753  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2754  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2755  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2756  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2757  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));
2758  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2759  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2760  }  }
# Line 2453  struct sljit_label *newlinelabel = NULL; Line 2768  struct sljit_label *newlinelabel = NULL;
2768  struct sljit_jump *start;  struct sljit_jump *start;
2769  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2770  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2771  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2772  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2773  #endif  #endif
2774  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2508  if (newlinecheck) Line 2823  if (newlinecheck)
2823    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2824    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2825    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);
2826    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2827  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2828    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2829  #endif  #endif
2830    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2831    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2531  if (newlinecheck) Line 2846  if (newlinecheck)
2846    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);
2847    
2848  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));
2849  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2850    #if defined COMPILE_PCRE8
2851  if (common->utf)  if (common->utf)
2852    {    {
2853    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2854    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);
2855    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2856    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2857    }    }
2858  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2859  if (common->utf)  if (common->utf)
2860    {    {
2861    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2862    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2863    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);
2864    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2865    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2866    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2867    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2868    }    }
2869  #endif  #endif /* COMPILE_PCRE[8|16] */
2870    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2871  JUMPHERE(start);  JUMPHERE(start);
2872    
2873  if (newlinecheck)  if (newlinecheck)
# Line 2563  if (newlinecheck) Line 2879  if (newlinecheck)
2879  return mainloop;  return mainloop;
2880  }  }
2881    
2882  static SLJIT_INLINE BOOL fast_forward_first_two_chars(compiler_common *common, BOOL firstline)  #define MAX_N_CHARS 3
2883    
2884    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2885  {  {
2886  DEFINE_COMPILER;  DEFINE_COMPILER;
2887  struct sljit_label *start;  struct sljit_label *start;
2888  struct sljit_jump *quit;  struct sljit_jump *quit;
2889  struct sljit_jump *found;  pcre_uint32 chars[MAX_N_CHARS * 2];
2890  pcre_int32 chars[4];  pcre_uchar *cc = common->start + 1 + LINK_SIZE;
 pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  
2891  int location = 0;  int location = 0;
2892  pcre_int32 len, c, bit, caseless;  pcre_int32 len, c, bit, caseless;
2893  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  
2894    
2895    /* We do not support alternatives now. */
2896  if (*(common->start + GET(common->start, 1)) == OP_ALT)  if (*(common->start + GET(common->start, 1)) == OP_ALT)
2897    return FALSE;    return FALSE;
2898    
2899  while (TRUE)  while (TRUE)
2900    {    {
2901    caseless = 0;    caseless = 0;
2902    must_end = TRUE;    must_stop = 1;
2903    switch(*cc)    switch(*cc)
2904      {      {
2905      case OP_CHAR:      case OP_CHAR:
2906      must_end = FALSE;      must_stop = 0;
2907      cc++;      cc++;
2908      break;      break;
2909    
2910      case OP_CHARI:      case OP_CHARI:
2911      caseless = 1;      caseless = 1;
2912      must_end = FALSE;      must_stop = 0;
2913      cc++;      cc++;
2914      break;      break;
2915    
# Line 2645  while (TRUE) Line 2951  while (TRUE)
2951      break;      break;
2952    
2953      default:      default:
2954      return FALSE;      must_stop = 2;
2955        break;
2956      }      }
2957    
2958      if (must_stop == 2)
2959          break;
2960    
2961    len = 1;    len = 1;
2962  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2963    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 2980  while (TRUE)
2980    else    else
2981      caseless = 0;      caseless = 0;
2982    
2983    while (len > 0 && location < 2 * 2)    while (len > 0 && location < MAX_N_CHARS * 2)
2984      {      {
2985      c = *cc;      c = *cc;
2986      bit = 0;      bit = 0;
# Line 2688  while (TRUE) Line 2998  while (TRUE)
2998      cc++;      cc++;
2999      }      }
3000    
3001    if (location == 2 * 2)    if (location >= MAX_N_CHARS * 2 || must_stop != 0)
3002      break;      break;
   else if (must_end)  
     return FALSE;  
3003    }    }
3004    
3005    /* At least two characters are required. */
3006    if (location < 2 * 2)
3007        return FALSE;
3008    
3009  if (firstline)  if (firstline)
3010    {    {
3011    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3012    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3013    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));
3014    }    }
3015  else  else
3016    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));
3017    
3018  start = LABEL();  start = LABEL();
3019  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  
3020    
3021  #else /* SLJIT_UNALIGNED */  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
   
 #if defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 #else /* SLJIT_BIG_ENDIAN */  
3022  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3023  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3024  #endif /* SLJIT_BIG_ENDIAN */  if (chars[1] != 0)
3025      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3026  #ifdef COMPILE_PCRE8  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3027  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 8);  if (location > 2 * 2)
3028  #else /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3029  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 16);  if (chars[3] != 0)
3030  #endif    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
3031  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
3032    if (location > 2 * 2)
3033  #endif    {
3034      if (chars[5] != 0)
3035  if (chars[1] != 0 || chars[3] != 0)      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
3036    {    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);  
3037    }    }
3038    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3039    
 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);  
3040  JUMPHERE(quit);  JUMPHERE(quit);
3041    
3042  if (firstline)  if (firstline)
3043    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3044  else  else
3045    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));
3046  return TRUE;  return TRUE;
3047  }  }
3048    
3049    #undef MAX_N_CHARS
3050    
3051  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)
3052  {  {
3053  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2787  if (first_char == oc) Line 3081  if (first_char == oc)
3081  else  else
3082    {    {
3083    bit = first_char ^ oc;    bit = first_char ^ oc;
3084    if (ispowerof2(bit))    if (is_powerof2(bit))
3085      {      {
3086      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3087      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 3089  else
3089    else    else
3090      {      {
3091      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);
3092      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3093      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);
3094      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);
3095      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3096      }      }
3097    }    }
# Line 2839  if (common->nltype == NLTYPE_FIXED && co Line 3133  if (common->nltype == NLTYPE_FIXED && co
3133    
3134    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3135    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);
3136    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3137  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3138    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3139  #endif  #endif
3140    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3141    
# Line 2882  if (common->nltype == NLTYPE_ANY || comm Line 3176  if (common->nltype == NLTYPE_ANY || comm
3176    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3177    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3178    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);
3179    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3180  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3181    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3182  #endif  #endif
3183    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3184    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
# Line 2897  if (firstline) Line 3191  if (firstline)
3191    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3192  }  }
3193    
3194    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3195    
3196  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)
3197  {  {
3198  DEFINE_COMPILER;  DEFINE_COMPILER;
3199  struct sljit_label *start;  struct sljit_label *start;
3200  struct sljit_jump *quit;  struct sljit_jump *quit;
3201  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3202    jump_list *matches = NULL;
3203    pcre_uint8 inverted_start_bits[32];
3204    int i;
3205  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3206  struct sljit_jump *jump;  struct sljit_jump *jump;
3207  #endif  #endif
3208    
3209    for (i = 0; i < 32; ++i)
3210      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3211    
3212  if (firstline)  if (firstline)
3213    {    {
3214    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 3223  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3223  if (common->utf)  if (common->utf)
3224    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3225  #endif  #endif
3226    
3227    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3228      {
3229  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3230  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3231  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3232  JUMPHERE(jump);    JUMPHERE(jump);
3233  #endif  #endif
3234  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3235  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3236  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3237  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3238  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);
3239  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3240      }
3241    
3242  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3243  if (common->utf)  if (common->utf)
3244    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3245  #endif  #endif
3246  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));
3247  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3248    #if defined COMPILE_PCRE8
3249  if (common->utf)  if (common->utf)
3250    {    {
3251    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3252    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);
3253    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3254    }    }
3255  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3256  if (common->utf)  if (common->utf)
3257    {    {
3258    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3259    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3260    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);
3261    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3262    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3263    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3264    }    }
3265  #endif  #endif /* COMPILE_PCRE[8|16] */
3266    #endif /* SUPPORT_UTF */
3267  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3268  JUMPHERE(found);  if (found != NULL)
3269      JUMPHERE(found);
3270    if (matches != NULL)
3271      set_jumps(matches, LABEL());
3272  JUMPHERE(quit);  JUMPHERE(quit);
3273    
3274  if (firstline)  if (firstline)
# Line 2974  struct sljit_jump *alreadyfound; Line 3284  struct sljit_jump *alreadyfound;
3284  struct sljit_jump *found;  struct sljit_jump *found;
3285  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3286  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3287  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3288    
3289  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3290  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 3315  if (req_char == oc)
3315  else  else
3316    {    {
3317    bit = req_char ^ oc;    bit = req_char ^ oc;
3318    if (ispowerof2(bit))    if (is_powerof2(bit))
3319      {      {
3320      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3321      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 3351  GET_LOCAL_BASE(TMP3, 0, 0);
3351  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3352  mainloop = LABEL();  mainloop = LABEL();
3353  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3354  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);
3355    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3356    
3357  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3358  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));
3359  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));
3360  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));
3361  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3362    
3363  JUMPHERE(jump);  JUMPHERE(jump);
3364  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3365  /* End of dropping frames. */  /* End of dropping frames. */
3366  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3367    
3368  JUMPHERE(jump);  JUMPHERE(jump);
3369  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3370  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3371  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3372  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));  
3373  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3374  }  }
3375    
# Line 3082  static void check_wordboundary(compiler_ Line 3377  static void check_wordboundary(compiler_
3377  {  {
3378  DEFINE_COMPILER;  DEFINE_COMPILER;
3379  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3380    jump_list *skipread_list = NULL;
3381  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3382  struct sljit_jump *jump;  struct sljit_jump *jump;
3383  #endif  #endif
# Line 3107  if (common->use_ucp) Line 3403  if (common->use_ucp)
3403    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3404    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3405    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);
3406    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3407    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);
3408    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);
3409    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3410    JUMPHERE(jump);    JUMPHERE(jump);
3411    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3412    }    }
# Line 3139  else Line 3435  else
3435  JUMPHERE(skipread);  JUMPHERE(skipread);
3436    
3437  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3438  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3439  peek_char(common);  peek_char(common);
3440    
3441  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3151  if (common->use_ucp) Line 3447  if (common->use_ucp)
3447    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3448    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3449    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);
3450    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3451    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);
3452    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);
3453    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3454    JUMPHERE(jump);    JUMPHERE(jump);
3455    }    }
3456  else  else
# Line 3180  else Line 3476  else
3476      JUMPHERE(jump);      JUMPHERE(jump);
3477  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3478    }    }
3479  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3480    
3481  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);
3482  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 3531  switch(ranges[0])
3531        }        }
3532      return TRUE;      return TRUE;
3533      }      }
3534    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]))
3535      {      {
3536      if (readch)      if (readch)
3537        read_char(common);        read_char(common);
# Line 3334  sljit_emit_fast_enter(compiler, RETURN_A Line 3630  sljit_emit_fast_enter(compiler, RETURN_A
3630    
3631  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3632  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);
3633  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3634  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);
3635  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3636  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3637  if (common->utf)  if (common->utf)
3638    {    {
3639  #endif  #endif
3640    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3641    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3642    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);
3643  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3644    }    }
3645  #endif  #endif
3646  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3647  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);
3648  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3649  }  }
3650    
# Line 3360  DEFINE_COMPILER; Line 3656  DEFINE_COMPILER;
3656  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3657    
3658  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);
3659  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3660  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);
3661  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3662  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);
3663  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3664  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3665  if (common->utf)  if (common->utf)
3666    {    {
3667  #endif  #endif
3668    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3669    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);
3670    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3671    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);
3672    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3673    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3674    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);
3675    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3676    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);
3677    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3678    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);
3679    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3680    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);
3681  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3682    }    }
3683  #endif  #endif
3684  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3685  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);
3686    
3687  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3688  }  }
# Line 3400  sljit_emit_fast_enter(compiler, RETURN_A Line 3696  sljit_emit_fast_enter(compiler, RETURN_A
3696    
3697  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3698  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);
3699  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3700  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);
3701  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3702  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3703  if (common->utf)  if (common->utf)
3704    {    {
3705  #endif  #endif
3706    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);
3707    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3708    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);
3709  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3710    }    }
3711  #endif  #endif
3712  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3713  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);
3714    
3715  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3716  }  }
# Line 3500  sljit_emit_fast_return(compiler, RETURN_ Line 3796  sljit_emit_fast_return(compiler, RETURN_
3796    
3797  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3798    
3799  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)
3800  {  {
3801  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3802  int c1, c2;  pcre_uint32 c1, c2;
3803  const pcre_uchar *src2 = args->uchar_ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3804  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
3805    const ucd_record *ur;
3806    const pcre_uint32 *pp;
3807    
3808  while (src1 < end1)  while (src1 < end1)
3809    {    {
# Line 3513  while (src1 < end1) Line 3811  while (src1 < end1)
3811      return (pcre_uchar*)1;      return (pcre_uchar*)1;
3812    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3813    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3814    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return NULL;    ur = GET_UCD(c2);
3815      if (c1 != c2 && c1 != c2 + ur->other_case)
3816        {
3817        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3818        for (;;)
3819          {
3820          if (c1 < *pp) return NULL;
3821          if (c1 == *pp++) break;
3822          }
3823        }
3824    }    }
3825  return src2;  return src2;
3826  }  }
# Line 3535  if (caseless && char_has_othercase(commo Line 3842  if (caseless && char_has_othercase(commo
3842    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3843    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3844    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3845  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3846    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3847    othercasebit &= 0xff;    othercasebit &= 0xff;
3848  #else  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3849  #ifdef COMPILE_PCRE16    /* Note that this code only handles characters in the BMP. If there
3850      ever are characters outside the BMP whose othercase differs in only one
3851      bit from itself (there currently are none), this code will need to be
3852      revised for COMPILE_PCRE32. */
3853    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3854    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3855      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
3856    else    else
3857      othercasebit &= 0xff;      othercasebit &= 0xff;
3858  #endif  #endif /* COMPILE_PCRE[8|16|32] */
 #endif  
3859    }    }
3860    
3861  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3862    {    {
3863  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3864  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3865    if (context->length >= 4)    if (context->length >= 4)
3866      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 3869  if (context->sourcereg == -1)
3869    else    else
3870  #endif  #endif
3871      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3872  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
3873  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3874    if (context->length >= 4)    if (context->length >= 4)
3875      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3876    else    else
3877  #endif  #endif
3878      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3879  #endif  #elif defined COMPILE_PCRE32
3880  #endif /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3881    #endif /* COMPILE_PCRE[8|16|32] */
3882    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3883    }    }
3884    
# Line 3583  do Line 3892  do
3892  #endif  #endif
3893    
3894    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3895  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3896    
3897    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3898    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3598  do Line 3907  do
3907      }      }
3908    context->ucharptr++;    context->ucharptr++;
3909    
3910  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3911    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))
3912  #else  #else
3913    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
# Line 3606  do Line 3915  do
3915      {      {
3916      if (context->length >= 4)      if (context->length >= 4)
3917        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  
3918      else if (context->length >= 2)      else if (context->length >= 2)
3919        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);
3920    #if defined COMPILE_PCRE8
3921      else if (context->length >= 1)      else if (context->length >= 1)
3922        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);
3923  #else  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3924      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3925    
3926      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3648  do Line 3954  do
3954    
3955  #else  #else
3956    
3957    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3958  #ifdef COMPILE_PCRE8    if (context->length >= 1)
3959    if (context->length > 0)      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3960      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  
3961    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3962    
3963    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3705  static void compile_xclass_matchingpath( Line 4007  static void compile_xclass_matchingpath(
4007  DEFINE_COMPILER;  DEFINE_COMPILER;
4008  jump_list *found = NULL;  jump_list *found = NULL;
4009  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;
4010  unsigned int c;  pcre_int32 c, charoffset;
4011  int compares;  const pcre_uint32 *other_cases;
4012  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4013  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4014    int compares, invertcmp, numberofcmps;
4015  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4016  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4017  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4018  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4019  unsigned int typeoffset;  pcre_int32 typeoffset;
4020  #endif  #endif
 int invertcmp, numberofcmps;  
 unsigned int charoffset;  
4021    
4022  /* Although SUPPORT_UTF must be defined, we are  /* Although SUPPORT_UTF must be defined, we are
4023     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 4038  if ((*cc++ & XCL_MAP) != 0)
4038      {      {
4039      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4040      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4041      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4042      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4043      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);
4044      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 4115  while (*cc != XCL_END)
4115        needschar = TRUE;        needschar = TRUE;
4116        break;        break;
4117    
4118          case PT_CLIST:
4119          case PT_UCNC:
4120          needschar = TRUE;
4121          break;
4122    
4123        default:        default:
4124        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
4125        break;        break;
# Line 3850  if (needstype || needsscript) Line 4156  if (needstype || needsscript)
4156      {      {
4157      if (scriptreg == TMP1)      if (scriptreg == TMP1)
4158        {        {
4159        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));
4160        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
4161        }        }
4162      else      else
4163        {        {
4164        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
4165        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));
4166        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
4167        }        }
4168      }      }
# Line 3892  while (*cc != XCL_END) Line 4198  while (*cc != XCL_END)
4198      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4199        {        {
4200        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);
4201        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);
4202        numberofcmps++;        numberofcmps++;
4203        }        }
4204      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4205        {        {
4206        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);
4207        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);
4208        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4209        numberofcmps = 0;        numberofcmps = 0;
4210        }        }
# Line 3931  while (*cc != XCL_END) Line 4237  while (*cc != XCL_END)
4237      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4238        {        {
4239        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);
4240        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);
4241        numberofcmps++;        numberofcmps++;
4242        }        }
4243      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4244        {        {
4245        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);
4246        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);
4247        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4248        numberofcmps = 0;        numberofcmps = 0;
4249        }        }
# Line 3968  while (*cc != XCL_END) Line 4274  while (*cc != XCL_END)
4274    
4275        case PT_LAMP:        case PT_LAMP:
4276        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);
4277        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4278        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);
4279        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4280        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);
4281        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);
4282        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4283        break;        break;
4284    
# Line 3999  while (*cc != XCL_END) Line 4305  while (*cc != XCL_END)
4305          }          }
4306        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4307        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);
4308        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4309        if (*cc == PT_SPACE)        if (*cc == PT_SPACE)
4310          JUMPHERE(jump);          JUMPHERE(jump);
4311    
4312        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4313        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);
4314        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);
4315        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4316        break;        break;
4317    
4318        case PT_WORD:        case PT_WORD:
4319        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);
4320        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4321        /* ... fall through */        /* Fall through. */
4322    
4323        case PT_ALNUM:        case PT_ALNUM:
4324        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
4325        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);
4326        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);
4327        SET_TYPE_OFFSET(ucp_Nd);        SET_TYPE_OFFSET(ucp_Nd);
4328        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);
4329        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);
4330          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4331          break;
4332    
4333          case PT_CLIST:
4334          other_cases = PRIV(ucd_caseless_sets) + cc[1];
4335    
4336          /* At least three characters are required.
4337             Otherwise this case would be handled by the normal code path. */
4338          SLJIT_ASSERT(other_cases[0] != NOTACHAR && other_cases[1] != NOTACHAR && other_cases[2] != NOTACHAR);
4339          SLJIT_ASSERT(other_cases[0] < other_cases[1] && other_cases[1] < other_cases[2]);
4340    
4341          /* Optimizing character pairs, if their difference is power of 2. */
4342          if (is_powerof2(other_cases[1] ^ other_cases[0]))
4343            {
4344            if (charoffset == 0)
4345              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4346            else
4347              {
4348              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4349              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4350              }
4351            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[1]);
4352            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4353            other_cases += 2;
4354            }
4355          else if (is_powerof2(other_cases[2] ^ other_cases[1]))
4356            {
4357            if (charoffset == 0)
4358              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[2] ^ other_cases[1]);
4359            else
4360              {
4361              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4362              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4363              }
4364            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[2]);
4365            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4366    
4367            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, other_cases[0] - charoffset);
4368            OP_FLAGS(SLJIT_OR | ((other_cases[3] == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4369    
4370            other_cases += 3;
4371            }
4372          else
4373            {
4374            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4375            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4376            }
4377    
4378          while (*other_cases != NOTACHAR)
4379            {
4380            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4381            OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4382            }
4383          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4384          break;
4385    
4386          case PT_UCNC:
4387          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);
4388          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4389          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);
4390          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4391          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);
4392          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4393    
4394          SET_CHAR_OFFSET(0xa0);
4395          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);
4396          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4397          SET_CHAR_OFFSET(0);
4398          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4399          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4400        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4401        break;        break;
4402        }        }
# Line 4048  int length; Line 4424  int length;
4424  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4425  compare_context context;  compare_context context;
4426  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4427    jump_list *end_list;
4428  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4429  struct sljit_label *label;  struct sljit_label *label;
4430  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4116  switch(type) Line 4493  switch(type)
4493    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4494      {      {
4495      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);
4496        end_list = NULL;
4497      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4498        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));
4499      else      else
4500        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
4501    
4502      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4503      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));
4504      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
4505      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4506      }      }
4507    else    else
# Line 4138  switch(type) Line 4515  switch(type)
4515      {      {
4516      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4517      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));
4518  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
4519    #if defined COMPILE_PCRE8
4520      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4521      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);
4522      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4523  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
4524      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
4525      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4526      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);
4527      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4528      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4529      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4530  #endif /* COMPILE_PCRE16 */  #endif
 #endif /* COMPILE_PCRE8 */  
4531      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4532    #endif /* COMPILE_PCRE[8|16] */
4533      return cc;      return cc;
4534      }      }
4535  #endif  #endif
# Line 4183  switch(type) Line 4560  switch(type)
4560    read_char(common);    read_char(common);
4561    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);
4562    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
4563      end_list = NULL;
4564    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4565      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));
4566    else    else
4567      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
4568    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4569    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);
4570    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));
4571    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
4572    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4573    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
4574      set_jumps(end_list, LABEL());
4575    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4576    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
4577    return cc;    return cc;
4578    
4579    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
# Line 4219  switch(type) Line 4597  switch(type)
4597    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4598    read_char(common);    read_char(common);
4599    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4600    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));
4601    OP1(SLJIT_MOV_UB, TMP3, 0, SLJIT_MEM2(TMP1, TMP2), 3);    /* Optimize register allocation: use a real register. */
4602      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4603      OP1(SLJIT_MOV_UB, STACK_TOP, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4604    
4605    label = LABEL();    label = LABEL();
4606    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);
4607    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
4608    read_char(common);    read_char(common);
4609    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4610    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));
4611    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4612    
4613    OP2(SLJIT_MUL, TMP1, 0, TMP3, 0, SLJIT_IMM, ucp_gbCount);    OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);
4614    OP1(SLJIT_MOV, TMP3, 0, TMP2, 0);    OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STACK_TOP), (sljit_sw)PRIV(ucp_gbtable));
4615    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);    OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);
4616    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(ucp_gbtable));    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4617    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, label);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4618      JUMPTO(SLJIT_C_NOT_ZERO, label);
4619    
4620    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
4621    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4622      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
4623    
4624    if (common->mode == JIT_PARTIAL_HARD_COMPILE)    if (common->mode == JIT_PARTIAL_HARD_COMPILE)
4625      {      {
4626      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 4644  switch(type)
4644        {        {
4645        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);
4646        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);
4647        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS);
4648        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);
4649        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);
4650        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));
4651        check_partial(common, TRUE);        check_partial(common, TRUE);
4652        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
# Line 4443  switch(type) Line 4826  switch(type)
4826      }      }
4827    oc = char_othercase(common, c);    oc = char_othercase(common, c);
4828    bit = c ^ oc;    bit = c ^ oc;
4829    if (ispowerof2(bit))    if (is_powerof2(bit))
4830      {      {
4831      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4832      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));
4833      return cc + length;      return cc + length;
4834      }      }
4835    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);
4836    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4837    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);
4838    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);
4839    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4840    return cc + length;    return cc + length;
4841    
# Line 4479  switch(type) Line 4862  switch(type)
4862        /* Skip the variable-length character. */        /* Skip the variable-length character. */
4863        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));
4864        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4865        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);
4866        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4867        JUMPHERE(jump[0]);        JUMPHERE(jump[0]);
4868        return cc + 1;        return cc + 1;
# Line 4504  switch(type) Line 4887  switch(type)
4887      {      {
4888      oc = char_othercase(common, c);      oc = char_othercase(common, c);
4889      bit = c ^ oc;      bit = c ^ oc;
4890      if (ispowerof2(bit))      if (is_powerof2(bit))
4891        {        {
4892        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4893        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 4925  switch(type)
4925  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4926    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4927    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4928    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4929    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4930    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);
4931    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 4552  switch(type) Line 4935  switch(type)
4935  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4936    return cc + 32 / sizeof(pcre_uchar);    return cc + 32 / sizeof(pcre_uchar);
4937    
4938  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4939    case OP_XCLASS:    case OP_XCLASS:
4940    compile_xclass_matchingpath(common, cc + LINK_SIZE, backtracks);    compile_xclass_matchingpath(common, cc + LINK_SIZE, backtracks);
4941    return cc + GET(cc, 0) - 1;    return cc + GET(cc, 0) - 1;
# Line 4666  if (!common->jscript_compat) Line 5049  if (!common->jscript_compat)
5049      {      {
5050      /* OVECTOR(1) contains the "string begin - 1" constant. */      /* OVECTOR(1) contains the "string begin - 1" constant. */
5051      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));
5052      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
5053      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));
5054      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);
5055      return JUMP(SLJIT_C_NOT_ZERO);      return JUMP(SLJIT_C_NOT_ZERO);
5056      }      }
5057    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 5107  if (withchecks && !common->jscript_compa
5107  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5108  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5109    {    {
5110    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);
5111    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));
5112    if (withchecks)    if (withchecks)
5113      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5114    
5115    /* Needed to save important temporary registers. */    /* Needed to save important temporary registers. */
5116    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5117    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
5118    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);
5119    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));
5120    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5121    if (common->mode == JIT_COMPILE)    if (common->mode == JIT_COMPILE)
# Line 4845  if (!minimize) Line 5228  if (!minimize)
5228      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5229      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5230      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5231      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));
5232      zerolength = compile_ref_checks(common, ccbegin, NULL);      zerolength = compile_ref_checks(common, ccbegin, NULL);
5233      /* Restore if not zero length. */      /* Restore if not zero length. */
5234      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));
5235      }      }
5236    else    else
5237      {      {
# Line 4940  DEFINE_COMPILER; Line 5323  DEFINE_COMPILER;
5323  backtrack_common *backtrack;  backtrack_common *backtrack;
5324  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5325  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5326  int start = GET(cc, 1);  sljit_sw start = GET(cc, 1);
5327    pcre_uchar *start_cc;
5328    BOOL needs_control_head;
5329    
5330  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5331    
5332    /* Inlining simple patterns. */
5333    if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head) == no_stack)
5334      {
5335      start_cc = common->start + start;
5336      compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
5337      BACKTRACK_AS(recurse_backtrack)->inlined_pattern = TRUE;
5338      return cc + 1 + LINK_SIZE;
5339      }
5340    
5341  while (entry != NULL)  while (entry != NULL)
5342    {    {
5343    if (entry->start == start)    if (entry->start == start)
# Line 4991  add_jump(compiler, &backtrack->topbacktr Line 5386  add_jump(compiler, &backtrack->topbacktr
5386  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5387  }  }
5388    
5389    static int SLJIT_CALL do_callout(struct jit_arguments* arguments, PUBL(callout_block) *callout_block, pcre_uchar **jit_ovector)
5390    {
5391    const pcre_uchar *begin = arguments->begin;
5392    int *offset_vector = arguments->offsets;
5393    int offset_count = arguments->offset_count;
5394    int i;
5395    
5396    if (PUBL(callout) == NULL)
5397      return 0;
5398    
5399    callout_block->version = 2;
5400    callout_block->callout_data = arguments->callout_data;
5401    
5402    /* Offsets in subject. */
5403    callout_block->subject_length = arguments->end - arguments->begin;
5404    callout_block->start_match = (pcre_uchar*)callout_block->subject - arguments->begin;
5405    callout_block->current_position = (pcre_uchar*)callout_block->offset_vector - arguments->begin;
5406    #if defined COMPILE_PCRE8
5407    callout_block->subject = (PCRE_SPTR)begin;
5408    #elif defined COMPILE_PCRE16
5409    callout_block->subject = (PCRE_SPTR16)begin;
5410    #elif defined COMPILE_PCRE32
5411    callout_block->subject = (PCRE_SPTR32)begin;
5412    #endif
5413    
5414    /* Convert and copy the JIT offset vector to the offset_vector array. */
5415    callout_block->capture_top = 0;
5416    callout_block->offset_vector = offset_vector;
5417    for (i = 2; i < offset_count; i += 2)
5418      {
5419      offset_vector[i] = jit_ovector[i] - begin;
5420      offset_vector[i + 1] = jit_ovector[i + 1] - begin;
5421      if (jit_ovector[i] >= begin)
5422        callout_block->capture_top = i;
5423      }
5424    
5425    callout_block->capture_top = (callout_block->capture_top >> 1) + 1;
5426    if (offset_count > 0)
5427      offset_vector[0] = -1;
5428    if (offset_count > 1)
5429      offset_vector[1] = -1;
5430    return (*PUBL(callout))(callout_block);
5431    }
5432    
5433    /* Aligning to 8 byte. */
5434    #define CALLOUT_ARG_SIZE \
5435        (((int)sizeof(PUBL(callout_block)) + 7) & ~7)
5436    
5437    #define CALLOUT_ARG_OFFSET(arg) \
5438        (-CALLOUT_ARG_SIZE + SLJIT_OFFSETOF(PUBL(callout_block), arg))
5439    
5440    static SLJIT_INLINE pcre_uchar *compile_callout_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5441    {
5442    DEFINE_COMPILER;
5443    backtrack_common *backtrack;
5444    
5445    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
5446    
5447    allocate_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5448    
5449    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5450    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
5451    SLJIT_ASSERT(common->capture_last_ptr != 0);
5452    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
5453    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
5454    
5455    /* These pointer sized fields temporarly stores internal variables. */
5456    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
5457    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0);
5458    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(subject), TMP2, 0);
5459    
5460    if (common->mark_ptr != 0)
5461      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));
5462    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));
5463    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));
5464    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
5465    
5466    /* Needed to save important temporary registers. */
5467    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5468    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, STACK_TOP, 0, SLJIT_IMM, CALLOUT_ARG_SIZE);
5469    GET_LOCAL_BASE(SLJIT_SCRATCH_REG3, 0, OVECTOR_START);
5470    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout));
5471    OP1(SLJIT_MOV_SI, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0);
5472    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5473    free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5474    
5475    /* Check return value. */
5476    OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
5477    add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_C_SIG_GREATER));
5478    if (common->forced_quit_label == NULL)
5479      add_jump(compiler, &common->forced_quit, JUMP(SLJIT_C_SIG_LESS));
5480    else
5481      JUMPTO(SLJIT_C_SIG_LESS, common->forced_quit_label);
5482    return cc + 2 + 2 * LINK_SIZE;
5483    }
5484    
5485    #undef CALLOUT_ARG_SIZE
5486    #undef CALLOUT_ARG_OFFSET
5487    
5488  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)
5489  {  {
5490  DEFINE_COMPILER;  DEFINE_COMPILER;
5491  int framesize;  int framesize;
5492    int extrasize;
5493    BOOL needs_control_head;
5494  int private_data_ptr;  int private_data_ptr;
5495  backtrack_common altbacktrack;  backtrack_common altbacktrack;
5496  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5004  jump_list *tmp = NULL; Line 5500  jump_list *tmp = NULL;
5500  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5501  jump_list **found;  jump_list **found;
5502  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5503  struct sljit_label *save_quitlabel = common->quitlabel;  BOOL save_local_exit = common->local_exit;
5504  struct sljit_label *save_acceptlabel = common->acceptlabel;  then_trap_backtrack *save_then_trap = common->then_trap;
5505    struct sljit_label *save_quit_label = common->quit_label;
5506    struct sljit_label *save_accept_label = common->accept_label;
5507  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5508  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
5509  struct sljit_jump *jump;  struct sljit_jump *jump;
5510  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
5511    
5512    /* Assert captures then. */
5513    common->then_trap = NULL;
5514    
5515  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
5516    {    {
5517    SLJIT_ASSERT(!conditional);    SLJIT_ASSERT(!conditional);
# Line 5019  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5520  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5520    }    }
5521  private_data_ptr = PRIVATE_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
5522  SLJIT_ASSERT(private_data_ptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
5523  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
5524  backtrack->framesize = framesize;  backtrack->framesize = framesize;
5525  backtrack->private_data_ptr = private_data_ptr;  backtrack->private_data_ptr = private_data_ptr;
5526  opcode = *cc;  opcode = *cc;
# Line 5038  if (bra == OP_BRAMINZERO) Line 5539  if (bra == OP_BRAMINZERO)
5539    
5540  if (framesize < 0)  if (framesize < 0)
5541    {    {
5542    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    extrasize = needs_control_head ? 2 : 1;
5543    allocate_stack(common, 1);    if (framesize == no_frame)
5544        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5545      allocate_stack(common, extrasize);
5546      if (needs_control_head)
5547        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5548    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5549      if (needs_control_head)
5550        {
5551        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5552        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5553        }
5554    }    }
5555  else  else
5556    {    {
5557    allocate_stack(common, framesize + 2);    extrasize = needs_control_head ? 3 : 2;
5558      allocate_stack(common, framesize + extrasize);
5559    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);
5560    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));
5561    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);
5562      if (needs_control_head)
5563        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5564    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5565    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    if (needs_control_head)
5566    init_frame(common, ccbegin, framesize + 1, 2, FALSE);      {
5567        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
5568        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
5569        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5570        }
5571      else
5572        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5573      init_frame(common, ccbegin, NULL, framesize + extrasize - 1, extrasize, FALSE);
5574    }    }
5575    
5576  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5577  common->quitlabel = NULL;  common->local_exit = TRUE;
5578    common->quit_label = NULL;
5579  common->quit = NULL;  common->quit = NULL;
5580  while (1)  while (1)
5581    {    {
5582    common->acceptlabel = NULL;    common->accept_label = NULL;
5583    common->accept = NULL;    common->accept = NULL;
5584    altbacktrack.top = NULL;    altbacktrack.top = NULL;
5585    altbacktrack.topbacktracks = NULL;    altbacktrack.topbacktracks = NULL;
# Line 5070  while (1) Line 5591  while (1)
5591    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5592    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5593      {      {
5594      common->quitlabel = save_quitlabel;      common->local_exit = save_local_exit;
5595      common->acceptlabel = save_acceptlabel;      common->then_trap = save_then_trap;
5596        common->quit_label = save_quit_label;
5597        common->accept_label = save_accept_label;
5598      common->quit = save_quit;      common->quit = save_quit;
5599      common->accept = save_accept;      common->accept = save_accept;
5600      return NULL;      return NULL;
5601      }      }
5602    common->acceptlabel = LABEL();    common->accept_label = LABEL();
5603    if (common->accept != NULL)    if (common->accept != NULL)
5604      set_jumps(common->accept, common->acceptlabel);      set_jumps(common->accept, common->accept_label);
5605    
5606    /* Reset stack. */    /* Reset stack. */
5607    if (framesize < 0)    if (framesize < 0)
5608      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      {
5609    else {      if (framesize == no_frame)
5610          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5611        else
5612          free_stack(common, extrasize);
5613        if (needs_control_head)
5614          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5615        }
5616      else
5617        {
5618      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
5619        {        {
5620        /* 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. */
5621        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));
5622          if (needs_control_head)
5623            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5624        }        }
5625      else      else
5626        {        {
5627        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);
5628          if (needs_control_head)
5629            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));
5630        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5631        }        }
5632    }      }
5633    
5634    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5635      {      {
5636      /* 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. */
5637      if (conditional)      if (conditional)
5638        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);
5639      else if (bra == OP_BRAZERO)      else if (bra == OP_BRAZERO)
5640        {        {
5641        if (framesize < 0)        if (framesize < 0)
5642          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));
5643        else        else
5644          {          {
5645          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));
5646          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));
5647          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);
5648          }          }
5649        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));
5650        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5651        }        }
5652      else if (framesize >= 0)      else if (framesize >= 0)
5653        {        {
5654        /* For OP_BRA and OP_BRAMINZERO. */        /* For OP_BRA and OP_BRAMINZERO. */
5655        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));
5656        }        }
5657      }      }
5658    add_jump(compiler, found, JUMP(SLJIT_JUMP));    add_jump(compiler, found, JUMP(SLJIT_JUMP));
# Line 5125  while (1) Line 5660  while (1)
5660    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5661    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5662      {      {
5663      common->quitlabel = save_quitlabel;      common->local_exit = save_local_exit;
5664      common->acceptlabel = save_acceptlabel;      common->then_trap = save_then_trap;
5665        common->quit_label = save_quit_label;
5666        common->accept_label = save_accept_label;
5667      common->quit = save_quit;      common->quit = save_quit;
5668      common->accept = save_accept;      common->accept = save_accept;
5669      return NULL;      return NULL;
# Line 5139  while (1) Line 5676  while (1)
5676    ccbegin = cc;    ccbegin = cc;
5677    cc += GET(cc, 1);    cc += GET(cc, 1);
5678    }    }
5679  /* None of them matched. */  
5680  if (common->quit != NULL)  /* None of them matched. */
5681    set_jumps(common->quit, LABEL());  if (common->quit != NULL)
5682      {
5683      jump = JUMP(SLJIT_JUMP);
5684      set_jumps(common->quit, LABEL());
5685      SLJIT_ASSERT(framesize != no_stack);
5686      if (framesize < 0)
5687        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
5688      else
5689        {
5690        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5691        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5692        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
5693        }
5694      JUMPHERE(jump);
5695      }
5696    
5697    if (needs_control_head)
5698      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(1));
5699    
5700  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)
5701    {    {
# Line 5153  if (opcode == OP_ASSERT || opcode == OP_ Line 5707  if (opcode == OP_ASSERT || opcode == OP_
5707      {      {
5708      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5709      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5710          {
5711          if (extrasize == 2)
5712            free_stack(common, 1);
5713        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5714          }
5715      else      else
5716        free_stack(common, 1);        free_stack(common, extrasize);
5717      }      }
5718    else    else
5719      {      {
5720      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5721      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5722      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5723        {        {
5724        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
5725        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5726        }        }
5727      else      else
5728        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
5729      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);
5730      }      }
5731    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
# Line 5179  if (opcode == OP_ASSERT || opcode == OP_ Line 5737  if (opcode == OP_ASSERT || opcode == OP_
5737    if (framesize < 0)    if (framesize < 0)
5738      {      {
5739      /* 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. */
5740      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));
5741      /* Keep the STR_PTR on the top of the stack. */      /* Keep the STR_PTR on the top of the stack. */
5742      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5743        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));        {
5744          OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5745          if (extrasize == 2)
5746            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5747          }
5748      else if (bra == OP_BRAMINZERO)      else if (bra == OP_BRAMINZERO)
5749        {        {
5750        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));
5751        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5752        }        }
5753      }      }
# Line 5194  if (opcode == OP_ASSERT || opcode == OP_ Line 5756  if (opcode == OP_ASSERT || opcode == OP_
5756      if (bra == OP_BRA)      if (bra == OP_BRA)
5757        {        {
5758        /* 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. */
5759        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));
5760        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));
5761        }        }
5762      else      else
5763        {        {
5764        /* 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. */
5765        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));
5766        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        if (extrasize == 2)
5767        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);          {
5768            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5769            if (bra == OP_BRAMINZERO)
5770              OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5771            }
5772          else
5773            {
5774            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5775            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);
5776            }
5777        }        }
5778      }      }
5779    
5780    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
5781      {      {
5782      backtrack->matchingpath = LABEL();      backtrack->matchingpath = LABEL();
5783      sljit_set_label(jump, backtrack->matchingpath);      SET_LABEL(jump, backtrack->matchingpath);
5784      }      }
5785    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
5786      {      {
# Line 5219  if (opcode == OP_ASSERT || opcode == OP_ Line 5790  if (opcode == OP_ASSERT || opcode == OP_
5790        {        {
5791        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);
5792        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5793        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));
5794        }        }
5795      set_jumps(backtrack->common.topbacktracks, LABEL());      set_jumps(backtrack->common.topbacktracks, LABEL());
5796      }      }
# Line 5231  else Line 5802  else
5802      {      {
5803      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5804      if (bra != OP_BRA)      if (bra != OP_BRA)
5805          {
5806          if (extrasize == 2)
5807            free_stack(common, 1);
5808        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5809          }
5810      else      else
5811        free_stack(common, 1);        free_stack(common, extrasize);
5812      }      }
5813    else    else
5814      {      {
5815      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5816      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5817      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5818      if (bra != OP_BRA)      if (bra != OP_BRA)
5819        {        {
5820        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
5821        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5822        }        }
5823      else      else
5824        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
5825      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);
5826      }      }
5827    
# Line 5266  else Line 5841  else
5841      }      }
5842    }    }
5843    
5844  common->quitlabel = save_quitlabel;  common->local_exit = save_local_exit;
5845  common->acceptlabel = save_acceptlabel;  common->then_trap = save_then_trap;
5846    common->quit_label = save_quit_label;
5847    common->accept_label = save_accept_label;
5848  common->quit = save_quit;  common->quit = save_quit;
5849  common->accept = save_accept;  common->accept = save_accept;
5850  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5851  }  }
5852    
5853  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)
5854  {  {
5855  int condition = FALSE;  int condition = FALSE;
5856  pcre_uchar *slotA = name_table;  pcre_uchar *slotA = name_table;
5857  pcre_uchar *slotB;  pcre_uchar *slotB;
5858  sljit_w name_count = locals[LOCALS0 / sizeof(sljit_w)];  sljit_sw name_count = locals[LOCALS0 / sizeof(sljit_sw)];
5859  sljit_w name_entry_size = locals[LOCALS1 / sizeof(sljit_w)];  sljit_sw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];
5860  sljit_w no_capture;  sljit_sw no_capture;
5861  int i;  int i;
5862    
5863  locals += refno & 0xff;  locals += refno & 0xff;
# Line 5330  if (i < name_count) Line 5907  if (i < name_count)
5907  return condition;  return condition;
5908  }  }
5909    
5910  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)
5911  {  {
5912  int condition = FALSE;  int condition = FALSE;
5913  pcre_uchar *slotA = name_table;  pcre_uchar *slotA = name_table;
5914  pcre_uchar *slotB;  pcre_uchar *slotB;
5915  sljit_w name_count = locals[LOCALS0 / sizeof(sljit_w)];  sljit_uw name_count = locals[LOCALS0 / sizeof(sljit_sw)];
5916  sljit_w name_entry_size = locals[LOCALS1 / sizeof(sljit_w)];  sljit_uw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];
5917  sljit_w group_num = locals[POSSESSIVE0 / sizeof(sljit_w)];  sljit_uw group_num = locals[POSSESSIVE0 / sizeof(sljit_sw)];
5918  int i;  sljit_uw i;
5919    
5920  for (i = 0; i < name_count; i++)  for (i = 0; i < name_count; i++)
5921    {    {
# Line 5383  if (i < name_count) Line 5960  if (i < name_count)
5960  return condition;  return condition;
5961  }  }
5962    
5963    static SLJIT_INLINE void match_once_common(compiler_common *common, pcre_uchar ket, int framesize, int private_data_ptr, BOOL has_alternatives, BOOL needs_control_head)
5964    {
5965    DEFINE_COMPILER;
5966    int stacksize;
5967    
5968    if (framesize < 0)
5969      {
5970      if (framesize == no_frame)
5971        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5972      else
5973        {
5974        stacksize = needs_control_head ? 1 : 0;
5975        if (ket != OP_KET || has_alternatives)
5976          stacksize++;
5977        free_stack(common, stacksize);
5978        }
5979    
5980      if (needs_control_head)
5981        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), (ket != OP_KET || has_alternatives) ? sizeof(sljit_sw) : 0);
5982    
5983      /* TMP2 which is set here used by OP_KETRMAX below. */
5984      if (ket == OP_KETRMAX)
5985        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);
5986      else if (ket == OP_KETRMIN)
5987        {
5988        /* Move the STR_PTR to the private_data_ptr. */
5989        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);
5990        }
5991      }
5992    else
5993      {
5994      stacksize = (ket != OP_KET || has_alternatives) ? 2 : 1;
5995      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + stacksize) * sizeof(sljit_sw));
5996      if (needs_control_head)
5997        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 0);
5998    
5999      if (ket == OP_KETRMAX)
6000        {
6001        /* TMP2 which is set here used by OP_KETRMAX below. */
6002        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6003        }
6004      }
6005    if (needs_control_head)
6006      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);
6007    }
6008<