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

Diff of /code/trunk/pcre_jit_compile.c

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

revision 1306 by zherczeg, Mon Apr 1 17:04:17 2013 UTC revision 1632 by zherczeg, Fri Feb 12 14:43:22 2016 UTC
# Line 52  POSSIBILITY OF SUCH DAMAGE. Line 52  POSSIBILITY OF SUCH DAMAGE.
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
53  system files. */  system files. */
54    
55  #define SLJIT_MALLOC(size) (PUBL(malloc))(size)  #define SLJIT_MALLOC(size, allocator_data) (PUBL(malloc))(size)
56  #define SLJIT_FREE(ptr) (PUBL(free))(ptr)  #define SLJIT_FREE(ptr, allocator_data) (PUBL(free))(ptr)
57  #define SLJIT_CONFIG_AUTO 1  #define SLJIT_CONFIG_AUTO 1
58  #define SLJIT_CONFIG_STATIC 1  #define SLJIT_CONFIG_STATIC 1
59  #define SLJIT_VERBOSE 0  #define SLJIT_VERBOSE 0
# Line 168  typedef struct jit_arguments { Line 168  typedef struct jit_arguments {
168    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
169    void *callout_data;    void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171      pcre_uint32 limit_match;
172    int real_offset_count;    int real_offset_count;
173    int offset_count;    int offset_count;
   int call_limit;  
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 179  typedef struct jit_arguments { Line 179  typedef struct jit_arguments {
179    
180  typedef struct executable_functions {  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182      void *read_only_data_heads[JIT_NUMBER_OF_COMPILE_MODES];
183      sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
184    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
185    void *userdata;    void *userdata;
186    pcre_uint32 top_bracket;    pcre_uint32 top_bracket;
187    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    pcre_uint32 limit_match;
188  } executable_functions;  } executable_functions;
189    
190  typedef struct jump_list {  typedef struct jump_list {
# Line 196  typedef struct stub_list { Line 198  typedef struct stub_list {
198    struct stub_list *next;    struct stub_list *next;
199  } stub_list;  } stub_list;
200    
201    typedef struct label_addr_list {
202      struct sljit_label *label;
203      sljit_uw *update_addr;
204      struct label_addr_list *next;
205    } label_addr_list;
206    
207  enum frame_types {  enum frame_types {
208    no_frame = -1,    no_frame = -1,
209    no_stack = -2    no_stack = -2
# Line 210  typedef int (SLJIT_CALL *jit_function)(j Line 218  typedef int (SLJIT_CALL *jit_function)(j
218    
219  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
220  code generator. It is allocated by compile_matchingpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
221  the aguments for compile_backtrackingpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
222  of its descendants. */  of its descendants. */
223  typedef struct backtrack_common {  typedef struct backtrack_common {
224    /* Concatenation stack. */    /* Concatenation stack. */
# Line 269  typedef struct braminzero_backtrack { Line 277  typedef struct braminzero_backtrack {
277    struct sljit_label *matchingpath;    struct sljit_label *matchingpath;
278  } braminzero_backtrack;  } braminzero_backtrack;
279    
280  typedef struct iterator_backtrack {  typedef struct char_iterator_backtrack {
281      backtrack_common common;
282      /* Next iteration. */
283      struct sljit_label *matchingpath;
284      union {
285        jump_list *backtracks;
286        struct {
287          unsigned int othercasebit;
288          pcre_uchar chr;
289          BOOL enabled;
290        } charpos;
291      } u;
292    } char_iterator_backtrack;
293    
294    typedef struct ref_iterator_backtrack {
295    backtrack_common common;    backtrack_common common;
296    /* Next iteration. */    /* Next iteration. */
297    struct sljit_label *matchingpath;    struct sljit_label *matchingpath;
298  } iterator_backtrack;  } ref_iterator_backtrack;
299    
300  typedef struct recurse_entry {  typedef struct recurse_entry {
301    struct recurse_entry *next;    struct recurse_entry *next;
# Line 305  typedef struct then_trap_backtrack { Line 327  typedef struct then_trap_backtrack {
327    int framesize;    int framesize;
328  } then_trap_backtrack;  } then_trap_backtrack;
329    
330  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 4
331    
332  typedef struct compiler_common {  typedef struct compiler_common {
333    /* The sljit ceneric compiler. */    /* The sljit ceneric compiler. */
# Line 314  typedef struct compiler_common { Line 336  typedef struct compiler_common {
336    pcre_uchar *start;    pcre_uchar *start;
337    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
338    sljit_si *private_data_ptrs;    sljit_si *private_data_ptrs;
339      /* Chain list of read-only data ptrs. */
340      void *read_only_data_head;
341    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
342    pcre_uint8 *optimized_cbracket;    sljit_ub *optimized_cbracket;
343    /* Tells whether the starting offset is a target of then. */    /* Tells whether the starting offset is a target of then. */
344    pcre_uint8 *then_offsets;    sljit_ub *then_offsets;
345    /* Current position where a THEN must jump. */    /* Current position where a THEN must jump. */
346    then_trap_backtrack *then_trap;    then_trap_backtrack *then_trap;
347    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
348    int cbra_ptr;    sljit_si cbra_ptr;
349    /* Output vector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
350    int ovector_start;    sljit_si ovector_start;
351      /* Points to the starting character of the current match. */
352      sljit_si start_ptr;
353    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
354    int req_char_ptr;    sljit_si req_char_ptr;
355    /* Head of the last recursion. */    /* Head of the last recursion. */
356    int recursive_head_ptr;    sljit_si recursive_head_ptr;
357    /* First inspected character for partial matching. */    /* First inspected character for partial matching.
358    int start_used_ptr;       (Needed for avoiding zero length partial matches.) */
359      sljit_si start_used_ptr;
360    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
361    int hit_start;    sljit_si hit_start;
362    /* End pointer of the first line. */    /* End pointer of the first line. */
363    int first_line_end;    sljit_si first_line_end;
364    /* Points to the marked string. */    /* Points to the marked string. */
365    int mark_ptr;    sljit_si mark_ptr;
366    /* Recursive control verb management chain. */    /* Recursive control verb management chain. */
367    int control_head_ptr;    sljit_si control_head_ptr;
368    /* Points to the last matched capture block index. */    /* Points to the last matched capture block index. */
369    int capture_last_ptr;    sljit_si capture_last_ptr;
370    /* Points to the starting position of the current match. */    /* Fast forward skipping byte code pointer. */
371    int start_ptr;    pcre_uchar *fast_forward_bc_ptr;
372      /* Locals used by fast fail optimization. */
373      sljit_si fast_fail_start_ptr;
374      sljit_si fast_fail_end_ptr;
375    
376    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
377    const pcre_uint8 *fcc;    const sljit_ub *fcc;
378    sljit_sw lcc;    sljit_sw lcc;
379    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
380    int mode;    int mode;
381      /* TRUE, when minlength is greater than 0. */
382      BOOL might_be_empty;
383    /* \K is found in the pattern. */    /* \K is found in the pattern. */
384    BOOL has_set_som;    BOOL has_set_som;
385    /* (*SKIP:arg) is found in the pattern. */    /* (*SKIP:arg) is found in the pattern. */
386    BOOL has_skip_arg;    BOOL has_skip_arg;
387    /* (*THEN) is found in the pattern. */    /* (*THEN) is found in the pattern. */
388    BOOL has_then;    BOOL has_then;
389    /* Needs to know the start position anytime. */    /* (*SKIP) or (*SKIP:arg) is found in lookbehind assertion. */
390    BOOL needs_start_ptr;    BOOL has_skip_in_assert_back;
391    /* Currently in recurse or negative assert. */    /* Currently in recurse or negative assert. */
392    BOOL local_exit;    BOOL local_exit;
393    /* Currently in a positive assert. */    /* Currently in a positive assert. */
394    BOOL positive_assert;    BOOL positive_assert;
395    /* Newline control. */    /* Newline control. */
396    int nltype;    int nltype;
397      sljit_ui nlmax;
398      sljit_ui nlmin;
399    int newline;    int newline;
400    int bsr_nltype;    int bsr_nltype;
401      sljit_ui bsr_nlmax;
402      sljit_ui bsr_nlmin;
403    /* Dollar endonly. */    /* Dollar endonly. */
404    int endonly;    int endonly;
405    /* Tables. */    /* Tables. */
406    sljit_sw ctypes;    sljit_sw ctypes;
   int digits[2 + MAX_RANGE_SIZE];  
407    /* Named capturing brackets. */    /* Named capturing brackets. */
408    sljit_uw name_table;    pcre_uchar *name_table;
409    sljit_sw name_count;    sljit_sw name_count;
410    sljit_sw name_entry_size;    sljit_sw name_entry_size;
411    
# Line 379  typedef struct compiler_common { Line 414  typedef struct compiler_common {
414    struct sljit_label *quit_label;    struct sljit_label *quit_label;
415    struct sljit_label *forced_quit_label;    struct sljit_label *forced_quit_label;
416    struct sljit_label *accept_label;    struct sljit_label *accept_label;
417      struct sljit_label *ff_newline_shortcut;
418    stub_list *stubs;    stub_list *stubs;
419      label_addr_list *label_addrs;
420    recurse_entry *entries;    recurse_entry *entries;
421    recurse_entry *currententry;    recurse_entry *currententry;
422    jump_list *partialmatch;    jump_list *partialmatch;
# Line 402  typedef struct compiler_common { Line 439  typedef struct compiler_common {
439    BOOL utf;    BOOL utf;
440  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
441    BOOL use_ucp;    BOOL use_ucp;
442  #endif    jump_list *getucd;
 #ifndef COMPILE_PCRE32  
   jump_list *utfreadchar;  
443  #endif  #endif
444  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
445      jump_list *utfreadchar;
446      jump_list *utfreadchar16;
447    jump_list *utfreadtype8;    jump_list *utfreadtype8;
448  #endif  #endif
449  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
 #ifdef SUPPORT_UCP  
   jump_list *getucd;  
 #endif  
450  } compiler_common;  } compiler_common;
451    
452  /* For byte_sequence_compare. */  /* For byte_sequence_compare. */
# Line 455  typedef struct compare_context { Line 489  typedef struct compare_context {
489  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
490  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
491    
492  #define TMP1          SLJIT_SCRATCH_REG1  #define TMP1          SLJIT_R0
493  #define TMP2          SLJIT_SCRATCH_REG3  #define TMP2          SLJIT_R2
494  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_R3
495  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_S0
496  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_S1
497  #define STACK_TOP     SLJIT_SCRATCH_REG2  #define STACK_TOP     SLJIT_R1
498  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_S2
499  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define COUNT_MATCH   SLJIT_S3
500  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define ARGUMENTS     SLJIT_S4
501  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_R4
502    
503  /* Local space layout. */  /* Local space layout. */
504  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
# Line 474  typedef struct compare_context { Line 508  typedef struct compare_context {
508  #define POSSESSIVE0      (2 * sizeof(sljit_sw))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
509  #define POSSESSIVE1      (3 * sizeof(sljit_sw))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
510  /* Max limit of recursions. */  /* Max limit of recursions. */
511  #define CALL_LIMIT       (4 * sizeof(sljit_sw))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
512  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
513  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
514  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
515  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. */
516  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
517  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
518  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
519  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
520    
521  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
# Line 523  the start pointers when the end of the c Line 557  the start pointers when the end of the c
557  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
558    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
559    
560  static pcre_uchar* bracketend(pcre_uchar* cc)  #define READ_CHAR_MAX 0x7fffffff
561    
562    static pcre_uchar *bracketend(pcre_uchar *cc)
563  {  {
564  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));
565  do cc += GET(cc, 1); while (*cc == OP_ALT);  do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 532  cc += 1 + LINK_SIZE; Line 568  cc += 1 + LINK_SIZE;
568  return cc;  return cc;
569  }  }
570    
571    static int no_alternatives(pcre_uchar *cc)
572    {
573    int count = 0;
574    SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
575    do
576      {
577      cc += GET(cc, 1);
578      count++;
579      }
580    while (*cc == OP_ALT);
581    SLJIT_ASSERT(*cc >= OP_KET && *cc <= OP_KETRPOS);
582    return count;
583    }
584    
585    static int ones_in_half_byte[16] = {
586      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
587      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
588    };
589    
590  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
591   next_opcode   next_opcode
592   check_opcode_types   check_opcode_types
# Line 584  switch(*cc) Line 639  switch(*cc)
639    case OP_CRMINQUERY:    case OP_CRMINQUERY:
640    case OP_CRRANGE:    case OP_CRRANGE:
641    case OP_CRMINRANGE:    case OP_CRMINRANGE:
642      case OP_CRPOSSTAR:
643      case OP_CRPOSPLUS:
644      case OP_CRPOSQUERY:
645      case OP_CRPOSRANGE:
646    case OP_CLASS:    case OP_CLASS:
647    case OP_NCLASS:    case OP_NCLASS:
648    case OP_REF:    case OP_REF:
649    case OP_REFI:    case OP_REFI:
650      case OP_DNREF:
651      case OP_DNREFI:
652    case OP_RECURSE:    case OP_RECURSE:
653    case OP_CALLOUT:    case OP_CALLOUT:
654    case OP_ALT:    case OP_ALT:
# Line 613  switch(*cc) Line 674  switch(*cc)
674    case OP_SCBRAPOS:    case OP_SCBRAPOS:
675    case OP_SCOND:    case OP_SCOND:
676    case OP_CREF:    case OP_CREF:
677    case OP_NCREF:    case OP_DNCREF:
678    case OP_RREF:    case OP_RREF:
679    case OP_NRREF:    case OP_DNRREF:
680    case OP_DEF:    case OP_DEF:
681    case OP_BRAZERO:    case OP_BRAZERO:
682    case OP_BRAMINZERO:    case OP_BRAMINZERO:
# Line 735  switch(*cc) Line 796  switch(*cc)
796    
797  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
798  {  {
799  pcre_uchar *name;  int count;
800  pcre_uchar *name2;  pcre_uchar *slot;
801  int i, cbra_index;  pcre_uchar *assert_back_end = cc - 1;
802    
803  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
804  while (cc < ccend)  while (cc < ccend)
# Line 746  while (cc < ccend) Line 807  while (cc < ccend)
807      {      {
808      case OP_SET_SOM:      case OP_SET_SOM:
809      common->has_set_som = TRUE;      common->has_set_som = TRUE;
810        common->might_be_empty = TRUE;
811      cc += 1;      cc += 1;
812      break;      break;
813    
# Line 771  while (cc < ccend) Line 833  while (cc < ccend)
833      break;      break;
834    
835      case OP_CREF:      case OP_CREF:
836      i = GET2(cc, 1);      common->optimized_cbracket[GET2(cc, 1)] = 0;
     common->optimized_cbracket[i] = 0;  
837      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
838      break;      break;
839    
840      case OP_NCREF:      case OP_DNREF:
841      cbra_index = GET2(cc, 1);      case OP_DNREFI:
842      name = (pcre_uchar *)common->name_table;      case OP_DNCREF:
843      name2 = name;      count = GET2(cc, 1 + IMM2_SIZE);
844      for (i = 0; i < common->name_count; i++)      slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
845        {      while (count-- > 0)
846        if (GET2(name, 0) == cbra_index) break;        {
847        name += common->name_entry_size;        common->optimized_cbracket[GET2(slot, 0)] = 0;
848        }        slot += common->name_entry_size;
     SLJIT_ASSERT(i != common->name_count);  
   
     for (i = 0; i < common->name_count; i++)  
       {  
       if (STRCMP_UC_UC(name2 + IMM2_SIZE, name + IMM2_SIZE) == 0)  
         common->optimized_cbracket[GET2(name2, 0)] = 0;  
       name2 += common->name_entry_size;  
849        }        }
850      cc += 1 + IMM2_SIZE;      cc += 1 + 2 * IMM2_SIZE;
851      break;      break;
852    
853      case OP_RECURSE:      case OP_RECURSE:
# Line 815  while (cc < ccend) Line 869  while (cc < ccend)
869      cc += 2 + 2 * LINK_SIZE;      cc += 2 + 2 * LINK_SIZE;
870      break;      break;
871    
872        case OP_ASSERTBACK:
873        slot = bracketend(cc);
874        if (slot > assert_back_end)
875          assert_back_end = slot;
876        cc += 1 + LINK_SIZE;
877        break;
878    
879      case OP_THEN_ARG:      case OP_THEN_ARG:
880      common->has_then = TRUE;      common->has_then = TRUE;
881      common->control_head_ptr = 1;      common->control_head_ptr = 1;
882      /* Fall through. */      /* Fall through. */
883    
884      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
     common->needs_start_ptr = TRUE;  
     /* Fall through. */  
   
885      case OP_MARK:      case OP_MARK:
886      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
887        {        {
# Line 836  while (cc < ccend) Line 894  while (cc < ccend)
894      case OP_THEN:      case OP_THEN:
895      common->has_then = TRUE;      common->has_then = TRUE;
896      common->control_head_ptr = 1;      common->control_head_ptr = 1;
897      /* Fall through. */      cc += 1;
898        break;
899    
     case OP_PRUNE:  
900      case OP_SKIP:      case OP_SKIP:
901      common->needs_start_ptr = TRUE;      if (cc < assert_back_end)
902          common->has_skip_in_assert_back = TRUE;
903      cc += 1;      cc += 1;
904      break;      break;
905    
906      case OP_SKIP_ARG:      case OP_SKIP_ARG:
907      common->control_head_ptr = 1;      common->control_head_ptr = 1;
908      common->has_skip_arg = TRUE;      common->has_skip_arg = TRUE;
909        if (cc < assert_back_end)
910          common->has_skip_in_assert_back = TRUE;
911      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
912      break;      break;
913    
# Line 860  while (cc < ccend) Line 921  while (cc < ccend)
921  return TRUE;  return TRUE;
922  }  }
923    
924    static BOOL is_accelerated_repeat(pcre_uchar *cc)
925    {
926    switch(*cc)
927      {
928      case OP_TYPESTAR:
929      case OP_TYPEMINSTAR:
930      case OP_TYPEPLUS:
931      case OP_TYPEMINPLUS:
932      case OP_TYPEPOSSTAR:
933      case OP_TYPEPOSPLUS:
934      return (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI);
935    
936      case OP_STAR:
937      case OP_MINSTAR:
938      case OP_PLUS:
939      case OP_MINPLUS:
940      case OP_POSSTAR:
941      case OP_POSPLUS:
942    
943      case OP_STARI:
944      case OP_MINSTARI:
945      case OP_PLUSI:
946      case OP_MINPLUSI:
947      case OP_POSSTARI:
948      case OP_POSPLUSI:
949    
950      case OP_NOTSTAR:
951      case OP_NOTMINSTAR:
952      case OP_NOTPLUS:
953      case OP_NOTMINPLUS:
954      case OP_NOTPOSSTAR:
955      case OP_NOTPOSPLUS:
956    
957      case OP_NOTSTARI:
958      case OP_NOTMINSTARI:
959      case OP_NOTPLUSI:
960      case OP_NOTMINPLUSI:
961      case OP_NOTPOSSTARI:
962      case OP_NOTPOSPLUSI:
963      return TRUE;
964    
965      case OP_CLASS:
966      case OP_NCLASS:
967    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
968      case OP_XCLASS:
969      cc += (*cc == OP_XCLASS) ? GET(cc, 1) : (int)(1 + (32 / sizeof(pcre_uchar)));
970    #else
971      cc += (1 + (32 / sizeof(pcre_uchar)));
972    #endif
973    
974      switch(*cc)
975        {
976        case OP_CRSTAR:
977        case OP_CRMINSTAR:
978        case OP_CRPLUS:
979        case OP_CRMINPLUS:
980        case OP_CRPOSSTAR:
981        case OP_CRPOSPLUS:
982        return TRUE;
983        }
984      break;
985      }
986    return FALSE;
987    }
988    
989    static SLJIT_INLINE void detect_fast_fail(compiler_common *common, pcre_uchar *cc, int *private_data_start, sljit_si depth)
990    {
991      pcre_uchar *next_alt;
992    
993      SLJIT_ASSERT(*cc == OP_BRA || *cc == OP_CBRA);
994    
995      if (*cc == OP_CBRA && common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
996        return;
997    
998      next_alt = bracketend(cc) - (1 + LINK_SIZE);
999      if (*next_alt != OP_KET || PRIVATE_DATA(next_alt) != 0)
1000        return;
1001    
1002      do
1003        {
1004        next_alt = cc + GET(cc, 1);
1005    
1006        cc += 1 + LINK_SIZE + ((*cc == OP_CBRA) ? IMM2_SIZE : 0);
1007    
1008        while (TRUE)
1009          {
1010          switch(*cc)
1011            {
1012            case OP_SOD:
1013            case OP_SOM:
1014            case OP_SET_SOM:
1015            case OP_NOT_WORD_BOUNDARY:
1016            case OP_WORD_BOUNDARY:
1017            case OP_EODN:
1018            case OP_EOD:
1019            case OP_CIRC:
1020            case OP_CIRCM:
1021            case OP_DOLL:
1022            case OP_DOLLM:
1023            /* Zero width assertions. */
1024            cc++;
1025            continue;
1026            }
1027          break;
1028          }
1029    
1030        if (depth > 0 && (*cc == OP_BRA || *cc == OP_CBRA))
1031          detect_fast_fail(common, cc, private_data_start, depth - 1);
1032    
1033        if (is_accelerated_repeat(cc))
1034          {
1035          common->private_data_ptrs[(cc + 1) - common->start] = *private_data_start;
1036    
1037          if (common->fast_fail_start_ptr == 0)
1038            common->fast_fail_start_ptr = *private_data_start;
1039    
1040          *private_data_start += sizeof(sljit_sw);
1041          common->fast_fail_end_ptr = *private_data_start;
1042    
1043          if (*private_data_start > SLJIT_MAX_LOCAL_SIZE)
1044            return;
1045          }
1046    
1047        cc = next_alt;
1048        }
1049      while (*cc == OP_ALT);
1050    }
1051    
1052  static int get_class_iterator_size(pcre_uchar *cc)  static int get_class_iterator_size(pcre_uchar *cc)
1053  {  {
1054    sljit_ui min;
1055    sljit_ui max;
1056  switch(*cc)  switch(*cc)
1057    {    {
1058    case OP_CRSTAR:    case OP_CRSTAR:
# Line 876  switch(*cc) Line 1067  switch(*cc)
1067    
1068    case OP_CRRANGE:    case OP_CRRANGE:
1069    case OP_CRMINRANGE:    case OP_CRMINRANGE:
1070    if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))    min = GET2(cc, 1);
1071      return 0;    max = GET2(cc, 1 + IMM2_SIZE);
1072    return 2;    if (max == 0)
1073        return (*cc == OP_CRRANGE) ? 2 : 1;
1074      max -= min;
1075      if (max > 2)
1076        max = 2;
1077      return max;
1078    
1079    default:    default:
1080    return 0;    return 0;
# Line 892  pcre_uchar *next; Line 1088  pcre_uchar *next;
1088  pcre_uchar *next_end;  pcre_uchar *next_end;
1089  pcre_uchar *max_end;  pcre_uchar *max_end;
1090  pcre_uchar type;  pcre_uchar type;
1091  sljit_uw length = end - begin;  sljit_sw length = end - begin;
1092  int min, max, i;  int min, max, i;
1093    
1094  /* Detect fixed iterations first. */  /* Detect fixed iterations first. */
# Line 1029  pcre_uchar *alternative; Line 1225  pcre_uchar *alternative;
1225  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1226  int private_data_ptr = *private_data_start;  int private_data_ptr = *private_data_start;
1227  int space, size, bracketlen;  int space, size, bracketlen;
1228    BOOL repeat_check = TRUE;
1229    
1230  while (cc < ccend)  while (cc < ccend)
1231    {    {
# Line 1036  while (cc < ccend) Line 1233  while (cc < ccend)
1233    size = 0;    size = 0;
1234    bracketlen = 0;    bracketlen = 0;
1235    if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)    if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1236      return;      break;
1237    
1238    if (*cc == OP_BRA || *cc == OP_CBRA || *cc == OP_ONCE || *cc == OP_ONCE_NC)    if (repeat_check && (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND))
1239        {
1240      if (detect_repeat(common, cc))      if (detect_repeat(common, cc))
1241        {        {
1242        /* These brackets are converted to repeats, so no global        /* These brackets are converted to repeats, so no global
# Line 1046  while (cc < ccend) Line 1244  while (cc < ccend)
1244        if (cc >= end)        if (cc >= end)
1245          end = bracketend(cc);          end = bracketend(cc);
1246        }        }
1247        }
1248      repeat_check = TRUE;
1249    
1250    switch(*cc)    switch(*cc)
1251      {      {
# Line 1101  while (cc < ccend) Line 1301  while (cc < ccend)
1301      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1302      break;      break;
1303    
1304        case OP_BRAZERO:
1305        case OP_BRAMINZERO:
1306        case OP_BRAPOSZERO:
1307        repeat_check = FALSE;
1308        size = 1;
1309        break;
1310    
1311      CASE_ITERATOR_PRIVATE_DATA_1      CASE_ITERATOR_PRIVATE_DATA_1
1312      space = 1;      space = 1;
1313      size = -2;      size = -2;
# Line 1127  while (cc < ccend) Line 1334  while (cc < ccend)
1334      size = 1;      size = 1;
1335      break;      break;
1336    
1337      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B      case OP_TYPEUPTO:
1338      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1339        space = 2;        space = 2;
1340      size = 1 + IMM2_SIZE;      size = 1 + IMM2_SIZE;
1341      break;      break;
1342    
1343        case OP_TYPEMINUPTO:
1344        space = 2;
1345        size = 1 + IMM2_SIZE;
1346        break;
1347    
1348      case OP_CLASS:      case OP_CLASS:
1349      case OP_NCLASS:      case OP_NCLASS:
1350      size += 1 + 32 / sizeof(pcre_uchar);      size += 1 + 32 / sizeof(pcre_uchar);
# Line 1188  while (cc < ccend) Line 1400  while (cc < ccend)
1400  }  }
1401    
1402  /* Returns with a frame_types (always < 0) if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1403  static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head)  static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL *needs_control_head)
1404  {  {
1405  int length = 0;  int length = 0;
1406  int possessive = 0;  int possessive = 0;
# Line 1281  while (cc < ccend) Line 1493  while (cc < ccend)
1493      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1494      break;      break;
1495    
1496        case OP_THEN:
1497        stack_restore = TRUE;
1498        if (common->control_head_ptr != 0)
1499          *needs_control_head = TRUE;
1500        cc ++;
1501        break;
1502    
1503      default:      default:
1504      stack_restore = TRUE;      stack_restore = TRUE;
1505      /* Fall through. */      /* Fall through. */
# Line 1348  while (cc < ccend) Line 1567  while (cc < ccend)
1567      case OP_CLASS:      case OP_CLASS:
1568      case OP_NCLASS:      case OP_NCLASS:
1569      case OP_XCLASS:      case OP_XCLASS:
1570        case OP_CALLOUT:
1571    
1572      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1573      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 1392  while (cc < ccend) Line 1612  while (cc < ccend)
1612      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1613      if (!setsom_found)      if (!setsom_found)
1614        {        {
1615        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0));
1616        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1617        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1618        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
# Line 1408  while (cc < ccend) Line 1628  while (cc < ccend)
1628      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1629      if (!setmark_found)      if (!setmark_found)
1630        {        {
1631        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr);
1632        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1633        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1634        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
# Line 1421  while (cc < ccend) Line 1641  while (cc < ccend)
1641      case OP_RECURSE:      case OP_RECURSE:
1642      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1643        {        {
1644        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0));
1645        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1646        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1647        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
# Line 1430  while (cc < ccend) Line 1650  while (cc < ccend)
1650        }        }
1651      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1652        {        {
1653        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr);
1654        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1655        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1656        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
# Line 1439  while (cc < ccend) Line 1659  while (cc < ccend)
1659        }        }
1660      if (common->capture_last_ptr != 0 && !capture_last_found)      if (common->capture_last_ptr != 0 && !capture_last_found)
1661        {        {
1662        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr);
1663        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1664        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1665        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
# Line 1455  while (cc < ccend) Line 1675  while (cc < ccend)
1675      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1676      if (common->capture_last_ptr != 0 && !capture_last_found)      if (common->capture_last_ptr != 0 && !capture_last_found)
1677        {        {
1678        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr);
1679        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1680        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1681        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
# Line 1465  while (cc < ccend) Line 1685  while (cc < ccend)
1685      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1686      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1687      stackpos += (int)sizeof(sljit_sw);      stackpos += (int)sizeof(sljit_sw);
1688      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset));
1689      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1));
1690      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1691      stackpos += (int)sizeof(sljit_sw);      stackpos += (int)sizeof(sljit_sw);
1692      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
# Line 1496  while (cc < ccend) Line 1716  while (cc < ccend)
1716    size = 0;    size = 0;
1717    switch(*cc)    switch(*cc)
1718      {      {
1719        case OP_KET:
1720        if (PRIVATE_DATA(cc) != 0)
1721          {
1722          private_data_length++;
1723          SLJIT_ASSERT(PRIVATE_DATA(cc + 1) != 0);
1724          cc += PRIVATE_DATA(cc + 1);
1725          }
1726        cc += 1 + LINK_SIZE;
1727        break;
1728    
1729      case OP_ASSERT:      case OP_ASSERT:
1730      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1731      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1507  while (cc < ccend) Line 1737  while (cc < ccend)
1737      case OP_SBRAPOS:      case OP_SBRAPOS:
1738      case OP_SCOND:      case OP_SCOND:
1739      private_data_length++;      private_data_length++;
1740        SLJIT_ASSERT(PRIVATE_DATA(cc) != 0);
1741      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1742      break;      break;
1743    
# Line 1664  do Line 1895  do
1895    
1896      switch(*cc)      switch(*cc)
1897        {        {
1898          case OP_KET:
1899          if (PRIVATE_DATA(cc) != 0)
1900            {
1901            count = 1;
1902            srcw[0] = PRIVATE_DATA(cc);
1903            SLJIT_ASSERT(PRIVATE_DATA(cc + 1) != 0);
1904            cc += PRIVATE_DATA(cc + 1);
1905            }
1906          cc += 1 + LINK_SIZE;
1907          break;
1908    
1909        case OP_ASSERT:        case OP_ASSERT:
1910        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1911        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1831  do Line 2073  do
2073            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
2074            stackptr += sizeof(sljit_sw);            stackptr += sizeof(sljit_sw);
2075            }            }
2076          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), srcw[count]);
2077          tmp1empty = FALSE;          tmp1empty = FALSE;
2078          tmp1next = FALSE;          tmp1next = FALSE;
2079          }          }
# Line 1842  do Line 2084  do
2084            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
2085            stackptr += sizeof(sljit_sw);            stackptr += sizeof(sljit_sw);
2086            }            }
2087          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), srcw[count]);
2088          tmp2empty = FALSE;          tmp2empty = FALSE;
2089          tmp1next = TRUE;          tmp1next = TRUE;
2090          }          }
# Line 1852  do Line 2094  do
2094        if (tmp1next)        if (tmp1next)
2095          {          {
2096          SLJIT_ASSERT(!tmp1empty);          SLJIT_ASSERT(!tmp1empty);
2097          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count], TMP1, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), srcw[count], TMP1, 0);
2098          tmp1empty = stackptr >= stacktop;          tmp1empty = stackptr >= stacktop;
2099          if (!tmp1empty)          if (!tmp1empty)
2100            {            {
# Line 1864  do Line 2106  do
2106        else        else
2107          {          {
2108          SLJIT_ASSERT(!tmp2empty);          SLJIT_ASSERT(!tmp2empty);
2109          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count], TMP2, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), srcw[count], TMP2, 0);
2110          tmp2empty = stackptr >= stacktop;          tmp2empty = stackptr >= stacktop;
2111          if (!tmp2empty)          if (!tmp2empty)
2112            {            {
# Line 1966  while (list) Line 2208  while (list)
2208    }    }
2209  }  }
2210    
2211  static SLJIT_INLINE void add_jump(struct sljit_compiler *compiler, jump_list **list, struct sljit_jump* jump)  static SLJIT_INLINE void add_jump(struct sljit_compiler *compiler, jump_list **list, struct sljit_jump *jump)
2212  {  {
2213  jump_list *list_item = sljit_alloc_memory(compiler, sizeof(jump_list));  jump_list *list_item = sljit_alloc_memory(compiler, sizeof(jump_list));
2214  if (list_item)  if (list_item)
# Line 1980  if (list_item) Line 2222  if (list_item)
2222  static void add_stub(compiler_common *common, struct sljit_jump *start)  static void add_stub(compiler_common *common, struct sljit_jump *start)
2223  {  {
2224  DEFINE_COMPILER;  DEFINE_COMPILER;
2225  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list *list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
2226    
2227  if (list_item)  if (list_item)
2228    {    {
# Line 1994  if (list_item) Line 2236  if (list_item)
2236  static void flush_stubs(compiler_common *common)  static void flush_stubs(compiler_common *common)
2237  {  {
2238  DEFINE_COMPILER;  DEFINE_COMPILER;
2239  stub_list* list_item = common->stubs;  stub_list *list_item = common->stubs;
2240    
2241  while (list_item)  while (list_item)
2242    {    {
# Line 2006  while (list_item) Line 2248  while (list_item)
2248  common->stubs = NULL;  common->stubs = NULL;
2249  }  }
2250    
2251  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static void add_label_addr(compiler_common *common, sljit_uw *update_addr)
2252  {  {
2253  DEFINE_COMPILER;  DEFINE_COMPILER;
2254    label_addr_list *label_addr;
2255    
2256  OP2(SLJIT_SUB | SLJIT_SET_E, CALL_COUNT, 0, CALL_COUNT, 0, SLJIT_IMM, 1);  label_addr = sljit_alloc_memory(compiler, sizeof(label_addr_list));
2257  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  if (label_addr == NULL)
2258      return;
2259    label_addr->label = LABEL();
2260    label_addr->update_addr = update_addr;
2261    label_addr->next = common->label_addrs;
2262    common->label_addrs = label_addr;
2263    }
2264    
2265    static SLJIT_INLINE void count_match(compiler_common *common)
2266    {
2267    DEFINE_COMPILER;
2268    
2269    OP2(SLJIT_SUB | SLJIT_SET_E, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1);
2270    add_jump(compiler, &common->calllimit, JUMP(SLJIT_ZERO));
2271  }  }
2272    
2273  static SLJIT_INLINE void allocate_stack(compiler_common *common, int size)  static SLJIT_INLINE void allocate_stack(compiler_common *common, int size)
# Line 2019  static SLJIT_INLINE void allocate_stack( Line 2275  static SLJIT_INLINE void allocate_stack(
2275  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2276  DEFINE_COMPILER;  DEFINE_COMPILER;
2277    
2278    SLJIT_ASSERT(size > 0);
2279  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
2280  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2281  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2282  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
2283  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2284  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS0, TMP1, 0);
2285  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, TMP1, 0);
2286  #endif  #endif
2287  add_stub(common, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));  add_stub(common, CMP(SLJIT_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));
2288  }  }
2289    
2290  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2291  {  {
2292  DEFINE_COMPILER;  DEFINE_COMPILER;
2293    
2294    SLJIT_ASSERT(size > 0);
2295  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
2296  }  }
2297    
2298    static sljit_uw * allocate_read_only_data(compiler_common *common, sljit_uw size)
2299    {
2300    DEFINE_COMPILER;
2301    sljit_uw *result;
2302    
2303    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
2304      return NULL;
2305    
2306    result = (sljit_uw *)SLJIT_MALLOC(size + sizeof(sljit_uw), compiler->allocator_data);
2307    if (SLJIT_UNLIKELY(result == NULL))
2308      {
2309      sljit_set_compiler_memory_error(compiler);
2310      return NULL;
2311      }
2312    
2313    *(void**)result = common->read_only_data_head;
2314    common->read_only_data_head = (void *)result;
2315    return result + 1;
2316    }
2317    
2318    static void free_read_only_data(void *current, void *allocator_data)
2319    {
2320    void *next;
2321    
2322    SLJIT_UNUSED_ARG(allocator_data);
2323    
2324    while (current != NULL)
2325      {
2326      next = *(void**)current;
2327      SLJIT_FREE(current, allocator_data);
2328      current = next;
2329      }
2330    }
2331    
2332  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
2333  {  {
2334  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2045  int i; Line 2338  int i;
2338  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2339  SLJIT_ASSERT(length > 1);  SLJIT_ASSERT(length > 1);
2340  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2341  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
2342  if (length < 8)  if (length < 8)
2343    {    {
2344    for (i = 1; i < length; i++)    for (i = 1; i < length; i++)
2345      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(i), SLJIT_R0, 0);
2346    }    }
2347  else  else
2348    {    {
2349    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);    GET_LOCAL_BASE(SLJIT_R1, 0, OVECTOR_START);
2350    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);    OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, length - 1);
2351    loop = LABEL();    loop = LABEL();
2352    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_sw), SLJIT_R0, 0);
2353    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, 1);
2354    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_NOT_ZERO, loop);
2355    }    }
2356  }  }
2357    
2358    static SLJIT_INLINE void reset_fast_fail(compiler_common *common)
2359    {
2360    DEFINE_COMPILER;
2361    sljit_si i;
2362    
2363    SLJIT_ASSERT(common->fast_fail_start_ptr < common->fast_fail_end_ptr);
2364    
2365    OP2(SLJIT_SUB, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2366    for (i = common->fast_fail_start_ptr; i < common->fast_fail_end_ptr; i += sizeof(sljit_sw))
2367      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), i, TMP1, 0);
2368    }
2369    
2370  static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)  static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2371  {  {
2372  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2071  int i; Line 2376  int i;
2376  SLJIT_ASSERT(length > 1);  SLJIT_ASSERT(length > 1);
2377  /* OVECTOR(1) contains the "string begin - 1" constant. */  /* OVECTOR(1) contains the "string begin - 1" constant. */
2378  if (length > 2)  if (length > 2)
2379    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1));
2380  if (length < 8)  if (length < 8)
2381    {    {
2382    for (i = 2; i < length; i++)    for (i = 2; i < length; i++)
2383      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(i), TMP1, 0);
2384    }    }
2385  else  else
2386    {    {
# Line 2084  else Line 2389  else
2389    loop = LABEL();    loop = LABEL();
2390    OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2391    OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2392    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_NOT_ZERO, loop);
2393    }    }
2394    
2395  OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2396  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2397    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->mark_ptr, SLJIT_IMM, 0);
2398  if (common->control_head_ptr != 0)  if (common->control_head_ptr != 0)
2399    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_IMM, 0);
2400  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2401  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->start_ptr);
2402  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2403  }  }
2404    
# Line 2115  while (current != NULL) Line 2420  while (current != NULL)
2420      SLJIT_ASSERT_STOP();      SLJIT_ASSERT_STOP();
2421      break;      break;
2422      }      }
2423      SLJIT_ASSERT(current > (sljit_sw*)current[-1]);
2424    current = (sljit_sw*)current[-1];    current = (sljit_sw*)current[-1];
2425    }    }
2426  return -1;  return -1;
# Line 2127  struct sljit_label *loop; Line 2433  struct sljit_label *loop;
2433  struct sljit_jump *early_quit;  struct sljit_jump *early_quit;
2434    
2435  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2436  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  OP1(SLJIT_MOV, SLJIT_S2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1));
2437  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(1), STR_PTR, 0);
2438    
2439  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_R0, 0, ARGUMENTS, 0);
2440  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2441    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);    OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr);
2442  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offset_count));  OP1(SLJIT_MOV_SI, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, offset_count));
2443  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2444    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_R2, 0);
2445  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));  OP2(SLJIT_SUB, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
2446  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, begin));
2447  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_S0, 0, OVECTOR_START);
2448  /* Unlikely, but possible */  /* Unlikely, but possible */
2449  early_quit = CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);  early_quit = CMP(SLJIT_EQUAL, SLJIT_R1, 0, SLJIT_IMM, 0);
2450  loop = LABEL();  loop = LABEL();
2451  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);  OP2(SLJIT_SUB, SLJIT_S1, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
2452  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));  OP2(SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, sizeof(sljit_sw));
2453  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2454  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2455  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, UCHAR_SHIFT);
2456  #endif  #endif
2457  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_R2), sizeof(int), SLJIT_S1, 0);
2458  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1);
2459  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_NOT_ZERO, loop);
2460  JUMPHERE(early_quit);  JUMPHERE(early_quit);
2461    
2462  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2463  if (topbracket > 1)  if (topbracket > 1)
2464    {    {
2465    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));    GET_LOCAL_BASE(SLJIT_R0, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
2466    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, topbracket + 1);
2467    
2468    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_S2. */
2469    loop = LABEL();    loop = LABEL();
2470    OP1(SLJIT_MOVU, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -(2 * (sljit_sw)sizeof(sljit_sw)));    OP1(SLJIT_MOVU, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R0), -(2 * (sljit_sw)sizeof(sljit_sw)));
2471    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1);
2472    CMPTO(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG3, 0, loop);    CMPTO(SLJIT_EQUAL, SLJIT_R2, 0, SLJIT_S2, 0, loop);
2473    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_R1, 0);
2474    }    }
2475  else  else
2476    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 2175  static SLJIT_INLINE void return_with_par Line 2481  static SLJIT_INLINE void return_with_par
2481  DEFINE_COMPILER;  DEFINE_COMPILER;
2482  struct sljit_jump *jump;  struct sljit_jump *jump;
2483    
2484  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_S1, str_end_must_be_saved_reg2);
2485  SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0  SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0
2486    && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));    && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2487    
2488  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_R1, 0, ARGUMENTS, 0);
2489  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2490  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count));  OP1(SLJIT_MOV_SI, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R1), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
2491  CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);  CMPTO(SLJIT_SIG_LESS, SLJIT_R2, 0, SLJIT_IMM, 2, quit);
2492    
2493  /* Store match begin and end. */  /* Store match begin and end. */
2494  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_S0, 0, SLJIT_MEM1(SLJIT_R1), SLJIT_OFFSETOF(jit_arguments, begin));
2495  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));  OP1(SLJIT_MOV, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R1), SLJIT_OFFSETOF(jit_arguments, offsets));
2496    
2497  jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);  jump = CMP(SLJIT_SIG_LESS, SLJIT_R2, 0, SLJIT_IMM, 3);
2498  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);  OP2(SLJIT_SUB, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_S0, 0);
2499  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2500  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, UCHAR_SHIFT);
2501  #endif  #endif
2502  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_R1), 2 * sizeof(int), SLJIT_R2, 0);
2503  JUMPHERE(jump);  JUMPHERE(jump);
2504    
2505  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);  OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);
2506  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_S1, 0, STR_END, 0, SLJIT_S0, 0);
2507  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2508  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, UCHAR_SHIFT);
2509  #endif  #endif
2510  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_R1), sizeof(int), SLJIT_S1, 0);
2511    
2512  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_S0, 0);
2513  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2514  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, UCHAR_SHIFT);
2515  #endif  #endif
2516  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_R1), 0, SLJIT_R2, 0);
2517    
2518  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2519  }  }
# Line 2221  struct sljit_jump *jump; Line 2527  struct sljit_jump *jump;
2527  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2528    {    {
2529    /* The value of -1 must be kept for start_used_ptr! */    /* The value of -1 must be kept for start_used_ptr! */
2530    OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, SLJIT_IMM, 1);
2531    /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting    /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting
2532    is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */    is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */
2533    jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_PTR, 0);    jump = CMP(SLJIT_LESS_EQUAL, TMP1, 0, STR_PTR, 0);
2534    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0);
2535    JUMPHERE(jump);    JUMPHERE(jump);
2536    }    }
2537  else if (common->mode == JIT_PARTIAL_HARD_COMPILE)  else if (common->mode == JIT_PARTIAL_HARD_COMPILE)
2538    {    {
2539    jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    jump = CMP(SLJIT_LESS_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0);
2540    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0);
2541    JUMPHERE(jump);    JUMPHERE(jump);
2542    }    }
2543  }  }
2544    
2545  static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar* cc)  static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar *cc)
2546  {  {
2547  /* Detects if the character has an othercase. */  /* Detects if the character has an othercase. */
2548  unsigned int c;  unsigned int c;
# Line 2279  if (common->utf && c > 127) Line 2585  if (common->utf && c > 127)
2585  return TABLE_GET(c, common->fcc, c);  return TABLE_GET(c, common->fcc, c);
2586  }  }
2587    
2588  static unsigned int char_get_othercase_bit(compiler_common *common, pcre_uchar* cc)  static unsigned int char_get_othercase_bit(compiler_common *common, pcre_uchar *cc)
2589  {  {
2590  /* Detects if the character and its othercase has only 1 bit difference. */  /* Detects if the character and its othercase has only 1 bit difference. */
2591  unsigned int c, oc, bit;  unsigned int c, oc, bit;
# Line 2357  return (bit < 256) ? ((0 << 8) | bit) : Line 2663  return (bit < 256) ? ((0 << 8) | bit) :
2663    
2664  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2665  {  {
2666  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2667  DEFINE_COMPILER;  DEFINE_COMPILER;
2668  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2669    
# Line 2367  if (common->mode == JIT_COMPILE) Line 2673  if (common->mode == JIT_COMPILE)
2673    return;    return;
2674    
2675  if (!force)  if (!force)
2676    jump = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    jump = CMP(SLJIT_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0);
2677  else if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  else if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2678    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);    jump = CMP(SLJIT_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, SLJIT_IMM, -1);
2679    
2680  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2681    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0);
2682  else  else
2683    {    {
2684    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2393  struct sljit_jump *jump; Line 2699  struct sljit_jump *jump;
2699    
2700  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2701    {    {
2702    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));    add_jump(compiler, end_reached, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2703    return;    return;
2704    }    }
2705    
2706  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_LESS, STR_PTR, 0, STR_END, 0);
2707  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2708    {    {
2709    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));    add_jump(compiler, end_reached, CMP(SLJIT_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0));
2710    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0);
2711    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
2712    }    }
2713  else  else
2714    {    {
2715    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));    add_jump(compiler, end_reached, CMP(SLJIT_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0));
2716    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2717      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2718    else    else
# Line 2422  struct sljit_jump *jump; Line 2728  struct sljit_jump *jump;
2728    
2729  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2730    {    {
2731    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));    add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2732    return;    return;
2733    }    }
2734    
2735  /* Partial matching mode. */  /* Partial matching mode. */
2736  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_LESS, STR_PTR, 0, STR_END, 0);
2737  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_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0));
2738  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2739    {    {
2740    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0);
2741    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2742    }    }
2743  else  else
# Line 2444  else Line 2750  else
2750  JUMPHERE(jump);  JUMPHERE(jump);
2751  }  }
2752    
2753  static void read_char(compiler_common *common)  static void peek_char(compiler_common *common, sljit_ui max)
2754  {  {
2755  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2756  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2757  DEFINE_COMPILER;  DEFINE_COMPILER;
2758  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2759  struct sljit_jump *jump;  struct sljit_jump *jump;
2760  #endif  #endif
2761    
2762    SLJIT_UNUSED_ARG(max);
2763    
2764  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2765  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2766  if (common->utf)  if (common->utf)
2767    {    {
2768  #if defined COMPILE_PCRE8    if (max < 128) return;
2769    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);  
2770  #elif defined COMPILE_PCRE16    jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2771    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 #endif /* COMPILE_PCRE[8|16] */  
2772    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2773      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2774    JUMPHERE(jump);    JUMPHERE(jump);
2775    }    }
2776  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2777  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
2778    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2779    if (common->utf)
2780      {
2781      if (max < 0xd800) return;
2782    
2783      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2784      jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2785      /* TMP2 contains the high surrogate. */
2786      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2787      OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2788      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2789      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2790      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2791      JUMPHERE(jump);
2792      }
2793    #endif
2794  }  }
2795    
2796  static void peek_char(compiler_common *common)  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2797    
2798    static BOOL is_char7_bitset(const sljit_ub *bitset, BOOL nclass)
2799  {  {
2800  /* Reads the character into TMP1, keeps STR_PTR.  /* Tells whether the character codes below 128 are enough
2801  Does not check STR_END. TMP2 Destroyed. */  to determine a match. */
2802    const sljit_ub value = nclass ? 0xff : 0;
2803    const sljit_ub *end = bitset + 32;
2804    
2805    bitset += 16;
2806    do
2807      {
2808      if (*bitset++ != value)
2809        return FALSE;
2810      }
2811    while (bitset < end);
2812    return TRUE;
2813    }
2814    
2815    static void read_char7_type(compiler_common *common, BOOL full_read)
2816    {
2817    /* Reads the precise character type of a character into TMP1, if the character
2818    is less than 128. Otherwise it returns with zero. Does not check STR_END. The
2819    full_read argument tells whether characters above max are accepted or not. */
2820  DEFINE_COMPILER;  DEFINE_COMPILER;
 #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  
2821  struct sljit_jump *jump;  struct sljit_jump *jump;
 #endif  
2822    
2823  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  SLJIT_ASSERT(common->utf);
2824  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  
2825  if (common->utf)  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2826    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2827    
2828    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2829    
2830    if (full_read)
2831    {    {
2832  #if defined COMPILE_PCRE8    jump = CMP(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2833    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);
2834  #elif defined COMPILE_PCRE16    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
   jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);  
 #endif /* COMPILE_PCRE[8|16] */  
   add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));  
   OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  
2835    JUMPHERE(jump);    JUMPHERE(jump);
2836    }    }
 #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  
2837  }  }
2838    
2839  static void read_char8_type(compiler_common *common)  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2840    
2841    static void read_char_range(compiler_common *common, sljit_ui min, sljit_ui max, BOOL update_str_ptr)
2842  {  {
2843  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */  /* Reads the precise value of a character into TMP1, if the character is
2844    between min and max (c >= min && c <= max). Otherwise it returns with a value
2845    outside the range. Does not check STR_END. */
2846  DEFINE_COMPILER;  DEFINE_COMPILER;
2847  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2848  struct sljit_jump *jump;  struct sljit_jump *jump;
2849  #endif  #endif
2850    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2851    struct sljit_jump *jump2;
2852    #endif
2853    
2854  #ifdef SUPPORT_UTF  SLJIT_UNUSED_ARG(update_str_ptr);
2855    SLJIT_UNUSED_ARG(min);
2856    SLJIT_UNUSED_ARG(max);
2857    SLJIT_ASSERT(min <= max);
2858    
2859    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2860    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2861    
2862    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2863  if (common->utf)  if (common->utf)
2864    {    {
2865    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    if (max < 128 && !update_str_ptr) return;
2866    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
2867  #if defined COMPILE_PCRE8    jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2868    /* This can be an extra read in some situations, but hopefully    if (min >= 0x10000)
2869    it is needed in most cases. */      {
2870    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xf0);
2871    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);      if (update_str_ptr)
2872    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));        OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2873    JUMPHERE(jump);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2874  #elif defined COMPILE_PCRE16      jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0x7);
2875    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2876    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2877    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2878        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2879        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2880        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2881        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2882        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2883        if (!update_str_ptr)
2884          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2885        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2886        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2887        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2888        JUMPHERE(jump2);
2889        if (update_str_ptr)
2890          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2891        }
2892      else if (min >= 0x800 && max <= 0xffff)
2893        {
2894        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xe0);
2895        if (update_str_ptr)
2896          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2897        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2898        jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xf);
2899        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2900        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2901        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2902        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2903        if (!update_str_ptr)
2904          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2905        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2906        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2907        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2908        JUMPHERE(jump2);
2909        if (update_str_ptr)
2910          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2911        }
2912      else if (max >= 0x800)
2913        add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2914      else if (max < 128)
2915        {
2916        OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2917        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2918        }
2919      else
2920        {
2921        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2922        if (!update_str_ptr)
2923          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2924        else
2925          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2926        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2927        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2928        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2929        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2930        if (update_str_ptr)
2931          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2932        }
2933    JUMPHERE(jump);    JUMPHERE(jump);
2934      }
2935    #endif
2936    
2937    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2938    if (common->utf)
2939      {
2940      if (max >= 0x10000)
2941        {
2942        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2943        jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2944        /* TMP2 contains the high surrogate. */
2945        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2946        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2947        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2948        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2949        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2950        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2951        JUMPHERE(jump);
2952        return;
2953        }
2954    
2955      if (max < 0xd800 && !update_str_ptr) return;
2956    
2957    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2958    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2959    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2960    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);    if (update_str_ptr)
2961    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2962    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    if (max >= 0xd800)
2963  #elif defined COMPILE_PCRE32      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
   OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  
   jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  
2964    JUMPHERE(jump);    JUMPHERE(jump);
 #endif /* COMPILE_PCRE[8|16|32] */  
   return;  
2965    }    }
2966  #endif /* SUPPORT_UTF */  #endif
2967    }
2968    
2969    static SLJIT_INLINE void read_char(compiler_common *common)
2970    {
2971    read_char_range(common, 0, READ_CHAR_MAX, TRUE);
2972    }
2973    
2974    static void read_char8_type(compiler_common *common, BOOL update_str_ptr)
2975    {
2976    /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */
2977    DEFINE_COMPILER;
2978    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2979    struct sljit_jump *jump;
2980    #endif
2981    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2982    struct sljit_jump *jump2;
2983    #endif
2984    
2985    SLJIT_UNUSED_ARG(update_str_ptr);
2986    
2987  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2988  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));
2989  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  
2990    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2991    if (common->utf)
2992      {
2993      /* This can be an extra read in some situations, but hopefully
2994      it is needed in most cases. */
2995      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2996      jump = CMP(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2997      if (!update_str_ptr)
2998        {
2999        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
3000        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3001        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
3002        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
3003        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
3004        OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
3005        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
3006        jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 255);
3007        OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
3008        JUMPHERE(jump2);
3009        }
3010      else
3011        add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
3012      JUMPHERE(jump);
3013      return;
3014      }
3015    #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
3016    
3017    #if !defined COMPILE_PCRE8
3018  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
3019  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
3020  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 255);
3021  #endif  #endif
3022  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
3023  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if !defined COMPILE_PCRE8
3024  JUMPHERE(jump);  JUMPHERE(jump);
3025  #endif  #endif
3026    
3027    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
3028    if (common->utf && update_str_ptr)
3029      {
3030      /* Skip low surrogate if necessary. */
3031      OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
3032      jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
3033      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3034      JUMPHERE(jump);
3035      }
3036    #endif /* SUPPORT_UTF && COMPILE_PCRE16 */
3037  }  }
3038    
3039  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
# Line 2561  if (common->utf) Line 3050  if (common->utf)
3050    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
3051    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));
3052    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);
3053    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
3054    return;    return;
3055    }    }
3056  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
# Line 2572  if (common->utf) Line 3061  if (common->utf)
3061    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
3062    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3063    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);
3064    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL);
3065    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3066    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3067    return;    return;
# Line 2582  if (common->utf) Line 3071  if (common->utf)
3071  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));
3072  }  }
3073    
3074  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)
3075  {  {
3076  /* 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. */
3077  DEFINE_COMPILER;  DEFINE_COMPILER;
3078    struct sljit_jump *jump;
3079    
3080  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
3081    {    {
3082    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
3083    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpifmatch ? SLJIT_NOT_ZERO : SLJIT_ZERO));
3084    }    }
3085  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
3086    {    {
3087    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    if (jumpifmatch)
3088    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);      {
3089    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);      add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR));
3090    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);      add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
3091    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));      }
3092      else
3093        {
3094        jump = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
3095        add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
3096        JUMPHERE(jump);
3097        }
3098    }    }
3099  else  else
3100    {    {
3101    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
3102    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_EQUAL : SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
3103    }    }
3104  }  }
3105    
# Line 2613  else Line 3109  else
3109  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
3110  {  {
3111  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
3112  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. */
3113  DEFINE_COMPILER;  DEFINE_COMPILER;
3114  struct sljit_jump *jump;  struct sljit_jump *jump;
3115    
3116  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3117  /* Searching for the first zero. */  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
3118  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
 jump = JUMP(SLJIT_C_NOT_ZERO);  
 /* Two byte sequence. */  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  
3119  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
3120  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
3121  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
3122  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
3123    /* Searching for the first zero. */
3124    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
3125    jump = JUMP(SLJIT_NOT_ZERO);
3126    /* Two byte sequence. */
3127    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3128    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
3129  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
3130    
3131  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);  JUMPHERE(jump);
 jump = JUMP(SLJIT_C_NOT_ZERO);  
 /* Three byte sequence. */  
3132  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3133  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
3134  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
3135  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);  
3136  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
3137  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  
3138    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10000);
3139    jump = JUMP(SLJIT_NOT_ZERO);
3140    /* Three byte sequence. */
3141  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));
3142  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));  
3143  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
3144    
3145  /* Four byte sequence. */  /* Four byte sequence. */
3146  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  JUMPHERE(jump);
3147  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
3148  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
3149    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
3150    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
3151  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);  
3152  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
3153  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(4));
3154    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3155    }
3156    
3157    static void do_utfreadchar16(compiler_common *common)
3158    {
3159    /* Fast decoding a UTF-8 character. TMP1 contains the first byte
3160    of the character (>= 0xc0). Return value in TMP1. */
3161    DEFINE_COMPILER;
3162    struct sljit_jump *jump;
3163    
3164    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3165    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
3166    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
3167    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
3168  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);  
3169  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
3170  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));  
3171  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));  /* Searching for the first zero. */
3172    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
3173    jump = JUMP(SLJIT_NOT_ZERO);
3174    /* Two byte sequence. */
3175    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3176    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3177    
3178    JUMPHERE(jump);
3179    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
3180    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_NOT_ZERO);
3181    /* This code runs only in 8 bit mode. No need to shift the value. */
3182    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3183    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3184    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
3185    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
3186  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
3187  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
3188  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));  /* Three byte sequence. */
3189    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
3190  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3191  }  }
3192    
# Line 2679  struct sljit_jump *compare; Line 3201  struct sljit_jump *compare;
3201  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3202    
3203  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);
3204  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_NOT_ZERO);
3205  /* Two byte sequence. */  /* Two byte sequence. */
3206  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
3207  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));
3208  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
3209    /* The upper 5 bits are known at this point. */
3210    compare = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0x3);
3211  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
3212  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
3213  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);  
3214  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
3215  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3216    
3217  JUMPHERE(compare);  JUMPHERE(compare);
3218  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
3219  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
3220    
3221  /* 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_sw)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);  
 }  
   
 #elif defined 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);  
   
3222  JUMPHERE(jump);  JUMPHERE(jump);
3223  /* Combine two 16 bit characters. */  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
3224  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
3225  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);  
3226  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3227  }  }
3228    
3229  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE8 */
3230    
3231  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3232    
# Line 2791  if (firstline) Line 3287  if (firstline)
3287      {      {
3288      mainloop = LABEL();      mainloop = LABEL();
3289      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));
3290      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      end = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3291      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
3292      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
3293      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);      CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);
3294      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);      CMPTO(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);
3295      JUMPHERE(end);      JUMPHERE(end);
3296      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_SP), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3297      }      }
3298    else    else
3299      {      {
3300      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      end = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3301      mainloop = LABEL();      mainloop = LABEL();
3302      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
3303      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->first_line_end, STR_PTR, 0);
3304      read_char(common);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
3305      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
3306      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_LESS, STR_PTR, 0, STR_END, 0, mainloop);
3307      JUMPHERE(end);      JUMPHERE(end);
3308      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->first_line_end, STR_PTR, 0);
3309      set_jumps(newline, LABEL());      set_jumps(newline, LABEL());
3310      }      }
3311    
# Line 2822  if (newlinecheck) Line 3318  if (newlinecheck)
3318    {    {
3319    newlinelabel = LABEL();    newlinelabel = LABEL();
3320    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));
3321    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3322    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3323    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);
3324    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL);
3325  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3326    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3327  #endif  #endif
# Line 2845  if (readuchar) Line 3341  if (readuchar)
3341    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3342    
3343  if (newlinecheck)  if (newlinecheck)
3344    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);    CMPTO(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);
3345    
3346  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));
3347  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3348  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
3349  if (common->utf)  if (common->utf)
3350    {    {
3351    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
3352    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
3353    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3354    JUMPHERE(singlechar);    JUMPHERE(singlechar);
# Line 2860  if (common->utf) Line 3356  if (common->utf)
3356  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
3357  if (common->utf)  if (common->utf)
3358    {    {
3359    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
3360    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3361    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);
3362    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL);
3363    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3364    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3365    JUMPHERE(singlechar);    JUMPHERE(singlechar);
# Line 2881  if (newlinecheck) Line 3377  if (newlinecheck)
3377  return mainloop;  return mainloop;
3378  }  }
3379    
3380  #define MAX_N_CHARS 3  #define MAX_N_CHARS 16
3381    #define MAX_N_BYTES 8
3382    
3383  static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)  static SLJIT_INLINE void add_prefix_byte(pcre_uint8 byte, pcre_uint8 *bytes)
3384  {  {
3385  DEFINE_COMPILER;  pcre_uint8 len = bytes[0];
3386  struct sljit_label *start;  int i;
 struct sljit_jump *quit;  
 pcre_uint32 chars[MAX_N_CHARS * 2];  
 pcre_uchar *cc = common->start + 1 + LINK_SIZE;  
 int location = 0;  
 pcre_int32 len, c, bit, caseless;  
 int must_stop;  
3387    
3388  /* We do not support alternatives now. */  if (len == 255)
3389  if (*(common->start + GET(common->start, 1)) == OP_ALT)    return;
3390    return FALSE;  
3391    if (len == 0)
3392      {
3393      bytes[0] = 1;
3394      bytes[1] = byte;
3395      return;
3396      }
3397    
3398    for (i = len; i > 0; i--)
3399      if (bytes[i] == byte)
3400        return;
3401    
3402    if (len >= MAX_N_BYTES - 1)
3403      {
3404      bytes[0] = 255;
3405      return;
3406      }
3407    
3408    len++;
3409    bytes[len] = byte;
3410    bytes[0] = len;
3411    }
3412    
3413    static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, pcre_uint8 *bytes, int max_chars, pcre_uint32 *rec_count)
3414    {
3415    /* Recursive function, which scans prefix literals. */
3416    BOOL last, any, caseless;
3417    int len, repeat, len_save, consumed = 0;
3418    pcre_uint32 chr, mask;
3419    pcre_uchar *alternative, *cc_save, *oc;
3420    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3421    pcre_uchar othercase[8];
3422    #elif defined SUPPORT_UTF && defined COMPILE_PCRE16
3423    pcre_uchar othercase[2];
3424    #else
3425    pcre_uchar othercase[1];
3426    #endif
3427    
3428    repeat = 1;
3429  while (TRUE)  while (TRUE)
3430    {    {
3431    caseless = 0;    if (*rec_count == 0)
3432    must_stop = 1;      return 0;
3433    switch(*cc)    (*rec_count)--;
3434      {  
3435      case OP_CHAR:    last = TRUE;
3436      must_stop = 0;    any = FALSE;
3437      cc++;    caseless = FALSE;
     break;  
3438    
3439      switch (*cc)
3440        {
3441      case OP_CHARI:      case OP_CHARI:
3442      caseless = 1;      caseless = TRUE;
3443      must_stop = 0;      case OP_CHAR:
3444        last = FALSE;
3445      cc++;      cc++;
3446      break;      break;
3447    
# Line 2930  while (TRUE) Line 3460  while (TRUE)
3460      cc++;      cc++;
3461      continue;      continue;
3462    
3463        case OP_ASSERT:
3464        case OP_ASSERT_NOT:
3465        case OP_ASSERTBACK:
3466        case OP_ASSERTBACK_NOT:
3467        cc = bracketend(cc);
3468        continue;
3469    
3470        case OP_PLUSI:
3471        case OP_MINPLUSI:
3472        case OP_POSPLUSI:
3473        caseless = TRUE;
3474      case OP_PLUS:      case OP_PLUS:
3475      case OP_MINPLUS:      case OP_MINPLUS:
3476      case OP_POSPLUS:      case OP_POSPLUS:
3477      cc++;      cc++;
3478      break;      break;
3479    
3480        case OP_EXACTI:
3481        caseless = TRUE;
3482      case OP_EXACT:      case OP_EXACT:
3483        repeat = GET2(cc, 1);
3484        last = FALSE;
3485      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3486      break;      break;
3487    
3488      case OP_PLUSI:      case OP_QUERYI:
3489      case OP_MINPLUSI:      case OP_MINQUERYI:
3490      case OP_POSPLUSI:      case OP_POSQUERYI:
3491      caseless = 1;      caseless = TRUE;
3492        case OP_QUERY:
3493        case OP_MINQUERY:
3494        case OP_POSQUERY:
3495        len = 1;
3496      cc++;      cc++;
3497    #ifdef SUPPORT_UTF
3498        if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3499    #endif
3500        max_chars = scan_prefix(common, cc + len, chars, bytes, max_chars, rec_count);
3501        if (max_chars == 0)
3502          return consumed;
3503        last = FALSE;
3504      break;      break;
3505    
3506      case OP_EXACTI:      case OP_KET:
3507      caseless = 1;      cc += 1 + LINK_SIZE;
3508      cc += 1 + IMM2_SIZE;      continue;
     break;  
3509    
3510      default:      case OP_ALT:
3511      must_stop = 2;      cc += GET(cc, 1);
3512      break;      continue;
     }  
3513    
3514    if (must_stop == 2)      case OP_ONCE:
3515        break;      case OP_ONCE_NC:
3516        case OP_BRA:
3517        case OP_BRAPOS:
3518        case OP_CBRA:
3519        case OP_CBRAPOS:
3520        alternative = cc + GET(cc, 1);
3521        while (*alternative == OP_ALT)
3522          {
3523          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, bytes, max_chars, rec_count);
3524          if (max_chars == 0)
3525            return consumed;
3526          alternative += GET(alternative, 1);
3527          }
3528    
3529    len = 1;      if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
3530  #ifdef SUPPORT_UTF        cc += IMM2_SIZE;
3531    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);      cc += 1 + LINK_SIZE;
3532        continue;
3533    
3534        case OP_CLASS:
3535    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3536        if (common->utf && !is_char7_bitset((const pcre_uint8 *)(cc + 1), FALSE)) return consumed;
3537  #endif  #endif
3538        any = TRUE;
3539        cc += 1 + 32 / sizeof(pcre_uchar);
3540        break;
3541    
3542    if (caseless && char_has_othercase(common, cc))      case OP_NCLASS:
3543    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3544        if (common->utf) return consumed;
3545    #endif
3546        any = TRUE;
3547        cc += 1 + 32 / sizeof(pcre_uchar);
3548        break;
3549    
3550    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3551        case OP_XCLASS:
3552    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3553        if (common->utf) return consumed;
3554    #endif
3555        any = TRUE;
3556        cc += GET(cc, 1);
3557        break;
3558    #endif
3559    
3560        case OP_DIGIT:
3561    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3562        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_digit, FALSE))
3563          return consumed;
3564    #endif
3565        any = TRUE;
3566        cc++;
3567        break;
3568    
3569        case OP_WHITESPACE:
3570    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3571        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_space, FALSE))
3572          return consumed;
3573    #endif
3574        any = TRUE;
3575        cc++;
3576        break;
3577    
3578        case OP_WORDCHAR:
3579    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3580        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_word, FALSE))
3581          return consumed;
3582    #endif
3583        any = TRUE;
3584        cc++;
3585        break;
3586    
3587        case OP_NOT:
3588        case OP_NOTI:
3589        cc++;
3590        /* Fall through. */
3591        case OP_NOT_DIGIT:
3592        case OP_NOT_WHITESPACE:
3593        case OP_NOT_WORDCHAR:
3594        case OP_ANY:
3595        case OP_ALLANY:
3596    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3597        if (common->utf) return consumed;
3598    #endif
3599        any = TRUE;
3600        cc++;
3601        break;
3602    
3603    #ifdef SUPPORT_UCP
3604        case OP_NOTPROP:
3605        case OP_PROP:
3606    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3607        if (common->utf) return consumed;
3608    #endif
3609        any = TRUE;
3610        cc += 1 + 2;
3611        break;
3612    #endif
3613    
3614        case OP_TYPEEXACT:
3615        repeat = GET2(cc, 1);
3616        cc += 1 + IMM2_SIZE;
3617        continue;
3618    
3619        case OP_NOTEXACT:
3620        case OP_NOTEXACTI:
3621    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3622        if (common->utf) return consumed;
3623    #endif
3624        any = TRUE;
3625        repeat = GET2(cc, 1);
3626        cc += 1 + IMM2_SIZE + 1;
3627        break;
3628    
3629        default:
3630        return consumed;
3631        }
3632    
3633      if (any)
3634      {      {
3635      caseless = char_get_othercase_bit(common, cc);  #if defined COMPILE_PCRE8
3636      if (caseless == 0)      mask = 0xff;
3637        return FALSE;  #elif defined COMPILE_PCRE16
3638  #ifdef COMPILE_PCRE8      mask = 0xffff;
3639      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));  #elif defined COMPILE_PCRE32
3640        mask = 0xffffffff;
3641  #else  #else
3642      if ((caseless & 0x100) != 0)      SLJIT_ASSERT_STOP();
3643        caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));  #endif
3644    
3645        do
3646          {
3647          chars[0] = mask;
3648          chars[1] = mask;
3649          bytes[0] = 255;
3650    
3651          consumed++;
3652          if (--max_chars == 0)
3653            return consumed;
3654          chars += 2;
3655          bytes += MAX_N_BYTES;
3656          }
3657        while (--repeat > 0);
3658    
3659        repeat = 1;
3660        continue;
3661        }
3662    
3663      len = 1;
3664    #ifdef SUPPORT_UTF
3665      if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3666    #endif
3667    
3668      if (caseless && char_has_othercase(common, cc))
3669        {
3670    #ifdef SUPPORT_UTF
3671        if (common->utf)
3672          {
3673          GETCHAR(chr, cc);
3674          if ((int)PRIV(ord2utf)(char_othercase(common, chr), othercase) != len)
3675            return consumed;
3676          }
3677      else      else
       caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));  
3678  #endif  #endif
3679          {
3680          chr = *cc;
3681          othercase[0] = TABLE_GET(chr, common->fcc, chr);
3682          }
3683      }      }
3684    else    else
3685      caseless = 0;      caseless = FALSE;
3686    
3687    while (len > 0 && location < MAX_N_CHARS * 2)    len_save = len;
3688      cc_save = cc;
3689      while (TRUE)
3690      {      {
3691      c = *cc;      oc = othercase;
3692      bit = 0;      do
     if (len == (caseless & 0xff))  
3693        {        {
3694        bit = caseless >> 8;        chr = *cc;
3695        c |= bit;  #ifdef COMPILE_PCRE32
3696          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3697            return consumed;
3698    #endif
3699          add_prefix_byte((pcre_uint8)chr, bytes);
3700    
3701          mask = 0;
3702          if (caseless)
3703            {
3704            add_prefix_byte((pcre_uint8)*oc, bytes);
3705            mask = *cc ^ *oc;
3706            chr |= mask;
3707            }
3708    
3709    #ifdef COMPILE_PCRE32
3710          if (chars[0] == NOTACHAR && chars[1] == 0)
3711    #else
3712          if (chars[0] == NOTACHAR)
3713    #endif
3714            {
3715            chars[0] = chr;
3716            chars[1] = mask;
3717            }
3718          else
3719            {
3720            mask |= chars[0] ^ chr;
3721            chr |= mask;
3722            chars[0] = chr;
3723            chars[1] |= mask;
3724            }
3725    
3726          len--;
3727          consumed++;
3728          if (--max_chars == 0)
3729            return consumed;
3730          chars += 2;
3731          bytes += MAX_N_BYTES;
3732          cc++;
3733          oc++;
3734        }        }
3735        while (len > 0);
3736    
3737      chars[location] = c;      if (--repeat == 0)
3738      chars[location + 1] = bit;        break;
3739    
3740      len--;      len = len_save;
3741      location += 2;      cc = cc_save;
3742      cc++;      }
3743    
3744      repeat = 1;
3745      if (last)
3746        return consumed;
3747      }
3748    }
3749    
3750    #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
3751    
3752    static sljit_si character_to_int32(pcre_uchar chr)
3753    {
3754    sljit_si value = (sljit_si)chr;
3755    #if defined COMPILE_PCRE8
3756    #define SSE2_COMPARE_TYPE_INDEX 0
3757    return (value << 24) | (value << 16) | (value << 8) | value;
3758    #elif defined COMPILE_PCRE16
3759    #define SSE2_COMPARE_TYPE_INDEX 1
3760    return (value << 16) | value;
3761    #elif defined COMPILE_PCRE32
3762    #define SSE2_COMPARE_TYPE_INDEX 2
3763    return value;
3764    #else
3765    #error "Unsupported unit width"
3766    #endif
3767    }
3768    
3769    static SLJIT_INLINE void fast_forward_first_char2_sse2(compiler_common *common, pcre_uchar char1, pcre_uchar char2)
3770    {
3771    DEFINE_COMPILER;
3772    struct sljit_label *start;
3773    struct sljit_jump *quit[3];
3774    struct sljit_jump *nomatch;
3775    sljit_ub instruction[8];
3776    sljit_si tmp1_ind = sljit_get_register_index(TMP1);
3777    sljit_si tmp2_ind = sljit_get_register_index(TMP2);
3778    sljit_si str_ptr_ind = sljit_get_register_index(STR_PTR);
3779    BOOL load_twice = FALSE;
3780    pcre_uchar bit;
3781    
3782    bit = char1 ^ char2;
3783    if (!is_powerof2(bit))
3784      bit = 0;
3785    
3786    if ((char1 != char2) && bit == 0)
3787      load_twice = TRUE;
3788    
3789    quit[0] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3790    
3791    /* First part (unaligned start) */
3792    
3793    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, character_to_int32(char1 | bit));
3794    
3795    SLJIT_ASSERT(tmp1_ind < 8 && tmp2_ind == 1);
3796    
3797    /* MOVD xmm, r/m32 */
3798    instruction[0] = 0x66;
3799    instruction[1] = 0x0f;
3800    instruction[2] = 0x6e;
3801    instruction[3] = 0xc0 | (2 << 3) | tmp1_ind;
3802    sljit_emit_op_custom(compiler, instruction, 4);
3803    
3804    if (char1 != char2)
3805      {
3806      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, character_to_int32(bit != 0 ? bit : char2));
3807    
3808      /* MOVD xmm, r/m32 */
3809      instruction[3] = 0xc0 | (3 << 3) | tmp1_ind;
3810      sljit_emit_op_custom(compiler, instruction, 4);
3811      }
3812    
3813    /* PSHUFD xmm1, xmm2/m128, imm8 */
3814    instruction[2] = 0x70;
3815    instruction[3] = 0xc0 | (2 << 3) | 2;
3816    instruction[4] = 0;
3817    sljit_emit_op_custom(compiler, instruction, 5);
3818    
3819    if (char1 != char2)
3820      {
3821      /* PSHUFD xmm1, xmm2/m128, imm8 */
3822      instruction[3] = 0xc0 | (3 << 3) | 3;
3823      instruction[4] = 0;
3824      sljit_emit_op_custom(compiler, instruction, 5);
3825      }
3826    
3827    OP2(SLJIT_AND, TMP2, 0, STR_PTR, 0, SLJIT_IMM, 0xf);
3828    OP2(SLJIT_AND, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, ~0xf);
3829    
3830    /* MOVDQA xmm1, xmm2/m128 */
3831    #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3832    
3833    if (str_ptr_ind < 8)
3834      {
3835      instruction[2] = 0x6f;
3836      instruction[3] = (0 << 3) | str_ptr_ind;
3837      sljit_emit_op_custom(compiler, instruction, 4);
3838    
3839      if (load_twice)
3840        {
3841        instruction[3] = (1 << 3) | str_ptr_ind;
3842        sljit_emit_op_custom(compiler, instruction, 4);
3843      }      }
3844      }
3845    else
3846      {
3847      instruction[1] = 0x41;
3848      instruction[2] = 0x0f;
3849      instruction[3] = 0x6f;
3850      instruction[4] = (0 << 3) | (str_ptr_ind & 0x7);
3851      sljit_emit_op_custom(compiler, instruction, 5);
3852    
3853      if (load_twice)
3854        {
3855        instruction[4] = (1 << 3) | str_ptr_ind;
3856        sljit_emit_op_custom(compiler, instruction, 5);
3857        }
3858      instruction[1] = 0x0f;
3859      }
3860    
3861    if (location >= MAX_N_CHARS * 2 || must_stop != 0)  #else
3862    
3863    instruction[2] = 0x6f;
3864    instruction[3] = (0 << 3) | str_ptr_ind;
3865    sljit_emit_op_custom(compiler, instruction, 4);
3866    
3867    if (load_twice)
3868      {
3869      instruction[3] = (1 << 3) | str_ptr_ind;
3870      sljit_emit_op_custom(compiler, instruction, 4);
3871      }
3872    
3873    #endif
3874    
3875    if (bit != 0)
3876      {
3877      /* POR xmm1, xmm2/m128 */
3878      instruction[2] = 0xeb;
3879      instruction[3] = 0xc0 | (0 << 3) | 3;
3880      sljit_emit_op_custom(compiler, instruction, 4);
3881      }
3882    
3883    /* PCMPEQB/W/D xmm1, xmm2/m128 */
3884    instruction[2] = 0x74 + SSE2_COMPARE_TYPE_INDEX;
3885    instruction[3] = 0xc0 | (0 << 3) | 2;
3886    sljit_emit_op_custom(compiler, instruction, 4);
3887    
3888    if (load_twice)
3889      {
3890      instruction[3] = 0xc0 | (1 << 3) | 3;
3891      sljit_emit_op_custom(compiler, instruction, 4);
3892      }
3893    
3894    /* PMOVMSKB reg, xmm */
3895    instruction[2] = 0xd7;
3896    instruction[3] = 0xc0 | (tmp1_ind << 3) | 0;
3897    sljit_emit_op_custom(compiler, instruction, 4);
3898    
3899    if (load_twice)
3900      {
3901      OP1(SLJIT_MOV, TMP3, 0, TMP2, 0);
3902      instruction[3] = 0xc0 | (tmp2_ind << 3) | 1;
3903      sljit_emit_op_custom(compiler, instruction, 4);
3904    
3905      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
3906      OP1(SLJIT_MOV, TMP2, 0, TMP3, 0);
3907      }
3908    
3909    OP2(SLJIT_ASHR, TMP1, 0, TMP1, 0, TMP2, 0);
3910    
3911    /* BSF r32, r/m32 */
3912    instruction[0] = 0x0f;
3913    instruction[1] = 0xbc;
3914    instruction[2] = 0xc0 | (tmp1_ind << 3) | tmp1_ind;
3915    sljit_emit_op_custom(compiler, instruction, 3);
3916    
3917    nomatch = JUMP(SLJIT_ZERO);
3918    
3919    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3920    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3921    quit[1] = JUMP(SLJIT_JUMP);
3922    
3923    JUMPHERE(nomatch);
3924    
3925    start = LABEL();
3926    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 16);
3927    quit[2] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3928    
3929    /* Second part (aligned) */
3930    
3931    instruction[0] = 0x66;
3932    instruction[1] = 0x0f;
3933    
3934    /* MOVDQA xmm1, xmm2/m128 */
3935    #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3936    
3937    if (str_ptr_ind < 8)
3938      {
3939      instruction[2] = 0x6f;
3940      instruction[3] = (0 << 3) | str_ptr_ind;
3941      sljit_emit_op_custom(compiler, instruction, 4);
3942    
3943      if (load_twice)
3944        {
3945        instruction[3] = (1 << 3) | str_ptr_ind;
3946        sljit_emit_op_custom(compiler, instruction, 4);
3947        }
3948      }
3949    else
3950      {
3951      instruction[1] = 0x41;
3952      instruction[2] = 0x0f;
3953      instruction[3] = 0x6f;
3954      instruction[4] = (0 << 3) | (str_ptr_ind & 0x7);
3955      sljit_emit_op_custom(compiler, instruction, 5);
3956    
3957      if (load_twice)
3958        {
3959        instruction[4] = (1 << 3) | str_ptr_ind;
3960        sljit_emit_op_custom(compiler, instruction, 5);
3961        }
3962      instruction[1] = 0x0f;
3963      }
3964    
3965    #else
3966    
3967    instruction[2] = 0x6f;
3968    instruction[3] = (0 << 3) | str_ptr_ind;
3969    sljit_emit_op_custom(compiler, instruction, 4);
3970    
3971    if (load_twice)
3972      {
3973      instruction[3] = (1 << 3) | str_ptr_ind;
3974      sljit_emit_op_custom(compiler, instruction, 4);
3975      }
3976    
3977    #endif
3978    
3979    if (bit != 0)
3980      {
3981      /* POR xmm1, xmm2/m128 */
3982      instruction[2] = 0xeb;
3983      instruction[3] = 0xc0 | (0 << 3) | 3;
3984      sljit_emit_op_custom(compiler, instruction, 4);
3985      }
3986    
3987    /* PCMPEQB/W/D xmm1, xmm2/m128 */
3988    instruction[2] = 0x74 + SSE2_COMPARE_TYPE_INDEX;
3989    instruction[3] = 0xc0 | (0 << 3) | 2;
3990    sljit_emit_op_custom(compiler, instruction, 4);
3991    
3992    if (load_twice)
3993      {
3994      instruction[3] = 0xc0 | (1 << 3) | 3;
3995      sljit_emit_op_custom(compiler, instruction, 4);
3996      }
3997    
3998    /* PMOVMSKB reg, xmm */
3999    instruction[2] = 0xd7;
4000    instruction[3] = 0xc0 | (tmp1_ind << 3) | 0;
4001    sljit_emit_op_custom(compiler, instruction, 4);
4002    
4003    if (load_twice)
4004      {
4005      instruction[3] = 0xc0 | (tmp2_ind << 3) | 1;
4006      sljit_emit_op_custom(compiler, instruction, 4);
4007    
4008      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
4009      }
4010    
4011    /* BSF r32, r/m32 */
4012    instruction[0] = 0x0f;
4013    instruction[1] = 0xbc;
4014    instruction[2] = 0xc0 | (tmp1_ind << 3) | tmp1_ind;
4015    sljit_emit_op_custom(compiler, instruction, 3);
4016    
4017    JUMPTO(SLJIT_ZERO, start);
4018    
4019    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4020    
4021    start = LABEL();
4022    SET_LABEL(quit[0], start);
4023    SET_LABEL(quit[1], start);
4024    SET_LABEL(quit[2], start);
4025    }
4026    
4027    #undef SSE2_COMPARE_TYPE_INDEX
4028    
4029    #endif
4030    
4031    static void fast_forward_first_char2(compiler_common *common, pcre_uchar char1, pcre_uchar char2, sljit_si offset)
4032    {
4033    DEFINE_COMPILER;
4034    struct sljit_label *start;
4035    struct sljit_jump *quit;
4036    struct sljit_jump *found;
4037    pcre_uchar mask;
4038    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4039    struct sljit_label *utf_start = NULL;
4040    struct sljit_jump *utf_quit = NULL;
4041    #endif
4042    BOOL has_first_line_end = (common->first_line_end != 0);
4043    
4044    if (offset > 0)
4045      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(offset));
4046    
4047    if (has_first_line_end)
4048      {
4049      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
4050    
4051      OP2(SLJIT_ADD, STR_END, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end, SLJIT_IMM, IN_UCHARS(offset + 1));
4052    #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4053      if (sljit_x86_is_cmov_available())
4054        {
4055        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_END, 0, TMP3, 0);
4056        sljit_x86_emit_cmov(compiler, SLJIT_GREATER, STR_END, TMP3, 0);
4057        }
4058    #endif
4059        {
4060        quit = CMP(SLJIT_LESS_EQUAL, STR_END, 0, TMP3, 0);
4061        OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
4062        JUMPHERE(quit);
4063        }
4064      }
4065    
4066    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4067    if (common->utf && offset > 0)
4068      utf_start = LABEL();
4069    #endif
4070    
4071    #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4072    
4073    /* SSE2 accelerated first character search. */
4074    
4075    if (sljit_x86_is_sse2_available())
4076      {
4077      fast_forward_first_char2_sse2(common, char1, char2);
4078    
4079      SLJIT_ASSERT(common->mode == JIT_COMPILE || offset == 0);
4080      if (common->mode == JIT_COMPILE)
4081        {
4082        /* In complete mode, we don't need to run a match when STR_PTR == STR_END. */
4083        SLJIT_ASSERT(common->forced_quit_label == NULL);
4084        OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);
4085        add_jump(compiler, &common->forced_quit, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
4086    
4087    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4088        if (common->utf && offset > 0)
4089          {
4090          SLJIT_ASSERT(common->mode == JIT_COMPILE);
4091    
4092          OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-offset));
4093          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
4094    #if defined COMPILE_PCRE8
4095          OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);
4096          CMPTO(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, utf_start);
4097    #elif defined COMPILE_PCRE16
4098          OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4099          CMPTO(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0xdc00, utf_start);
4100    #else
4101    #error "Unknown code width"
4102    #endif
4103          OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
4104          }
4105    #endif
4106    
4107        if (offset > 0)
4108          OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(offset));
4109        }
4110      else if (sljit_x86_is_cmov_available())
4111        {
4112        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, STR_END, 0);
4113        sljit_x86_emit_cmov(compiler, SLJIT_GREATER_EQUAL, STR_PTR, has_first_line_end ? SLJIT_MEM1(SLJIT_SP) : STR_END, has_first_line_end ? common->first_line_end : 0);
4114        }
4115      else
4116        {
4117        quit = CMP(SLJIT_LESS, STR_PTR, 0, STR_END, 0);
4118        OP1(SLJIT_MOV, STR_PTR, 0, has_first_line_end ? SLJIT_MEM1(SLJIT_SP) : STR_END, has_first_line_end ? common->first_line_end : 0);
4119        JUMPHERE(quit);
4120        }
4121    
4122      if (has_first_line_end)
4123        OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
4124      return;
4125      }
4126    
4127    #endif
4128    
4129    quit = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
4130    
4131    start = LABEL();
4132    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4133    
4134    if (char1 == char2)
4135      found = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, char1);
4136    else
4137      {
4138      mask = char1 ^ char2;
4139      if (is_powerof2(mask))
4140        {
4141        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, mask);
4142        found = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, char1 | mask);
4143        }
4144      else
4145        {
4146        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, char1);
4147        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL);
4148        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, char2);
4149        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_EQUAL);
4150        found = JUMP(SLJIT_NOT_ZERO);
4151        }
4152      }
4153    
4154    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
4155    CMPTO(SLJIT_LESS, STR_PTR, 0, STR_END, 0, start);
4156    
4157    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4158    if (common->utf && offset > 0)
4159      utf_quit = JUMP(SLJIT_JUMP);
4160    #endif
4161    
4162    JUMPHERE(found);
4163    
4164    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4165    if (common->utf && offset > 0)
4166      {
4167      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-offset));
4168      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
4169    #if defined COMPILE_PCRE8
4170      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);
4171      CMPTO(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, utf_start);
4172    #elif defined COMPILE_PCRE16
4173      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4174      CMPTO(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0xdc00, utf_start);
4175    #else
4176    #error "Unknown code width"
4177    #endif
4178      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
4179      JUMPHERE(utf_quit);
4180      }
4181    #endif
4182    
4183    JUMPHERE(quit);
4184    
4185    if (has_first_line_end)
4186      {
4187      quit = CMP(SLJIT_LESS, STR_PTR, 0, STR_END, 0);
4188      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end);
4189      if (offset > 0)
4190        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(offset));
4191      JUMPHERE(quit);
4192      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
4193      }
4194    
4195    if (offset > 0)
4196      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(offset));
4197    }
4198    
4199    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
4200    {
4201    DEFINE_COMPILER;
4202    struct sljit_label *start;
4203    struct sljit_jump *quit;
4204    pcre_uint32 chars[MAX_N_CHARS * 2];
4205    pcre_uint8 bytes[MAX_N_CHARS * MAX_N_BYTES];
4206    pcre_uint8 ones[MAX_N_CHARS];
4207    int offsets[3];
4208    pcre_uint32 mask;
4209    pcre_uint8 *byte_set, *byte_set_end;
4210    int i, max, from;
4211    int range_right = -1, range_len = 3 - 1;
4212    sljit_ub *update_table = NULL;
4213    BOOL in_range;
4214    pcre_uint32 rec_count;
4215    
4216    for (i = 0; i < MAX_N_CHARS; i++)
4217      {
4218      chars[i << 1] = NOTACHAR;
4219      chars[(i << 1) + 1] = 0;
4220      bytes[i * MAX_N_BYTES] = 0;
4221      }
4222    
4223    rec_count = 10000;
4224    max = scan_prefix(common, common->start, chars, bytes, MAX_N_CHARS, &rec_count);
4225    
4226    if (max <= 1)
4227      return FALSE;
4228    
4229    for (i = 0; i < max; i++)
4230      {
4231      mask = chars[(i << 1) + 1];
4232      ones[i] = ones_in_half_byte[mask & 0xf];
4233      mask >>= 4;
4234      while (mask != 0)
4235        {
4236        ones[i] += ones_in_half_byte[mask & 0xf];
4237        mask >>= 4;
4238        }
4239      }
4240    
4241    in_range = FALSE;
4242    from = 0;   /* Prevent compiler "uninitialized" warning */
4243    for (i = 0; i <= max; i++)
4244      {
4245      if (in_range && (i - from) > range_len && (bytes[(i - 1) * MAX_N_BYTES] <= 4))
4246        {
4247        range_len = i - from;
4248        range_right = i - 1;
4249        }
4250    
4251      if (i < max && bytes[i * MAX_N_BYTES] < 255)
4252        {
4253        if (!in_range)
4254          {
4255          in_range = TRUE;
4256          from = i;
4257          }
4258        }
4259      else if (in_range)
4260        in_range = FALSE;
4261      }
4262    
4263    if (range_right >= 0)
4264      {
4265      update_table = (sljit_ub *)allocate_read_only_data(common, 256);
4266      if (update_table == NULL)
4267        return TRUE;
4268      memset(update_table, IN_UCHARS(range_len), 256);
4269    
4270      for (i = 0; i < range_len; i++)
4271        {
4272        byte_set = bytes + ((range_right - i) * MAX_N_BYTES);
4273        SLJIT_ASSERT(byte_set[0] > 0 && byte_set[0] < 255);
4274        byte_set_end = byte_set + byte_set[0];
4275        byte_set++;
4276        while (byte_set <= byte_set_end)
4277          {
4278          if (update_table[*byte_set] > IN_UCHARS(i))
4279            update_table[*byte_set] = IN_UCHARS(i);
4280          byte_set++;
4281          }
4282        }
4283      }
4284    
4285    offsets[0] = -1;
4286    /* Scan forward. */
4287    for (i = 0; i < max; i++)
4288      if (ones[i] <= 2) {
4289        offsets[0] = i;
4290      break;      break;
4291    }    }
4292    
4293  /* At least two characters are required. */  if (offsets[0] < 0 && range_right < 0)
4294  if (location < 2 * 2)    return FALSE;
4295    
4296    if (offsets[0] >= 0)
4297      {
4298      /* Scan backward. */
4299      offsets[1] = -1;
4300      for (i = max - 1; i > offsets[0]; i--)
4301        if (ones[i] <= 2 && i != range_right)
4302          {
4303          offsets[1] = i;
4304          break;
4305          }
4306    
4307      /* This case is handled better by fast_forward_first_char. */
4308      if (offsets[1] == -1 && offsets[0] == 0 && range_right < 0)
4309      return FALSE;      return FALSE;
4310    
4311      offsets[2] = -1;
4312      /* We only search for a middle character if there is no range check. */
4313      if (offsets[1] >= 0 && range_right == -1)
4314        {
4315        /* Scan from middle. */
4316        for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
4317          if (ones[i] <= 2)
4318            {
4319            offsets[2] = i;
4320            break;
4321            }
4322    
4323        if (offsets[2] == -1)
4324          {
4325          for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
4326            if (ones[i] <= 2)
4327              {
4328              offsets[2] = i;
4329              break;
4330              }
4331          }
4332        }
4333    
4334      SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
4335      SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
4336    
4337      chars[0] = chars[offsets[0] << 1];
4338      chars[1] = chars[(offsets[0] << 1) + 1];
4339      if (offsets[2] >= 0)
4340        {
4341        chars[2] = chars[offsets[2] << 1];
4342        chars[3] = chars[(offsets[2] << 1) + 1];
4343        }
4344      if (offsets[1] >= 0)
4345        {
4346        chars[4] = chars[offsets[1] << 1];
4347        chars[5] = chars[(offsets[1] << 1) + 1];
4348        }
4349      }
4350    
4351    max -= 1;
4352  if (firstline)  if (firstline)
4353    {    {
4354    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
4355      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end);
4356    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
4357    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
4358      quit = CMP(SLJIT_LESS_EQUAL, STR_END, 0, TMP1, 0);
4359      OP1(SLJIT_MOV, STR_END, 0, TMP1, 0);
4360      JUMPHERE(quit);
4361    }    }
4362  else  else
4363    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
4364    
4365    #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
4366    if (range_right >= 0)
4367      OP1(SLJIT_MOV, RETURN_ADDR, 0, SLJIT_IMM, (sljit_sw)update_table);
4368    #endif
4369    
4370  start = LABEL();  start = LABEL();
4371  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
4372    
4373  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  SLJIT_ASSERT(range_right >= 0 || offsets[0] >= 0);
4374  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
4375  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  if (range_right >= 0)
4376  if (chars[1] != 0)    {
4377    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);  #if defined COMPILE_PCRE8 || (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
4378  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right));
4379  if (location > 2 * 2)  #else
4380    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right + 1) - 1);
4381  if (chars[3] != 0)  #endif
4382    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);  
4383  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);  #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
4384  if (location > 2 * 2)    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(RETURN_ADDR, TMP1), 0);
4385    {  #else
4386    if (chars[5] != 0)    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)update_table);
4387      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);  #endif
4388    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4389      CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, start);
4390      }
4391    
4392    if (offsets[0] >= 0)
4393      {
4394      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
4395      if (offsets[1] >= 0)
4396        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
4397      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
4398    
4399      if (chars[1] != 0)
4400        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
4401      CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
4402      if (offsets[2] >= 0)
4403        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
4404    
4405      if (offsets[1] >= 0)
4406        {
4407        if (chars[5] != 0)
4408          OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
4409        CMPTO(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
4410        }
4411    
4412      if (offsets[2] >= 0)
4413        {
4414        if (chars[3] != 0)
4415          OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
4416        CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
4417        }
4418      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
4419    }    }
 OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
4420    
4421  JUMPHERE(quit);  JUMPHERE(quit);
4422    
4423  if (firstline)  if (firstline)
4424      {
4425      if (range_right >= 0)
4426        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end);
4427    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
4428      if (range_right >= 0)
4429        {
4430        quit = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
4431        OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
4432        JUMPHERE(quit);
4433        }
4434      }
4435  else  else
4436    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
4437  return TRUE;  return TRUE;
4438  }  }
4439    
4440  #undef MAX_N_CHARS  #undef MAX_N_CHARS
4441    #undef MAX_N_BYTES
4442    
4443  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless)
4444  {  {
4445  DEFINE_COMPILER;  pcre_uchar oc;
 struct sljit_label *start;  
 struct sljit_jump *quit;  
 struct sljit_jump *found;  
 pcre_uchar oc, bit;  
   
 if (firstline)  
   {  
   SLJIT_ASSERT(common->first_line_end != 0);  
   OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);  
   OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);  
   }  
   
 start = LABEL();  
 quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  
 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
4446    
4447  oc = first_char;  oc = first_char;
4448  if (caseless)  if (caseless)
4449    {    {
4450    oc = TABLE_GET(first_char, common->fcc, first_char);    oc = TABLE_GET(first_char, common->fcc, first_char);
4451  #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)  #if defined SUPPORT_UTF && !defined COMPILE_PCRE8
4452    if (first_char > 127 && common->utf)    if (first_char > 127 && common->utf)
4453      oc = UCD_OTHERCASE(first_char);      oc = UCD_OTHERCASE(first_char);
4454  #endif  #endif
4455    }    }
 if (first_char == oc)  
   found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, first_char);  
 else  
   {  
   bit = first_char ^ oc;  
   if (is_powerof2(bit))  
     {  
     OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);  
     found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);  
     }  
   else  
     {  
     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char);  
     OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);  
     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);  
     OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);  
     found = JUMP(SLJIT_C_NOT_ZERO);  
     }  
   }  
   
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 JUMPTO(SLJIT_JUMP, start);  
 JUMPHERE(found);  
 JUMPHERE(quit);  
4456    
4457  if (firstline)  fast_forward_first_char2(common, first_char, oc, 0);
   OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);  
4458  }  }
4459    
4460  static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline)  static SLJIT_INLINE void fast_forward_newline(compiler_common *common)
4461  {  {
4462  DEFINE_COMPILER;  DEFINE_COMPILER;
4463  struct sljit_label *loop;  struct sljit_label *loop;
# Line 3118  struct sljit_jump *foundcr = NULL; Line 4468  struct sljit_jump *foundcr = NULL;
4468  struct sljit_jump *notfoundnl;  struct sljit_jump *notfoundnl;
4469  jump_list *newline = NULL;  jump_list *newline = NULL;
4470    
4471  if (firstline)  if (common->first_line_end != 0)
4472    {    {
   SLJIT_ASSERT(common->first_line_end != 0);  
4473    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
4474    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end);
4475    }    }
4476    
4477  if (common->nltype == NLTYPE_FIXED && common->newline > 255)  if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4478    {    {
4479    lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    lastchar = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
4480    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
4481    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
4482    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
4483    firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);    firstchar = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP2, 0);
4484    
4485    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
4486    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);
4487    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_GREATER_EQUAL);
4488  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4489    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
4490  #endif  #endif
# Line 3143  if (common->nltype == NLTYPE_FIXED && co Line 4492  if (common->nltype == NLTYPE_FIXED && co
4492    
4493    loop = LABEL();    loop = LABEL();
4494    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));
4495    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
4496    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
4497    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
4498    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);    CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);
4499    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);    CMPTO(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);
4500    
4501    JUMPHERE(quit);    JUMPHERE(quit);
4502    JUMPHERE(firstchar);    JUMPHERE(firstchar);
4503    JUMPHERE(lastchar);    JUMPHERE(lastchar);
4504    
4505    if (firstline)    if (common->first_line_end != 0)
4506      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
4507    return;    return;
4508    }    }
4509    
4510  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
4511  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
4512  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);  firstchar = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP2, 0);
4513  skip_char_back(common);  skip_char_back(common);
4514    
4515  loop = LABEL();  loop = LABEL();
4516  read_char(common);  common->ff_newline_shortcut = loop;
4517  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  
4518    read_char_range(common, common->nlmin, common->nlmax, TRUE);
4519    lastchar = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
4520  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
4521    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
4522  check_newlinechar(common, common->nltype, &newline, FALSE);  check_newlinechar(common, common->nltype, &newline, FALSE);
4523  set_jumps(newline, loop);  set_jumps(newline, loop);
4524    
# Line 3175  if (common->nltype == NLTYPE_ANY || comm Line 4526  if (common->nltype == NLTYPE_ANY || comm
4526    {    {
4527    quit = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
4528    JUMPHERE(foundcr);    JUMPHERE(foundcr);
4529    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
4530    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4531    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);
4532    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL);
4533  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4534    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
4535  #endif  #endif
# Line 3189  if (common->nltype == NLTYPE_ANY || comm Line 4540  if (common->nltype == NLTYPE_ANY || comm
4540  JUMPHERE(lastchar);  JUMPHERE(lastchar);
4541  JUMPHERE(firstchar);  JUMPHERE(firstchar);
4542    
4543  if (firstline)  if (common->first_line_end != 0)
4544    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
4545  }  }
4546    
4547  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks);
4548    
4549  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_ub *start_bits)
4550  {  {
4551  DEFINE_COMPILER;  DEFINE_COMPILER;
4552  struct sljit_label *start;  struct sljit_label *start;
4553  struct sljit_jump *quit;  struct sljit_jump *quit;
4554  struct sljit_jump *found = NULL;  struct sljit_jump *found = NULL;
4555  jump_list *matches = NULL;  jump_list *matches = NULL;
 pcre_uint8 inverted_start_bits[32];  
 int i;  
4556  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
4557  struct sljit_jump *jump;  struct sljit_jump *jump;
4558  #endif  #endif
4559    
4560  for (i = 0; i < 32; ++i)  if (common->first_line_end != 0)
   inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);  
   
 if (firstline)  
4561    {    {
   SLJIT_ASSERT(common->first_line_end != 0);  
4562    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
4563    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end);
4564    }    }
4565    
4566  start = LABEL();  start = LABEL();
4567  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
4568  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4569  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4570  if (common->utf)  if (common->utf)
4571    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4572  #endif  #endif
4573    
4574  if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))  if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
4575    {    {
4576  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
4577    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 255);
4578    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
4579    JUMPHERE(jump);    JUMPHERE(jump);
4580  #endif  #endif
4581    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4582    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4583    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
4584    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4585    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);
4586    found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_NOT_ZERO);
4587    }    }
4588    
4589  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 3250  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S Line 4595  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S
4595  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
4596  if (common->utf)  if (common->utf)
4597    {    {
4598    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
4599    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
4600    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4601    }    }
4602  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
4603  if (common->utf)  if (common->utf)
4604    {    {
4605    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
4606    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4607    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);
4608    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL);
4609    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4610    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4611    }    }
# Line 3273  if (matches != NULL) Line 4618  if (matches != NULL)
4618    set_jumps(matches, LABEL());    set_jumps(matches, LABEL());
4619  JUMPHERE(quit);  JUMPHERE(quit);
4620    
4621  if (firstline)  if (common->first_line_end != 0)
4622    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
4623  }  }
4624    
# Line 3289  struct sljit_jump *notfound; Line 4634  struct sljit_jump *notfound;
4634  pcre_uint32 oc, bit;  pcre_uint32 oc, bit;
4635    
4636  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
4637  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->req_char_ptr);
4638  OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, REQ_BYTE_MAX);  OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, REQ_BYTE_MAX);
4639  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);  toolong = CMP(SLJIT_LESS, TMP1, 0, STR_END, 0);
4640  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);  alreadyfound = CMP(SLJIT_LESS, STR_PTR, 0, TMP2, 0);
4641    
4642  if (has_firstchar)  if (has_firstchar)
4643    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
# Line 3300  else Line 4645  else
4645    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);
4646    
4647  loop = LABEL();  loop = LABEL();
4648  notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);  notfound = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, STR_END, 0);
4649    
4650  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(TMP1), 0);
4651  oc = req_char;  oc = req_char;
# Line 3313  if (caseless) Line 4658  if (caseless)
4658  #endif  #endif
4659    }    }
4660  if (req_char == oc)  if (req_char == oc)
4661    found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);    found = CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
4662  else  else
4663    {    {
4664    bit = req_char ^ oc;    bit = req_char ^ oc;
4665    if (is_powerof2(bit))    if (is_powerof2(bit))
4666      {      {
4667      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
4668      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);      found = CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
4669      }      }
4670    else    else
4671      {      {
4672      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);      found = CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
4673      foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);      foundoc = CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, oc);
4674      }      }
4675    }    }
4676  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
# Line 3334  JUMPTO(SLJIT_JUMP, loop); Line 4679  JUMPTO(SLJIT_JUMP, loop);
4679  JUMPHERE(found);  JUMPHERE(found);
4680  if (foundoc)  if (foundoc)
4681    JUMPHERE(foundoc);    JUMPHERE(foundoc);
4682  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->req_char_ptr, TMP1, 0);
4683  JUMPHERE(alreadyfound);  JUMPHERE(alreadyfound);
4684  JUMPHERE(toolong);  JUMPHERE(toolong);
4685  return notfound;  return notfound;
# Line 3354  GET_LOCAL_BASE(TMP3, 0, 0); Line 4699  GET_LOCAL_BASE(TMP3, 0, 0);
4699  mainloop = LABEL();  mainloop = LABEL();
4700  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
4701  OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0);  OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0);
4702  jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);  jump = JUMP(SLJIT_SIG_LESS_EQUAL);
4703    
4704  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
4705  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
# Line 3363  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_I Line 4708  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_I
4708  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
4709    
4710  JUMPHERE(jump);  JUMPHERE(jump);
4711  jump = JUMP(SLJIT_C_SIG_LESS);  jump = JUMP(SLJIT_SIG_LESS);
4712  /* End of dropping frames. */  /* End of dropping frames. */
4713  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
4714    
# Line 3386  struct sljit_jump *jump; Line 4731  struct sljit_jump *jump;
4731    
4732  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
4733    
4734  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), LOCALS0);
4735  /* Get type of the previous char, and put it to LOCALS1. */  /* Get type of the previous char, and put it to LOCALS1. */
4736  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
4737  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
4738  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, SLJIT_IMM, 0);
4739  skipread = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);  skipread = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
4740  skip_char_back(common);  skip_char_back(common);
4741  check_start_used_ptr(common);  check_start_used_ptr(common);
4742  read_char(common);  read_char(common);
# Line 3401  read_char(common); Line 4746  read_char(common);
4746  if (common->use_ucp)  if (common->use_ucp)
4747    {    {
4748    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
4749    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);    jump = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
4750    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4751    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
4752    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);
4753    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_LESS_EQUAL);
4754    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);
4755    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);
4756    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_LESS_EQUAL);
4757    JUMPHERE(jump);    JUMPHERE(jump);
4758    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, TMP2, 0);
4759    }    }
4760  else  else
4761  #endif  #endif
4762    {    {
4763  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
4764    jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_GREATER, TMP1, 0, SLJIT_IMM, 255);
4765  #elif defined SUPPORT_UTF  #elif defined SUPPORT_UTF
4766    /* Here LOCALS1 has already been zeroed. */    /* Here LOCALS1 has already been zeroed. */
4767    jump = NULL;    jump = NULL;
4768    if (common->utf)    if (common->utf)
4769      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_GREATER, TMP1, 0, SLJIT_IMM, 255);
4770  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
4771    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);
4772    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);
4773    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4774    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, TMP1, 0);
4775  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
4776    JUMPHERE(jump);    JUMPHERE(jump);
4777  #elif defined SUPPORT_UTF  #elif defined SUPPORT_UTF
# Line 3438  JUMPHERE(skipread); Line 4783  JUMPHERE(skipread);
4783    
4784  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
4785  check_str_end(common, &skipread_list);  check_str_end(common, &skipread_list);
4786  peek_char(common);  peek_char(common, READ_CHAR_MAX);
4787    
4788  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
4789  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4790  if (common->use_ucp)  if (common->use_ucp)
4791    {    {
4792    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
4793    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);    jump = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
4794    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4795    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
4796    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);
4797    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_LESS_EQUAL);
4798    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);
4799    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);
4800    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_LESS_EQUAL);
4801    JUMPHERE(jump);    JUMPHERE(jump);
4802    }    }
4803  else  else
# Line 3461  else Line 4806  else
4806  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
4807    /* TMP2 may be destroyed by peek_char. */    /* TMP2 may be destroyed by peek_char. */
4808    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
4809    jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_GREATER, TMP1, 0, SLJIT_IMM, 255);
4810  #elif defined SUPPORT_UTF  #elif defined SUPPORT_UTF
4811    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
4812    jump = NULL;    jump = NULL;
4813    if (common->utf)    if (common->utf)
4814      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_GREATER, TMP1, 0, SLJIT_IMM, 255);
4815  #endif  #endif
4816    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);
4817    OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);    OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);
# Line 3480  else Line 4825  else
4825    }    }
4826  set_jumps(skipread_list, LABEL());  set_jumps(skipread_list, LABEL());
4827    
4828  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_SP), LOCALS1);
4829  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_SP), LOCALS0);
4830  }  }
4831    
4832  /*  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)  
4833  {  {
4834  DEFINE_COMPILER;  DEFINE_COMPILER;
4835  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]) && is_powerof2(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];  
4836  pcre_uint8 bit, cbit, all;  pcre_uint8 bit, cbit, all;
4837  int i, byte, length = 0;  int i, byte, length = 0;
4838    
4839  bit = bits[0] & 0x1;  bit = bits[0] & 0x1;
4840  ranges[1] = bit;  /* All bits will be zero or one (since bit is zero or one). */
 /* Can be 0 or 255. */  
4841  all = -bit;  all = -bit;
4842    
4843  for (i = 0; i < 256; )  for (i = 0; i < 256; )
# Line 3602  for (i = 0; i < 256; ) Line 4852  for (i = 0; i < 256; )
4852        {        {
4853        if (length >= MAX_RANGE_SIZE)        if (length >= MAX_RANGE_SIZE)
4854          return FALSE;          return FALSE;
4855        ranges[2 + length] = i;        ranges[length] = i;
4856        length++;        length++;
4857        bit = cbit;        bit = cbit;
4858        all = -cbit;        all = -cbit;
# Line 3615  if (((bit == 0) && nclass) || ((bit == 1 Line 4865  if (((bit == 0) && nclass) || ((bit == 1
4865    {    {
4866    if (length >= MAX_RANGE_SIZE)    if (length >= MAX_RANGE_SIZE)
4867      return FALSE;      return FALSE;
4868    ranges[2 + length] = 256;    ranges[length] = 256;
4869    length++;    length++;
4870    }    }
 ranges[0] = length;  
4871    
4872  return check_ranges(common, ranges, backtracks, FALSE);  if (length < 0 || length > 4)
4873      return FALSE;
4874    
4875    bit = bits[0] & 0x1;
4876    if (invert) bit ^= 0x1;
4877    
4878    /* No character is accepted. */
4879    if (length == 0 && bit == 0)
4880      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4881    
4882    switch(length)
4883      {
4884      case 0:
4885      /* When bit != 0, all characters are accepted. */
4886      return TRUE;
4887    
4888      case 1:
4889      add_jump(compiler, backtracks, CMP(bit == 0 ? SLJIT_LESS : SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
4890      return TRUE;
4891    
4892      case 2:
4893      if (ranges[0] + 1 != ranges[1])
4894        {
4895        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4896        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_LESS : SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4897        }
4898      else
4899        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_EQUAL : SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
4900      return TRUE;
4901    
4902      case 3:
4903      if (bit != 0)
4904        {
4905        add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
4906        if (ranges[0] + 1 != ranges[1])
4907          {
4908          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4909          add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4910          }
4911        else
4912          add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
4913        return TRUE;
4914        }
4915    
4916      add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, ranges[0]));
4917      if (ranges[1] + 1 != ranges[2])
4918        {
4919        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1]);
4920        add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
4921        }
4922      else
4923        add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1]));
4924      return TRUE;
4925    
4926      case 4:
4927      if ((ranges[1] - ranges[0]) == (ranges[3] - ranges[2])
4928          && (ranges[0] | (ranges[2] - ranges[0])) == ranges[2]
4929          && (ranges[1] & (ranges[2] - ranges[0])) == 0
4930          && is_powerof2(ranges[2] - ranges[0]))
4931        {
4932        SLJIT_ASSERT((ranges[0] & (ranges[2] - ranges[0])) == 0 && (ranges[2] & ranges[3] & (ranges[2] - ranges[0])) != 0);
4933        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[0]);
4934        if (ranges[2] + 1 != ranges[3])
4935          {
4936          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
4937          add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_LESS : SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
4938          }
4939        else
4940          add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_EQUAL : SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
4941        return TRUE;
4942        }
4943    
4944      if (bit != 0)
4945        {
4946        i = 0;
4947        if (ranges[0] + 1 != ranges[1])
4948          {
4949          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4950          add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4951          i = ranges[0];
4952          }
4953        else
4954          add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
4955    
4956        if (ranges[2] + 1 != ranges[3])
4957          {
4958          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - i);
4959          add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
4960          }
4961        else
4962          add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2] - i));
4963        return TRUE;
4964        }
4965    
4966      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4967      add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[0]));
4968      if (ranges[1] + 1 != ranges[2])
4969        {
4970        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]);
4971        add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
4972        }
4973      else
4974        add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4975      return TRUE;
4976    
4977      default:
4978      SLJIT_ASSERT_STOP();
4979      return FALSE;
4980      }
4981  }  }
4982    
4983  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
# Line 3632  sljit_emit_fast_enter(compiler, RETURN_A Line 4989  sljit_emit_fast_enter(compiler, RETURN_A
4989    
4990  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
4991  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);
4992  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_LESS_EQUAL);
4993  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);
4994  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4995  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4996  if (common->utf)  if (common->utf)
4997    {    {
4998  #endif  #endif
4999    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_EQUAL);
5000    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
5001    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);
5002  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
5003    }    }
5004  #endif  #endif
5005  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
5006  OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_EQUAL);
5007  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
5008  }  }
5009    
# Line 3658  DEFINE_COMPILER; Line 5015  DEFINE_COMPILER;
5015  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
5016    
5017  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);
5018  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL);
5019  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);
5020  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_EQUAL);
5021  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);
5022  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
5023  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
5024  if (common->utf)  if (common->utf)
5025    {    {
5026  #endif  #endif
5027    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_EQUAL);
5028    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);
5029    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_EQUAL);
5030    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);
5031    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_EQUAL);
5032    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
5033    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);
5034    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_LESS_EQUAL);
5035    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);
5036    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_EQUAL);
5037    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);
5038    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_EQUAL);
5039    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);
5040  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8