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

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

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

revision 1040 by zherczeg, Sun Sep 16 06:52:27 2012 UTC revision 1424 by zherczeg, Tue Dec 31 11:22:31 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      pcre_uint32 nlmax;
367    int newline;    int newline;
368    int bsr_nltype;    int bsr_nltype;
369      pcre_uint32 bsr_nlmax;
370    /* Dollar endonly. */    /* Dollar endonly. */
371    int endonly;    int endonly;
   BOOL has_set_som;  
372    /* Tables. */    /* Tables. */
373    sljit_w ctypes;    sljit_sw ctypes;
   int digits[2 + MAX_RANGE_SIZE];  
374    /* Named capturing brackets. */    /* Named capturing brackets. */
375    sljit_uw name_table;    pcre_uchar *name_table;
376    sljit_w name_count;    sljit_sw name_count;
377    sljit_w name_entry_size;    sljit_sw name_entry_size;
378    
379    /* Labels and jump lists. */    /* Labels and jump lists. */
380    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
381    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
382    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
383      struct sljit_label *accept_label;
384    stub_list *stubs;    stub_list *stubs;
385    recurse_entry *entries;    recurse_entry *entries;
386    recurse_entry *currententry;    recurse_entry *currententry;
387    jump_list *partialmatch;    jump_list *partialmatch;
388    jump_list *quit;    jump_list *quit;
389      jump_list *positive_assert_quit;
390      jump_list *forced_quit;
391    jump_list *accept;    jump_list *accept;
392    jump_list *calllimit;    jump_list *calllimit;
393    jump_list *stackalloc;    jump_list *stackalloc;
# Line 337  typedef struct compiler_common { Line 398  typedef struct compiler_common {
398    jump_list *vspace;    jump_list *vspace;
399    jump_list *casefulcmp;    jump_list *casefulcmp;
400    jump_list *caselesscmp;    jump_list *caselesscmp;
401      jump_list *reset_match;
402    BOOL jscript_compat;    BOOL jscript_compat;
403  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
404    BOOL utf;    BOOL utf;
405  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
406    BOOL use_ucp;    BOOL use_ucp;
407  #endif  #endif
   jump_list *utfreadchar;  
408  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
409      jump_list *utfreadchar;
410      jump_list *utfreadchar16;
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    
527    #define READ_CHAR_ANY 0x7fffffff
528    
529  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
530  {  {
531  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
# Line 473  cc += 1 + LINK_SIZE; Line 535  cc += 1 + LINK_SIZE;
535  return cc;  return cc;
536  }  }
537    
538    static int ones_in_half_byte[16] = {
539      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
540      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
541    };
542    
543  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
544   next_opcode   next_opcode
545   get_private_data_length   check_opcode_types
546   set_private_data_ptrs   set_private_data_ptrs
547   get_framesize   get_framesize
548   init_frame   init_frame
549   get_private_data_length_for_copy   get_private_data_copy_length
550   copy_private_data   copy_private_data
551   compile_matchingpath   compile_matchingpath
552   compile_backtrackingpath   compile_backtrackingpath
# Line 503  switch(*cc) Line 570  switch(*cc)
570    case OP_WORDCHAR:    case OP_WORDCHAR:
571    case OP_ANY:    case OP_ANY:
572    case OP_ALLANY:    case OP_ALLANY:
573      case OP_NOTPROP:
574      case OP_PROP:
575    case OP_ANYNL:    case OP_ANYNL:
576    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
577    case OP_HSPACE:    case OP_HSPACE:
# Line 515  switch(*cc) Line 584  switch(*cc)
584    case OP_CIRCM:    case OP_CIRCM:
585    case OP_DOLL:    case OP_DOLL:
586    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:  
587    case OP_CRSTAR:    case OP_CRSTAR:
588    case OP_CRMINSTAR:    case OP_CRMINSTAR:
589    case OP_CRPLUS:    case OP_CRPLUS:
590    case OP_CRMINPLUS:    case OP_CRMINPLUS:
591    case OP_CRQUERY:    case OP_CRQUERY:
592    case OP_CRMINQUERY:    case OP_CRMINQUERY:
593      case OP_CRRANGE:
594      case OP_CRMINRANGE:
595      case OP_CRPOSSTAR:
596      case OP_CRPOSPLUS:
597      case OP_CRPOSQUERY:
598      case OP_CRPOSRANGE:
599      case OP_CLASS:
600      case OP_NCLASS:
601      case OP_REF:
602      case OP_REFI:
603      case OP_DNREF:
604      case OP_DNREFI:
605      case OP_RECURSE:
606      case OP_CALLOUT:
607      case OP_ALT:
608      case OP_KET:
609      case OP_KETRMAX:
610      case OP_KETRMIN:
611      case OP_KETRPOS:
612      case OP_REVERSE:
613      case OP_ASSERT:
614      case OP_ASSERT_NOT:
615      case OP_ASSERTBACK:
616      case OP_ASSERTBACK_NOT:
617      case OP_ONCE:
618      case OP_ONCE_NC:
619      case OP_BRA:
620      case OP_BRAPOS:
621      case OP_CBRA:
622      case OP_CBRAPOS:
623      case OP_COND:
624      case OP_SBRA:
625      case OP_SBRAPOS:
626      case OP_SCBRA:
627      case OP_SCBRAPOS:
628      case OP_SCOND:
629      case OP_CREF:
630      case OP_DNCREF:
631      case OP_RREF:
632      case OP_DNRREF:
633    case OP_DEF:    case OP_DEF:
634    case OP_BRAZERO:    case OP_BRAZERO:
635    case OP_BRAMINZERO:    case OP_BRAMINZERO:
636    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
637      case OP_PRUNE:
638      case OP_SKIP:
639      case OP_THEN:
640    case OP_COMMIT:    case OP_COMMIT:
641    case OP_FAIL:    case OP_FAIL:
642    case OP_ACCEPT:    case OP_ACCEPT:
643    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
644      case OP_CLOSE:
645    case OP_SKIPZERO:    case OP_SKIPZERO:
646    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
647    
648    case OP_CHAR:    case OP_CHAR:
649    case OP_CHARI:    case OP_CHARI:
# Line 557  switch(*cc) Line 655  switch(*cc)
655    case OP_MINPLUS:    case OP_MINPLUS:
656    case OP_QUERY:    case OP_QUERY:
657    case OP_MINQUERY:    case OP_MINQUERY:
658      case OP_UPTO:
659      case OP_MINUPTO:
660      case OP_EXACT:
661    case OP_POSSTAR:    case OP_POSSTAR:
662    case OP_POSPLUS:    case OP_POSPLUS:
663    case OP_POSQUERY:    case OP_POSQUERY:
664      case OP_POSUPTO:
665    case OP_STARI:    case OP_STARI:
666    case OP_MINSTARI:    case OP_MINSTARI:
667    case OP_PLUSI:    case OP_PLUSI:
668    case OP_MINPLUSI:    case OP_MINPLUSI:
669    case OP_QUERYI:    case OP_QUERYI:
670    case OP_MINQUERYI:    case OP_MINQUERYI:
671      case OP_UPTOI:
672      case OP_MINUPTOI:
673      case OP_EXACTI:
674    case OP_POSSTARI:    case OP_POSSTARI:
675    case OP_POSPLUSI:    case OP_POSPLUSI:
676    case OP_POSQUERYI:    case OP_POSQUERYI:
677      case OP_POSUPTOI:
678    case OP_NOTSTAR:    case OP_NOTSTAR:
679    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
680    case OP_NOTPLUS:    case OP_NOTPLUS:
681    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
682    case OP_NOTQUERY:    case OP_NOTQUERY:
683    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
684      case OP_NOTUPTO:
685      case OP_NOTMINUPTO:
686      case OP_NOTEXACT:
687    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
688    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
689    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
690      case OP_NOTPOSUPTO:
691    case OP_NOTSTARI:    case OP_NOTSTARI:
692    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
693    case OP_NOTPLUSI:    case OP_NOTPLUSI:
694    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
695    case OP_NOTQUERYI:    case OP_NOTQUERYI:
696    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:  
697    case OP_NOTUPTOI:    case OP_NOTUPTOI:
698    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
699    case OP_NOTEXACTI:    case OP_NOTEXACTI:
700      case OP_NOTPOSSTARI:
701      case OP_NOTPOSPLUSI:
702      case OP_NOTPOSQUERYI:
703    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
704    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
705  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
706    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
707  #endif  #endif
708    return cc;    return cc;
709    
710    case OP_NOTPROP:    /* Special cases. */
711    case OP_PROP:    case OP_TYPESTAR:
712    return cc + 1 + 2;    case OP_TYPEMINSTAR:
713      case OP_TYPEPLUS:
714      case OP_TYPEMINPLUS:
715      case OP_TYPEQUERY:
716      case OP_TYPEMINQUERY:
717    case OP_TYPEUPTO:    case OP_TYPEUPTO:
718    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
719    case OP_TYPEEXACT:    case OP_TYPEEXACT:
720      case OP_TYPEPOSSTAR:
721      case OP_TYPEPOSPLUS:
722      case OP_TYPEPOSQUERY:
723    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
724    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;  
725    
726    case OP_CLASS:    case OP_ANYBYTE:
727    case OP_NCLASS:  #ifdef SUPPORT_UTF
728    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
729    #endif
730      return cc + 1;
731    
732  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
733    case OP_XCLASS:    case OP_XCLASS:
734    return cc + GET(cc, 1);    return cc + GET(cc, 1);
735  #endif  #endif
736    
   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;  
   
737    case OP_MARK:    case OP_MARK:
738      case OP_PRUNE_ARG:
739      case OP_SKIP_ARG:
740      case OP_THEN_ARG:
741    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
742    
743    default:    default:
744      /* All opcodes are supported now! */
745      SLJIT_ASSERT_STOP();
746    return NULL;    return NULL;
747    }    }
748  }  }
749    
750  #define CASE_ITERATOR_PRIVATE_DATA_1 \  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
751      case OP_MINSTAR: \  {
752      case OP_MINPLUS: \  int count;
753      case OP_QUERY: \  pcre_uchar *slot;
     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:  
754    
755  #define CASE_ITERATOR_PRIVATE_DATA_2A \  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
756      case OP_STAR: \  while (cc < ccend)
757      case OP_PLUS: \    {
758      case OP_STARI: \    switch(*cc)
759      case OP_PLUSI: \      {
760      case OP_NOTSTAR: \      case OP_SET_SOM:
761      case OP_NOTPLUS: \      common->has_set_som = TRUE;
762      case OP_NOTSTARI: \      cc += 1;
763      case OP_NOTPLUSI:      break;
764    
765  #define CASE_ITERATOR_PRIVATE_DATA_2B \      case OP_REF:
766      case OP_UPTO: \      case OP_REFI:
767      case OP_MINUPTO: \      common->optimized_cbracket[GET2(cc, 1)] = 0;
768      case OP_UPTOI: \      cc += 1 + IMM2_SIZE;
769      case OP_MINUPTOI: \      break;
     case OP_NOTUPTO: \  
     case OP_NOTMINUPTO: \  
     case OP_NOTUPTOI: \  
     case OP_NOTMINUPTOI:  
770    
771  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \      case OP_CBRAPOS:
772      case OP_TYPEMINSTAR: \      case OP_SCBRAPOS:
773      case OP_TYPEMINPLUS: \      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
774      case OP_TYPEQUERY: \      cc += 1 + LINK_SIZE + IMM2_SIZE;
775      case OP_TYPEMINQUERY:      break;
776    
777  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \      case OP_COND:
778      case OP_TYPESTAR: \      case OP_SCOND:
779      case OP_TYPEPLUS:      /* Only AUTO_CALLOUT can insert this opcode. We do
780           not intend to support this case. */
781        if (cc[1 + LINK_SIZE] == OP_CALLOUT)
782          return FALSE;
783        cc += 1 + LINK_SIZE;
784        break;
785    
786  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \      case OP_CREF:
787      case OP_TYPEUPTO: \      common->optimized_cbracket[GET2(cc, 1)] = 0;
788      case OP_TYPEMINUPTO:      cc += 1 + IMM2_SIZE;
789        break;
790    
791  static int get_class_iterator_size(pcre_uchar *cc)      case OP_DNREF:
792  {      case OP_DNREFI:
793  switch(*cc)      case OP_DNCREF:
794    {      count = GET2(cc, 1 + IMM2_SIZE);
795    case OP_CRSTAR:      slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
796    case OP_CRPLUS:      while (count-- > 0)
797    return 2;        {
798          common->optimized_cbracket[GET2(slot, 0)] = 0;
799          slot += common->name_entry_size;
800          }
801        cc += 1 + 2 * IMM2_SIZE;
802        break;
803    
804        case OP_RECURSE:
805        /* Set its value only once. */
806        if (common->recursive_head_ptr == 0)
807          {
808          common->recursive_head_ptr = common->ovector_start;
809          common->ovector_start += sizeof(sljit_sw);
810          }
811        cc += 1 + LINK_SIZE;
812        break;
813    
814        case OP_CALLOUT:
815        if (common->capture_last_ptr == 0)
816          {
817          common->capture_last_ptr = common->ovector_start;
818          common->ovector_start += sizeof(sljit_sw);
819          }
820        cc += 2 + 2 * LINK_SIZE;
821        break;
822    
823        case OP_THEN_ARG:
824        common->has_then = TRUE;
825        common->control_head_ptr = 1;
826        /* Fall through. */
827    
828        case OP_PRUNE_ARG:
829        common->needs_start_ptr = TRUE;
830        /* Fall through. */
831    
832        case OP_MARK:
833        if (common->mark_ptr == 0)
834          {
835          common->mark_ptr = common->ovector_start;
836          common->ovector_start += sizeof(sljit_sw);
837          }
838        cc += 1 + 2 + cc[1];
839        break;
840    
841        case OP_THEN:
842        common->has_then = TRUE;
843        common->control_head_ptr = 1;
844        /* Fall through. */
845    
846        case OP_PRUNE:
847        case OP_SKIP:
848        common->needs_start_ptr = TRUE;
849        cc += 1;
850        break;
851    
852        case OP_SKIP_ARG:
853        common->control_head_ptr = 1;
854        common->has_skip_arg = TRUE;
855        cc += 1 + 2 + cc[1];
856        break;
857    
858        default:
859        cc = next_opcode(common, cc);
860        if (cc == NULL)
861          return FALSE;
862        break;
863        }
864      }
865    return TRUE;
866    }
867    
868    static int get_class_iterator_size(pcre_uchar *cc)
869    {
870    switch(*cc)
871      {
872      case OP_CRSTAR:
873      case OP_CRPLUS:
874      return 2;
875    
876    case OP_CRMINSTAR:    case OP_CRMINSTAR:
877    case OP_CRMINPLUS:    case OP_CRMINPLUS:
# Line 758  switch(*cc) Line 890  switch(*cc)
890    }    }
891  }  }
892    
893  static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
894  {  {
895  int private_data_length = 0;  pcre_uchar *end = bracketend(begin);
896  pcre_uchar *alternative;  pcre_uchar *next;
897  pcre_uchar *name;  pcre_uchar *next_end;
898  pcre_uchar *end = NULL;  pcre_uchar *max_end;
899  int space, size, bracketlen, i;  pcre_uchar type;
900    sljit_sw length = end - begin;
901    int min, max, i;
902    
903  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Detect fixed iterations first. */
904  while (cc < ccend)  if (end[-(1 + LINK_SIZE)] != OP_KET)
905      return FALSE;
906    
907    /* Already detected repeat. */
908    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
909      return TRUE;
910    
911    next = end;
912    min = 1;
913    while (1)
914    {    {
915    space = 0;    if (*next != *begin)
   size = 0;  
   bracketlen = 0;  
   switch(*cc)  
     {  
     case OP_SET_SOM:  
     common->has_set_som = TRUE;  
     cc += 1;  
916      break;      break;
917      next_end = bracketend(next);
918      case OP_REF:    if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
     case OP_REFI:  
     common->optimized_cbracket[GET2(cc, 1)] = 0;  
     cc += 1 + IMM2_SIZE;  
919      break;      break;
920      next = next_end;
921      min++;
922      }
923    
924      case OP_ASSERT:  if (min == 2)
925      case OP_ASSERT_NOT:    return FALSE;
     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;  
926    
927      case OP_CBRAPOS:  max = 0;
928      case OP_SCBRAPOS:  max_end = next;
929      private_data_length += sizeof(sljit_w);  if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
930      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;    {
931      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;    type = *next;
932      break;    while (1)
933        {
934        if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
935          break;
936        next_end = bracketend(next + 2 + LINK_SIZE);
937        if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
938          break;
939        next = next_end;
940        max++;
941        }
942    
943      case OP_COND:    if (next[0] == type && next[1] == *begin && max >= 1)
944      case OP_SCOND:      {
945      bracketlen = cc[1 + LINK_SIZE];      next_end = bracketend(next + 1);
946      if (bracketlen == OP_CREF)      if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
       {  
       bracketlen = GET2(cc, 1 + LINK_SIZE + 1);  
       common->optimized_cbracket[bracketlen] = 0;  
       }  
     else if (bracketlen == OP_NCREF)  
947        {        {
948        bracketlen = GET2(cc, 1 + LINK_SIZE + 1);        for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
949        name = (pcre_uchar *)common->name_table;          if (*next_end != OP_KET)
950        alternative = name;            break;
       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);  
951    
952        for (i = 0; i < common->name_count; i++)        if (i == max)
953          {          {
954          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)          common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
955            common->optimized_cbracket[GET2(alternative, 0)] = 0;          common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
956          alternative += common->name_entry_size;          /* +2 the original and the last. */
957            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
958            if (min == 1)
959              return TRUE;
960            min--;
961            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
962          }          }
963        }        }
964        }
965      }
966    
967      if (*cc == OP_COND)  if (min >= 3)
968        {    {
969        /* Might be a hidden SCOND. */    common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
970        alternative = cc + GET(cc, 1);    common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
971        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)    common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
972          private_data_length += sizeof(sljit_w);    return TRUE;
973        }    }
     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;  
     break;  
   
     case OP_CLASS:  
     case OP_NCLASS:  
     size += 1 + 32 / sizeof(pcre_uchar);  
     space = get_class_iterator_size(cc + size);  
     break;  
974    
975  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  return FALSE;
976      case OP_XCLASS:  }
     size = GET(cc, 1);  
     space = get_class_iterator_size(cc + size);  
     break;  
 #endif  
977    
978      case OP_RECURSE:  #define CASE_ITERATOR_PRIVATE_DATA_1 \
979      /* Set its value only once. */      case OP_MINSTAR: \
980      if (common->recursive_head == 0)      case OP_MINPLUS: \
981        {      case OP_QUERY: \
982        common->recursive_head = common->ovector_start;      case OP_MINQUERY: \
983        common->ovector_start += sizeof(sljit_w);      case OP_MINSTARI: \
984        }      case OP_MINPLUSI: \
985      cc += 1 + LINK_SIZE;      case OP_QUERYI: \
986      break;      case OP_MINQUERYI: \
987        case OP_NOTMINSTAR: \
988        case OP_NOTMINPLUS: \
989        case OP_NOTQUERY: \
990        case OP_NOTMINQUERY: \
991        case OP_NOTMINSTARI: \
992        case OP_NOTMINPLUSI: \
993        case OP_NOTQUERYI: \
994        case OP_NOTMINQUERYI:
995    
996      case OP_MARK:  #define CASE_ITERATOR_PRIVATE_DATA_2A \
997      if (common->mark_ptr == 0)      case OP_STAR: \
998        {      case OP_PLUS: \
999        common->mark_ptr = common->ovector_start;      case OP_STARI: \
1000        common->ovector_start += sizeof(sljit_w);      case OP_PLUSI: \
1001        }      case OP_NOTSTAR: \
1002      cc += 1 + 2 + cc[1];      case OP_NOTPLUS: \
1003      break;      case OP_NOTSTARI: \
1004        case OP_NOTPLUSI:
1005    
1006      default:  #define CASE_ITERATOR_PRIVATE_DATA_2B \
1007      cc = next_opcode(common, cc);      case OP_UPTO: \
1008      if (cc == NULL)      case OP_MINUPTO: \
1009        return -1;      case OP_UPTOI: \
1010      break;      case OP_MINUPTOI: \
1011      }      case OP_NOTUPTO: \
1012        case OP_NOTMINUPTO: \
1013        case OP_NOTUPTOI: \
1014        case OP_NOTMINUPTOI:
1015    
1016    if (space > 0 && cc >= end)  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1017      private_data_length += sizeof(sljit_w) * space;      case OP_TYPEMINSTAR: \
1018        case OP_TYPEMINPLUS: \
1019        case OP_TYPEQUERY: \
1020        case OP_TYPEMINQUERY:
1021    
1022    if (size != 0)  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1023      {      case OP_TYPESTAR: \
1024      if (size < 0)      case OP_TYPEPLUS:
       {  
       cc += -size;  
 #ifdef SUPPORT_UTF  
       if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
       }  
     else  
       cc += size;  
     }  
1025    
1026    if (bracketlen > 0)  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1027      {      case OP_TYPEUPTO: \
1028      if (cc >= end)      case OP_TYPEMINUPTO:
       {  
       end = bracketend(cc);  
       if (end[-1 - LINK_SIZE] == OP_KET)  
         end = NULL;  
       }  
     cc += bracketlen;  
     }  
   }  
 return private_data_length;  
 }  
1029    
1030  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)  static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1031  {  {
1032  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1033  pcre_uchar *alternative;  pcre_uchar *alternative;
1034  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1035    int private_data_ptr = *private_data_start;
1036  int space, size, bracketlen;  int space, size, bracketlen;
1037    
1038  while (cc < ccend)  while (cc < ccend)
# Line 967  while (cc < ccend) Line 1040  while (cc < ccend)
1040    space = 0;    space = 0;
1041    size = 0;    size = 0;
1042    bracketlen = 0;    bracketlen = 0;
1043      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1044        return;
1045    
1046      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1047        if (detect_repeat(common, cc))
1048          {
1049          /* These brackets are converted to repeats, so no global
1050          based single character repeat is allowed. */
1051          if (cc >= end)
1052            end = bracketend(cc);
1053          }
1054    
1055    switch(*cc)    switch(*cc)
1056      {      {
1057        case OP_KET:
1058        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1059          {
1060          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1061          private_data_ptr += sizeof(sljit_sw);
1062          cc += common->private_data_ptrs[cc + 1 - common->start];
1063          }
1064        cc += 1 + LINK_SIZE;
1065        break;
1066    
1067      case OP_ASSERT:      case OP_ASSERT:
1068      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1069      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 980  while (cc < ccend) Line 1075  while (cc < ccend)
1075      case OP_SBRAPOS:      case OP_SBRAPOS:
1076      case OP_SCOND:      case OP_SCOND:
1077      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1078      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1079      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1080      break;      break;
1081    
1082      case OP_CBRAPOS:      case OP_CBRAPOS:
1083      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1084      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1085      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1086      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1087      break;      break;
1088    
# Line 997  while (cc < ccend) Line 1092  while (cc < ccend)
1092      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1093        {        {
1094        common->private_data_ptrs[cc - common->start] = private_data_ptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1095        private_data_ptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1096        }        }
1097      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1098      break;      break;
# Line 1062  while (cc < ccend) Line 1157  while (cc < ccend)
1157      break;      break;
1158      }      }
1159    
1160      /* Character iterators, which are not inside a repeated bracket,
1161         gets a private slot instead of allocating it on the stack. */
1162    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1163      {      {
1164      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1165      private_data_ptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1166      }      }
1167    
1168    if (size != 0)    if (size != 0)
# Line 1092  while (cc < ccend) Line 1189  while (cc < ccend)
1189      cc += bracketlen;      cc += bracketlen;
1190      }      }
1191    }    }
1192    *private_data_start = private_data_ptr;
1193  }  }
1194    
1195  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1196  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)
1197  {  {
 pcre_uchar *ccend = bracketend(cc);  
1198  int length = 0;  int length = 0;
1199  BOOL possessive = FALSE;  int possessive = 0;
1200    BOOL stack_restore = FALSE;
1201  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1202  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1203    /* The last capture is a local variable even for recursions. */
1204    BOOL capture_last_found = FALSE;
1205    
1206  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1207    SLJIT_ASSERT(common->control_head_ptr != 0);
1208    *needs_control_head = TRUE;
1209    #else
1210    *needs_control_head = FALSE;
1211    #endif
1212    
1213    if (ccend == NULL)
1214    {    {
1215    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1216    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1217        {
1218        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1219        /* This is correct regardless of common->capture_last_ptr. */
1220        capture_last_found = TRUE;
1221        }
1222      cc = next_opcode(common, cc);
1223    }    }
1224    
 cc = next_opcode(common, cc);  
1225  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1226  while (cc < ccend)  while (cc < ccend)
1227    switch(*cc)    switch(*cc)
1228      {      {
1229      case OP_SET_SOM:      case OP_SET_SOM:
1230      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1231        stack_restore = TRUE;
1232      if (!setsom_found)      if (!setsom_found)
1233        {        {
1234        length += 2;        length += 2;
# Line 1125  while (cc < ccend) Line 1238  while (cc < ccend)
1238      break;      break;
1239    
1240      case OP_MARK:      case OP_MARK:
1241        case OP_PRUNE_ARG:
1242        case OP_THEN_ARG:
1243      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1244        stack_restore = TRUE;
1245      if (!setmark_found)      if (!setmark_found)
1246        {        {
1247        length += 2;        length += 2;
1248        setmark_found = TRUE;        setmark_found = TRUE;
1249        }        }
1250        if (common->control_head_ptr != 0)
1251          *needs_control_head = TRUE;
1252      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1253      break;      break;
1254    
1255      case OP_RECURSE:      case OP_RECURSE:
1256        stack_restore = TRUE;
1257      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1258        {        {
1259        length += 2;        length += 2;
# Line 1145  while (cc < ccend) Line 1264  while (cc < ccend)
1264        length += 2;        length += 2;
1265        setmark_found = TRUE;        setmark_found = TRUE;
1266        }        }
1267        if (common->capture_last_ptr != 0 && !capture_last_found)
1268          {
1269          length += 2;
1270          capture_last_found = TRUE;
1271          }
1272      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1273      break;      break;
1274    
# Line 1152  while (cc < ccend) Line 1276  while (cc < ccend)
1276      case OP_CBRAPOS:      case OP_CBRAPOS:
1277      case OP_SCBRA:      case OP_SCBRA:
1278      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1279        stack_restore = TRUE;
1280        if (common->capture_last_ptr != 0 && !capture_last_found)
1281          {
1282          length += 2;
1283          capture_last_found = TRUE;
1284          }
1285      length += 3;      length += 3;
1286      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1287      break;      break;
1288    
1289      default:      default:
1290        stack_restore = TRUE;
1291        /* Fall through. */
1292    
1293        case OP_NOT_WORD_BOUNDARY:
1294        case OP_WORD_BOUNDARY:
1295        case OP_NOT_DIGIT:
1296        case OP_DIGIT:
1297        case OP_NOT_WHITESPACE:
1298        case OP_WHITESPACE:
1299        case OP_NOT_WORDCHAR:
1300        case OP_WORDCHAR:
1301        case OP_ANY:
1302        case OP_ALLANY:
1303        case OP_ANYBYTE:
1304        case OP_NOTPROP:
1305        case OP_PROP:
1306        case OP_ANYNL:
1307        case OP_NOT_HSPACE:
1308        case OP_HSPACE:
1309        case OP_NOT_VSPACE:
1310        case OP_VSPACE:
1311        case OP_EXTUNI:
1312        case OP_EODN:
1313        case OP_EOD:
1314        case OP_CIRC:
1315        case OP_CIRCM:
1316        case OP_DOLL:
1317        case OP_DOLLM:
1318        case OP_CHAR:
1319        case OP_CHARI:
1320        case OP_NOT:
1321        case OP_NOTI:
1322    
1323        case OP_EXACT:
1324        case OP_POSSTAR:
1325        case OP_POSPLUS:
1326        case OP_POSQUERY:
1327        case OP_POSUPTO:
1328    
1329        case OP_EXACTI:
1330        case OP_POSSTARI:
1331        case OP_POSPLUSI:
1332        case OP_POSQUERYI:
1333        case OP_POSUPTOI:
1334    
1335        case OP_NOTEXACT:
1336        case OP_NOTPOSSTAR:
1337        case OP_NOTPOSPLUS:
1338        case OP_NOTPOSQUERY:
1339        case OP_NOTPOSUPTO:
1340    
1341        case OP_NOTEXACTI:
1342        case OP_NOTPOSSTARI:
1343        case OP_NOTPOSPLUSI:
1344        case OP_NOTPOSQUERYI:
1345        case OP_NOTPOSUPTOI:
1346    
1347        case OP_TYPEEXACT:
1348        case OP_TYPEPOSSTAR:
1349        case OP_TYPEPOSPLUS:
1350        case OP_TYPEPOSQUERY:
1351        case OP_TYPEPOSUPTO:
1352    
1353        case OP_CLASS:
1354        case OP_NCLASS:
1355        case OP_XCLASS:
1356    
1357      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1358      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1359      break;      break;
1360      }      }
1361    
1362  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1363  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1364    return -1;    return stack_restore ? no_frame : no_stack;
1365    
1366  if (length > 0)  if (length > 0)
1367    return length + 1;    return length + 1;
1368  return -1;  return stack_restore ? no_frame : no_stack;
1369  }  }
1370    
1371  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)
1372  {  {
1373  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1374  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1375  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1376    /* The last capture is a local variable even for recursions. */
1377    BOOL capture_last_found = FALSE;
1378  int offset;  int offset;
1379    
1380  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1184  SLJIT_UNUSED_ARG(stacktop); Line 1382  SLJIT_UNUSED_ARG(stacktop);
1382  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1383    
1384  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1385  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1386    cc = next_opcode(common, cc);    {
1387      ccend = bracketend(cc) - (1 + LINK_SIZE);
1388      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1389        cc = next_opcode(common, cc);
1390      }
1391    
1392  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1393  while (cc < ccend)  while (cc < ccend)
1394    switch(*cc)    switch(*cc)
# Line 1195  while (cc < ccend) Line 1398  while (cc < ccend)
1398      if (!setsom_found)      if (!setsom_found)
1399        {        {
1400        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1401        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1402        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1403        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1404        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1405        setsom_found = TRUE;        setsom_found = TRUE;
1406        }        }
1407      cc += 1;      cc += 1;
1408      break;      break;
1409    
1410      case OP_MARK:      case OP_MARK:
1411        case OP_PRUNE_ARG:
1412        case OP_THEN_ARG:
1413      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1414      if (!setmark_found)      if (!setmark_found)
1415        {        {
1416        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);
1417        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);
1418        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1419        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1420        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1421        setmark_found = TRUE;        setmark_found = TRUE;
1422        }        }
1423      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1222  while (cc < ccend) Line 1427  while (cc < ccend)
1427      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1428        {        {
1429        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1430        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1431        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1432        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1433        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1434        setsom_found = TRUE;        setsom_found = TRUE;
1435        }        }
1436      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1437        {        {
1438        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);
1439        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);
1440        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1441        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1442        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1443        setmark_found = TRUE;        setmark_found = TRUE;
1444        }        }
1445        if (common->capture_last_ptr != 0 && !capture_last_found)
1446          {
1447          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1448          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1449          stackpos += (int)sizeof(sljit_sw);
1450          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1451          stackpos += (int)sizeof(sljit_sw);
1452          capture_last_found = TRUE;
1453          }
1454      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1455      break;      break;
1456    
# Line 1244  while (cc < ccend) Line 1458  while (cc < ccend)
1458      case OP_CBRAPOS:      case OP_CBRAPOS:
1459      case OP_SCBRA:      case OP_SCBRA:
1460      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1461        if (common->capture_last_ptr != 0 && !capture_last_found)
1462          {
1463          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1464          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1465          stackpos += (int)sizeof(sljit_sw);
1466          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1467          stackpos += (int)sizeof(sljit_sw);
1468          capture_last_found = TRUE;
1469          }
1470      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1471      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1472      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1473      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1474      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));
1475      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1476      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1477      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1478      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1479    
1480      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1481      break;      break;
# Line 1263  while (cc < ccend) Line 1486  while (cc < ccend)
1486      break;      break;
1487      }      }
1488    
1489  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1490  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1491  }  }
1492    
1493  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)
1494  {  {
1495  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1496  int size;  int size;
1497  pcre_uchar *alternative;  pcre_uchar *alternative;
1498  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1278  while (cc < ccend) Line 1501  while (cc < ccend)
1501    size = 0;    size = 0;
1502    switch(*cc)    switch(*cc)
1503      {      {
1504        case OP_KET:
1505        if (PRIVATE_DATA(cc) != 0)
1506          private_data_length++;
1507        cc += 1 + LINK_SIZE;
1508        break;
1509    
1510      case OP_ASSERT:      case OP_ASSERT:
1511      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1512      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1382  return private_data_length; Line 1611  return private_data_length;
1611  }  }
1612    
1613  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,
1614    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1615  {  {
1616  DEFINE_COMPILER;  DEFINE_COMPILER;
1617  int srcw[2];  int srcw[2];
# Line 1403  stacktop = STACK(stacktop - 1); Line 1632  stacktop = STACK(stacktop - 1);
1632    
1633  if (!save)  if (!save)
1634    {    {
1635    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1636    if (stackptr < stacktop)    if (stackptr < stacktop)
1637      {      {
1638      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1639      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1640      tmp1empty = FALSE;      tmp1empty = FALSE;
1641      }      }
1642    if (stackptr < stacktop)    if (stackptr < stacktop)
1643      {      {
1644      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1645      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1646      tmp2empty = FALSE;      tmp2empty = FALSE;
1647      }      }
1648    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1649    }    }
1650    
1651  while (status != end)  do
1652    {    {
1653    count = 0;    count = 0;
1654    switch(status)    switch(status)
1655      {      {
1656      case start:      case start:
1657      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1658      count = 1;      count = 1;
1659      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1660        if (needs_control_head)
1661          {
1662          SLJIT_ASSERT(common->control_head_ptr != 0);
1663          count = 2;
1664          srcw[1] = common->control_head_ptr;
1665          }
1666      status = loop;      status = loop;
1667      break;      break;
1668    
# Line 1440  while (status != end) Line 1675  while (status != end)
1675    
1676      switch(*cc)      switch(*cc)
1677        {        {
1678          case OP_KET:
1679          if (PRIVATE_DATA(cc) != 0)
1680            {
1681            count = 1;
1682            srcw[0] = PRIVATE_DATA(cc);
1683            }
1684          cc += 1 + LINK_SIZE;
1685          break;
1686    
1687        case OP_ASSERT:        case OP_ASSERT:
1688        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1689        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1504  while (status != end) Line 1748  while (status != end)
1748          {          {
1749          count = 2;          count = 2;
1750          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1751          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1752          }          }
1753        cc += 2;        cc += 2;
1754  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1517  while (status != end) Line 1761  while (status != end)
1761          {          {
1762          count = 2;          count = 2;
1763          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1764          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1765          }          }
1766        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1767  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1539  while (status != end) Line 1783  while (status != end)
1783          {          {
1784          count = 2;          count = 2;
1785          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1786          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1787          }          }
1788        cc += 1;        cc += 1;
1789        break;        break;
# Line 1549  while (status != end) Line 1793  while (status != end)
1793          {          {
1794          count = 2;          count = 2;
1795          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1796          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1797          }          }
1798        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1799        break;        break;
# Line 1573  while (status != end) Line 1817  while (status != end)
1817            case 2:            case 2:
1818            count = 2;            count = 2;
1819            srcw[0] = PRIVATE_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1820            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1821            break;            break;
1822    
1823            default:            default:
# Line 1605  while (status != end) Line 1849  while (status != end)
1849          if (!tmp1empty)          if (!tmp1empty)
1850            {            {
1851            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1852            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1853            }            }
1854          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1855          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1616  while (status != end) Line 1860  while (status != end)
1860          if (!tmp2empty)          if (!tmp2empty)
1861            {            {
1862            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1863            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1864            }            }
1865          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1866          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1633  while (status != end) Line 1877  while (status != end)
1877          if (!tmp1empty)          if (!tmp1empty)
1878            {            {
1879            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1880            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1881            }            }
1882          tmp1next = FALSE;          tmp1next = FALSE;
1883          }          }
# Line 1645  while (status != end) Line 1889  while (status != end)
1889          if (!tmp2empty)          if (!tmp2empty)
1890            {            {
1891            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1892            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1893            }            }
1894          tmp1next = TRUE;          tmp1next = TRUE;
1895          }          }
1896        }        }
1897      }      }
1898    }    }
1899    while (status != end);
1900    
1901  if (save)  if (save)
1902    {    {
# Line 1660  if (save) Line 1905  if (save)
1905      if (!tmp1empty)      if (!tmp1empty)
1906        {        {
1907        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1908        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1909        }        }
1910      if (!tmp2empty)      if (!tmp2empty)
1911        {        {
1912        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1913        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1914        }        }
1915      }      }
1916    else    else
# Line 1673  if (save) Line 1918  if (save)
1918      if (!tmp2empty)      if (!tmp2empty)
1919        {        {
1920        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1921        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1922        }        }
1923      if (!tmp1empty)      if (!tmp1empty)
1924        {        {
1925        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1926        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1927        }        }
1928      }      }
1929    }    }
1930  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1931  }  }
1932    
1933    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1934    {
1935    pcre_uchar *end = bracketend(cc);
1936    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1937    
1938    /* Assert captures then. */
1939    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1940      current_offset = NULL;
1941    /* Conditional block does not. */
1942    if (*cc == OP_COND || *cc == OP_SCOND)
1943      has_alternatives = FALSE;
1944    
1945    cc = next_opcode(common, cc);
1946    if (has_alternatives)
1947      current_offset = common->then_offsets + (cc - common->start);
1948    
1949    while (cc < end)
1950      {
1951      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1952        cc = set_then_offsets(common, cc, current_offset);
1953      else
1954        {
1955        if (*cc == OP_ALT && has_alternatives)
1956          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1957        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1958          *current_offset = 1;
1959        cc = next_opcode(common, cc);
1960        }
1961      }
1962    
1963    return end;
1964    }
1965    
1966  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1967  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1968  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1692  SLJIT_ASSERT(cc == ccend && stackptr == Line 1970  SLJIT_ASSERT(cc == ccend && stackptr ==
1970  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1971  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1972    
1973  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1974  {  {
1975  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1976  }  }
# Line 1703  while (list) Line 1981  while (list)
1981    {    {
1982    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1983    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1984    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1985    list = list->next;    list = list->next;
1986    }    }
1987  }  }
# Line 1719  if (list_item) Line 1997  if (list_item)
1997    }    }
1998  }  }
1999    
2000  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)
2001  {  {
2002  DEFINE_COMPILER;  DEFINE_COMPILER;
2003  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
2004    
2005  if (list_item)  if (list_item)
2006    {    {
   list_item->type = type;  
   list_item->data = data;  
2007    list_item->start = start;    list_item->start = start;
2008    list_item->quit = LABEL();    list_item->quit = LABEL();
2009    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1743  stub_list* list_item = common->stubs; Line 2019  stub_list* list_item = common->stubs;
2019  while (list_item)  while (list_item)
2020    {    {
2021    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2022    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;  
     }  
2023    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2024    list_item = list_item->next;    list_item = list_item->next;
2025    }    }
2026  common->stubs = NULL;  common->stubs = NULL;
2027  }  }
2028    
2029  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2030  {  {
2031  DEFINE_COMPILER;  DEFINE_COMPILER;
2032    
2033  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);
2034  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2035  }  }
2036    
# Line 1768  static SLJIT_INLINE void allocate_stack( Line 2039  static SLJIT_INLINE void allocate_stack(
2039  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2040  DEFINE_COMPILER;  DEFINE_COMPILER;
2041    
2042  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));
2043  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2044  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2045  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 2047  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2047  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2048  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2049  #endif  #endif
2050  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));
2051  }  }
2052    
2053  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2054  {  {
2055  DEFINE_COMPILER;  DEFINE_COMPILER;
2056  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));
2057  }  }
2058    
2059  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 2061  static SLJIT_INLINE void reset_ovector(c
2061  DEFINE_COMPILER;  DEFINE_COMPILER;
2062  struct sljit_label *loop;  struct sljit_label *loop;
2063  int i;  int i;
2064    
2065  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2066    SLJIT_ASSERT(length > 1);
2067  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2068  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));
2069    if (length < 8)
2070      {
2071      for (i = 1; i < length; i++)
2072        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2073      }
2074    else
2075      {
2076      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2077      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2078      loop = LABEL();
2079      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2080      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2081      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2082      }
2083    }
2084    
2085    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2086    {
2087    DEFINE_COMPILER;
2088    struct sljit_label *loop;
2089    int i;
2090    
2091    SLJIT_ASSERT(length > 1);
2092    /* OVECTOR(1) contains the "string begin - 1" constant. */
2093    if (length > 2)
2094      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2095  if (length < 8)  if (length < 8)
2096    {    {
2097    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2098      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);
2099    }    }
2100  else  else
2101    {    {
2102    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2103    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2104    loop = LABEL();    loop = LABEL();
2105    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);
2106    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);
2107    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2108    }    }
2109    
2110    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2111    if (common->mark_ptr != 0)
2112      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2113    if (common->control_head_ptr != 0)
2114      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2115    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2116    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2117    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2118    }
2119    
2120    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2121    {
2122    while (current != NULL)
2123      {
2124      switch (current[-2])
2125        {
2126        case type_then_trap:
2127        break;
2128    
2129        case type_mark:
2130        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2131          return current[-4];
2132        break;
2133    
2134        default:
2135        SLJIT_ASSERT_STOP();
2136        break;
2137        }
2138      current = (sljit_sw*)current[-1];
2139      }
2140    return -1;
2141  }  }
2142    
2143  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2144  {  {
2145  DEFINE_COMPILER;  DEFINE_COMPILER;
2146  struct sljit_label *loop;  struct sljit_label *loop;
2147  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2148    
2149  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2150  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));
2151  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);
2152    
2153  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2154  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2155    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);
2156  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));
2157  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2158    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);
2159  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));
2160  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));
2161  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2162  /* Unlikely, but possible */  /* Unlikely, but possible */
2163  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);
2164  loop = LABEL();  loop = LABEL();
2165  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);
2166  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));
2167  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2168  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2169  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);
2170  #endif  #endif
2171  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);
2172  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);
2173  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2174  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2175    
2176  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2177  if (topbracket > 1)  if (topbracket > 1)
2178    {    {
2179    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));
2180    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2181    
2182    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2183    loop = LABEL();    loop = LABEL();
2184    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)));
2185    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);
2186    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);
2187    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2188    }    }
2189  else  else
2190    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1862  else Line 2193  else
2193  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)
2194  {  {
2195  DEFINE_COMPILER;  DEFINE_COMPILER;
2196    struct sljit_jump *jump;
2197    
2198  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);
2199  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
2200      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2201    
2202  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2203  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2204  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));
2205  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);
2206    
2207  /* Store match begin and end. */  /* Store match begin and end. */
2208  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));
2209  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));
2210  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);  
2211    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2212    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);
2213    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2214    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2215    #endif
2216    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2217    JUMPHERE(jump);
2218    
2219    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);
2220  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);
2221  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2222  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);
2223  #endif  #endif
2224  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);
2225    
2226  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);
2227  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2228  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);
2229  #endif  #endif
2230  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);
2231    
2232  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2233  }  }
# Line 1998  if (c <= 127 && bit == 0x20) Line 2340  if (c <= 127 && bit == 0x20)
2340    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2341    
2342  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2343  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2344    return 0;    return 0;
2345    
2346  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2347    
2348  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2349  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 2017  if (common->utf && c > 127) Line 2359  if (common->utf && c > 127)
2359  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2360  return (0 << 8) | bit;  return (0 << 8) | bit;
2361    
2362  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2363    
 #ifdef COMPILE_PCRE16  
2364  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2365  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2366    {    {
# Line 2030  if (common->utf && c > 65535) Line 2371  if (common->utf && c > 65535)
2371    }    }
2372  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2373  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2374    
2375  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2376  }  }
2377    
2378  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2379  {  {
2380  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2381  DEFINE_COMPILER;  DEFINE_COMPILER;
2382  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2383    
# Line 2052  else if (common->mode == JIT_PARTIAL_SOF Line 2392  else if (common->mode == JIT_PARTIAL_SOF
2392    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);
2393    
2394  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2395    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);
2396  else  else
2397    {    {
2398    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2065  if (jump != NULL) Line 2405  if (jump != NULL)
2405    JUMPHERE(jump);    JUMPHERE(jump);
2406  }  }
2407    
2408  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2409  {  {
2410  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2411  DEFINE_COMPILER;  DEFINE_COMPILER;
2412  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2413    
2414  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2415    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2416      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2417      return;
2418      }
2419    
2420  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2421  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2422    {    {
2423    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));
2424    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);
2425    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2426    }    }
2427  else  else
2428    {    {
2429    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));
2430    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2431      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2432    else    else
2433      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2434    }    }
2435  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2436  }  }
2437    
2438  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 2451  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2451  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));
2452  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2453    {    {
2454    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);
2455    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2456    }    }
2457  else  else
2458    {    {
2459    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2460      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2461    else    else
2462      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2463      }
2464    JUMPHERE(jump);
2465    }
2466    
2467    static void peek_char(compiler_common *common)
2468    {
2469    /* Reads the character into TMP1, keeps STR_PTR.
2470    Does not check STR_END. TMP2 Destroyed. */
2471    DEFINE_COMPILER;
2472    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2473    struct sljit_jump *jump;
2474    #endif
2475    
2476    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2477    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2478    if (common->utf)
2479      {
2480      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2481      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2482      add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2483      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2484      JUMPHERE(jump);
2485      }
2486    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2487    
2488    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2489    if (common->utf)
2490      {
2491      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2492      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2493      /* TMP2 contains the high surrogate. */
2494      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2495      OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2496      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2497      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2498      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2499      JUMPHERE(jump);
2500      }
2501    #endif
2502    }
2503    
2504    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2505    
2506    static BOOL is_char7_bitset(const pcre_uint8* bitset, BOOL nclass)
2507    {
2508    /* Tells whether the character codes below 128 are enough
2509    to determine a match. */
2510    const pcre_uint8 value = nclass ? 0xff : 0;
2511    const pcre_uint8* end = bitset + 32;
2512    
2513    bitset += 16;
2514    do
2515      {
2516      if (*bitset++ != value)
2517        return FALSE;
2518    }    }
2519  JUMPHERE(jump);  while (bitset < end);
2520    return TRUE;
2521  }  }
2522    
2523  static void read_char(compiler_common *common)  static void read_char7_type(compiler_common *common, BOOL full_read)
2524  {  {
2525  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the precise character type of a character into TMP1, if the character
2526  Does not check STR_END. TMP2 Destroyed. */  is less than 128. Otherwise it returns with zero. Does not check STR_END. The
2527    full_read argument tells whether characters above max are accepted or not. */
2528  DEFINE_COMPILER;  DEFINE_COMPILER;
 #ifdef SUPPORT_UTF  
2529  struct sljit_jump *jump;  struct sljit_jump *jump;
 #endif  
2530    
2531  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  SLJIT_ASSERT(common->utf);
2532  #ifdef SUPPORT_UTF  
2533  if (common->utf)  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2534    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2535    
2536    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2537    
2538    if (full_read)
2539    {    {
2540  #ifdef COMPILE_PCRE8    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2541    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2542  #else    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
 #ifdef COMPILE_PCRE16  
   jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);  
 #endif  
 #endif /* COMPILE_PCRE8 */  
   add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));  
2543    JUMPHERE(jump);    JUMPHERE(jump);
2544    }    }
 #endif  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
2545  }  }
2546    
2547  static void peek_char(compiler_common *common)  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2548    
2549    static void read_char_max(compiler_common *common, pcre_uint32 max, BOOL full_read)
2550  {  {
2551  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the precise value of a character into TMP1, if the character is
2552  Does not check STR_END. TMP2 Destroyed. */  less than or equal to max. Otherwise it returns with a value greater than max.
2553    Does not check STR_END. The full_read argument tells whether characters above
2554    max are accepted or not. */
2555  DEFINE_COMPILER;  DEFINE_COMPILER;
2556  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2557  struct sljit_jump *jump;  struct sljit_jump *jump;
2558  #endif  #endif
2559    
2560    SLJIT_UNUSED_ARG(full_read);
2561    SLJIT_UNUSED_ARG(max);
2562    
2563  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2564  #ifdef SUPPORT_UTF  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2565    
2566    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2567  if (common->utf)  if (common->utf)
2568    {    {
2569  #ifdef COMPILE_PCRE8    if (max < 128 && !full_read)
2570        return;
2571    
2572    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2573  #else    if (max >= 0x800)
2574  #ifdef COMPILE_PCRE16      add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2575    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    else if (max < 128)
2576        {
2577        OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2578        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2579        }
2580      else
2581        {
2582        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2583        if (!full_read)
2584          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2585        else
2586          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2587        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2588        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2589        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2590        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2591        if (full_read)
2592          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2593        }
2594      JUMPHERE(jump);
2595      }
2596  #endif  #endif
2597  #endif /* COMPILE_PCRE8 */  
2598    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));  #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2599    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  if (common->utf)
2600      {
2601      if (max >= 0x10000)
2602        {
2603        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2604        jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2605        /* TMP2 contains the high surrogate. */
2606        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2607        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2608        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2609        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2610        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2611        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2612        JUMPHERE(jump);
2613        return;
2614        }
2615    
2616      if (max < 0xd800 && !full_read)
2617        return;
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);    JUMPHERE(jump);
2627    }    }
2628  #endif  #endif
2629  }  }
2630    
2631  static void read_char8_type(compiler_common *common)  static SLJIT_INLINE void read_char(compiler_common *common)
2632    {
2633    read_char_max(common, READ_CHAR_ANY, TRUE);
2634    }
2635    
2636    static void read_char8_type(compiler_common *common, BOOL full_read)
2637  {  {
2638  /* 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.
2639    The full_read argument tells whether characters above max are accepted or not. */
2640  DEFINE_COMPILER;  DEFINE_COMPILER;
2641  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2642  struct sljit_jump *jump;  struct sljit_jump *jump;
2643  #endif  #endif
2644    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2645    struct sljit_jump *jump2;
2646    #endif
2647    
2648  #ifdef SUPPORT_UTF  SLJIT_UNUSED_ARG(full_read);
2649    
2650    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2651    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2652    
2653    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2654  if (common->utf)  if (common->utf)
2655    {    {
   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  
2656    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2657    it is needed in most cases. */    it is needed in most cases. */
2658    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2659    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2660    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    if (!full_read)
2661    JUMPHERE(jump);      {
2662  #else      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2663  #ifdef COMPILE_PCRE16      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2664    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2665    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2666    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2667        OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
2668        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2669        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2670        OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2671        JUMPHERE(jump2);
2672        }
2673      else
2674        add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2675    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 */  
2676    return;    return;
2677    }    }
2678  #endif  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2679  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
2680  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  #if !defined COMPILE_PCRE8
 #ifdef COMPILE_PCRE16  
2681  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2682  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2683  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2684  #endif  #endif
2685  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2686  #ifdef COMPILE_PCRE16  #if !defined COMPILE_PCRE8
2687  JUMPHERE(jump);  JUMPHERE(jump);
2688  #endif  #endif
2689    
2690    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2691    if (common->utf && full_read)
2692      {
2693      /* Skip low surrogate if necessary. */
2694      OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2695      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2696      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2697      JUMPHERE(jump);
2698      }
2699    #endif /* SUPPORT_UTF && COMPILE_PCRE16 */
2700  }  }
2701    
2702  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
2703  {  {
2704  /* 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. */
2705  DEFINE_COMPILER;  DEFINE_COMPILER;
2706  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2707    #if defined COMPILE_PCRE8
2708  struct sljit_label *label;  struct sljit_label *label;
2709    
2710  if (common->utf)  if (common->utf)
# Line 2245  if (common->utf) Line 2716  if (common->utf)
2716    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2717    return;    return;
2718    }    }
2719  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2720  if (common->utf)  if (common->utf)
2721    {    {
2722    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 2724  if (common->utf)
2724    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2725    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2726    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);
2727    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2728    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2729    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2730    return;    return;
2731    }    }
2732  #endif  #endif /* COMPILE_PCRE[8|16] */
2733    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2734  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));
2735  }  }
2736    
2737  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpiftrue)  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpifmatch)
2738  {  {
2739  /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */  /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */
2740  DEFINE_COMPILER;  DEFINE_COMPILER;
2741    struct sljit_jump *jump;
2742    
2743  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2744    {    {
2745    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2746    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpifmatch ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2747    }    }
2748  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2749    {    {
2750    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    if (jumpifmatch)
2751    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      {
2752    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR));
2753    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2754    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));      }
2755      else
2756        {
2757        jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
2758        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2759        JUMPHERE(jump);
2760        }
2761    }    }
2762  else  else
2763    {    {
2764    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2765    add_jump(compiler, backtracks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));    add_jump(compiler, backtracks, CMP(jumpifmatch ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
2766    }    }
2767  }  }
2768    
2769  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2770    
2771  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2772  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2773  {  {
2774  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2775  of the character (>= 0xc0). Return char value in TMP1, length - 1 in TMP2. */  of the character (>= 0xc0). Return char value in TMP1, length in TMP2. */
2776  DEFINE_COMPILER;  DEFINE_COMPILER;
2777  struct sljit_jump *jump;  struct sljit_jump *jump;
2778    
2779  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2780    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2781    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2782    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2783    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2784    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2785    
2786  /* Searching for the first zero. */  /* Searching for the first zero. */
2787  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, 0x800);
2788  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2789  /* Two byte sequence. */  /* Two byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
2790  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));
2791  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2792    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2793    
2794    JUMPHERE(jump);
2795    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2796    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2797  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2798  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2799  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 JUMPHERE(jump);  
2800    
2801  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, 0x10000);
2802  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2803  /* Three byte sequence. */  /* Three byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  
2804  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));
2805  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));  
2806  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2807    
2808  /* Four byte sequence. */  /* Four byte sequence. */
2809  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  JUMPHERE(jump);
2810  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2811  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2812    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2813    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2814  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  
2815  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2816  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(4));
2817    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2818    }
2819    
2820    static void do_utfreadchar16(compiler_common *common)
2821    {
2822    /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2823    of the character (>= 0xc0). Return value in TMP1. */
2824    DEFINE_COMPILER;
2825    struct sljit_jump *jump;
2826    
2827    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2828    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2829    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2830    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2831  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
2832  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2833  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));  
2834  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));  /* Searching for the first zero. */
2835    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2836    jump = JUMP(SLJIT_C_NOT_ZERO);
2837    /* Two byte sequence. */
2838    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2839    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2840    
2841    JUMPHERE(jump);
2842    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
2843    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
2844    /* This code runs only in 8 bit mode. No need to shift the value. */
2845    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2846    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2847    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2848    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2849  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2850  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2851  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));  /* Three byte sequence. */
2852    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2853  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2854  }  }
2855    
# Line 2365  jump = JUMP(SLJIT_C_NOT_ZERO); Line 2869  jump = JUMP(SLJIT_C_NOT_ZERO);
2869  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2870  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));
2871  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2872    /* The upper 5 bits are known at this point. */
2873    compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x3);
2874  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2875  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2876  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);  
2877  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2878  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2879    
2880  JUMPHERE(compare);  JUMPHERE(compare);
2881  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2882  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2883    
2884  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0);  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 }  
   
 #else /* COMPILE_PCRE8 */  
   
 #ifdef COMPILE_PCRE16  
 static void do_utfreadchar(compiler_common *common)  
 {  
 /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  
 of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */  
 DEFINE_COMPILER;  
 struct sljit_jump *jump;  
   
 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  
 jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);  
 /* Do nothing, only return. */  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
   
2885  JUMPHERE(jump);  JUMPHERE(jump);
2886  /* Combine two 16 bit characters. */  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2887  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2888  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  
2889  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2890  }  }
 #endif /* COMPILE_PCRE16 */  
2891    
2892  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
2893    
# Line 2433  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2909  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2909    
2910  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2911  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2912  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));
2913  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2914  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2915  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2916  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2917  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2918  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));
2919  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2920  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2921  }  }
# Line 2453  struct sljit_label *newlinelabel = NULL; Line 2929  struct sljit_label *newlinelabel = NULL;
2929  struct sljit_jump *start;  struct sljit_jump *start;
2930  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2931  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2932  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2933  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2934  #endif  #endif
2935  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2488  if (firstline) Line 2964  if (firstline)
2964      mainloop = LABEL();      mainloop = LABEL();
2965      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
2966      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2967      read_char(common);      read_char_max(common, common->nlmax, TRUE);
2968      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
2969      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2970      JUMPHERE(end);      JUMPHERE(end);
# Line 2508  if (newlinecheck) Line 2984  if (newlinecheck)
2984    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2985    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2986    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);
2987    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2988  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2989    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2990  #endif  #endif
2991    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2992    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2531  if (newlinecheck) Line 3007  if (newlinecheck)
3007    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);
3008    
3009  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));
3010  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3011    #if defined COMPILE_PCRE8
3012  if (common->utf)  if (common->utf)
3013    {    {
3014    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
3015    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);
3016    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3017    JUMPHERE(singlechar);    JUMPHERE(singlechar);
3018    }    }
3019  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3020  if (common->utf)  if (common->utf)
3021    {    {
3022    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
3023    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3024    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);
3025    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3026    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3027    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3028    JUMPHERE(singlechar);    JUMPHERE(singlechar);
3029    }    }
3030  #endif  #endif /* COMPILE_PCRE[8|16] */
3031    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
3032  JUMPHERE(start);  JUMPHERE(start);
3033    
3034  if (newlinecheck)  if (newlinecheck)
# Line 2563  if (newlinecheck) Line 3040  if (newlinecheck)
3040  return mainloop;  return mainloop;
3041  }  }
3042    
3043  #define MAX_N_CHARS 3  static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, int max_chars)
   
 static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)  
3044  {  {
3045  DEFINE_COMPILER;  /* Recursive function, which scans prefix literals. */
3046  struct sljit_label *start;  int len, repeat, len_save, consumed = 0;
3047  struct sljit_jump *quit;  pcre_uint32 caseless, chr, mask;
3048  pcre_int32 chars[MAX_N_CHARS * 2];  pcre_uchar *alternative, *cc_save;
3049  pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  BOOL last, any;
 int location = 0;  
 pcre_int32 len, c, bit, caseless;  
 int must_stop;  
   
 /* We do not support alternatives now. */  
 if (*(common->start + GET(common->start, 1)) == OP_ALT)  
   return FALSE;  
3050    
3051    repeat = 1;
3052  while (TRUE)  while (TRUE)
3053    {    {
3054      last = TRUE;
3055      any = FALSE;
3056    caseless = 0;    caseless = 0;
3057    must_stop = 1;    switch (*cc)
   switch(*cc)  
3058      {      {
     case OP_CHAR:  
     must_stop = 0;  
     cc++;  
     break;  
   
3059      case OP_CHARI:      case OP_CHARI:
3060      caseless = 1;      caseless = 1;
3061      must_stop = 0;      case OP_CHAR:
3062        last = FALSE;
3063      cc++;      cc++;
3064      break;      break;
3065    
# Line 2612  while (TRUE) Line 3078  while (TRUE)
3078      cc++;      cc++;
3079      continue;      continue;
3080    
3081      case OP_PLUS:      case OP_PLUS:
3082      case OP_MINPLUS:      case OP_MINPLUS:
3083      case OP_POSPLUS:      case OP_POSPLUS:
3084      cc++;      cc++;
3085        break;
3086    
3087        case OP_EXACTI:
3088        caseless = 1;
3089        case OP_EXACT:
3090        repeat = GET2(cc, 1);
3091        last = FALSE;
3092        cc += 1 + IMM2_SIZE;
3093        break;
3094    
3095        case OP_PLUSI:
3096        case OP_MINPLUSI:
3097        case OP_POSPLUSI:
3098        caseless = 1;
3099        cc++;
3100        break;
3101    
3102        case OP_KET:
3103        cc += 1 + LINK_SIZE;
3104        continue;
3105    
3106        case OP_ALT:
3107        cc += GET(cc, 1);
3108        continue;
3109    
3110        case OP_ONCE:
3111        case OP_ONCE_NC:
3112        case OP_BRA:
3113        case OP_BRAPOS:
3114        case OP_CBRA:
3115        case OP_CBRAPOS:
3116        alternative = cc + GET(cc, 1);
3117        while (*alternative == OP_ALT)
3118          {
3119          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, max_chars);
3120          if (max_chars == 0)
3121            return consumed;
3122          alternative += GET(alternative, 1);
3123          }
3124    
3125        if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
3126          cc += IMM2_SIZE;
3127        cc += 1 + LINK_SIZE;
3128        continue;
3129    
3130        case OP_CLASS:
3131        case OP_NCLASS:
3132        any = TRUE;
3133        cc += 1 + 32 / sizeof(pcre_uchar);
3134      break;      break;
3135    
3136      case OP_EXACT:  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3137      cc += 1 + IMM2_SIZE;      case OP_XCLASS:
3138        any = TRUE;
3139        cc += GET(cc, 1);
3140      break;      break;
3141    #endif
3142    
3143      case OP_PLUSI:      case OP_NOT_DIGIT:
3144      case OP_MINPLUSI:      case OP_DIGIT:
3145      case OP_POSPLUSI:      case OP_NOT_WHITESPACE:
3146      caseless = 1;      case OP_WHITESPACE:
3147        case OP_NOT_WORDCHAR:
3148        case OP_WORDCHAR:
3149        case OP_ANY:
3150        case OP_ALLANY:
3151        any = TRUE;
3152      cc++;      cc++;
3153      break;      break;
3154    
3155      case OP_EXACTI:  #ifdef SUPPORT_UCP
3156      caseless = 1;      case OP_NOTPROP:
3157      cc += 1 + IMM2_SIZE;      case OP_PROP:
3158        any = TRUE;
3159        cc += 1 + 2;
3160      break;      break;
3161    #endif
3162    
3163        case OP_TYPEEXACT:
3164        repeat = GET2(cc, 1);
3165        cc += 1 + IMM2_SIZE;
3166        continue;
3167    
3168      default:      default:
3169      must_stop = 2;      return consumed;
     break;  
3170      }      }
3171    
3172    if (must_stop == 2)    if (any)
3173        break;      {
3174    #ifdef SUPPORT_UTF
3175        if (common->utf) return consumed;
3176    #endif
3177    #if defined COMPILE_PCRE8
3178        mask = 0xff;
3179    #elif defined COMPILE_PCRE16
3180        mask = 0xffff;
3181    #elif defined COMPILE_PCRE32
3182        mask = 0xffffffff;
3183    #else
3184        SLJIT_ASSERT_STOP();
3185    #endif
3186    
3187        do
3188          {
3189          chars[0] = mask;
3190          chars[1] = mask;
3191    
3192          if (--max_chars == 0)
3193            return consumed;
3194          consumed++;
3195          chars += 2;
3196          }
3197        while (--repeat > 0);
3198    
3199        repeat = 1;
3200        continue;
3201        }
3202    
3203    len = 1;    len = 1;
3204  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3205    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3206  #endif  #endif
3207    
3208    if (caseless && char_has_othercase(common, cc))    if (caseless != 0 && char_has_othercase(common, cc))
3209      {      {
3210      caseless = char_get_othercase_bit(common, cc);      caseless = char_get_othercase_bit(common, cc);
3211      if (caseless == 0)      if (caseless == 0)
3212        return FALSE;        return consumed;
3213  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3214      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
3215  #else  #else
# Line 2664  while (TRUE) Line 3222  while (TRUE)
3222    else    else
3223      caseless = 0;      caseless = 0;
3224    
3225    while (len > 0 && location < MAX_N_CHARS * 2)    len_save = len;
3226      {    cc_save = cc;
3227      c = *cc;    while (TRUE)
3228      bit = 0;      {
3229      if (len == (caseless & 0xff))      do
3230        {        {
3231        bit = caseless >> 8;        chr = *cc;
3232        c |= bit;  #ifdef COMPILE_PCRE32
3233          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3234            return consumed;
3235    #endif
3236          mask = 0;
3237          if ((pcre_uint32)len == (caseless & 0xff))
3238            {
3239            mask = caseless >> 8;
3240            chr |= mask;
3241            }
3242    
3243          if (chars[0] == NOTACHAR)
3244            {
3245            chars[0] = chr;
3246            chars[1] = mask;
3247            }
3248          else
3249            {
3250            mask |= chars[0] ^ chr;
3251            chr |= mask;
3252            chars[0] = chr;
3253            chars[1] |= mask;
3254            }
3255    
3256          len--;
3257          if (--max_chars == 0)
3258            return consumed;
3259          consumed++;
3260          chars += 2;
3261          cc++;
3262        }        }
3263        while (len > 0);
3264    
3265      chars[location] = c;      if (--repeat == 0)
3266      chars[location + 1] = bit;        break;
3267    
3268      len--;      len = len_save;
3269      location += 2;      cc = cc_save;
3270      cc++;      }
3271    
3272      repeat = 1;
3273      if (last)
3274        return consumed;
3275      }
3276    }
3277    
3278    #define MAX_N_CHARS 16
3279    
3280    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3281    {
3282    DEFINE_COMPILER;
3283    struct sljit_label *start;
3284    struct sljit_jump *quit;
3285    pcre_uint32 chars[MAX_N_CHARS * 2];
3286    pcre_uint8 ones[MAX_N_CHARS];
3287    pcre_uint32 mask;
3288    int i, max;
3289    int offsets[3];
3290    
3291    for (i = 0; i < MAX_N_CHARS; i++)
3292      {
3293      chars[i << 1] = NOTACHAR;
3294      chars[(i << 1) + 1] = 0;
3295      }
3296    
3297    max = scan_prefix(common, common->start, chars, MAX_N_CHARS);
3298    
3299    if (max <= 1)
3300      return FALSE;
3301    
3302    for (i = 0; i < max; i++)
3303      {
3304      mask = chars[(i << 1) + 1];
3305      ones[i] = ones_in_half_byte[mask & 0xf];
3306      mask >>= 4;
3307      while (mask != 0)
3308        {
3309        ones[i] += ones_in_half_byte[mask & 0xf];
3310        mask >>= 4;
3311      }      }
3312      }
3313    
3314    if (location >= MAX_N_CHARS * 2 || must_stop != 0)  offsets[0] = -1;
3315    /* Scan forward. */
3316    for (i = 0; i < max; i++)
3317      if (ones[i] <= 2) {
3318        offsets[0] = i;
3319      break;      break;
3320    }    }
3321    
3322  /* At least two characters are required. */  if (offsets[0] == -1)
3323  if (location < 2 * 2)    return FALSE;
3324      return FALSE;  
3325    /* Scan backward. */
3326    offsets[1] = -1;
3327    for (i = max - 1; i > offsets[0]; i--)
3328      if (ones[i] <= 2) {
3329        offsets[1] = i;
3330        break;
3331      }
3332    
3333    offsets[2] = -1;
3334    if (offsets[1] >= 0)
3335      {
3336      /* Scan from middle. */
3337      for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3338        if (ones[i] <= 2)
3339          {
3340          offsets[2] = i;
3341          break;
3342          }
3343    
3344      if (offsets[2] == -1)
3345        {
3346        for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3347          if (ones[i] <= 2)
3348            {
3349            offsets[2] = i;
3350            break;
3351            }
3352        }
3353      }
3354    
3355    SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3356    SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3357    
3358    chars[0] = chars[offsets[0] << 1];
3359    chars[1] = chars[(offsets[0] << 1) + 1];
3360    if (offsets[2] >= 0)
3361      {
3362      chars[2] = chars[offsets[2] << 1];
3363      chars[3] = chars[(offsets[2] << 1) + 1];
3364      }
3365    if (offsets[1] >= 0)
3366      {
3367      chars[4] = chars[offsets[1] << 1];
3368      chars[5] = chars[(offsets[1] << 1) + 1];
3369      }
3370    
3371    max -= 1;
3372  if (firstline)  if (firstline)
3373    {    {
3374    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3375    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3376    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, (location >> 1) - 1);    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS(max));
3377    }    }
3378  else  else
3379    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, (location >> 1) - 1);    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3380    
3381  start = LABEL();  start = LABEL();
3382  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3383    
3384  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3385  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  if (offsets[1] >= 0)
3386      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3387  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));
3388    
3389  if (chars[1] != 0)  if (chars[1] != 0)
3390    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3391  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3392  if (location > 2 * 2)  if (offsets[2] >= 0)
3393    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3394  if (chars[3] != 0)  
3395    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);  if (offsets[1] >= 0)
 CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);  
 if (location > 2 * 2)  
3396    {    {
3397    if (chars[5] != 0)    if (chars[5] != 0)
3398      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3399    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3400      }
3401    
3402    if (offsets[2] >= 0)
3403      {
3404      if (chars[3] != 0)
3405        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3406      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3407    }    }
3408  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));
3409    
# Line 2726  JUMPHERE(quit); Line 3412  JUMPHERE(quit);
3412  if (firstline)  if (firstline)
3413    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3414  else  else
3415    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, (location >> 1) - 1);    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3416  return TRUE;  return TRUE;
3417  }  }
3418    
# Line 2765  if (first_char == oc) Line 3451  if (first_char == oc)
3451  else  else
3452    {    {
3453    bit = first_char ^ oc;    bit = first_char ^ oc;
3454    if (ispowerof2(bit))    if (is_powerof2(bit))
3455      {      {
3456      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3457      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 2773  else Line 3459  else
3459    else    else
3460      {      {
3461      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);
3462      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3463      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);
3464      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);
3465      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3466      }      }
3467    }    }
# Line 2817  if (common->nltype == NLTYPE_FIXED && co Line 3503  if (common->nltype == NLTYPE_FIXED && co
3503    
3504    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3505    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);
3506    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3507  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3508    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3509  #endif  #endif
3510    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3511    
# Line 2846  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3532  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3532  skip_char_back(common);  skip_char_back(common);
3533    
3534  loop = LABEL();  loop = LABEL();
3535  read_char(common);  read_char_max(common, common->nlmax, TRUE);
3536  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3537  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3538    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
# Line 2860  if (common->nltype == NLTYPE_ANY || comm Line 3546  if (common->nltype == NLTYPE_ANY || comm
3546    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3547    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3548    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);
3549    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3550  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3551    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3552  #endif  #endif
3553    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3554    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
# Line 2875  if (firstline) Line 3561  if (firstline)
3561    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3562  }  }
3563    
3564  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);
3565    
3566    static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, pcre_uint8 *start_bits, BOOL firstline)
3567  {  {
3568  DEFINE_COMPILER;  DEFINE_COMPILER;
3569  struct sljit_label *start;  struct sljit_label *start;
3570  struct sljit_jump *quit;  struct sljit_jump *quit;
3571  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3572    jump_list *matches = NULL;
3573  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3574  struct sljit_jump *jump;  struct sljit_jump *jump;
3575  #endif  #endif
# Line 2899  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3588  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3588  if (common->utf)  if (common->utf)
3589    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3590  #endif  #endif
3591    
3592    if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
3593      {
3594  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3595  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3596  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3597  JUMPHERE(jump);    JUMPHERE(jump);
3598  #endif  #endif
3599  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3600  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3601  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3602  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3603  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);
3604  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3605      }
3606    
3607  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3608  if (common->utf)  if (common->utf)
3609    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3610  #endif  #endif
3611  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));
3612  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3613    #if defined COMPILE_PCRE8
3614  if (common->utf)  if (common->utf)
3615    {    {
3616    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3617    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);
3618    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3619    }    }
3620  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3621  if (common->utf)  if (common->utf)
3622    {    {
3623    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3624    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3625    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);
3626    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3627    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3628    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3629    }    }
3630  #endif  #endif /* COMPILE_PCRE[8|16] */
3631    #endif /* SUPPORT_UTF */
3632  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3633  JUMPHERE(found);  if (found != NULL)
3634      JUMPHERE(found);
3635    if (matches != NULL)
3636      set_jumps(matches, LABEL());
3637  JUMPHERE(quit);  JUMPHERE(quit);
3638    
3639  if (firstline)  if (firstline)
# Line 2952  struct sljit_jump *alreadyfound; Line 3649  struct sljit_jump *alreadyfound;
3649  struct sljit_jump *found;  struct sljit_jump *found;
3650  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3651  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3652  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3653    
3654  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3655  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 2983  if (req_char == oc) Line 3680  if (req_char == oc)
3680  else  else
3681    {    {
3682    bit = req_char ^ oc;    bit = req_char ^ oc;
3683    if (ispowerof2(bit))    if (is_powerof2(bit))
3684      {      {
3685      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3686      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 3019  GET_LOCAL_BASE(TMP3, 0, 0); Line 3716  GET_LOCAL_BASE(TMP3, 0, 0);
3716  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3717  mainloop = LABEL();  mainloop = LABEL();
3718  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3719  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);
3720    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3721    
3722  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3723  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));
3724  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));
3725  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));
3726  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3727    
3728  JUMPHERE(jump);  JUMPHERE(jump);
3729  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3730  /* End of dropping frames. */  /* End of dropping frames. */
3731  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3732    
3733  JUMPHERE(jump);  JUMPHERE(jump);
3734  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3735  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3736  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3737  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));  
3738  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3739  }  }
3740    
# Line 3060  static void check_wordboundary(compiler_ Line 3742  static void check_wordboundary(compiler_
3742  {  {
3743  DEFINE_COMPILER;  DEFINE_COMPILER;
3744  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3745    jump_list *skipread_list = NULL;
3746  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3747  struct sljit_jump *jump;  struct sljit_jump *jump;
3748  #endif  #endif
# Line 3085  if (common->use_ucp) Line 3768  if (common->use_ucp)
3768    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3769    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3770    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);
3771    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3772    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);
3773    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);
3774    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3775    JUMPHERE(jump);    JUMPHERE(jump);
3776    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3777    }    }
# Line 3117  else Line 3800  else
3800  JUMPHERE(skipread);  JUMPHERE(skipread);
3801    
3802  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3803  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3804  peek_char(common);  peek_char(common);
3805    
3806  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3129  if (common->use_ucp) Line 3812  if (common->use_ucp)
3812    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3813    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3814    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);
3815    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3816    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);
3817    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);
3818    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3819    JUMPHERE(jump);    JUMPHERE(jump);
3820    }    }
3821  else  else
# Line 3158  else Line 3841  else
3841      JUMPHERE(jump);      JUMPHERE(jump);
3842  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3843    }    }
3844  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3845    
3846  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3847  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3848  }  }
3849    
3850  /*  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks)
   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)  
3851  {  {
3852  DEFINE_COMPILER;  DEFINE_COMPILER;
3853  struct sljit_jump *jump;  int ranges[MAX_RANGE_SIZE];
   
 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;  
   }  
 }  
   
 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;  
   
 for (i = 1; i < 256; i++)  
   if ((ctypes[i] & flag) != bit)  
     {  
     if (length >= MAX_RANGE_SIZE)  
       return;  
     ranges[2 + length] = i;  
     length++;  
     bit ^= flag;  
     }  
   
 if (bit != 0)  
   {  
   if (length >= MAX_RANGE_SIZE)  
     return;  
   ranges[2 + length] = 256;  
   length++;  
   }  
 ranges[0] = length;  
 }  
   
 static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)  
 {  
 int ranges[2 + MAX_RANGE_SIZE];  
3854  pcre_uint8 bit, cbit, all;  pcre_uint8 bit, cbit, all;
3855  int i, byte, length = 0;  int i, byte, length = 0;
3856    
3857  bit = bits[0] & 0x1;  bit = bits[0] & 0x1;
3858  ranges[1] = bit;  /* All bits will be zero or one (since bit is zero or one). */
 /* Can be 0 or 255. */  
3859  all = -bit;  all = -bit;
3860    
3861  for (i = 0; i < 256; )  for (i = 0; i < 256; )
# Line 3282  for (i = 0; i < 256; ) Line 3870  for (i = 0; i < 256; )
3870        {        {
3871        if (length >= MAX_RANGE_SIZE)        if (length >= MAX_RANGE_SIZE)
3872          return FALSE;          return FALSE;
3873        ranges[2 + length] = i;        ranges[length] = i;
3874        length++;        length++;
3875        bit = cbit;        bit = cbit;
3876        all = -cbit;        all = -cbit;
# Line 3295  if (((bit == 0) && nclass) || ((bit == 1 Line 3883  if (((bit == 0) && nclass) || ((bit == 1
3883    {    {
3884    if (length >= MAX_RANGE_SIZE)    if (length >= MAX_RANGE_SIZE)
3885      return FALSE;      return FALSE;
3886    ranges[2 + length] = 256;    ranges[length] = 256;
3887    length++;    length++;
3888    }    }
 ranges[0] = length;  
3889    
3890  return check_ranges(common, ranges, backtracks, FALSE);  if (length < 0 || length > 4)
3891      return FALSE;
3892    
3893    bit = bits[0] & 0x1;
3894    if (invert) bit ^= 0x1;
3895    
3896    /* No character is accepted. */
3897    if (length == 0 && bit == 0)
3898      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
3899    
3900    switch(length)
3901      {
3902      case 0:
3903      /* When bit != 0, all characters are accepted. */
3904      return TRUE;
3905    
3906      case 1:
3907      add_jump(compiler, backtracks, CMP(bit == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3908      return TRUE;
3909    
3910      case 2:
3911      if (ranges[0] + 1 != ranges[1])
3912        {
3913        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3914        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3915        }
3916      else
3917        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3918      return TRUE;
3919    
3920      case 3:
3921      if (bit != 0)
3922        {
3923        add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3924        if (ranges[0] + 1 != ranges[1])
3925          {
3926          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3927          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3928          }
3929        else
3930          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3931        return TRUE;
3932        }
3933    
3934      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[0]));
3935      if (ranges[1] + 1 != ranges[2])
3936        {
3937        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1]);
3938        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
3939        }
3940      else
3941        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1]));
3942      return TRUE;
3943    
3944      case 4:
3945      if ((ranges[1] - ranges[0]) == (ranges[3] - ranges[2])
3946          && (ranges[0] | (ranges[2] - ranges[0])) == ranges[2]
3947          && is_powerof2(ranges[2] - ranges[0]))
3948        {
3949        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[0]);
3950        if (ranges[2] + 1 != ranges[3])
3951          {
3952          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3953          add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3954          }
3955        else
3956          add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3957        return TRUE;
3958        }
3959    
3960      if (bit != 0)
3961        {
3962        i = 0;
3963        if (ranges[0] + 1 != ranges[1])
3964          {
3965          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3966          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3967          i = ranges[0];
3968          }
3969        else
3970          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3971    
3972        if (ranges[2] + 1 != ranges[3])
3973          {
3974          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - i);
3975          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3976          }
3977        else
3978          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2] - i));
3979        return TRUE;
3980        }
3981    
3982      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3983      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[0]));
3984      if (ranges[1] + 1 != ranges[2])
3985        {
3986        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]);
3987        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
3988        }
3989      else
3990        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3991      return TRUE;
3992    
3993      default:
3994      SLJIT_ASSERT_STOP();
3995      return FALSE;
3996      }
3997  }  }
3998    
3999  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
# Line 3312  sljit_emit_fast_enter(compiler, RETURN_A Line 4005  sljit_emit_fast_enter(compiler, RETURN_A
4005    
4006  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
4007  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);
4008  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4009  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);
4010  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4011  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4012  if (common->utf)  if (common->utf)
4013    {    {
4014  #endif  #endif
4015    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4016    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
4017    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);
4018  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4019    }    }
4020  #endif  #endif
4021  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
4022  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);
4023  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
4024  }  }
4025    
# Line 3338  DEFINE_COMPILER; Line 4031  DEFINE_COMPILER;
4031  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
4032    
4033  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);
4034  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4035  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);
4036  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4037  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);
4038  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4039  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4040  if (common->utf)  if (common->utf)
4041    {    {
4042  #endif  #endif
4043    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4044    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);
4045    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4046    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);
4047    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4048    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
4049    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);
4050    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4051    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);
4052    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4053    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);
4054    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4055    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);
4056  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4057    }    }
4058  #endif  #endif
4059  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
4060  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);
4061    
4062  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
4063  }  }
# Line 3378  sljit_emit_fast_enter(compiler, RETURN_A Line 4071  sljit_emit_fast_enter(compiler, RETURN_A
4071    
4072  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
4073  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);
4074  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4075  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);
4076  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4077  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4078  if (common->utf)  if (common->utf)
4079    {    {
4080  #endif  #endif
4081    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);
4082    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
4083    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);
4084  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4085    }    }
4086  #endif  #endif
4087  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
4088  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);
4089    
4090  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
4091  }  }
# Line 3478  sljit_emit_fast_return(compiler, RETURN_ Line 4171  sljit_emit_fast_return(compiler, RETURN_
4171    
4172  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
4173    
4174  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)
4175  {  {
4176  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
4177  int c1, c2;  pcre_uint32 c1, c2;
4178  const pcre_uchar *src2 = args->uchar_ptr;  const pcre_uchar *src2 = args->uchar_ptr;
4179  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
4180    const ucd_record *ur;
4181    const pcre_uint32 *pp;
4182    
4183  while (src1 < end1)  while (src1 < end1)
4184    {    {
# Line 3491  while (src1 < end1) Line 4186  while (src1 < end1)
4186      return (pcre_uchar*)1;      return (pcre_uchar*)1;
4187    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
4188    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
4189    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return NULL;    ur = GET_UCD(c2);
4190      if (c1 != c2 && c1 != c2 + ur->other_case)
4191        {
4192        pp = PRIV(ucd_caseless_sets) + ur->caseset;
4193        for (;;)
4194          {
4195          if (c1 < *pp) return NULL;
4196          if (c1 == *pp++) break;
4197          }
4198        }
4199    }    }
4200  return src2;  return src2;
4201  }  }
# Line 3513  if (caseless && char_has_othercase(commo Line 4217  if (caseless && char_has_othercase(commo
4217    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
4218    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
4219    /* Extracting bit difference info. */    /* Extracting bit difference info. */
4220  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
4221    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
4222    othercasebit &= 0xff;    othercasebit &= 0xff;
4223  #else  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4224  #ifdef COMPILE_PCRE16    /* Note that this code only handles characters in the BMP. If there
4225      ever are characters outside the BMP whose othercase differs in only one
4226      bit from itself (there currently are none), this code will need to be
4227      revised for COMPILE_PCRE32. */
4228    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
4229    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
4230      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
4231    else    else
4232      othercasebit &= 0xff;      othercasebit &= 0xff;
4233  #endif  #endif /* COMPILE_PCRE[8|16|32] */
 #endif  
4234    }    }
4235    
4236  if (context->sourcereg == -1)  if (context->sourcereg == -1)
4237    {    {
4238  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
4239  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
4240    if (context->length >= 4)    if (context->length >= 4)
4241      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 3538  if (context->sourcereg == -1) Line 4244  if (context->sourcereg == -1)
4244    else    else
4245  #endif  #endif
4246      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
4247  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
4248  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
4249    if (context->length >= 4)    if (context->length >= 4)
4250      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
4251    else    else
4252  #endif  #endif
4253      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
4254  #endif  #elif defined COMPILE_PCRE32
4255  #endif /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
4256    #endif /* COMPILE_PCRE[8|16|32] */
4257    context->sourcereg = TMP2;    context->sourcereg = TMP2;
4258    }    }
4259    
# Line 3561  do Line 4267  do
4267  #endif  #endif
4268    
4269    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
4270  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
4271    
4272    /* Unaligned read is supported. */    /* Unaligned read is supported. */
4273    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3576  do Line 4282  do
4282      }      }
4283    context->ucharptr++;    context->ucharptr++;
4284    
4285  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
4286    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))
4287  #else  #else
4288    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
# Line 3584  do Line 4290  do
4290      {      {
4291      if (context->length >= 4)      if (context->length >= 4)
4292        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  
4293      else if (context->length >= 2)      else if (context->length >= 2)
4294        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);
4295    #if defined COMPILE_PCRE8
4296      else if (context->length >= 1)      else if (context->length >= 1)
4297        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);
4298  #else  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
4299      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
4300    
4301      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3626  do Line 4329  do
4329    
4330  #else  #else
4331    
4332    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
4333  #ifdef COMPILE_PCRE8    if (context->length >= 1)
4334    if (context->length > 0)      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
4335      OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #else  
   if (context->length > 0)