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

Diff of /code/trunk/pcre_jit_compile.c

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

revision 1015 by ph10, Sun Aug 26 16:07:14 2012 UTC revision 1421 by zherczeg, Mon Dec 30 13:25:20 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11    The machine code generator part (this module) was written by Zoltan Herczeg    The machine code generator part (this module) was written by Zoltan Herczeg
12                        Copyright (c) 2010-2012                        Copyright (c) 2010-2013
13    
14  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
15  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 46  POSSIBILITY OF SUCH DAMAGE. Line 46  POSSIBILITY OF SUCH DAMAGE.
46    
47  #include "pcre_internal.h"  #include "pcre_internal.h"
48    
49  #ifdef SUPPORT_JIT  #if defined SUPPORT_JIT
50    
51  /* All-in-one: Since we use the JIT compiler only from here,  /* All-in-one: Since we use the JIT compiler only from here,
52  we just include it. This way we don't need to touch the build  we just include it. This way we don't need to touch the build
# Line 65  system files. */ Line 65  system files. */
65  #error Unsupported architecture  #error Unsupported architecture
66  #endif  #endif
67    
68    /* Defines for debugging purposes. */
69    
70    /* 1 - Use unoptimized capturing brackets.
71       2 - Enable capture_last_ptr (includes option 1). */
72    /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */
73    
74    /* 1 - Always have a control head. */
75    /* #define DEBUG_FORCE_CONTROL_HEAD 1 */
76    
77  /* Allocate memory for the regex stack on the real machine stack.  /* Allocate memory for the regex stack on the real machine stack.
78  Fast, but limited size. */  Fast, but limited size. */
79  #define MACHINE_STACK_SIZE 32768  #define MACHINE_STACK_SIZE 32768
# Line 157  typedef struct jit_arguments { Line 166  typedef struct jit_arguments {
166    int *offsets;    int *offsets;
167    pcre_uchar *uchar_ptr;    pcre_uchar *uchar_ptr;
168    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
169      void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171    int offsetcount;    pcre_uint32 limit_match;
172    int calllimit;    int real_offset_count;
173      int offset_count;
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 170  typedef struct executable_functions { Line 181  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184      pcre_uint32 top_bracket;
185      pcre_uint32 limit_match;
186    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
187  } executable_functions;  } executable_functions;
188    
# Line 178  typedef struct jump_list { Line 191  typedef struct jump_list {
191    struct jump_list *next;    struct jump_list *next;
192  } jump_list;  } jump_list;
193    
 enum stub_types { stack_alloc };  
   
194  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
195    struct sljit_jump *start;    struct sljit_jump *start;
196    struct sljit_label *quit;    struct sljit_label *quit;
197    struct stub_list *next;    struct stub_list *next;
198  } stub_list;  } stub_list;
199    
200    enum frame_types {
201      no_frame = -1,
202      no_stack = -2
203    };
204    
205    enum control_types {
206      type_mark = 0,
207      type_then_trap = 1
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
213  code generator. It is allocated by compile_matchingpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_backtrackingpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct backtrack_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
# Line 208  typedef struct backtrack_common { Line 227  typedef struct backtrack_common {
227  typedef struct assert_backtrack {  typedef struct assert_backtrack {
228    backtrack_common common;    backtrack_common common;
229    jump_list *condfailed;    jump_list *condfailed;
230    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
231    int framesize;    int framesize;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int private_data_ptr;    int private_data_ptr;
# Line 229  typedef struct bracket_backtrack { Line 248  typedef struct bracket_backtrack {
248      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
249      jump_list *condfailed;      jump_list *condfailed;
250      assert_backtrack *assert;      assert_backtrack *assert;
251      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
252      int framesize;      int framesize;
253    } u;    } u;
254    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
# Line 264  typedef struct recurse_entry { Line 283  typedef struct recurse_entry {
283    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
284    jump_list *calls;    jump_list *calls;
285    /* Points to the starting opcode. */    /* Points to the starting opcode. */
286    int start;    sljit_sw start;
287  } recurse_entry;  } recurse_entry;
288    
289  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
290    backtrack_common common;    backtrack_common common;
291      BOOL inlined_pattern;
292  } recurse_backtrack;  } recurse_backtrack;
293    
294  #define MAX_RANGE_SIZE 6  #define OP_THEN_TRAP OP_TABLE_LENGTH
295    
296    typedef struct then_trap_backtrack {
297      backtrack_common common;
298      /* If then_trap is not NULL, this structure contains the real
299      then_trap for the backtracking path. */
300      struct then_trap_backtrack *then_trap;
301      /* Points to the starting opcode. */
302      sljit_sw start;
303      /* Exit point for the then opcodes of this alternative. */
304      jump_list *quit;
305      /* Frame size of the current alternative. */
306      int framesize;
307    } then_trap_backtrack;
308    
309    #define MAX_RANGE_SIZE 4
310    
311  typedef struct compiler_common {  typedef struct compiler_common {
312      /* The sljit ceneric compiler. */
313    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
314      /* First byte code. */
315    pcre_uchar *start;    pcre_uchar *start;
   
316    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
317    int *private_data_ptrs;    sljit_si *private_data_ptrs;
318    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
319    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
320      /* Tells whether the starting offset is a target of then. */
321      pcre_uint8 *then_offsets;
322      /* Current position where a THEN must jump. */
323      then_trap_backtrack *then_trap;
324    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
325    int cbraptr;    int cbra_ptr;
326    /* OVector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
327    int ovector_start;    int ovector_start;
328    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
329    int req_char_ptr;    int req_char_ptr;
330    /* Head of the last recursion. */    /* Head of the last recursion. */
331    int recursive_head;    int recursive_head_ptr;
332    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
333    int start_used_ptr;    int start_used_ptr;
334    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 297  typedef struct compiler_common { Line 337  typedef struct compiler_common {
337    int first_line_end;    int first_line_end;
338    /* Points to the marked string. */    /* Points to the marked string. */
339    int mark_ptr;    int mark_ptr;
340      /* Recursive control verb management chain. */
341      int control_head_ptr;
342      /* Points to the last matched capture block index. */
343      int capture_last_ptr;
344      /* Points to the starting position of the current match. */
345      int start_ptr;
346    
347    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
348    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
349    sljit_w lcc;    sljit_sw lcc;
350    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
351    int mode;    int mode;
352      /* \K is found in the pattern. */
353      BOOL has_set_som;
354      /* (*SKIP:arg) is found in the pattern. */
355      BOOL has_skip_arg;
356      /* (*THEN) is found in the pattern. */
357      BOOL has_then;
358      /* Needs to know the start position anytime. */
359      BOOL needs_start_ptr;
360      /* Currently in recurse or negative assert. */
361      BOOL local_exit;
362      /* Currently in a positive assert. */
363      BOOL positive_assert;
364    /* Newline control. */    /* Newline control. */
365    int nltype;    int nltype;
366    int newline;    int newline;
367    int bsr_nltype;    int bsr_nltype;
368    /* Dollar endonly. */    /* Dollar endonly. */
369    int endonly;    int endonly;
   BOOL has_set_som;  
370    /* Tables. */    /* Tables. */
371    sljit_w ctypes;    sljit_sw ctypes;
   int digits[2 + MAX_RANGE_SIZE];  
372    /* Named capturing brackets. */    /* Named capturing brackets. */
373    sljit_uw name_table;    pcre_uchar *name_table;
374    sljit_w name_count;    sljit_sw name_count;
375    sljit_w name_entry_size;    sljit_sw name_entry_size;
376    
377    /* Labels and jump lists. */    /* Labels and jump lists. */
378    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
379    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
380    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
381      struct sljit_label *accept_label;
382    stub_list *stubs;    stub_list *stubs;
383    recurse_entry *entries;    recurse_entry *entries;
384    recurse_entry *currententry;    recurse_entry *currententry;
385    jump_list *partialmatch;    jump_list *partialmatch;
386    jump_list *quit;    jump_list *quit;
387      jump_list *positive_assert_quit;
388      jump_list *forced_quit;
389    jump_list *accept;    jump_list *accept;
390    jump_list *calllimit;    jump_list *calllimit;
391    jump_list *stackalloc;    jump_list *stackalloc;
# Line 337  typedef struct compiler_common { Line 396  typedef struct compiler_common {
396    jump_list *vspace;    jump_list *vspace;
397    jump_list *casefulcmp;    jump_list *casefulcmp;
398    jump_list *caselesscmp;    jump_list *caselesscmp;
399      jump_list *reset_match;
400    BOOL jscript_compat;    BOOL jscript_compat;
401  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
402    BOOL utf;    BOOL utf;
403  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
404    BOOL use_ucp;    BOOL use_ucp;
405  #endif  #endif
406    #ifndef COMPILE_PCRE32
407    jump_list *utfreadchar;    jump_list *utfreadchar;
408    #endif
409  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
410      jump_list *utfreadchar11;
411    jump_list *utfreadtype8;    jump_list *utfreadtype8;
412  #endif  #endif
413  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
# Line 361  typedef struct compare_context { Line 424  typedef struct compare_context {
424  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
425    int ucharptr;    int ucharptr;
426    union {    union {
427      sljit_i asint;      sljit_si asint;
428      sljit_uh asushort;      sljit_uh asushort;
429  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
430      sljit_ub asbyte;      sljit_ub asbyte;
431      sljit_ub asuchars[4];      sljit_ub asuchars[4];
432  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
433      sljit_uh asuchars[2];      sljit_uh asuchars[2];
434  #endif  #elif defined COMPILE_PCRE32
435        sljit_ui asuchars[1];
436  #endif  #endif
437    } c;    } c;
438    union {    union {
439      sljit_i asint;      sljit_si asint;
440      sljit_uh asushort;      sljit_uh asushort;
441  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
442      sljit_ub asbyte;      sljit_ub asbyte;
443      sljit_ub asuchars[4];      sljit_ub asuchars[4];
444  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
445      sljit_uh asuchars[2];      sljit_uh asuchars[2];
446  #endif  #elif defined COMPILE_PCRE32
447        sljit_ui asuchars[1];
448  #endif  #endif
449    } oc;    } oc;
450  #endif  #endif
451  } compare_context;  } compare_context;
452    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
453  /* Undefine sljit macros. */  /* Undefine sljit macros. */
454  #undef CMP  #undef CMP
455    
456  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
457  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
458    
459  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
460  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
461  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
462  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
463  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
464  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
465  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
466  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
467  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
468  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
469    
470  /* Local space layout. */  /* Local space layout. */
471  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
472  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
473  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
474  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
475  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
476  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
477  /* Max limit of recursions. */  /* Max limit of recursions. */
478  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
479  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
480  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
481  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
482  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
483  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
484  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
485  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
486  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
487    
488  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
489  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
490  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
491  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
492  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
493  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
494    #elif defined COMPILE_PCRE32
495    #define MOV_UCHAR  SLJIT_MOV_UI
496    #define MOVU_UCHAR SLJIT_MOVU_UI
497  #else  #else
498  #error Unsupported compiling mode  #error Unsupported compiling mode
499  #endif  #endif
 #endif  
500    
501  /* Shortcuts. */  /* Shortcuts. */
502  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 455  the start pointers when the end of the c Line 513  the start pointers when the end of the c
513    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
514  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
515    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
516    #define SET_LABEL(jump, label) \
517      sljit_set_label((jump), (label))
518  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
519    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
520  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
521    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))
522  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
523    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
524  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
525    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
526    
# Line 473  cc += 1 + LINK_SIZE; Line 533  cc += 1 + LINK_SIZE;
533  return cc;  return cc;
534  }  }
535    
536    static int ones_in_half_byte[16] = {
537      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
538      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
539    };
540    
541  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
542   next_opcode   next_opcode
543   get_private_data_length   check_opcode_types
544   set_private_data_ptrs   set_private_data_ptrs
545   get_framesize   get_framesize
546   init_frame   init_frame
547   get_private_data_length_for_copy   get_private_data_copy_length
548   copy_private_data   copy_private_data
549   compile_matchingpath   compile_matchingpath
550   compile_backtrackingpath   compile_backtrackingpath
# Line 503  switch(*cc) Line 568  switch(*cc)
568    case OP_WORDCHAR:    case OP_WORDCHAR:
569    case OP_ANY:    case OP_ANY:
570    case OP_ALLANY:    case OP_ALLANY:
571      case OP_NOTPROP:
572      case OP_PROP:
573    case OP_ANYNL:    case OP_ANYNL:
574    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
575    case OP_HSPACE:    case OP_HSPACE:
# Line 515  switch(*cc) Line 582  switch(*cc)
582    case OP_CIRCM:    case OP_CIRCM:
583    case OP_DOLL:    case OP_DOLL:
584    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:  
585    case OP_CRSTAR:    case OP_CRSTAR:
586    case OP_CRMINSTAR:    case OP_CRMINSTAR:
587    case OP_CRPLUS:    case OP_CRPLUS:
588    case OP_CRMINPLUS:    case OP_CRMINPLUS:
589    case OP_CRQUERY:    case OP_CRQUERY:
590    case OP_CRMINQUERY:    case OP_CRMINQUERY:
591      case OP_CRRANGE:
592      case OP_CRMINRANGE:
593      case OP_CRPOSSTAR:
594      case OP_CRPOSPLUS:
595      case OP_CRPOSQUERY:
596      case OP_CRPOSRANGE:
597      case OP_CLASS:
598      case OP_NCLASS:
599      case OP_REF:
600      case OP_REFI:
601      case OP_DNREF:
602      case OP_DNREFI:
603      case OP_RECURSE:
604      case OP_CALLOUT:
605      case OP_ALT:
606      case OP_KET:
607      case OP_KETRMAX:
608      case OP_KETRMIN:
609      case OP_KETRPOS:
610      case OP_REVERSE:
611      case OP_ASSERT:
612      case OP_ASSERT_NOT:
613      case OP_ASSERTBACK:
614      case OP_ASSERTBACK_NOT:
615      case OP_ONCE:
616      case OP_ONCE_NC:
617      case OP_BRA:
618      case OP_BRAPOS:
619      case OP_CBRA:
620      case OP_CBRAPOS:
621      case OP_COND:
622      case OP_SBRA:
623      case OP_SBRAPOS:
624      case OP_SCBRA:
625      case OP_SCBRAPOS:
626      case OP_SCOND:
627      case OP_CREF:
628      case OP_DNCREF:
629      case OP_RREF:
630      case OP_DNRREF:
631    case OP_DEF:    case OP_DEF:
632    case OP_BRAZERO:    case OP_BRAZERO:
633    case OP_BRAMINZERO:    case OP_BRAMINZERO:
634    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
635      case OP_PRUNE:
636      case OP_SKIP:
637      case OP_THEN:
638    case OP_COMMIT:    case OP_COMMIT:
639    case OP_FAIL:    case OP_FAIL:
640    case OP_ACCEPT:    case OP_ACCEPT:
641    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
642      case OP_CLOSE:
643    case OP_SKIPZERO:    case OP_SKIPZERO:
644    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
645    
646    case OP_CHAR:    case OP_CHAR:
647    case OP_CHARI:    case OP_CHARI:
# Line 557  switch(*cc) Line 653  switch(*cc)
653    case OP_MINPLUS:    case OP_MINPLUS:
654    case OP_QUERY:    case OP_QUERY:
655    case OP_MINQUERY:    case OP_MINQUERY:
656      case OP_UPTO:
657      case OP_MINUPTO:
658      case OP_EXACT:
659    case OP_POSSTAR:    case OP_POSSTAR:
660    case OP_POSPLUS:    case OP_POSPLUS:
661    case OP_POSQUERY:    case OP_POSQUERY:
662      case OP_POSUPTO:
663    case OP_STARI:    case OP_STARI:
664    case OP_MINSTARI:    case OP_MINSTARI:
665    case OP_PLUSI:    case OP_PLUSI:
666    case OP_MINPLUSI:    case OP_MINPLUSI:
667    case OP_QUERYI:    case OP_QUERYI:
668    case OP_MINQUERYI:    case OP_MINQUERYI:
669      case OP_UPTOI:
670      case OP_MINUPTOI:
671      case OP_EXACTI:
672    case OP_POSSTARI:    case OP_POSSTARI:
673    case OP_POSPLUSI:    case OP_POSPLUSI:
674    case OP_POSQUERYI:    case OP_POSQUERYI:
675      case OP_POSUPTOI:
676    case OP_NOTSTAR:    case OP_NOTSTAR:
677    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
678    case OP_NOTPLUS:    case OP_NOTPLUS:
679    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
680    case OP_NOTQUERY:    case OP_NOTQUERY:
681    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
682      case OP_NOTUPTO:
683      case OP_NOTMINUPTO:
684      case OP_NOTEXACT:
685    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
686    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
687    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
688      case OP_NOTPOSUPTO:
689    case OP_NOTSTARI:    case OP_NOTSTARI:
690    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
691    case OP_NOTPLUSI:    case OP_NOTPLUSI:
692    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
693    case OP_NOTQUERYI:    case OP_NOTQUERYI:
694    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:  
695    case OP_NOTUPTOI:    case OP_NOTUPTOI:
696    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
697    case OP_NOTEXACTI:    case OP_NOTEXACTI:
698      case OP_NOTPOSSTARI:
699      case OP_NOTPOSPLUSI:
700      case OP_NOTPOSQUERYI:
701    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
702    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
703  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
704    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
705  #endif  #endif
706    return cc;    return cc;
707    
708    case OP_NOTPROP:    /* Special cases. */
709    case OP_PROP:    case OP_TYPESTAR:
710    return cc + 1 + 2;    case OP_TYPEMINSTAR:
711      case OP_TYPEPLUS:
712      case OP_TYPEMINPLUS:
713      case OP_TYPEQUERY:
714      case OP_TYPEMINQUERY:
715    case OP_TYPEUPTO:    case OP_TYPEUPTO:
716    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
717    case OP_TYPEEXACT:    case OP_TYPEEXACT:
718      case OP_TYPEPOSSTAR:
719      case OP_TYPEPOSPLUS:
720      case OP_TYPEPOSQUERY:
721    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
722    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_NCREF:  
   case OP_RREF:  
   case OP_NRREF:  
   case OP_CLOSE:  
   cc += 1 + IMM2_SIZE;  
   return cc;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   return cc + 1 + 2 * IMM2_SIZE;  
723    
724    case OP_CLASS:    case OP_ANYBYTE:
725    case OP_NCLASS:  #ifdef SUPPORT_UTF
726    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
727    #endif
728      return cc + 1;
729    
730  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
731    case OP_XCLASS:    case OP_XCLASS:
732    return cc + GET(cc, 1);    return cc + GET(cc, 1);
733  #endif  #endif
734    
   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;  
   
735    case OP_MARK:    case OP_MARK:
736      case OP_PRUNE_ARG:
737      case OP_SKIP_ARG:
738      case OP_THEN_ARG:
739    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
740    
741    default:    default:
742      /* All opcodes are supported now! */
743      SLJIT_ASSERT_STOP();
744    return NULL;    return NULL;
745    }    }
746  }  }
747    
748  #define CASE_ITERATOR_PRIVATE_DATA_1 \  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
     case OP_MINSTAR: \  
     case OP_MINPLUS: \  
     case OP_QUERY: \  
     case OP_MINQUERY: \  
     case OP_MINSTARI: \  
     case OP_MINPLUSI: \  
     case OP_QUERYI: \  
     case OP_MINQUERYI: \  
     case OP_NOTMINSTAR: \  
     case OP_NOTMINPLUS: \  
     case OP_NOTQUERY: \  
     case OP_NOTMINQUERY: \  
     case OP_NOTMINSTARI: \  
     case OP_NOTMINPLUSI: \  
     case OP_NOTQUERYI: \  
     case OP_NOTMINQUERYI:  
   
 #define CASE_ITERATOR_PRIVATE_DATA_2A \  
     case OP_STAR: \  
     case OP_PLUS: \  
     case OP_STARI: \  
     case OP_PLUSI: \  
     case OP_NOTSTAR: \  
     case OP_NOTPLUS: \  
     case OP_NOTSTARI: \  
     case OP_NOTPLUSI:  
   
 #define CASE_ITERATOR_PRIVATE_DATA_2B \  
     case OP_UPTO: \  
     case OP_MINUPTO: \  
     case OP_UPTOI: \  
     case OP_MINUPTOI: \  
     case OP_NOTUPTO: \  
     case OP_NOTMINUPTO: \  
     case OP_NOTUPTOI: \  
     case OP_NOTMINUPTOI:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \  
     case OP_TYPEMINSTAR: \  
     case OP_TYPEMINPLUS: \  
     case OP_TYPEQUERY: \  
     case OP_TYPEMINQUERY:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \  
     case OP_TYPESTAR: \  
     case OP_TYPEPLUS:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \  
     case OP_TYPEUPTO: \  
     case OP_TYPEMINUPTO:  
   
 static int get_class_iterator_size(pcre_uchar *cc)  
 {  
 switch(*cc)  
   {  
   case OP_CRSTAR:  
   case OP_CRPLUS:  
   return 2;  
   
   case OP_CRMINSTAR:  
   case OP_CRMINPLUS:  
   case OP_CRQUERY:  
   case OP_CRMINQUERY:  
   return 1;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))  
     return 0;  
   return 2;  
   
   default:  
   return 0;  
   }  
 }  
   
 static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  
749  {  {
750  int private_data_length = 0;  int count;
751  pcre_uchar *alternative;  pcre_uchar *slot;
 pcre_uchar *name;  
 pcre_uchar *end = NULL;  
 int space, size, bracketlen, i;  
752    
753  /* 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. */
754  while (cc < ccend)  while (cc < ccend)
755    {    {
   space = 0;  
   size = 0;  
   bracketlen = 0;  
756    switch(*cc)    switch(*cc)
757      {      {
758      case OP_SET_SOM:      case OP_SET_SOM:
# Line 785  while (cc < ccend) Line 766  while (cc < ccend)
766      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
767      break;      break;
768    
     case OP_ASSERT:  
     case OP_ASSERT_NOT:  
     case OP_ASSERTBACK:  
     case OP_ASSERTBACK_NOT:  
     case OP_ONCE:  
     case OP_ONCE_NC:  
     case OP_BRAPOS:  
     case OP_SBRA:  
     case OP_SBRAPOS:  
     private_data_length += sizeof(sljit_w);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
769      case OP_CBRAPOS:      case OP_CBRAPOS:
770      case OP_SCBRAPOS:      case OP_SCBRAPOS:
     private_data_length += sizeof(sljit_w);  
771      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
772      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
773      break;      break;
774    
775      case OP_COND:      case OP_COND:
776      case OP_SCOND:      case OP_SCOND:
777      bracketlen = cc[1 + LINK_SIZE];      /* Only AUTO_CALLOUT can insert this opcode. We do
778      if (bracketlen == OP_CREF)         not intend to support this case. */
779        {      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
780        bracketlen = GET2(cc, 1 + LINK_SIZE + 1);        return FALSE;
781        common->optimized_cbracket[bracketlen] = 0;      cc += 1 + LINK_SIZE;
       }  
     else if (bracketlen == OP_NCREF)  
       {  
       bracketlen = GET2(cc, 1 + LINK_SIZE + 1);  
       name = (pcre_uchar *)common->name_table;  
       alternative = name;  
       for (i = 0; i < common->name_count; i++)  
         {  
         if (GET2(name, 0) == bracketlen) break;  
         name += common->name_entry_size;  
         }  
       SLJIT_ASSERT(i != common->name_count);  
   
       for (i = 0; i < common->name_count; i++)  
         {  
         if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)  
           common->optimized_cbracket[GET2(alternative, 0)] = 0;  
         alternative += common->name_entry_size;  
         }  
       }  
   
     if (*cc == OP_COND)  
       {  
       /* Might be a hidden SCOND. */  
       alternative = cc + GET(cc, 1);  
       if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)  
         private_data_length += sizeof(sljit_w);  
       }  
     else  
       private_data_length += sizeof(sljit_w);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_BRA:  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_CBRA:  
     case OP_SCBRA:  
     bracketlen = 1 + LINK_SIZE + IMM2_SIZE;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_1  
     space = 1;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_2A  
     space = 2;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_2B  
     space = 2;  
     size = -(2 + IMM2_SIZE);  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_1  
     space = 1;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_2A  
     if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)  
       space = 2;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_2B  
     if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)  
       space = 2;  
     size = 1 + IMM2_SIZE;  
782      break;      break;
783    
784      case OP_CLASS:      case OP_CREF:
785      case OP_NCLASS:      common->optimized_cbracket[GET2(cc, 1)] = 0;
786      size += 1 + 32 / sizeof(pcre_uchar);      cc += 1 + IMM2_SIZE;
     space = get_class_iterator_size(cc + size);  
787      break;      break;
788    
789  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8      case OP_DNREF:
790      case OP_XCLASS:      case OP_DNREFI:
791      size = GET(cc, 1);      case OP_DNCREF:
792      space = get_class_iterator_size(cc + size);      count = GET2(cc, 1 + IMM2_SIZE);
793        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
794        while (count-- > 0)
795          {
796          common->optimized_cbracket[GET2(slot, 0)] = 0;
797          slot += common->name_entry_size;
798          }
799        cc += 1 + 2 * IMM2_SIZE;
800      break;      break;
 #endif  
801    
802      case OP_RECURSE:      case OP_RECURSE:
803      /* Set its value only once. */      /* Set its value only once. */
804      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
805        {        {
806        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
807        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
808        }        }
809      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
810      break;      break;
811    
812        case OP_CALLOUT:
813        if (common->capture_last_ptr == 0)
814          {
815          common->capture_last_ptr = common->ovector_start;
816          common->ovector_start += sizeof(sljit_sw);
817          }
818        cc += 2 + 2 * LINK_SIZE;
819        break;
820    
821        case OP_THEN_ARG:
822        common->has_then = TRUE;
823        common->control_head_ptr = 1;
824        /* Fall through. */
825    
826        case OP_PRUNE_ARG:
827        common->needs_start_ptr = TRUE;
828        /* Fall through. */
829    
830      case OP_MARK:      case OP_MARK:
831      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
832        {        {
833        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
834        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
835        }        }
836      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
837      break;      break;
838    
839        case OP_THEN:
840        common->has_then = TRUE;
841        common->control_head_ptr = 1;
842        /* Fall through. */
843    
844        case OP_PRUNE:
845        case OP_SKIP:
846        common->needs_start_ptr = TRUE;
847        cc += 1;
848        break;
849    
850        case OP_SKIP_ARG:
851        common->control_head_ptr = 1;
852        common->has_skip_arg = TRUE;
853        cc += 1 + 2 + cc[1];
854        break;
855    
856      default:      default:
857      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
858      if (cc == NULL)      if (cc == NULL)
859        return -1;        return FALSE;
860      break;      break;
861      }      }
862      }
863    return TRUE;
864    }
865    
866    if (space > 0 && cc >= end)  static int get_class_iterator_size(pcre_uchar *cc)
867      private_data_length += sizeof(sljit_w) * space;  {
868    switch(*cc)
869      {
870      case OP_CRSTAR:
871      case OP_CRPLUS:
872      return 2;
873    
874    if (size != 0)    case OP_CRMINSTAR:
875      case OP_CRMINPLUS:
876      case OP_CRQUERY:
877      case OP_CRMINQUERY:
878      return 1;
879    
880      case OP_CRRANGE:
881      case OP_CRMINRANGE:
882      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
883        return 0;
884      return 2;
885    
886      default:
887      return 0;
888      }
889    }
890    
891    static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
892    {
893    pcre_uchar *end = bracketend(begin);
894    pcre_uchar *next;
895    pcre_uchar *next_end;
896    pcre_uchar *max_end;
897    pcre_uchar type;
898    sljit_sw length = end - begin;
899    int min, max, i;
900    
901    /* Detect fixed iterations first. */
902    if (end[-(1 + LINK_SIZE)] != OP_KET)
903      return FALSE;
904    
905    /* Already detected repeat. */
906    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
907      return TRUE;
908    
909    next = end;
910    min = 1;
911    while (1)
912      {
913      if (*next != *begin)
914        break;
915      next_end = bracketend(next);
916      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
917        break;
918      next = next_end;
919      min++;
920      }
921    
922    if (min == 2)
923      return FALSE;
924    
925    max = 0;
926    max_end = next;
927    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
928      {
929      type = *next;
930      while (1)
931      {      {
932      if (size < 0)      if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
933        {        break;
934        cc += -size;      next_end = bracketend(next + 2 + LINK_SIZE);
935  #ifdef SUPPORT_UTF      if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
936        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        break;
937  #endif      next = next_end;
938        }      max++;
     else  
       cc += size;  
939      }      }
940    
941    if (bracketlen > 0)    if (next[0] == type && next[1] == *begin && max >= 1)
942      {      {
943      if (cc >= end)      next_end = bracketend(next + 1);
944        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
945        {        {
946        end = bracketend(cc);        for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
947        if (end[-1 - LINK_SIZE] == OP_KET)          if (*next_end != OP_KET)
948          end = NULL;            break;
949    
950          if (i == max)
951            {
952            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
953            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
954            /* +2 the original and the last. */
955            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
956            if (min == 1)
957              return TRUE;
958            min--;
959            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
960            }
961        }        }
     cc += bracketlen;  
962      }      }
963    }    }
964  return private_data_length;  
965    if (min >= 3)
966      {
967      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
968      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
969      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
970      return TRUE;
971      }
972    
973    return FALSE;
974  }  }
975    
976  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
977        case OP_MINSTAR: \
978        case OP_MINPLUS: \
979        case OP_QUERY: \
980        case OP_MINQUERY: \
981        case OP_MINSTARI: \
982        case OP_MINPLUSI: \
983        case OP_QUERYI: \
984        case OP_MINQUERYI: \
985        case OP_NOTMINSTAR: \
986        case OP_NOTMINPLUS: \
987        case OP_NOTQUERY: \
988        case OP_NOTMINQUERY: \
989        case OP_NOTMINSTARI: \
990        case OP_NOTMINPLUSI: \
991        case OP_NOTQUERYI: \
992        case OP_NOTMINQUERYI:
993    
994    #define CASE_ITERATOR_PRIVATE_DATA_2A \
995        case OP_STAR: \
996        case OP_PLUS: \
997        case OP_STARI: \
998        case OP_PLUSI: \
999        case OP_NOTSTAR: \
1000        case OP_NOTPLUS: \
1001        case OP_NOTSTARI: \
1002        case OP_NOTPLUSI:
1003    
1004    #define CASE_ITERATOR_PRIVATE_DATA_2B \
1005        case OP_UPTO: \
1006        case OP_MINUPTO: \
1007        case OP_UPTOI: \
1008        case OP_MINUPTOI: \
1009        case OP_NOTUPTO: \
1010        case OP_NOTMINUPTO: \
1011        case OP_NOTUPTOI: \
1012        case OP_NOTMINUPTOI:
1013    
1014    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1015        case OP_TYPEMINSTAR: \
1016        case OP_TYPEMINPLUS: \
1017        case OP_TYPEQUERY: \
1018        case OP_TYPEMINQUERY:
1019    
1020    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1021        case OP_TYPESTAR: \
1022        case OP_TYPEPLUS:
1023    
1024    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1025        case OP_TYPEUPTO: \
1026        case OP_TYPEMINUPTO:
1027    
1028    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1029  {  {
1030  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1031  pcre_uchar *alternative;  pcre_uchar *alternative;
1032  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1033    int private_data_ptr = *private_data_start;
1034  int space, size, bracketlen;  int space, size, bracketlen;
1035    
1036  while (cc < ccend)  while (cc < ccend)
# Line 967  while (cc < ccend) Line 1038  while (cc < ccend)
1038    space = 0;    space = 0;
1039    size = 0;    size = 0;
1040    bracketlen = 0;    bracketlen = 0;
1041      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1042        return;
1043    
1044      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1045        if (detect_repeat(common, cc))
1046          {
1047          /* These brackets are converted to repeats, so no global
1048          based single character repeat is allowed. */
1049          if (cc >= end)
1050            end = bracketend(cc);
1051          }
1052    
1053    switch(*cc)    switch(*cc)
1054      {      {
1055        case OP_KET:
1056        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1057          {
1058          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1059          private_data_ptr += sizeof(sljit_sw);
1060          cc += common->private_data_ptrs[cc + 1 - common->start];
1061          }
1062        cc += 1 + LINK_SIZE;
1063        break;
1064    
1065      case OP_ASSERT:      case OP_ASSERT:
1066      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1067      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 980  while (cc < ccend) Line 1073  while (cc < ccend)
1073      case OP_SBRAPOS:      case OP_SBRAPOS:
1074      case OP_SCOND:      case OP_SCOND:
1075      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1076      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1077      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1078      break;      break;
1079    
1080      case OP_CBRAPOS:      case OP_CBRAPOS:
1081      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1082      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1083      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1084      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1085      break;      break;
1086    
# Line 997  while (cc < ccend) Line 1090  while (cc < ccend)
1090      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1091        {        {
1092        common->private_data_ptrs[cc - common->start] = private_data_ptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1093        private_data_ptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1094        }        }
1095      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1096      break;      break;
# Line 1062  while (cc < ccend) Line 1155  while (cc < ccend)
1155      break;      break;
1156      }      }
1157    
1158      /* Character iterators, which are not inside a repeated bracket,
1159         gets a private slot instead of allocating it on the stack. */
1160    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1161      {      {
1162      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1163      private_data_ptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1164      }      }
1165    
1166    if (size != 0)    if (size != 0)
# Line 1092  while (cc < ccend) Line 1187  while (cc < ccend)
1187      cc += bracketlen;      cc += bracketlen;
1188      }      }
1189    }    }
1190    *private_data_start = private_data_ptr;
1191  }  }
1192    
1193  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1194  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)
1195  {  {
 pcre_uchar *ccend = bracketend(cc);  
1196  int length = 0;  int length = 0;
1197  BOOL possessive = FALSE;  int possessive = 0;
1198    BOOL stack_restore = FALSE;
1199  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1200  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1201    /* The last capture is a local variable even for recursions. */
1202    BOOL capture_last_found = FALSE;
1203    
1204    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1205    SLJIT_ASSERT(common->control_head_ptr != 0);
1206    *needs_control_head = TRUE;
1207    #else
1208    *needs_control_head = FALSE;
1209    #endif
1210    
1211  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (ccend == NULL)
1212    {    {
1213    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1214    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1215        {
1216        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1217        /* This is correct regardless of common->capture_last_ptr. */
1218        capture_last_found = TRUE;
1219        }
1220      cc = next_opcode(common, cc);
1221    }    }
1222    
 cc = next_opcode(common, cc);  
1223  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1224  while (cc < ccend)  while (cc < ccend)
1225    switch(*cc)    switch(*cc)
1226      {      {
1227      case OP_SET_SOM:      case OP_SET_SOM:
1228      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1229        stack_restore = TRUE;
1230      if (!setsom_found)      if (!setsom_found)
1231        {        {
1232        length += 2;        length += 2;
# Line 1125  while (cc < ccend) Line 1236  while (cc < ccend)
1236      break;      break;
1237    
1238      case OP_MARK:      case OP_MARK:
1239        case OP_PRUNE_ARG:
1240        case OP_THEN_ARG:
1241      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1242        stack_restore = TRUE;
1243      if (!setmark_found)      if (!setmark_found)
1244        {        {
1245        length += 2;        length += 2;
1246        setmark_found = TRUE;        setmark_found = TRUE;
1247        }        }
1248        if (common->control_head_ptr != 0)
1249          *needs_control_head = TRUE;
1250      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1251      break;      break;
1252    
1253      case OP_RECURSE:      case OP_RECURSE:
1254        stack_restore = TRUE;
1255      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1256        {        {
1257        length += 2;        length += 2;
# Line 1145  while (cc < ccend) Line 1262  while (cc < ccend)
1262        length += 2;        length += 2;
1263        setmark_found = TRUE;        setmark_found = TRUE;
1264        }        }
1265        if (common->capture_last_ptr != 0 && !capture_last_found)
1266          {
1267          length += 2;
1268          capture_last_found = TRUE;
1269          }
1270      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1271      break;      break;
1272    
# Line 1152  while (cc < ccend) Line 1274  while (cc < ccend)
1274      case OP_CBRAPOS:      case OP_CBRAPOS:
1275      case OP_SCBRA:      case OP_SCBRA:
1276      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1277        stack_restore = TRUE;
1278        if (common->capture_last_ptr != 0 && !capture_last_found)
1279          {
1280          length += 2;
1281          capture_last_found = TRUE;
1282          }
1283      length += 3;      length += 3;
1284      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1285      break;      break;
1286    
1287      default:      default:
1288        stack_restore = TRUE;
1289        /* Fall through. */
1290    
1291        case OP_NOT_WORD_BOUNDARY:
1292        case OP_WORD_BOUNDARY:
1293        case OP_NOT_DIGIT:
1294        case OP_DIGIT:
1295        case OP_NOT_WHITESPACE:
1296        case OP_WHITESPACE:
1297        case OP_NOT_WORDCHAR:
1298        case OP_WORDCHAR:
1299        case OP_ANY:
1300        case OP_ALLANY:
1301        case OP_ANYBYTE:
1302        case OP_NOTPROP:
1303        case OP_PROP:
1304        case OP_ANYNL:
1305        case OP_NOT_HSPACE:
1306        case OP_HSPACE:
1307        case OP_NOT_VSPACE:
1308        case OP_VSPACE:
1309        case OP_EXTUNI:
1310        case OP_EODN:
1311        case OP_EOD:
1312        case OP_CIRC:
1313        case OP_CIRCM:
1314        case OP_DOLL:
1315        case OP_DOLLM:
1316        case OP_CHAR:
1317        case OP_CHARI:
1318        case OP_NOT:
1319        case OP_NOTI:
1320    
1321        case OP_EXACT:
1322        case OP_POSSTAR:
1323        case OP_POSPLUS:
1324        case OP_POSQUERY:
1325        case OP_POSUPTO:
1326    
1327        case OP_EXACTI:
1328        case OP_POSSTARI:
1329        case OP_POSPLUSI:
1330        case OP_POSQUERYI:
1331        case OP_POSUPTOI:
1332    
1333        case OP_NOTEXACT:
1334        case OP_NOTPOSSTAR:
1335        case OP_NOTPOSPLUS:
1336        case OP_NOTPOSQUERY:
1337        case OP_NOTPOSUPTO:
1338    
1339        case OP_NOTEXACTI:
1340        case OP_NOTPOSSTARI:
1341        case OP_NOTPOSPLUSI:
1342        case OP_NOTPOSQUERYI:
1343        case OP_NOTPOSUPTOI:
1344    
1345        case OP_TYPEEXACT:
1346        case OP_TYPEPOSSTAR:
1347        case OP_TYPEPOSPLUS:
1348        case OP_TYPEPOSQUERY:
1349        case OP_TYPEPOSUPTO:
1350    
1351        case OP_CLASS:
1352        case OP_NCLASS:
1353        case OP_XCLASS:
1354    
1355      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1356      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1357      break;      break;
1358      }      }
1359    
1360  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1361  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1362    return -1;    return stack_restore ? no_frame : no_stack;
1363    
1364  if (length > 0)  if (length > 0)
1365    return length + 1;    return length + 1;
1366  return -1;  return stack_restore ? no_frame : no_stack;
1367  }  }
1368    
1369  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)
1370  {  {
1371  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1372  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1373  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1374    /* The last capture is a local variable even for recursions. */
1375    BOOL capture_last_found = FALSE;
1376  int offset;  int offset;
1377    
1378  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1184  SLJIT_UNUSED_ARG(stacktop); Line 1380  SLJIT_UNUSED_ARG(stacktop);
1380  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1381    
1382  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1383  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1384    cc = next_opcode(common, cc);    {
1385      ccend = bracketend(cc) - (1 + LINK_SIZE);
1386      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1387        cc = next_opcode(common, cc);
1388      }
1389    
1390  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1391  while (cc < ccend)  while (cc < ccend)
1392    switch(*cc)    switch(*cc)
# Line 1195  while (cc < ccend) Line 1396  while (cc < ccend)
1396      if (!setsom_found)      if (!setsom_found)
1397        {        {
1398        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1399        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1400        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1401        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1402        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1403        setsom_found = TRUE;        setsom_found = TRUE;
1404        }        }
1405      cc += 1;      cc += 1;
1406      break;      break;
1407    
1408      case OP_MARK:      case OP_MARK:
1409        case OP_PRUNE_ARG:
1410        case OP_THEN_ARG:
1411      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1412      if (!setmark_found)      if (!setmark_found)
1413        {        {
1414        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);
1415        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);
1416        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1417        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1418        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1419        setmark_found = TRUE;        setmark_found = TRUE;
1420        }        }
1421      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1222  while (cc < ccend) Line 1425  while (cc < ccend)
1425      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1426        {        {
1427        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1428        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1429        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1430        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1431        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1432        setsom_found = TRUE;        setsom_found = TRUE;
1433        }        }
1434      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1435        {        {
1436        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);
1437        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);
1438        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1439        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1440        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1441        setmark_found = TRUE;        setmark_found = TRUE;
1442        }        }
1443        if (common->capture_last_ptr != 0 && !capture_last_found)
1444          {
1445          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1446          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1447          stackpos += (int)sizeof(sljit_sw);
1448          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1449          stackpos += (int)sizeof(sljit_sw);
1450          capture_last_found = TRUE;
1451          }
1452      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1453      break;      break;
1454    
# Line 1244  while (cc < ccend) Line 1456  while (cc < ccend)
1456      case OP_CBRAPOS:      case OP_CBRAPOS:
1457      case OP_SCBRA:      case OP_SCBRA:
1458      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1459        if (common->capture_last_ptr != 0 && !capture_last_found)
1460          {
1461          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1462          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1463          stackpos += (int)sizeof(sljit_sw);
1464          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1465          stackpos += (int)sizeof(sljit_sw);
1466          capture_last_found = TRUE;
1467          }
1468      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1469      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1470      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1471      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1472      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));
1473      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1474      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1475      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1476      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1477    
1478      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1479      break;      break;
# Line 1263  while (cc < ccend) Line 1484  while (cc < ccend)
1484      break;      break;
1485      }      }
1486    
1487  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1488  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1489  }  }
1490    
1491  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)
1492  {  {
1493  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1494  int size;  int size;
1495  pcre_uchar *alternative;  pcre_uchar *alternative;
1496  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1278  while (cc < ccend) Line 1499  while (cc < ccend)
1499    size = 0;    size = 0;
1500    switch(*cc)    switch(*cc)
1501      {      {
1502        case OP_KET:
1503        if (PRIVATE_DATA(cc) != 0)
1504          private_data_length++;
1505        cc += 1 + LINK_SIZE;
1506        break;
1507    
1508      case OP_ASSERT:      case OP_ASSERT:
1509      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1510      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1382  return private_data_length; Line 1609  return private_data_length;
1609  }  }
1610    
1611  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,
1612    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1613  {  {
1614  DEFINE_COMPILER;  DEFINE_COMPILER;
1615  int srcw[2];  int srcw[2];
# Line 1403  stacktop = STACK(stacktop - 1); Line 1630  stacktop = STACK(stacktop - 1);
1630    
1631  if (!save)  if (!save)
1632    {    {
1633    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1634    if (stackptr < stacktop)    if (stackptr < stacktop)
1635      {      {
1636      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1637      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1638      tmp1empty = FALSE;      tmp1empty = FALSE;
1639      }      }
1640    if (stackptr < stacktop)    if (stackptr < stacktop)
1641      {      {
1642      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1643      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1644      tmp2empty = FALSE;      tmp2empty = FALSE;
1645      }      }
1646    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1647    }    }
1648    
1649  while (status != end)  do
1650    {    {
1651    count = 0;    count = 0;
1652    switch(status)    switch(status)
1653      {      {
1654      case start:      case start:
1655      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1656      count = 1;      count = 1;
1657      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1658        if (needs_control_head)
1659          {
1660          SLJIT_ASSERT(common->control_head_ptr != 0);
1661          count = 2;
1662          srcw[1] = common->control_head_ptr;
1663          }
1664      status = loop;      status = loop;
1665      break;      break;
1666    
# Line 1440  while (status != end) Line 1673  while (status != end)
1673    
1674      switch(*cc)      switch(*cc)
1675        {        {
1676          case OP_KET:
1677          if (PRIVATE_DATA(cc) != 0)
1678            {
1679            count = 1;
1680            srcw[0] = PRIVATE_DATA(cc);
1681            }
1682          cc += 1 + LINK_SIZE;
1683          break;
1684    
1685        case OP_ASSERT:        case OP_ASSERT:
1686        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1687        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1504  while (status != end) Line 1746  while (status != end)
1746          {          {
1747          count = 2;          count = 2;
1748          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1749          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1750          }          }
1751        cc += 2;        cc += 2;
1752  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1517  while (status != end) Line 1759  while (status != end)
1759          {          {
1760          count = 2;          count = 2;
1761          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1762          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1763          }          }
1764        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1765  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1539  while (status != end) Line 1781  while (status != end)
1781          {          {
1782          count = 2;          count = 2;
1783          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1784          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1785          }          }
1786        cc += 1;        cc += 1;
1787        break;        break;
# Line 1549  while (status != end) Line 1791  while (status != end)
1791          {          {
1792          count = 2;          count = 2;
1793          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1794          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1795          }          }
1796        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1797        break;        break;
# Line 1573  while (status != end) Line 1815  while (status != end)
1815            case 2:            case 2:
1816            count = 2;            count = 2;
1817            srcw[0] = PRIVATE_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1818            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1819            break;            break;
1820    
1821            default:            default:
# Line 1605  while (status != end) Line 1847  while (status != end)
1847          if (!tmp1empty)          if (!tmp1empty)
1848            {            {
1849            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1850            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1851            }            }
1852          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1853          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1616  while (status != end) Line 1858  while (status != end)
1858          if (!tmp2empty)          if (!tmp2empty)
1859            {            {
1860            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1861            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1862            }            }
1863          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1864          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1633  while (status != end) Line 1875  while (status != end)
1875          if (!tmp1empty)          if (!tmp1empty)
1876            {            {
1877            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1878            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1879            }            }
1880          tmp1next = FALSE;          tmp1next = FALSE;
1881          }          }
# Line 1645  while (status != end) Line 1887  while (status != end)
1887          if (!tmp2empty)          if (!tmp2empty)
1888            {            {
1889            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1890            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1891            }            }
1892          tmp1next = TRUE;          tmp1next = TRUE;
1893          }          }
1894        }        }
1895      }      }
1896    }    }
1897    while (status != end);
1898    
1899  if (save)  if (save)
1900    {    {
# Line 1660  if (save) Line 1903  if (save)
1903      if (!tmp1empty)      if (!tmp1empty)
1904        {        {
1905        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1906        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1907        }        }
1908      if (!tmp2empty)      if (!tmp2empty)
1909        {        {
1910        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1911        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1912        }        }
1913      }      }
1914    else    else
# Line 1673  if (save) Line 1916  if (save)
1916      if (!tmp2empty)      if (!tmp2empty)
1917        {        {
1918        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1919        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1920        }        }
1921      if (!tmp1empty)      if (!tmp1empty)
1922        {        {
1923        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1924        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1925        }        }
1926      }      }
1927    }    }
1928  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1929  }  }
1930    
1931    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1932    {
1933    pcre_uchar *end = bracketend(cc);
1934    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1935    
1936    /* Assert captures then. */
1937    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1938      current_offset = NULL;
1939    /* Conditional block does not. */
1940    if (*cc == OP_COND || *cc == OP_SCOND)
1941      has_alternatives = FALSE;
1942    
1943    cc = next_opcode(common, cc);
1944    if (has_alternatives)
1945      current_offset = common->then_offsets + (cc - common->start);
1946    
1947    while (cc < end)
1948      {
1949      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1950        cc = set_then_offsets(common, cc, current_offset);
1951      else
1952        {
1953        if (*cc == OP_ALT && has_alternatives)
1954          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1955        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1956          *current_offset = 1;
1957        cc = next_opcode(common, cc);
1958        }
1959      }
1960    
1961    return end;
1962    }
1963    
1964  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1965  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1966  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1692  SLJIT_ASSERT(cc == ccend && stackptr == Line 1968  SLJIT_ASSERT(cc == ccend && stackptr ==
1968  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1969  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1970    
1971  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1972  {  {
1973  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1974  }  }
# Line 1703  while (list) Line 1979  while (list)
1979    {    {
1980    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1981    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1982    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1983    list = list->next;    list = list->next;
1984    }    }
1985  }  }
# Line 1719  if (list_item) Line 1995  if (list_item)
1995    }    }
1996  }  }
1997    
1998  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)
1999  {  {
2000  DEFINE_COMPILER;  DEFINE_COMPILER;
2001  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
2002    
2003  if (list_item)  if (list_item)
2004    {    {
   list_item->type = type;  
   list_item->data = data;  
2005    list_item->start = start;    list_item->start = start;
2006    list_item->quit = LABEL();    list_item->quit = LABEL();
2007    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1743  stub_list* list_item = common->stubs; Line 2017  stub_list* list_item = common->stubs;
2017  while (list_item)  while (list_item)
2018    {    {
2019    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2020    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;  
     }  
2021    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2022    list_item = list_item->next;    list_item = list_item->next;
2023    }    }
2024  common->stubs = NULL;  common->stubs = NULL;
2025  }  }
2026    
2027  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2028  {  {
2029  DEFINE_COMPILER;  DEFINE_COMPILER;
2030    
2031  OP2(SLJIT_SUB | SLJIT_SET_E, CALL_COUNT, 0, CALL_COUNT, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1);
2032  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2033  }  }
2034    
# Line 1768  static SLJIT_INLINE void allocate_stack( Line 2037  static SLJIT_INLINE void allocate_stack(
2037  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2038  DEFINE_COMPILER;  DEFINE_COMPILER;
2039    
2040  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));
2041  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2042  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2043  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 2045  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2045  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2046  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2047  #endif  #endif
2048  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));
2049  }  }
2050    
2051  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2052  {  {
2053  DEFINE_COMPILER;  DEFINE_COMPILER;
2054  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));
2055  }  }
2056    
2057  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 2059  static SLJIT_INLINE void reset_ovector(c
2059  DEFINE_COMPILER;  DEFINE_COMPILER;
2060  struct sljit_label *loop;  struct sljit_label *loop;
2061  int i;  int i;
2062    
2063  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2064    SLJIT_ASSERT(length > 1);
2065  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2066  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));
2067    if (length < 8)
2068      {
2069      for (i = 1; i < length; i++)
2070        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2071      }
2072    else
2073      {
2074      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2075      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2076      loop = LABEL();
2077      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2078      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2079      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2080      }
2081    }
2082    
2083    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2084    {
2085    DEFINE_COMPILER;
2086    struct sljit_label *loop;
2087    int i;
2088    
2089    SLJIT_ASSERT(length > 1);
2090    /* OVECTOR(1) contains the "string begin - 1" constant. */
2091    if (length > 2)
2092      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2093  if (length < 8)  if (length < 8)
2094    {    {
2095    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2096      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_TEMPORARY_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
2097    }    }
2098  else  else
2099    {    {
2100    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2101    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2102    loop = LABEL();    loop = LABEL();
2103    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2104    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2105    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2106    }    }
2107    
2108    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2109    if (common->mark_ptr != 0)
2110      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2111    if (common->control_head_ptr != 0)
2112      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2113    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2114    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2115    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2116    }
2117    
2118    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2119    {
2120    while (current != NULL)
2121      {
2122      switch (current[-2])
2123        {
2124        case type_then_trap:
2125        break;
2126    
2127        case type_mark:
2128        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2129          return current[-4];
2130        break;
2131    
2132        default:
2133        SLJIT_ASSERT_STOP();
2134        break;
2135        }
2136      current = (sljit_sw*)current[-1];
2137      }
2138    return -1;
2139  }  }
2140    
2141  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2142  {  {
2143  DEFINE_COMPILER;  DEFINE_COMPILER;
2144  struct sljit_label *loop;  struct sljit_label *loop;
2145  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2146    
2147  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2148  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));
2149  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);
2150    
2151  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2152  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2153    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);
2154  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));
2155  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2156    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);
2157  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));
2158  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));
2159  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2160  /* Unlikely, but possible */  /* Unlikely, but possible */
2161  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);
2162  loop = LABEL();  loop = LABEL();
2163  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);
2164  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));
2165  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2166  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2167  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);
2168  #endif  #endif
2169  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);
2170  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);
2171  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2172  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2173    
2174  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2175  if (topbracket > 1)  if (topbracket > 1)
2176    {    {
2177    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));
2178    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2179    
2180    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2181    loop = LABEL();    loop = LABEL();
2182    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)));
2183    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);
2184    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);
2185    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2186    }    }
2187  else  else
2188    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1862  else Line 2191  else
2191  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)
2192  {  {
2193  DEFINE_COMPILER;  DEFINE_COMPILER;
2194    struct sljit_jump *jump;
2195    
2196  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);
2197  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
2198      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2199    
2200  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2201  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2202  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));
2203  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);
2204    
2205  /* Store match begin and end. */  /* Store match begin and end. */
2206  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));
2207  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));
2208  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);  
2209    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2210    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);
2211    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2212    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2213    #endif
2214    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2215    JUMPHERE(jump);
2216    
2217    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);
2218  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);
2219  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2220  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);
2221  #endif  #endif
2222  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);
2223    
2224  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);
2225  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2226  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);
2227  #endif  #endif
2228  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);
2229    
2230  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2231  }  }
# Line 1998  if (c <= 127 && bit == 0x20) Line 2338  if (c <= 127 && bit == 0x20)
2338    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2339    
2340  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2341  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2342    return 0;    return 0;
2343    
2344  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2345    
2346  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2347  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 2017  if (common->utf && c > 127) Line 2357  if (common->utf && c > 127)
2357  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2358  return (0 << 8) | bit;  return (0 << 8) | bit;
2359    
2360  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2361    
 #ifdef COMPILE_PCRE16  
2362  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2363  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2364    {    {
# Line 2030  if (common->utf && c > 65535) Line 2369  if (common->utf && c > 65535)
2369    }    }
2370  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2371  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2372    
2373  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2374  }  }
2375    
2376  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2377  {  {
2378  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2379  DEFINE_COMPILER;  DEFINE_COMPILER;
2380  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2381    
# Line 2052  else if (common->mode == JIT_PARTIAL_SOF Line 2390  else if (common->mode == JIT_PARTIAL_SOF
2390    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);
2391    
2392  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2393    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);
2394  else  else
2395    {    {
2396    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2065  if (jump != NULL) Line 2403  if (jump != NULL)
2403    JUMPHERE(jump);    JUMPHERE(jump);
2404  }  }
2405    
2406  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2407  {  {
2408  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2409  DEFINE_COMPILER;  DEFINE_COMPILER;
2410  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2411    
2412  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2413    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2414      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2415      return;
2416      }
2417    
2418  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2419  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2420    {    {
2421    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));
2422    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);
2423    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2424    }    }
2425  else  else
2426    {    {
2427    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));
2428    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2429      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2430    else    else
2431      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2432    }    }
2433  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2434  }  }
2435    
2436  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 2449  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2449  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));
2450  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2451    {    {
2452    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);
2453    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2454    }    }
2455  else  else
# Line 2130  static void read_char(compiler_common *c Line 2467  static void read_char(compiler_common *c
2467  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2468  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2469  DEFINE_COMPILER;  DEFINE_COMPILER;
2470  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2471  struct sljit_jump *jump;  struct sljit_jump *jump;
2472  #endif  #endif
2473    
2474  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2475  #ifdef SUPPORT_UTF  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2476    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2477  if (common->utf)  if (common->utf)
2478    {    {
2479  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2480    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2481  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2482    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2483  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2484    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2485    JUMPHERE(jump);    JUMPHERE(jump);
2486    }    }
2487  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
2488  }  }
2489    
2490  static void peek_char(compiler_common *common)  static void peek_char(compiler_common *common)
# Line 2157  static void peek_char(compiler_common *c Line 2492  static void peek_char(compiler_common *c
2492  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2493  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2494  DEFINE_COMPILER;  DEFINE_COMPILER;
2495  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2496  struct sljit_jump *jump;  struct sljit_jump *jump;
2497  #endif  #endif
2498    
2499  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2500  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2501  if (common->utf)  if (common->utf)
2502    {    {
2503  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2504    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2505  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2506    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2507  #endif  #endif /* COMPILE_PCRE[8|16] */
2508  #endif /* COMPILE_PCRE8 */    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2509    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2510    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2511    JUMPHERE(jump);    JUMPHERE(jump);
2512    }    }
2513    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2514    }
2515    
2516    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2517    
2518    static BOOL is_char7_bitset(const pcre_uint8* bitset, BOOL nclass)
2519    {
2520    const pcre_uint8 value = nclass ? 0xff : 0;
2521    const pcre_uint8* end = bitset + 32;
2522    
2523    bitset += 16;
2524    do
2525      {
2526      if (*bitset++ != value)
2527        return FALSE;
2528      }
2529    while (bitset < end);
2530    return TRUE;
2531    }
2532    
2533    static void read_char7_type(compiler_common *common, BOOL full_read)
2534    {
2535    /* Reads the precise character type of a character into TMP1, if the character is
2536    less than 128. Otherwise it returns with zero. */
2537    DEFINE_COMPILER;
2538    struct sljit_jump *jump;
2539    
2540    SLJIT_ASSERT(common->utf);
2541    
2542    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2543    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2544    
2545    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2546    
2547    if (full_read)
2548      {
2549      jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2550      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2551      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2552      JUMPHERE(jump);
2553      }
2554    }
2555    
2556    #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2557    
2558    static void read_char_max(compiler_common *common, pcre_uint32 max, BOOL full_read)
2559    {
2560    /* Reads the precise value of a character into TMP1, if the character is
2561    less than or equal to max. Otherwise it returns with a value greater than max. */
2562    DEFINE_COMPILER;
2563    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2564    struct sljit_jump *jump;
2565    #endif
2566    
2567    SLJIT_UNUSED_ARG(full_read);
2568    SLJIT_UNUSED_ARG(max);
2569    
2570    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2571    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2572    
2573    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2574    if (common->utf)
2575      {
2576      if (max < 128 && !full_read)
2577        return;
2578    
2579      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2580      if (max < 128)
2581        {
2582        OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2583        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2584        }
2585      else if (max < 0x400)
2586        {
2587        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2588        if (!full_read)
2589          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2590        else
2591          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2592        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2593        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2594        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2595        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2596        if (full_read)
2597          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2598        }
2599      else
2600        add_jump(compiler, (max < 0x800) ? &common->utfreadchar11 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2601      JUMPHERE(jump);
2602      }
2603    #endif
2604    
2605    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2606    if (common->utf)
2607      {
2608      if (max < 0xd800 && !full_read)
2609        return;
2610    
2611      if (max >= 0x10000)
2612        {
2613        jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2614        add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2615        JUMPHERE(jump);
2616        return;
2617        }
2618    
2619      /* Skip low surrogate if necessary. */
2620      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2621      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2622      if (full_read)
2623        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2624      if (max >= 0xd800)
2625        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
2626      JUMPHERE(jump);
2627      }
2628  #endif  #endif
2629  }  }
2630    
2631  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common, BOOL full_read)
2632  {  {
2633  /* 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. */
2634  DEFINE_COMPILER;  DEFINE_COMPILER;
2635  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2636  struct sljit_jump *jump;  struct sljit_jump *jump;
2637  #endif  #endif
2638    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2639    struct sljit_jump *jump2;
2640    #endif
2641    
2642  #ifdef SUPPORT_UTF  SLJIT_UNUSED_ARG(full_read);
2643    
2644    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2645    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2646    
2647    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2648  if (common->utf)  if (common->utf)
2649    {    {
   OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 #ifdef COMPILE_PCRE8  
2650    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2651    it is needed in most cases. */    it is needed in most cases. */
2652    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2653    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2654    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    if (!full_read)
2655    JUMPHERE(jump);      {
2656  #else      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2657  #ifdef COMPILE_PCRE16      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2658    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2659    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2660    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2661        OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
2662        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2663        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2664        OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2665        JUMPHERE(jump2);
2666        }
2667      else
2668        add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2669    JUMPHERE(jump);    JUMPHERE(jump);
   /* Skip low surrogate if necessary. */  
   OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);  
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);  
   COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  
   OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  
 #endif  
 #endif /* COMPILE_PCRE8 */  
2670    return;    return;
2671    }    }
2672  #endif  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2673  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
2674  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  #if !defined COMPILE_PCRE8
 #ifdef COMPILE_PCRE16  
2675  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2676  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2677  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2678  #endif  #endif
2679  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2680  #ifdef COMPILE_PCRE16  #if !defined COMPILE_PCRE8
2681  JUMPHERE(jump);  JUMPHERE(jump);
2682  #endif  #endif
2683    
2684    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2685    if (common->utf && full_read)
2686      {
2687      /* Skip low surrogate if necessary. */
2688      OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2689      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2690      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2691      JUMPHERE(jump);
2692      }
2693    #endif /* SUPPORT_UTF && COMPILE_PCRE16 */
2694  }  }
2695    
2696  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
2697  {  {
2698  /* 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. */
2699  DEFINE_COMPILER;  DEFINE_COMPILER;
2700  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2701    #if defined COMPILE_PCRE8
2702  struct sljit_label *label;  struct sljit_label *label;
2703    
2704  if (common->utf)  if (common->utf)
# Line 2245  if (common->utf) Line 2710  if (common->utf)
2710    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2711    return;    return;
2712    }    }
2713  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2714  if (common->utf)  if (common->utf)
2715    {    {
2716    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 2718  if (common->utf)
2718    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2719    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2720    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);
2721    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2722    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2723    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2724    return;    return;
2725    }    }
2726  #endif  #endif /* COMPILE_PCRE[8|16] */
2727    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2728  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));
2729  }  }
2730    
# Line 2276  if (nltype == NLTYPE_ANY) Line 2741  if (nltype == NLTYPE_ANY)
2741  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2742    {    {
2743    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);
2744    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2745    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);
2746    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);
2747    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));
2748    }    }
2749  else  else
# Line 2290  else Line 2755  else
2755    
2756  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2757    
2758  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2759  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2760  {  {
2761  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
# Line 2303  sljit_emit_fast_enter(compiler, RETURN_A Line 2768  sljit_emit_fast_enter(compiler, RETURN_A
2768  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
2769  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2770  /* Two byte sequence. */  /* Two byte sequence. */
2771  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2772  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));
2773  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);
2774  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2775  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2776  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2777  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2778  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2779  JUMPHERE(jump);  JUMPHERE(jump);
2780    
2781  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);
2782  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2783  /* Three byte sequence. */  /* Three byte sequence. */
2784  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2785  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);
2786  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);
2787  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2788  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2789  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2790  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2791  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2792  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2793  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2794  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
2795  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2796  JUMPHERE(jump);  JUMPHERE(jump);
2797    
2798  /* Four byte sequence. */  /* Four byte sequence. */
2799  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2800  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);
2801  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);
2802  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2803  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);
2804  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2805  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2806  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2807  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2808  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2809  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2810  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2811  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2812  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2813  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(4));
2814    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2815    }
2816    
2817    static void do_utfreadchar11(compiler_common *common)
2818    {
2819    /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2820    of the character (>= 0xc0). Return value in TMP1. */
2821    DEFINE_COMPILER;
2822    struct sljit_jump *jump;
2823    
2824    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2825    
2826    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
2827    jump = JUMP(SLJIT_C_NOT_ZERO);
2828    /* Two byte sequence. */
2829    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2830    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2831    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);
2832    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2833    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2834    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2835    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2836    
2837    JUMPHERE(jump);
2838    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2839    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x800);
2840    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2841  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2842  }  }
2843    
# Line 2365  jump = JUMP(SLJIT_C_NOT_ZERO); Line 2857  jump = JUMP(SLJIT_C_NOT_ZERO);
2857  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2858  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));
2859  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2860    /* The upper 5 bits are known at this point. */
2861    compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x3);
2862  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2863  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2864  OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);  OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
 compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  
2865  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2866  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2867    
2868  JUMPHERE(compare);  JUMPHERE(compare);
2869  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2870  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2871    
2872  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2873  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0);  JUMPHERE(jump);
2874  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2875  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2876    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2877  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2878  }  }
2879    
2880  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2881    
 #ifdef COMPILE_PCRE16  
2882  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2883  {  {
2884  /* 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 2401  sljit_emit_fast_return(compiler, RETURN_ Line 2893  sljit_emit_fast_return(compiler, RETURN_
2893    
2894  JUMPHERE(jump);  JUMPHERE(jump);
2895  /* Combine two 16 bit characters. */  /* Combine two 16 bit characters. */
2896  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2897  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));
2898  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2899  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);
2900  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff);
2901  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2902  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2903  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2904  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2905  }  }
 #endif /* COMPILE_PCRE16 */  
2906    
2907  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2908    
2909  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2910    
# Line 2433  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2924  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2924    
2925  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2926  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2927  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));
2928  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2929  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2930  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2931  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2932  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2933  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));
2934  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2935  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2936  }  }
# Line 2453  struct sljit_label *newlinelabel = NULL; Line 2944  struct sljit_label *newlinelabel = NULL;
2944  struct sljit_jump *start;  struct sljit_jump *start;
2945  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2946  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2947  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2948  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2949  #endif  #endif
2950  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2508  if (newlinecheck) Line 2999  if (newlinecheck)
2999    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3000    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3001    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);
3002    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3003  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3004    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3005  #endif  #endif
3006    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3007    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2531  if (newlinecheck) Line 3022  if (newlinecheck)
3022    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);
3023    
3024  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));
3025  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3026    #if defined COMPILE_PCRE8
3027  if (common->utf)  if (common->utf)
3028    {    {
3029    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
3030    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);
3031    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3032    JUMPHERE(singlechar);    JUMPHERE(singlechar);
3033    }    }
3034  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3035  if (common->utf)  if (common->utf)
3036    {    {
3037    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
3038    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3039    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);
3040    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3041    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3042    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3043    JUMPHERE(singlechar);    JUMPHERE(singlechar);
3044    }    }
3045  #endif  #endif /* COMPILE_PCRE[8|16] */
3046    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
3047  JUMPHERE(start);  JUMPHERE(start);
3048    
3049  if (newlinecheck)  if (newlinecheck)
# Line 2563  if (newlinecheck) Line 3055  if (newlinecheck)
3055  return mainloop;  return mainloop;
3056  }  }
3057    
3058  static SLJIT_INLINE BOOL fast_forward_first_two_chars(compiler_common *common, BOOL firstline)  static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, int max_chars)
3059  {  {
3060  DEFINE_COMPILER;  /* Recursive function, which scans prefix literals. */
3061  struct sljit_label *start;  int len, repeat, len_save, consumed = 0;
3062  struct sljit_jump *quit;  pcre_uint32 caseless, chr, mask;
3063  struct sljit_jump *found;  pcre_uchar *alternative, *cc_save;
3064  pcre_int32 chars[4];  BOOL last, any;
 pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  
 int location = 0;  
 pcre_int32 len, c, bit, caseless;  
 BOOL must_end;  
   
 #ifdef COMPILE_PCRE8  
 union {  
     sljit_uh ascombined;  
     sljit_ub asuchars[2];  
 } pair;  
 #else  
 union {  
     sljit_ui ascombined;  
     sljit_uh asuchars[2];  
 } pair;  
 #endif  
   
 if (*(common->start + GET(common->start, 1)) == OP_ALT)  
   return FALSE;  
3065    
3066    repeat = 1;
3067  while (TRUE)  while (TRUE)
3068    {    {
3069      last = TRUE;
3070      any = FALSE;
3071    caseless = 0;    caseless = 0;
3072    must_end = TRUE;    switch (*cc)
   switch(*cc)  
3073      {      {
     case OP_CHAR:  
     must_end = FALSE;  
     cc++;  
     break;  
   
3074      case OP_CHARI:      case OP_CHARI:
3075      caseless = 1;      caseless = 1;
3076      must_end = FALSE;      case OP_CHAR:
3077        last = FALSE;
3078      cc++;      cc++;
3079      break;      break;
3080    
# Line 2622  while (TRUE) Line 3093  while (TRUE)
3093      cc++;      cc++;
3094      continue;      continue;
3095    
3096      case OP_PLUS:      case OP_PLUS:
3097      case OP_MINPLUS:      case OP_MINPLUS:
3098      case OP_POSPLUS:      case OP_POSPLUS:
3099      cc++;      cc++;
3100        break;
3101    
3102        case OP_EXACTI:
3103        caseless = 1;
3104        case OP_EXACT:
3105        repeat = GET2(cc, 1);
3106        last = FALSE;
3107        cc += 1 + IMM2_SIZE;
3108        break;
3109    
3110        case OP_PLUSI:
3111        case OP_MINPLUSI:
3112        case OP_POSPLUSI:
3113        caseless = 1;
3114        cc++;
3115        break;
3116    
3117        case OP_KET:
3118        cc += 1 + LINK_SIZE;
3119        continue;
3120    
3121        case OP_ALT:
3122        cc += GET(cc, 1);
3123        continue;
3124    
3125        case OP_ONCE:
3126        case OP_ONCE_NC:
3127        case OP_BRA:
3128        case OP_BRAPOS:
3129        case OP_CBRA:
3130        case OP_CBRAPOS:
3131        alternative = cc + GET(cc, 1);
3132        while (*alternative == OP_ALT)
3133          {
3134          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, max_chars);
3135          if (max_chars == 0)
3136            return consumed;
3137          alternative += GET(alternative, 1);
3138          }
3139    
3140        if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
3141          cc += IMM2_SIZE;
3142        cc += 1 + LINK_SIZE;
3143        continue;
3144    
3145        case OP_CLASS:
3146        case OP_NCLASS:
3147        any = TRUE;
3148        cc += 1 + 32 / sizeof(pcre_uchar);
3149      break;      break;
3150    
3151      case OP_EXACT:  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3152      cc += 1 + IMM2_SIZE;      case OP_XCLASS:
3153        any = TRUE;
3154        cc += GET(cc, 1);
3155      break;      break;
3156    #endif
3157    
3158      case OP_PLUSI:      case OP_NOT_DIGIT:
3159      case OP_MINPLUSI:      case OP_DIGIT:
3160      case OP_POSPLUSI:      case OP_NOT_WHITESPACE:
3161      caseless = 1;      case OP_WHITESPACE:
3162        case OP_NOT_WORDCHAR:
3163        case OP_WORDCHAR:
3164        case OP_ANY:
3165        case OP_ALLANY:
3166        any = TRUE;
3167      cc++;      cc++;
3168      break;      break;
3169    
3170      case OP_EXACTI:  #ifdef SUPPORT_UCP
3171      caseless = 1;      case OP_NOTPROP:
3172      cc += 1 + IMM2_SIZE;      case OP_PROP:
3173        any = TRUE;
3174        cc += 1 + 2;
3175      break;      break;
3176    #endif
3177    
3178        case OP_TYPEEXACT:
3179        repeat = GET2(cc, 1);
3180        cc += 1 + IMM2_SIZE;
3181        continue;
3182    
3183      default:      default:
3184      return FALSE;      return consumed;
3185        }
3186    
3187      if (any)
3188        {
3189    #ifdef SUPPORT_UTF
3190        if (common->utf) return consumed;
3191    #endif
3192    #if defined COMPILE_PCRE8
3193        mask = 0xff;
3194    #elif defined COMPILE_PCRE16
3195        mask = 0xffff;
3196    #elif defined COMPILE_PCRE32
3197        mask = 0xffffffff;
3198    #else
3199        SLJIT_ASSERT_STOP();
3200    #endif
3201    
3202        do
3203          {
3204          chars[0] = mask;
3205          chars[1] = mask;
3206    
3207          if (--max_chars == 0)
3208            return consumed;
3209          consumed++;
3210          chars += 2;
3211          }
3212        while (--repeat > 0);
3213    
3214        repeat = 1;
3215        continue;
3216      }      }
3217    
3218    len = 1;    len = 1;
3219  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3220    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3221  #endif  #endif
3222    
3223    if (caseless && char_has_othercase(common, cc))    if (caseless != 0 && char_has_othercase(common, cc))
3224      {      {
3225      caseless = char_get_othercase_bit(common, cc);      caseless = char_get_othercase_bit(common, cc);
3226      if (caseless == 0)      if (caseless == 0)
3227        return FALSE;        return consumed;
3228  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3229      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
3230  #else  #else
# Line 2670  while (TRUE) Line 3237  while (TRUE)
3237    else    else
3238      caseless = 0;      caseless = 0;
3239    
3240    while (len > 0 && location < 2 * 2)    len_save = len;
3241      {    cc_save = cc;
3242      c = *cc;    while (TRUE)
3243      bit = 0;      {
3244      if (len == (caseless & 0xff))      do
3245        {        {
3246        bit = caseless >> 8;        chr = *cc;
3247        c |= bit;  #ifdef COMPILE_PCRE32
3248          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3249            return consumed;
3250    #endif
3251          mask = 0;
3252          if (len == (caseless & 0xff))
3253            {
3254            mask = caseless >> 8;
3255            chr |= mask;
3256            }
3257    
3258          if (chars[0] == NOTACHAR)
3259            {
3260            chars[0] = chr;
3261            chars[1] = mask;
3262            }
3263          else
3264            {
3265            mask |= chars[0] ^ chr;
3266            chr |= mask;
3267            chars[0] = chr;
3268            chars[1] |= mask;
3269            }
3270    
3271          len--;
3272          if (--max_chars == 0)
3273            return consumed;
3274          consumed++;
3275          chars += 2;
3276          cc++;
3277        }        }
3278        while (len > 0);
3279    
3280        if (--repeat == 0)
3281          break;
3282    
3283      chars[location] = c;      len = len_save;
3284      chars[location + 1] = bit;      cc = cc_save;
3285        }
3286    
3287      len--;    repeat = 1;
3288      location += 2;    if (last)
3289      cc++;      return consumed;
3290      }
3291    }
3292    
3293    #define MAX_N_CHARS 16
3294    
3295    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3296    {
3297    DEFINE_COMPILER;
3298    struct sljit_label *start;
3299    struct sljit_jump *quit;
3300    pcre_uint32 chars[MAX_N_CHARS * 2];
3301    pcre_uint8 ones[MAX_N_CHARS];
3302    pcre_uint32 mask;
3303    int i, max;
3304    int offsets[3];
3305    
3306    for (i = 0; i < MAX_N_CHARS; i++)
3307      {
3308      chars[i << 1] = NOTACHAR;
3309      chars[(i << 1) + 1] = 0;
3310      }
3311    
3312    max = scan_prefix(common, common->start, chars, MAX_N_CHARS);
3313    
3314    if (max <= 1)
3315      return FALSE;
3316    
3317    for (i = 0; i < max; i++)
3318      {
3319      mask = chars[(i << 1) + 1];
3320      ones[i] = ones_in_half_byte[mask & 0xf];
3321      mask >>= 4;
3322      while (mask != 0)
3323        {
3324        ones[i] += ones_in_half_byte[mask & 0xf];
3325        mask >>= 4;
3326      }      }
3327      }
3328    
3329    if (location == 2 * 2)  offsets[0] = -1;
3330    /* Scan forward. */
3331    for (i = 0; i < max; i++)
3332      if (ones[i] <= 2) {
3333        offsets[0] = i;
3334      break;      break;
   else if (must_end)  
     return FALSE;  
3335    }    }
3336    
3337    if (offsets[0] == -1)
3338      return FALSE;
3339    
3340    /* Scan backward. */
3341    offsets[1] = -1;
3342    for (i = max - 1; i > offsets[0]; i--)
3343      if (ones[i] <= 2) {
3344        offsets[1] = i;
3345        break;
3346      }
3347    
3348    offsets[2] = -1;
3349    if (offsets[1] >= 0)
3350      {
3351      /* Scan from middle. */
3352      for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3353        if (ones[i] <= 2)
3354          {
3355          offsets[2] = i;
3356          break;
3357          }
3358    
3359      if (offsets[2] == -1)
3360        {
3361        for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3362          if (ones[i] <= 2)
3363            {
3364            offsets[2] = i;
3365            break;
3366            }
3367        }
3368      }
3369    
3370    SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3371    SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3372    
3373    chars[0] = chars[offsets[0] << 1];
3374    chars[1] = chars[(offsets[0] << 1) + 1];
3375    if (offsets[2] >= 0)
3376      {
3377      chars[2] = chars[offsets[2] << 1];
3378      chars[3] = chars[(offsets[2] << 1) + 1];
3379      }
3380    if (offsets[1] >= 0)
3381      {
3382      chars[4] = chars[offsets[1] << 1];
3383      chars[5] = chars[(offsets[1] << 1) + 1];
3384      }
3385    
3386    max -= 1;
3387  if (firstline)  if (firstline)
3388    {    {
3389    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3390    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3391    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(max));
3392    }    }
3393  else  else
3394    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(max));
3395    
3396  start = LABEL();  start = LABEL();
3397  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  
 #ifdef COMPILE_PCRE8  
 OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #else /* COMPILE_PCRE8 */  
 OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #endif  
   
 #else /* SLJIT_UNALIGNED */  
3398    
3399  #if defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3400  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  if (offsets[1] >= 0)
3401  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3402  #else /* SLJIT_BIG_ENDIAN */  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #endif /* SLJIT_BIG_ENDIAN */  
   
 #ifdef COMPILE_PCRE8  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 8);  
 #else /* COMPILE_PCRE8 */  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 16);  
 #endif  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
3403    
3404  #endif  if (chars[1] != 0)
3405      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3406    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3407    if (offsets[2] >= 0)
3408      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3409    
3410  if (chars[1] != 0 || chars[3] != 0)  if (offsets[1] >= 0)
3411    {    {
3412    pair.asuchars[0] = chars[1];    if (chars[5] != 0)
3413    pair.asuchars[1] = chars[3];      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3414    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, pair.ascombined);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3415    }    }
3416    
3417  pair.asuchars[0] = chars[0];  if (offsets[2] >= 0)
3418  pair.asuchars[1] = chars[2];    {
3419  found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, pair.ascombined);    if (chars[3] != 0)
3420        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3421      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3422      }
3423    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3424    
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 JUMPTO(SLJIT_JUMP, start);  
 JUMPHERE(found);  
3425  JUMPHERE(quit);  JUMPHERE(quit);
3426    
3427  if (firstline)  if (firstline)
3428    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3429  else  else
3430    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(max));
3431  return TRUE;  return TRUE;
3432  }  }
3433    
3434    #undef MAX_N_CHARS
3435    
3436  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)
3437  {  {
3438  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2787  if (first_char == oc) Line 3466  if (first_char == oc)
3466  else  else
3467    {    {
3468    bit = first_char ^ oc;    bit = first_char ^ oc;
3469    if (ispowerof2(bit))    if (is_powerof2(bit))
3470      {      {
3471      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3472      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 3474  else
3474    else    else
3475      {      {
3476      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);
3477      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3478      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);
3479      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);
3480      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3481      }      }
3482    }    }
# Line 2839  if (common->nltype == NLTYPE_FIXED && co Line 3518  if (common->nltype == NLTYPE_FIXED && co
3518    
3519    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3520    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);
3521    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3522  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3523    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3524  #endif  #endif
3525    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3526    
# Line 2882  if (common->nltype == NLTYPE_ANY || comm Line 3561  if (common->nltype == NLTYPE_ANY || comm
3561    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3562    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3563    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);
3564    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3565  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3566    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3567  #endif  #endif
3568    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3569    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
# Line 2897  if (firstline) Line 3576  if (firstline)
3576    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3577  }  }
3578    
3579  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks);
3580    
3581    static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, pcre_uint8 *start_bits, BOOL firstline)
3582  {  {
3583  DEFINE_COMPILER;  DEFINE_COMPILER;
3584  struct sljit_label *start;  struct sljit_label *start;
3585  struct sljit_jump *quit;  struct sljit_jump *quit;
3586  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3587    jump_list *matches = NULL;
3588  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3589  struct sljit_jump *jump;  struct sljit_jump *jump;
3590  #endif  #endif
# Line 2921  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3603  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3603  if (common->utf)  if (common->utf)
3604    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3605  #endif  #endif
3606    
3607    if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
3608      {
3609  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3610  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3611  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3612  JUMPHERE(jump);    JUMPHERE(jump);
3613  #endif  #endif
3614  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3615  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3616  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3617  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3618  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);
3619  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3620      }
3621    
3622  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3623  if (common->utf)  if (common->utf)
3624    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3625  #endif  #endif
3626  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));
3627  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3628    #if defined COMPILE_PCRE8
3629  if (common->utf)  if (common->utf)
3630    {    {
3631    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3632    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);
3633    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3634    }    }
3635  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3636  if (common->utf)  if (common->utf)
3637    {    {
3638    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3639    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3640    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);
3641    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3642    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3643    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3644    }    }
3645  #endif  #endif /* COMPILE_PCRE[8|16] */
3646    #endif /* SUPPORT_UTF */
3647  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3648  JUMPHERE(found);  if (found != NULL)
3649      JUMPHERE(found);
3650    if (matches != NULL)
3651      set_jumps(matches, LABEL());
3652  JUMPHERE(quit);  JUMPHERE(quit);
3653    
3654  if (firstline)  if (firstline)
# Line 2974  struct sljit_jump *alreadyfound; Line 3664  struct sljit_jump *alreadyfound;
3664  struct sljit_jump *found;  struct sljit_jump *found;
3665  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3666  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3667  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3668    
3669  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3670  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 3695  if (req_char == oc)
3695  else  else
3696    {    {
3697    bit = req_char ^ oc;    bit = req_char ^ oc;
3698    if (ispowerof2(bit))    if (is_powerof2(bit))
3699      {      {
3700      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3701      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 3731  GET_LOCAL_BASE(TMP3, 0, 0);
3731  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3732  mainloop = LABEL();  mainloop = LABEL();
3733  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3734  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);
3735    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3736    
3737  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3738  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));
3739  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));
3740  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));
3741  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3742    
3743  JUMPHERE(jump);  JUMPHERE(jump);
3744  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3745  /* End of dropping frames. */  /* End of dropping frames. */
3746  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3747    
3748  JUMPHERE(jump);  JUMPHERE(jump);
3749  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3750  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3751  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3752  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));  
3753  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3754  }  }
3755    
# Line 3082  static void check_wordboundary(compiler_ Line 3757  static void check_wordboundary(compiler_
3757  {  {
3758  DEFINE_COMPILER;  DEFINE_COMPILER;
3759  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3760    jump_list *skipread_list = NULL;
3761  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3762  struct sljit_jump *jump;  struct sljit_jump *jump;
3763  #endif  #endif
# Line 3107  if (common->use_ucp) Line 3783  if (common->use_ucp)
3783    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3784    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3785    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);
3786    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3787    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);
3788    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);
3789    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3790    JUMPHERE(jump);    JUMPHERE(jump);
3791    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3792    }    }
# Line 3134  else Line 3810  else
3810  #elif defined SUPPORT_UTF  #elif defined SUPPORT_UTF
3811    if (jump != NULL)    if (jump != NULL)
3812      JUMPHERE(jump);      JUMPHERE(jump);
3813  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
   }  
 JUMPHERE(skipread);  
   
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  
 skipread = check_str_end(common);  
 peek_char(common);  
   
 /* Testing char type. This is a code duplication. */  
 #ifdef SUPPORT_UCP  
 if (common->use_ucp)  
   {  
   OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);  
   jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);  
   add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));  
   OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);  
   OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);  
   COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  
   OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);  
   OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);  
   COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);  
   JUMPHERE(jump);  
   }  
 else  
 #endif  
   {  
 #ifndef COMPILE_PCRE8  
   /* TMP2 may be destroyed by peek_char. */  
   OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  
   jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
 #elif defined SUPPORT_UTF  
   OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  
   jump = NULL;  
   if (common->utf)  
     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
 #endif  
   OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);  
   OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);  
   OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);  
 #ifndef COMPILE_PCRE8  
   JUMPHERE(jump);  
 #elif defined SUPPORT_UTF  
   if (jump != NULL)  
     JUMPHERE(jump);  
 #endif /* COMPILE_PCRE8 */  
   }  
 JUMPHERE(skipread);  
   
 OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  
 sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
 }  
   
 /*  
   range format:  
   
   ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).  
   ranges[1] = first bit (0 or 1)  
   ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)  
 */  
   
 static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)  
 {  
 DEFINE_COMPILER;  
 struct sljit_jump *jump;  
   
 if (ranges[0] < 0)  
   return FALSE;  
   
 switch(ranges[0])  
   {  
   case 1:  
   if (readch)  
     read_char(common);  
   add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));  
   return TRUE;  
   
   case 2:  
   if (readch)  
     read_char(common);  
   OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);  
   add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));  
   return TRUE;  
   
   case 4:  
   if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])  
     {  
     if (readch)  
       read_char(common);  
     if (ranges[1] != 0)  
       {  
       add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));  
       add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));  
       }  
     else  
       {  
       jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);  
       add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));  
       JUMPHERE(jump);  
       }  
     return TRUE;  
     }  
   if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && ispowerof2(ranges[4] - ranges[2]))  
     {  
     if (readch)  
       read_char(common);  
     OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);  
     OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);  
     add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));  
     return TRUE;  
     }  
   return FALSE;  
   
   default:  
   return FALSE;  
3814    }    }
3815  }  JUMPHERE(skipread);
   
 static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)  
 {  
 int i, bit, length;  
 const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;  
   
 bit = ctypes[0] & flag;  
 ranges[0] = -1;  
 ranges[1] = bit != 0 ? 1 : 0;  
 length = 0;  
3816    
3817  for (i = 1; i < 256; i++)  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3818    if ((ctypes[i] & flag) != bit)  check_str_end(common, &skipread_list);
3819      {  peek_char(common);
     if (length >= MAX_RANGE_SIZE)  
       return;  
     ranges[2 + length] = i;  
     length++;  
     bit ^= flag;  
     }  
3820    
3821  if (bit != 0)  /* Testing char type. This is a code duplication. */
3822    #ifdef SUPPORT_UCP
3823    if (common->use_ucp)
3824    {    {
3825    if (length >= MAX_RANGE_SIZE)    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
3826      return;    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
3827    ranges[2 + length] = 256;    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3828    length++;    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3829      OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
3830      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3831      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);
3832      OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
3833      OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3834      JUMPHERE(jump);
3835      }
3836    else
3837    #endif
3838      {
3839    #ifndef COMPILE_PCRE8
3840      /* TMP2 may be destroyed by peek_char. */
3841      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3842      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3843    #elif defined SUPPORT_UTF
3844      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3845      jump = NULL;
3846      if (common->utf)
3847        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3848    #endif
3849      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);
3850      OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);
3851      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
3852    #ifndef COMPILE_PCRE8
3853      JUMPHERE(jump);
3854    #elif defined SUPPORT_UTF
3855      if (jump != NULL)
3856        JUMPHERE(jump);
3857    #endif /* COMPILE_PCRE8 */
3858    }    }
3859  ranges[0] = length;  set_jumps(skipread_list, LABEL());
3860    
3861    OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3862    sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3863  }  }
3864    
3865  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks)
3866  {  {
3867  int ranges[2 + MAX_RANGE_SIZE];  DEFINE_COMPILER;
3868    int ranges[MAX_RANGE_SIZE];
3869  pcre_uint8 bit, cbit, all;  pcre_uint8 bit, cbit, all;
3870  int i, byte, length = 0;  int i, byte, length = 0;
3871    
3872  bit = bits[0] & 0x1;  bit = bits[0] & 0x1;
3873  ranges[1] = bit;  /* All bits will be zero or one (since bit is zero or one). */
 /* Can be 0 or 255. */  
3874  all = -bit;  all = -bit;
3875    
3876  for (i = 0; i < 256; )  for (i = 0; i < 256; )
# Line 3304  for (i = 0; i < 256; ) Line 3885  for (i = 0; i < 256; )
3885        {        {
3886        if (length >= MAX_RANGE_SIZE)        if (length >= MAX_RANGE_SIZE)
3887          return FALSE;          return FALSE;
3888        ranges[2 + length] = i;        ranges[length] = i;
3889        length++;        length++;
3890        bit = cbit;        bit = cbit;
3891        all = -cbit;        all = -cbit;
# Line 3317  if (((bit == 0) && nclass) || ((bit == 1 Line 3898  if (((bit == 0) && nclass) || ((bit == 1
3898    {    {
3899    if (length >= MAX_RANGE_SIZE)    if (length >= MAX_RANGE_SIZE)
3900      return FALSE;      return FALSE;
3901    ranges[2 + length] = 256;    ranges[length] = 256;
3902    length++;    length++;
3903    }    }
 ranges[0] = length;  
3904    
3905  return check_ranges(common, ranges, backtracks, FALSE);  if (length < 0 || length > 4)
3906      return FALSE;
3907    
3908    bit = bits[0] & 0x1;
3909    if (invert) bit ^= 0x1;
3910    
3911    /* No character is accepted. */
3912    if (length == 0 && bit == 0)
3913      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
3914    
3915    switch(length)
3916      {
3917      case 0:
3918      /* When bit != 0, all characters are accepted. */
3919      return TRUE;
3920    
3921      case 1:
3922      add_jump(compiler, backtracks, CMP(bit == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3923      return TRUE;
3924    
3925      case 2:
3926      if (ranges[0] + 1 != ranges[1])
3927        {
3928        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3929        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3930        }
3931      else
3932        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3933      return TRUE;
3934    
3935      case 3:
3936      if (bit != 0)
3937        {
3938        add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3939        if (ranges[0] + 1 != ranges[1])
3940          {
3941          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3942          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3943          }
3944        else
3945          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3946        return TRUE;
3947        }
3948    
3949      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[0]));
3950      if (ranges[1] + 1 != ranges[2])
3951        {
3952        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1]);
3953        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
3954        }
3955      else
3956        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1]));
3957      return TRUE;
3958    
3959      case 4:
3960      if ((ranges[1] - ranges[0]) == (ranges[3] - ranges[2])
3961          && (ranges[0] | (ranges[2] - ranges[0])) == ranges[2]
3962          && is_powerof2(ranges[2] - ranges[0]))
3963        {
3964        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[0]);
3965        if (ranges[2] + 1 != ranges[3])
3966          {
3967          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3968          add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3969          }
3970        else
3971          add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3972        return TRUE;
3973        }
3974    
3975      if (bit != 0)
3976        {
3977        i = 0;
3978        if (ranges[0] + 1 != ranges[1])
3979          {
3980          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3981          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3982          i = ranges[0];
3983          }
3984        else
3985          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3986    
3987        if (ranges[2] + 1 != ranges[3])
3988          {
3989          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - i);
3990          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3991          }
3992        else
3993          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2] - i));
3994        return TRUE;
3995        }
3996    
3997      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3998      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[0]));
3999      if (ranges[1] + 1 != ranges[2])
4000        {
4001        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]);
4002        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
4003        }
4004      else
4005        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4006      return TRUE;
4007    
4008      default:
4009      SLJIT_ASSERT_STOP();
4010      return FALSE;
4011      }
4012  }  }
4013    
4014  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
# Line 3334  sljit_emit_fast_enter(compiler, RETURN_A Line 4020  sljit_emit_fast_enter(compiler, RETURN_A
4020    
4021  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
4022  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);
4023  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4024  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);
4025  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4026  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4027  if (common->utf)  if (common->utf)
4028    {    {
4029  #endif  #endif
4030    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4031    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
4032    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);
4033  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4034    }    }
4035  #endif  #endif
4036  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
4037  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);
4038  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
4039  }  }
4040    
# Line 3360  DEFINE_COMPILER; Line 4046  DEFINE_COMPILER;
4046  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
4047    
4048  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);
4049  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4050  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);
4051  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4052  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);
4053  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4054  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4055  if (common->utf)  if (common->utf)
4056    {    {
4057  #endif  #endif
4058    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4059    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);
4060    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4061    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);
4062    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4063    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
4064    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);
4065    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4066    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);
4067    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4068    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);
4069    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4070    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);
4071  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4072    }    }
4073  #endif  #endif
4074  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
4075  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);
4076    
4077  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
4078  }  }
# Line 3400  sljit_emit_fast_enter(compiler, RETURN_A Line 4086  sljit_emit_fast_enter(compiler, RETURN_A
4086    
4087  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
4088  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);
4089  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4090  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);
4091  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4092  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4093  if (common->utf)  if (common->utf)
4094    {    {
4095  #endif  #endif
4096    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);
4097    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
4098    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);
4099  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4100    }    }
4101  #endif  #endif
4102  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
4103  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);
4104    
4105  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
4106  }  }
# Line 3500  sljit_emit_fast_return(compiler, RETURN_ Line 4186  sljit_emit_fast_return(compiler, RETURN_
4186    
4187  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
4188    
4189  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)
4190  {  {
4191  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
4192  int c1, c2;  pcre_uint32 c1, c2;
4193  const pcre_uchar *src2 = args->uchar_ptr;  const pcre_uchar *src2 = args->uchar_ptr;
4194  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
4195    const ucd_record *ur;
4196    const pcre_uint32 *pp;
4197    
4198  while (src1 < end1)  while (src1 < end1)
4199    {    {
# Line 3513  while (src1 < end1) Line 4201  while (src1 < end1)
4201      return (pcre_uchar*)1;      return (pcre_uchar*)1;
4202    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
4203    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
4204    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return NULL;    ur = GET_UCD(c2);
4205      if (c1 != c2 && c1 != c2 + ur->other_case)
4206        {
4207        pp = PRIV(ucd_caseless_sets) + ur->caseset;
4208        for (;;)
4209          {
4210          if (c1 < *pp) return NULL;
4211          if (c1 == *pp++) break;
4212          }
4213        }
4214    }    }
4215  return src2;  return src2;
4216  }  }
# Line 3535  if (caseless && char_has_othercase(commo Line 4232  if (caseless && char_has_othercase(commo
4232    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
4233    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
4234    /* Extracting bit difference info. */    /* Extracting bit difference info. */
4235  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
4236    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
4237    othercasebit &= 0xff;    othercasebit &= 0xff;
4238  #else  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4239  #ifdef COMPILE_PCRE16    /* Note that this code only handles characters in the BMP. If there
4240      ever are characters outside the BMP whose othercase differs in only one
4241      bit from itself (there currently are none), this code will need to be
4242      revised for COMPILE_PCRE32. */
4243    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
4244    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
4245      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
4246    else    else
4247      othercasebit &= 0xff;      othercasebit &= 0xff;
4248  #endif  #endif /* COMPILE_PCRE[8|16|32] */
 #endif  
4249    }    }
4250    
4251  if (context->sourcereg == -1)  if (context->sourcereg == -1)
4252    {    {
4253  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
4254  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
4255    if (context->length >= 4)    if (context->length >= 4)
4256      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 4259  if (context->sourcereg == -1)
4259    else    else
4260  #endif  #endif
4261      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
4262  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
4263  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
4264    if (context->length >= 4)    if (context->length >= 4)
4265      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
4266    else    else
4267  #endif  #endif
4268      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
4269  #endif  #elif defined COMPILE_PCRE32
4270  #endif /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
4271    #endif /* COMPILE_PCRE[8|16|32] */
4272    context->sourcereg = TMP2;    context->sourcereg = TMP2;
4273    }    }
4274    
# Line 3583  do Line 4282  do
4282  #endif  #endif
4283    
4284    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
4285  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
4286    
4287    /* Unaligned read is supported. */    /* Unaligned read is supported. */
4288    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3598  do Line 4297  do
4297      }      }
4298    context->ucharptr++;    context->ucharptr++;
4299    
4300  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
4301    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))
4302  #else  #else
4303    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
# Line 3606  do Line 4305  do
4305      {      {
4306      if (context->length >= 4)      if (context->length >= 4)
4307        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  
4308      else if (context->length >= 2)      else if (context->length >= 2)
4309        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);
4310    #if defined COMPILE_PCRE8
4311      else if (context->length >= 1)      else if (context->length >= 1)
4312        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);
4313  #else  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
4314      context->sourcereg = c