/[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 1420 by zherczeg, Sun Dec 29 11:43:10 2013 UTC revision 1474 by zherczeg, Thu Apr 24 06:43:50 2014 UTC
# 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      sljit_uw *read_only_data[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    pcre_uint32 limit_match;    pcre_uint32 limit_match;
   sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];  
188  } executable_functions;  } executable_functions;
189    
190  typedef struct jump_list {  typedef struct jump_list {
# Line 197  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 *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 315  typedef struct compiler_common { Line 322  typedef struct compiler_common {
322    pcre_uchar *start;    pcre_uchar *start;
323    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
324    sljit_si *private_data_ptrs;    sljit_si *private_data_ptrs;
325      /* This read-only data is available during runtime. */
326      sljit_uw *read_only_data;
327      /* The total size of the read-only data. */
328      sljit_uw read_only_data_size;
329      /* The next free entry of the read_only_data. */
330      sljit_uw *read_only_data_ptr;
331    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
332    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
333    /* Tells whether the starting offset is a target of then. */    /* Tells whether the starting offset is a target of then. */
# Line 349  typedef struct compiler_common { Line 362  typedef struct compiler_common {
362    sljit_sw lcc;    sljit_sw lcc;
363    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
364    int mode;    int mode;
365      /* TRUE, when minlength is greater than 0. */
366      BOOL might_be_empty;
367    /* \K is found in the pattern. */    /* \K is found in the pattern. */
368    BOOL has_set_som;    BOOL has_set_som;
369    /* (*SKIP:arg) is found in the pattern. */    /* (*SKIP:arg) is found in the pattern. */
# Line 363  typedef struct compiler_common { Line 378  typedef struct compiler_common {
378    BOOL positive_assert;    BOOL positive_assert;
379    /* Newline control. */    /* Newline control. */
380    int nltype;    int nltype;
381      pcre_uint32 nlmax;
382      pcre_uint32 nlmin;
383    int newline;    int newline;
384    int bsr_nltype;    int bsr_nltype;
385      pcre_uint32 bsr_nlmax;
386      pcre_uint32 bsr_nlmin;
387    /* Dollar endonly. */    /* Dollar endonly. */
388    int endonly;    int endonly;
389    /* Tables. */    /* Tables. */
# Line 379  typedef struct compiler_common { Line 398  typedef struct compiler_common {
398    struct sljit_label *quit_label;    struct sljit_label *quit_label;
399    struct sljit_label *forced_quit_label;    struct sljit_label *forced_quit_label;
400    struct sljit_label *accept_label;    struct sljit_label *accept_label;
401      struct sljit_label *ff_newline_shortcut;
402    stub_list *stubs;    stub_list *stubs;
403      label_addr_list *label_addrs;
404    recurse_entry *entries;    recurse_entry *entries;
405    recurse_entry *currententry;    recurse_entry *currententry;
406    jump_list *partialmatch;    jump_list *partialmatch;
# Line 403  typedef struct compiler_common { Line 424  typedef struct compiler_common {
424  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
425    BOOL use_ucp;    BOOL use_ucp;
426  #endif  #endif
 #ifndef COMPILE_PCRE32  
   jump_list *utfreadchar;  
 #endif  
427  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
428    jump_list *utfreadchar8;    jump_list *utfreadchar;
429      jump_list *utfreadchar16;
430    jump_list *utfreadtype8;    jump_list *utfreadtype8;
431  #endif  #endif
432  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
# Line 524  the start pointers when the end of the c Line 543  the start pointers when the end of the c
543  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
544    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
545    
546    #define READ_CHAR_MAX 0x7fffffff
547    
548  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
549  {  {
550  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
# Line 533  cc += 1 + LINK_SIZE; Line 554  cc += 1 + LINK_SIZE;
554  return cc;  return cc;
555  }  }
556    
557    static int no_alternatives(pcre_uchar* cc)
558    {
559    int count = 0;
560    SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
561    do
562      {
563      cc += GET(cc, 1);
564      count++;
565      }
566    while (*cc == OP_ALT);
567    SLJIT_ASSERT(*cc >= OP_KET && *cc <= OP_KETRPOS);
568    return count;
569    }
570    
571  static int ones_in_half_byte[16] = {  static int ones_in_half_byte[16] = {
572    /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,    /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
573    /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4    /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
# Line 757  while (cc < ccend) Line 792  while (cc < ccend)
792      {      {
793      case OP_SET_SOM:      case OP_SET_SOM:
794      common->has_set_som = TRUE;      common->has_set_som = TRUE;
795        common->might_be_empty = TRUE;
796      cc += 1;      cc += 1;
797      break;      break;
798    
# Line 766  while (cc < ccend) Line 802  while (cc < ccend)
802      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
803      break;      break;
804    
805        case OP_BRA:
806        case OP_CBRA:
807        case OP_SBRA:
808        case OP_SCBRA:
809        count = no_alternatives(cc);
810        if (count > 4)
811          common->read_only_data_size += count * sizeof(sljit_uw);
812        cc += 1 + LINK_SIZE + (*cc == OP_CBRA || *cc == OP_SCBRA ? IMM2_SIZE : 0);
813        break;
814    
815      case OP_CBRAPOS:      case OP_CBRAPOS:
816      case OP_SCBRAPOS:      case OP_SCBRAPOS:
817      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
# Line 2024  while (list_item) Line 2070  while (list_item)
2070  common->stubs = NULL;  common->stubs = NULL;
2071  }  }
2072    
2073    static void add_label_addr(compiler_common *common)
2074    {
2075    DEFINE_COMPILER;
2076    label_addr_list *label_addr;
2077    
2078    label_addr = sljit_alloc_memory(compiler, sizeof(label_addr_list));
2079    if (label_addr == NULL)
2080      return;
2081    label_addr->label = LABEL();
2082    label_addr->addr = common->read_only_data_ptr;
2083    label_addr->next = common->label_addrs;
2084    common->label_addrs = label_addr;
2085    common->read_only_data_ptr++;
2086    }
2087    
2088  static SLJIT_INLINE void count_match(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2089  {  {
2090  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2462  else Line 2523  else
2523  JUMPHERE(jump);  JUMPHERE(jump);
2524  }  }
2525    
2526  static void read_char(compiler_common *common)  static void peek_char(compiler_common *common, pcre_uint32 max)
2527  {  {
2528  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2529  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2530  DEFINE_COMPILER;  DEFINE_COMPILER;
2531  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2532  struct sljit_jump *jump;  struct sljit_jump *jump;
2533  #endif  #endif
2534    
2535    SLJIT_UNUSED_ARG(max);
2536    
2537  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2538  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2539  if (common->utf)  if (common->utf)
2540    {    {
2541  #if defined COMPILE_PCRE8    if (max < 128) return;
2542    
2543    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2544  #elif defined COMPILE_PCRE16    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
   jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);  
 #endif /* COMPILE_PCRE[8|16] */  
2545    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2546      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2547    JUMPHERE(jump);    JUMPHERE(jump);
2548    }    }
2549  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2550  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
2551    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2552    if (common->utf)
2553      {
2554      if (max < 0xd800) return;
2555    
2556      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2557      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2558      /* TMP2 contains the high surrogate. */
2559      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2560      OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2561      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2562      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2563      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2564      JUMPHERE(jump);
2565      }
2566    #endif
2567  }  }
2568    
2569  static void peek_char(compiler_common *common)  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2570    
2571    static BOOL is_char7_bitset(const pcre_uint8 *bitset, BOOL nclass)
2572  {  {
2573  /* Reads the character into TMP1, keeps STR_PTR.  /* Tells whether the character codes below 128 are enough
2574  Does not check STR_END. TMP2 Destroyed. */  to determine a match. */
2575    const pcre_uint8 value = nclass ? 0xff : 0;
2576    const pcre_uint8* end = bitset + 32;
2577    
2578    bitset += 16;
2579    do
2580      {
2581      if (*bitset++ != value)
2582        return FALSE;
2583      }
2584    while (bitset < end);
2585    return TRUE;
2586    }
2587    
2588    static void read_char7_type(compiler_common *common, BOOL full_read)
2589    {
2590    /* Reads the precise character type of a character into TMP1, if the character
2591    is less than 128. Otherwise it returns with zero. Does not check STR_END. The
2592    full_read argument tells whether characters above max are accepted or not. */
2593  DEFINE_COMPILER;  DEFINE_COMPILER;
 #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  
2594  struct sljit_jump *jump;  struct sljit_jump *jump;
 #endif  
2595    
2596  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  SLJIT_ASSERT(common->utf);
2597  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  
2598  if (common->utf)  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2599    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2600    
2601    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2602    
2603    if (full_read)
2604    {    {
2605  #if defined COMPILE_PCRE8    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2606    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);
2607  #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);  
2608    JUMPHERE(jump);    JUMPHERE(jump);
2609    }    }
 #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  
2610  }  }
2611    
2612  static void read_char8(compiler_common *common)  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2613    
2614    static void read_char_range(compiler_common *common, pcre_uint32 min, pcre_uint32 max, BOOL update_str_ptr)
2615  {  {
2616  /* Reads the precise value of a character into TMP1, if the character is  /* Reads the precise value of a character into TMP1, if the character is
2617  less than 256. Otherwise it returns with a value greater or equal than 256. */  between min and max (c >= min && c <= max). Otherwise it returns with a value
2618    outside the range. Does not check STR_END. */
2619  DEFINE_COMPILER;  DEFINE_COMPILER;
2620  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2621  struct sljit_jump *jump;  struct sljit_jump *jump;
2622  #endif  #endif
2623    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2624    struct sljit_jump *jump2;
2625    #endif
2626    
2627  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  SLJIT_UNUSED_ARG(update_str_ptr);
2628    SLJIT_UNUSED_ARG(min);
2629    SLJIT_UNUSED_ARG(max);
2630    SLJIT_ASSERT(min <= max);
2631    
2632    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2633  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));
2634    
2635  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2636  if (common->utf)  if (common->utf)
2637    {    {
2638  #if defined COMPILE_PCRE8    if (max < 128 && !update_str_ptr) return;
2639    
2640    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2641    add_jump(compiler, &common->utfreadchar8, JUMP(SLJIT_FAST_CALL));    if (min >= 0x10000)
2642        {
2643        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xf0);
2644        if (update_str_ptr)
2645          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2646        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2647        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x7);
2648        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2649        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2650        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2651        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2652        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2653        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2654        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2655        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2656        if (!update_str_ptr)
2657          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2658        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2659        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2660        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2661        JUMPHERE(jump2);
2662        if (update_str_ptr)
2663          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2664        }
2665      else if (min >= 0x800 && max <= 0xffff)
2666        {
2667        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xe0);
2668        if (update_str_ptr)
2669          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2670        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2671        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xf);
2672        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2673        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2674        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2675        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2676        if (!update_str_ptr)
2677          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2678        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2679        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2680        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2681        JUMPHERE(jump2);
2682        if (update_str_ptr)
2683          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2684        }
2685      else if (max >= 0x800)
2686        add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2687      else if (max < 128)
2688        {
2689        OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2690        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2691        }
2692      else
2693        {
2694        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2695        if (!update_str_ptr)
2696          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2697        else
2698          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2699        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2700        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2701        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2702        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2703        if (update_str_ptr)
2704          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2705        }
2706    JUMPHERE(jump);    JUMPHERE(jump);
2707  #elif defined COMPILE_PCRE16    }
2708    #endif
2709    
2710    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2711    if (common->utf)
2712      {
2713      if (max >= 0x10000)
2714        {
2715        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2716        jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2717        /* TMP2 contains the high surrogate. */
2718        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2719        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2720        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2721        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2722        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2723        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2724        JUMPHERE(jump);
2725        return;
2726        }
2727    
2728      if (max < 0xd800 && !update_str_ptr) return;
2729    
2730    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2731    OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2732    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2733    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    if (update_str_ptr)
2734        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2735      if (max >= 0xd800)
2736        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
2737    JUMPHERE(jump);    JUMPHERE(jump);
 #endif /* COMPILE_PCRE[8|16] */  
2738    }    }
2739  #endif  #endif
2740  }  }
2741    
2742  static void read_char8_type(compiler_common *common)  static SLJIT_INLINE void read_char(compiler_common *common)
2743    {
2744    read_char_range(common, 0, READ_CHAR_MAX, TRUE);
2745    }
2746    
2747    static void read_char8_type(compiler_common *common, BOOL update_str_ptr)
2748  {  {
2749  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */
2750  DEFINE_COMPILER;  DEFINE_COMPILER;
2751  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2752  struct sljit_jump *jump;  struct sljit_jump *jump;
2753  #endif  #endif
2754    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2755    struct sljit_jump *jump2;
2756    #endif
2757    
2758  #ifdef SUPPORT_UTF  SLJIT_UNUSED_ARG(update_str_ptr);
2759    
2760    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2761    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2762    
2763    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2764  if (common->utf)  if (common->utf)
2765    {    {
   OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 #if defined COMPILE_PCRE8  
2766    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2767    it is needed in most cases. */    it is needed in most cases. */
2768    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2769    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2770    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    if (!update_str_ptr)
2771    JUMPHERE(jump);      {
2772  #elif defined COMPILE_PCRE16      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2773    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2774    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2775    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2776    JUMPHERE(jump);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2777    /* Skip low surrogate if necessary. */      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
2778    OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2779    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);      jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2780    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2781    JUMPHERE(jump);      JUMPHERE(jump2);
2782  #elif defined COMPILE_PCRE32      }
2783    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    else
2784    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);      add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  
2785    JUMPHERE(jump);    JUMPHERE(jump);
 #endif /* COMPILE_PCRE[8|16|32] */  
2786    return;    return;
2787    }    }
2788  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2789  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
2790  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  #if !defined COMPILE_PCRE8
 #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  
2791  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2792  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2793  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2794  #endif  #endif
2795  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2796  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if !defined COMPILE_PCRE8
2797  JUMPHERE(jump);  JUMPHERE(jump);
2798  #endif  #endif
2799    
2800    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2801    if (common->utf && update_str_ptr)
2802      {
2803      /* Skip low surrogate if necessary. */
2804      OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2805      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2806      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2807      JUMPHERE(jump);
2808      }
2809    #endif /* SUPPORT_UTF && COMPILE_PCRE16 */
2810  }  }
2811    
2812  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
# Line 2629  if (common->utf) Line 2844  if (common->utf)
2844  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));
2845  }  }
2846    
2847  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)
2848  {  {
2849  /* 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. */
2850  DEFINE_COMPILER;  DEFINE_COMPILER;
2851    struct sljit_jump *jump;
2852    
2853  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2854    {    {
2855    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2856    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpifmatch ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2857    }    }
2858  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2859    {    {
2860    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    if (jumpifmatch)
2861    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);      {
2862    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR));
2863    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2864    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));      }
2865      else
2866        {
2867        jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
2868        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2869        JUMPHERE(jump);
2870        }
2871    }    }
2872  else  else
2873    {    {
2874    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2875    add_jump(compiler, backtracks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));    add_jump(compiler, backtracks, CMP(jumpifmatch ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
2876    }    }
2877  }  }
2878    
# Line 2660  else Line 2882  else
2882  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2883  {  {
2884  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2885  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. */
2886  DEFINE_COMPILER;  DEFINE_COMPILER;
2887  struct sljit_jump *jump;  struct sljit_jump *jump;
2888    
2889  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2890    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2891    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2892    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2893    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2894    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2895    
2896  /* Searching for the first zero. */  /* Searching for the first zero. */
2897  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2898  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2899  /* Two byte sequence. */  /* Two byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
2900  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));
2901  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2902    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2903    
2904    JUMPHERE(jump);
2905    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2906    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2907  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2908  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2909  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 JUMPHERE(jump);  
2910    
2911  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2912  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2913  /* Three byte sequence. */  /* Three byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  
2914  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));
2915  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));  
2916  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2917    
2918  /* Four byte sequence. */  /* Four byte sequence. */
2919  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  JUMPHERE(jump);
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
2920  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2921  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2922  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));  
2923  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2924  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2925  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2926  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(4));
2927  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2928  }  }
2929    
2930  static void do_utfreadchar8(compiler_common *common)  static void do_utfreadchar16(compiler_common *common)
2931  {  {
2932  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2933  of the character (>= 0xc0). Return value in TMP1. */  of the character (>= 0xc0). Return value in TMP1. */
# Line 2723  DEFINE_COMPILER; Line 2935  DEFINE_COMPILER;
2935  struct sljit_jump *jump;  struct sljit_jump *jump;
2936    
2937  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
   
 OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  
 jump = JUMP(SLJIT_C_NOT_ZERO);  
 /* Two byte sequence. */  
2938  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2939  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  
2940  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2941  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2942  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2943    
2944    /* Searching for the first zero. */
2945    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2946    jump = JUMP(SLJIT_C_NOT_ZERO);
2947    /* Two byte sequence. */
2948    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2949  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2950    
2951  JUMPHERE(jump);  JUMPHERE(jump);
2952  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
2953  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x800);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
2954    /* This code runs only in 8 bit mode. No need to shift the value. */
2955  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2956    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2957    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2958    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2959    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2960    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2961    /* Three byte sequence. */
2962    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2963  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2964  }  }
2965    
# Line 2778  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, T Line 2999  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, T
2999  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3000  }  }
3001    
3002  #elif defined COMPILE_PCRE16  #endif /* COMPILE_PCRE8 */
   
 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);  
   
 JUMPHERE(jump);  
 /* Combine two 16 bit characters. */  
 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, 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);  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 }  
   
 #endif /* COMPILE_PCRE[8|16] */  
3003    
3004  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3005    
# Line 2880  if (firstline) Line 3074  if (firstline)
3074      mainloop = LABEL();      mainloop = LABEL();
3075      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
3076      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
3077      read_char(common);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
3078      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
3079      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
3080      JUMPHERE(end);      JUMPHERE(end);
# Line 2956  if (newlinecheck) Line 3150  if (newlinecheck)
3150  return mainloop;  return mainloop;
3151  }  }
3152    
3153  static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, int max_chars)  #define MAX_N_CHARS 16
3154    #define MAX_N_BYTES 8
3155    
3156    static SLJIT_INLINE void add_prefix_byte(pcre_uint8 byte, pcre_uint8 *bytes)
3157  {  {
3158  /* Recursive function, which scans prefix literals. */  pcre_uint8 len = bytes[0];
3159  int len, repeat, len_save, consumed = 0;  int i;
 pcre_int32 caseless, chr, mask;  
 pcre_uchar *alternative, *cc_save;  
 BOOL last, any;  
3160    
3161  repeat = 1;  if (len == 255)
3162  while (TRUE)    return;
3163    
3164    if (len == 0)
3165    {    {
3166    last = TRUE;    bytes[0] = 1;
3167    any = FALSE;    bytes[1] = byte;
3168    caseless = 0;    return;
3169    switch (*cc)    }
3170    
3171    for (i = len; i > 0; i--)
3172      if (bytes[i] == byte)
3173        return;
3174    
3175    if (len >= MAX_N_BYTES - 1)
3176      {
3177      bytes[0] = 255;
3178      return;
3179      }
3180    
3181    len++;
3182    bytes[len] = byte;
3183    bytes[0] = len;
3184    }
3185    
3186    static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, pcre_uint8 *bytes, int max_chars)
3187    {
3188    /* Recursive function, which scans prefix literals. */
3189    BOOL last, any, caseless;
3190    int len, repeat, len_save, consumed = 0;
3191    pcre_uint32 chr, mask;
3192    pcre_uchar *alternative, *cc_save, *oc;
3193    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3194    pcre_uchar othercase[8];
3195    #elif defined SUPPORT_UTF && defined COMPILE_PCRE16
3196    pcre_uchar othercase[2];
3197    #else
3198    pcre_uchar othercase[1];
3199    #endif
3200    
3201    repeat = 1;
3202    while (TRUE)
3203      {
3204      last = TRUE;
3205      any = FALSE;
3206      caseless = FALSE;
3207      switch (*cc)
3208      {      {
3209      case OP_CHARI:      case OP_CHARI:
3210      caseless = 1;      caseless = TRUE;
3211      case OP_CHAR:      case OP_CHAR:
3212      last = FALSE;      last = FALSE;
3213      cc++;      cc++;
# Line 2994  while (TRUE) Line 3228  while (TRUE)
3228      cc++;      cc++;
3229      continue;      continue;
3230    
3231        case OP_ASSERT:
3232        case OP_ASSERT_NOT:
3233        case OP_ASSERTBACK:
3234        case OP_ASSERTBACK_NOT:
3235        cc = bracketend(cc);
3236        continue;
3237    
3238        case OP_PLUSI:
3239        case OP_MINPLUSI:
3240        case OP_POSPLUSI:
3241        caseless = TRUE;
3242      case OP_PLUS:      case OP_PLUS:
3243      case OP_MINPLUS:      case OP_MINPLUS:
3244      case OP_POSPLUS:      case OP_POSPLUS:
# Line 3001  while (TRUE) Line 3246  while (TRUE)
3246      break;      break;
3247    
3248      case OP_EXACTI:      case OP_EXACTI:
3249      caseless = 1;      caseless = TRUE;
3250      case OP_EXACT:      case OP_EXACT:
3251      repeat = GET2(cc, 1);      repeat = GET2(cc, 1);
3252      last = FALSE;      last = FALSE;
3253      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3254      break;      break;
3255    
3256      case OP_PLUSI:      case OP_QUERYI:
3257      case OP_MINPLUSI:      case OP_MINQUERYI:
3258      case OP_POSPLUSI:      case OP_POSQUERYI:
3259      caseless = 1;      caseless = TRUE;
3260        case OP_QUERY:
3261        case OP_MINQUERY:
3262        case OP_POSQUERY:
3263        len = 1;
3264      cc++;      cc++;
3265    #ifdef SUPPORT_UTF
3266        if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3267    #endif
3268        max_chars = scan_prefix(common, cc + len, chars, bytes, max_chars);
3269        if (max_chars == 0)
3270          return consumed;
3271        last = FALSE;
3272      break;      break;
3273    
3274      case OP_KET:      case OP_KET:
# Line 3032  while (TRUE) Line 3288  while (TRUE)
3288      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
3289      while (*alternative == OP_ALT)      while (*alternative == OP_ALT)
3290        {        {
3291        max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, max_chars);        max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, bytes, max_chars);
3292        if (max_chars == 0)        if (max_chars == 0)
3293          return consumed;          return consumed;
3294        alternative += GET(alternative, 1);        alternative += GET(alternative, 1);
# Line 3044  while (TRUE) Line 3300  while (TRUE)
3300      continue;      continue;
3301    
3302      case OP_CLASS:      case OP_CLASS:
3303    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3304        if (common->utf && !is_char7_bitset((const pcre_uint8 *)(cc + 1), FALSE)) return consumed;
3305    #endif
3306        any = TRUE;
3307        cc += 1 + 32 / sizeof(pcre_uchar);
3308        break;
3309    
3310      case OP_NCLASS:      case OP_NCLASS:
3311    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3312        if (common->utf) return consumed;
3313    #endif
3314      any = TRUE;      any = TRUE;
3315      cc += 1 + 32 / sizeof(pcre_uchar);      cc += 1 + 32 / sizeof(pcre_uchar);
3316      break;      break;
3317    
3318  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3319      case OP_XCLASS:      case OP_XCLASS:
3320    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3321        if (common->utf) return consumed;
3322    #endif
3323      any = TRUE;      any = TRUE;
3324      cc += GET(cc, 1);      cc += GET(cc, 1);
3325      break;      break;
3326  #endif  #endif
3327    
     case OP_NOT_DIGIT:  
3328      case OP_DIGIT:      case OP_DIGIT:
3329      case OP_NOT_WHITESPACE:  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3330        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_digit, FALSE))
3331          return consumed;
3332    #endif
3333        any = TRUE;
3334        cc++;
3335        break;
3336    
3337      case OP_WHITESPACE:      case OP_WHITESPACE:
3338      case OP_NOT_WORDCHAR:  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3339        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_space, FALSE))
3340          return consumed;
3341    #endif
3342        any = TRUE;
3343        cc++;
3344        break;
3345    
3346      case OP_WORDCHAR:      case OP_WORDCHAR:
3347    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3348        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_word, FALSE))
3349          return consumed;
3350    #endif
3351        any = TRUE;
3352        cc++;
3353        break;
3354    
3355        case OP_NOT:
3356        case OP_NOTI:
3357        cc++;
3358        /* Fall through. */
3359        case OP_NOT_DIGIT:
3360        case OP_NOT_WHITESPACE:
3361        case OP_NOT_WORDCHAR:
3362      case OP_ANY:      case OP_ANY:
3363      case OP_ALLANY:      case OP_ALLANY:
3364    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3365        if (common->utf) return consumed;
3366    #endif
3367      any = TRUE;      any = TRUE;
3368      cc++;      cc++;
3369      break;      break;
# Line 3071  while (TRUE) Line 3371  while (TRUE)
3371  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3372      case OP_NOTPROP:      case OP_NOTPROP:
3373      case OP_PROP:      case OP_PROP:
3374    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3375        if (common->utf) return consumed;
3376    #endif
3377      any = TRUE;      any = TRUE;
3378      cc += 1 + 2;      cc += 1 + 2;
3379      break;      break;
# Line 3081  while (TRUE) Line 3384  while (TRUE)
3384      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3385      continue;      continue;
3386    
3387        case OP_NOTEXACT:
3388        case OP_NOTEXACTI:
3389    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3390        if (common->utf) return consumed;
3391    #endif
3392        any = TRUE;
3393        repeat = GET2(cc, 1);
3394        cc += 1 + IMM2_SIZE + 1;
3395        break;
3396    
3397      default:      default:
3398      return consumed;      return consumed;
3399      }      }
3400    
3401    if (any)    if (any)
3402      {      {
 #ifdef SUPPORT_UTF  
     if (common->utf) return consumed;  
 #endif  
3403  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
3404      mask = 0xff;      mask = 0xff;
3405  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
# Line 3104  while (TRUE) Line 3414  while (TRUE)
3414        {        {
3415        chars[0] = mask;        chars[0] = mask;
3416        chars[1] = mask;        chars[1] = mask;
3417          bytes[0] = 255;
3418    
3419          consumed++;
3420        if (--max_chars == 0)        if (--max_chars == 0)
3421          return consumed;          return consumed;
       consumed++;  
3422        chars += 2;        chars += 2;
3423          bytes += MAX_N_BYTES;
3424        }        }
3425      while (--repeat > 0);      while (--repeat > 0);
3426    
# Line 3121  while (TRUE) Line 3433  while (TRUE)
3433    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3434  #endif  #endif
3435    
3436    if (caseless != 0 && char_has_othercase(common, cc))    if (caseless && char_has_othercase(common, cc))
3437      {      {
3438      caseless = char_get_othercase_bit(common, cc);  #ifdef SUPPORT_UTF
3439      if (caseless == 0)      if (common->utf)
3440        return consumed;        {
3441  #ifdef COMPILE_PCRE8        GETCHAR(chr, cc);
3442      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));        if ((int)PRIV(ord2utf)(char_othercase(common, chr), othercase) != len)
3443  #else          return consumed;
3444      if ((caseless & 0x100) != 0)        }
       caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));  
3445      else      else
       caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));  
3446  #endif  #endif
3447          {
3448          chr = *cc;
3449          othercase[0] = TABLE_GET(chr, common->fcc, chr);
3450          }
3451      }      }
3452    else    else
3453      caseless = 0;      caseless = FALSE;
3454    
3455    len_save = len;    len_save = len;
3456    cc_save = cc;    cc_save = cc;
3457    while (TRUE)    while (TRUE)
3458      {      {
3459        oc = othercase;
3460      do      do
3461        {        {
3462        chr = *cc;        chr = *cc;
# Line 3149  while (TRUE) Line 3464  while (TRUE)
3464        if (SLJIT_UNLIKELY(chr == NOTACHAR))        if (SLJIT_UNLIKELY(chr == NOTACHAR))
3465          return consumed;          return consumed;
3466  #endif  #endif
3467          add_prefix_byte((pcre_uint8)chr, bytes);
3468    
3469        mask = 0;        mask = 0;
3470        if (len == (caseless & 0xff))        if (caseless)
3471          {          {
3472          mask = caseless >> 8;          add_prefix_byte((pcre_uint8)*oc, bytes);
3473            mask = *cc ^ *oc;
3474          chr |= mask;          chr |= mask;
3475          }          }
3476    
3477    #ifdef COMPILE_PCRE32
3478          if (chars[0] == NOTACHAR && chars[1] == 0)
3479    #else
3480        if (chars[0] == NOTACHAR)        if (chars[0] == NOTACHAR)
3481    #endif
3482          {          {
3483          chars[0] = chr;          chars[0] = chr;
3484          chars[1] = mask;          chars[1] = mask;
# Line 3170  while (TRUE) Line 3492  while (TRUE)
3492          }          }
3493    
3494        len--;        len--;
3495          consumed++;
3496        if (--max_chars == 0)        if (--max_chars == 0)
3497          return consumed;          return consumed;
       consumed++;  
3498        chars += 2;        chars += 2;
3499          bytes += MAX_N_BYTES;
3500        cc++;        cc++;
3501          oc++;
3502        }        }
3503      while (len > 0);      while (len > 0);
3504    
# Line 3191  while (TRUE) Line 3515  while (TRUE)
3515    }    }
3516  }  }
3517    
 #define MAX_N_CHARS 16  
   
3518  static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)  static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3519  {  {
3520  DEFINE_COMPILER;  DEFINE_COMPILER;
3521  struct sljit_label *start;  struct sljit_label *start;
3522  struct sljit_jump *quit;  struct sljit_jump *quit;
3523  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uint32 chars[MAX_N_CHARS * 2];
3524    pcre_uint8 bytes[MAX_N_CHARS * MAX_N_BYTES];
3525  pcre_uint8 ones[MAX_N_CHARS];  pcre_uint8 ones[MAX_N_CHARS];
 pcre_uint32 mask;  
 int i, max;  
3526  int offsets[3];  int offsets[3];
3527    pcre_uint32 mask;
3528    pcre_uint8 *byte_set, *byte_set_end;
3529    int i, max, from;
3530    int range_right = -1, range_len = 3 - 1;
3531    sljit_ub *update_table = NULL;
3532    BOOL in_range;
3533    
3534    /* This is even TRUE, if both are NULL. */
3535    SLJIT_ASSERT(common->read_only_data_ptr == common->read_only_data);
3536    
3537  for (i = 0; i < MAX_N_CHARS; i++)  for (i = 0; i < MAX_N_CHARS; i++)
3538    {    {
3539    chars[i << 1] = NOTACHAR;    chars[i << 1] = NOTACHAR;
3540    chars[(i << 1) + 1] = 0;    chars[(i << 1) + 1] = 0;
3541      bytes[i * MAX_N_BYTES] = 0;
3542    }    }
3543    
3544  max = scan_prefix(common, common->start, chars, MAX_N_CHARS);  max = scan_prefix(common, common->start, chars, bytes, MAX_N_CHARS);
3545    
3546  if (max <= 1)  if (max <= 1)
3547    return FALSE;    return FALSE;
# Line 3227  for (i = 0; i < max; i++) Line 3558  for (i = 0; i < max; i++)
3558      }      }
3559    }    }
3560    
3561    in_range = FALSE;
3562    from = 0;   /* Prevent compiler "uninitialized" warning */
3563    for (i = 0; i <= max; i++)
3564      {
3565      if (in_range && (i - from) > range_len && (bytes[(i - 1) * MAX_N_BYTES] <= 4))
3566        {
3567        range_len = i - from;
3568        range_right = i - 1;
3569        }
3570    
3571      if (i < max && bytes[i * MAX_N_BYTES] < 255)
3572        {
3573        if (!in_range)
3574          {
3575          in_range = TRUE;
3576          from = i;
3577          }
3578        }
3579      else if (in_range)
3580        in_range = FALSE;
3581      }
3582    
3583    if (range_right >= 0)
3584      {
3585      /* Since no data is consumed (see the assert in the beginning
3586      of this function), this space can be reallocated. */
3587      if (common->read_only_data)
3588        SLJIT_FREE(common->read_only_data);
3589    
3590      common->read_only_data_size += 256;
3591      common->read_only_data = (sljit_uw *)SLJIT_MALLOC(common->read_only_data_size);
3592      if (common->read_only_data == NULL)
3593        return TRUE;
3594    
3595      update_table = (sljit_ub *)common->read_only_data;
3596      common->read_only_data_ptr = (sljit_uw *)(update_table + 256);
3597      memset(update_table, IN_UCHARS(range_len), 256);
3598    
3599      for (i = 0; i < range_len; i++)
3600        {
3601        byte_set = bytes + ((range_right - i) * MAX_N_BYTES);
3602        SLJIT_ASSERT(byte_set[0] > 0 && byte_set[0] < 255);
3603        byte_set_end = byte_set + byte_set[0];
3604        byte_set++;
3605        while (byte_set <= byte_set_end)
3606          {
3607          if (update_table[*byte_set] > IN_UCHARS(i))
3608            update_table[*byte_set] = IN_UCHARS(i);
3609          byte_set++;
3610          }
3611        }
3612      }
3613    
3614  offsets[0] = -1;  offsets[0] = -1;
3615  /* Scan forward. */  /* Scan forward. */
3616  for (i = 0; i < max; i++)  for (i = 0; i < max; i++)
# Line 3235  for (i = 0; i < max; i++) Line 3619  for (i = 0; i < max; i++)
3619      break;      break;
3620    }    }
3621    
3622  if (offsets[0] == -1)  if (offsets[0] < 0 && range_right < 0)
3623    return FALSE;    return FALSE;
3624    
3625  /* Scan backward. */  if (offsets[0] >= 0)
 offsets[1] = -1;  
 for (i = max - 1; i > offsets[0]; i--)  
   if (ones[i] <= 2) {  
     offsets[1] = i;  
     break;  
   }  
   
 offsets[2] = -1;  
 if (offsets[1] >= 0)  
3626    {    {
3627    /* Scan from middle. */    /* Scan backward. */
3628    for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)    offsets[1] = -1;
3629      if (ones[i] <= 2)    for (i = max - 1; i > offsets[0]; i--)
3630        if (ones[i] <= 2 && i != range_right)
3631        {        {
3632        offsets[2] = i;        offsets[1] = i;
3633        break;        break;
3634        }        }
3635    
3636    if (offsets[2] == -1)    /* This case is handled better by fast_forward_first_char. */
3637      if (offsets[1] == -1 && offsets[0] == 0 && range_right < 0)
3638        return FALSE;
3639    
3640      offsets[2] = -1;
3641      /* We only search for a middle character if there is no range check. */
3642      if (offsets[1] >= 0 && range_right == -1)
3643      {      {
3644      for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)      /* Scan from middle. */
3645        for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3646        if (ones[i] <= 2)        if (ones[i] <= 2)
3647          {          {
3648          offsets[2] = i;          offsets[2] = i;
3649          break;          break;
3650          }          }
3651    
3652        if (offsets[2] == -1)
3653          {
3654          for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3655            if (ones[i] <= 2)
3656              {
3657              offsets[2] = i;
3658              break;
3659              }
3660          }
3661      }      }
   }  
3662    
3663  SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));    SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3664  SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));    SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3665    
3666  chars[0] = chars[offsets[0] << 1];    chars[0] = chars[offsets[0] << 1];
3667  chars[1] = chars[(offsets[0] << 1) + 1];    chars[1] = chars[(offsets[0] << 1) + 1];
3668  if (offsets[2] >= 0)    if (offsets[2] >= 0)
3669    {      {
3670    chars[2] = chars[offsets[2] << 1];      chars[2] = chars[offsets[2] << 1];
3671    chars[3] = chars[(offsets[2] << 1) + 1];      chars[3] = chars[(offsets[2] << 1) + 1];
3672    }      }
3673  if (offsets[1] >= 0)    if (offsets[1] >= 0)
3674    {      {
3675    chars[4] = chars[offsets[1] << 1];      chars[4] = chars[offsets[1] << 1];
3676    chars[5] = chars[(offsets[1] << 1) + 1];      chars[5] = chars[(offsets[1] << 1) + 1];
3677        }
3678    }    }
3679    
3680  max -= 1;  max -= 1;
3681  if (firstline)  if (firstline)
3682    {    {
3683    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3684      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3685    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3686    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS(max));    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3687      quit = CMP(SLJIT_C_LESS_EQUAL, STR_END, 0, TMP1, 0);
3688      OP1(SLJIT_MOV, STR_END, 0, TMP1, 0);
3689      JUMPHERE(quit);
3690    }    }
3691  else  else
3692    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3693    
3694    #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3695    if (range_right >= 0)
3696      OP1(SLJIT_MOV, RETURN_ADDR, 0, SLJIT_IMM, (sljit_sw)update_table);
3697    #endif
3698    
3699  start = LABEL();  start = LABEL();
3700  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3701    
3702  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));  SLJIT_ASSERT(range_right >= 0 || offsets[0] >= 0);
 if (offsets[1] >= 0)  
   OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
   
 if (chars[1] != 0)  
   OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);  
 CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);  
 if (offsets[2] >= 0)  
   OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));  
3703    
3704  if (offsets[1] >= 0)  if (range_right >= 0)
3705    {    {
3706    if (chars[5] != 0)  #if defined COMPILE_PCRE8 || (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
3707      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right));
3708    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);  #else
3709      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right + 1) - 1);
3710    #endif
3711    
3712    #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3713      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(RETURN_ADDR, TMP1), 0);
3714    #else
3715      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)update_table);
3716    #endif
3717      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3718      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, start);
3719    }    }
3720    
3721  if (offsets[2] >= 0)  if (offsets[0] >= 0)
3722    {    {
3723    if (chars[3] != 0)    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3724      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);    if (offsets[1] >= 0)
3725    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3726      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3727    
3728      if (chars[1] != 0)
3729        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3730      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3731      if (offsets[2] >= 0)
3732        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3733    
3734      if (offsets[1] >= 0)
3735        {
3736        if (chars[5] != 0)
3737          OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3738        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3739        }
3740    
3741      if (offsets[2] >= 0)
3742        {
3743        if (chars[3] != 0)
3744          OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3745        CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3746        }
3747      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3748    }    }
 OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
3749    
3750  JUMPHERE(quit);  JUMPHERE(quit);
3751    
3752  if (firstline)  if (firstline)
3753      {
3754      if (range_right >= 0)
3755        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3756    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3757      if (range_right >= 0)
3758        {
3759        quit = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3760        OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
3761        JUMPHERE(quit);
3762        }
3763      }
3764  else  else
3765    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3766  return TRUE;  return TRUE;
3767  }  }
3768    
3769  #undef MAX_N_CHARS  #undef MAX_N_CHARS
3770    #undef MAX_N_BYTES
3771    
3772  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
3773  {  {
# Line 3438  if (common->nltype == NLTYPE_FIXED && co Line 3873  if (common->nltype == NLTYPE_FIXED && co
3873    JUMPHERE(lastchar);    JUMPHERE(lastchar);
3874    
3875    if (firstline)    if (firstline)
3876      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3877    return;    return;
3878    }    }
3879    
# Line 3448  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3883  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3883  skip_char_back(common);  skip_char_back(common);
3884    
3885  loop = LABEL();  loop = LABEL();
3886  read_char(common);  common->ff_newline_shortcut = loop;
3887    
3888    read_char_range(common, common->nlmin, common->nlmax, TRUE);
3889  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3890  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3891    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
# Line 3717  JUMPHERE(skipread); Line 4154  JUMPHERE(skipread);
4154    
4155  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
4156  check_str_end(common, &skipread_list);  check_str_end(common, &skipread_list);
4157  peek_char(common);  peek_char(common, READ_CHAR_MAX);
4158    
4159  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
4160  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3763  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSE Line 4200  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSE
4200  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
4201  }  }
4202    
4203  /*  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)  
4204  {  {
4205  DEFINE_COMPILER;  DEFINE_COMPILER;
4206  int offset;  int ranges[MAX_RANGE_SIZE];
4207    pcre_uint8 bit, cbit, all;
4208    int i, byte, length = 0;
4209    
4210    bit = bits[0] & 0x1;
4211    /* All bits will be zero or one (since bit is zero or one). */
4212    all = -bit;
4213    
4214  if (ranges[0] < 0 || ranges[0] > 4)  for (i = 0; i < 256; )
4215      {
4216      byte = i >> 3;
4217      if ((i & 0x7) == 0 && bits[byte] == all)
4218        i += 8;
4219      else
4220        {
4221        cbit = (bits[byte] >> (i & 0x7)) & 0x1;
4222        if (cbit != bit)
4223          {
4224          if (length >= MAX_RANGE_SIZE)
4225            return FALSE;
4226          ranges[length] = i;
4227          length++;
4228          bit = cbit;
4229          all = -cbit;
4230          }
4231        i++;
4232        }
4233      }
4234    
4235    if (((bit == 0) && nclass) || ((bit == 1) && !nclass))
4236      {
4237      if (length >= MAX_RANGE_SIZE)
4238        return FALSE;
4239      ranges[length] = 256;
4240      length++;
4241      }
4242    
4243    if (length < 0 || length > 4)
4244    return FALSE;    return FALSE;
4245    
4246    bit = bits[0] & 0x1;
4247    if (invert) bit ^= 0x1;
4248    
4249  /* No character is accepted. */  /* No character is accepted. */
4250  if (ranges[0] == 0 && ranges[1] == 0)  if (length == 0 && bit == 0)
4251    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4252    
4253  if (readch)  switch(length)
   read_char8(common);  
   
 switch(ranges[0])  
4254    {    {
4255    case 0:    case 0:
4256    /* When ranges[1] != 0, all characters are accepted. */    /* When bit != 0, all characters are accepted. */
4257    return TRUE;    return TRUE;
4258    
4259    case 1:    case 1:
4260    add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));    add_jump(compiler, backtracks, CMP(bit == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
4261    return TRUE;    return TRUE;
4262    
4263    case 2:    case 2:
4264    if (ranges[2] + 1 != ranges[3])    if (ranges[0] + 1 != ranges[1])
4265      {      {
4266      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4267      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));      add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4268      }      }
4269    else    else
4270      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));      add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
4271    return TRUE;    return TRUE;
4272    
4273    case 3:    case 3:
4274    if (ranges[1] != 0)    if (bit != 0)
4275      {      {
4276      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
4277      if (ranges[2] + 1 != ranges[3])      if (ranges[0] + 1 != ranges[1])
4278        {        {
4279        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4280        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4281        }        }
4282      else      else
4283        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[0]));
4284      return TRUE;      return TRUE;
4285      }      }
4286    
4287    add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2]));    add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[0]));
4288    if (ranges[3] + 1 != ranges[4])    if (ranges[1] + 1 != ranges[2])
4289      {      {
4290      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[3]);      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1]);
4291      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[3]));      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
4292      }      }
4293    else    else
4294      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3]));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1]));
4295    return TRUE;    return TRUE;
4296    
4297    case 4:    case 4:
4298    if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4])    if ((ranges[1] - ranges[0]) == (ranges[3] - ranges[2])
4299        && (ranges[2] | (ranges[4] - ranges[2])) == ranges[4]        && (ranges[0] | (ranges[2] - ranges[0])) == ranges[2]
4300        && is_powerof2(ranges[4] - ranges[2]))        && is_powerof2(ranges[2] - ranges[0]))
4301      {      {
4302      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[0]);
4303      if (ranges[4] + 1 != ranges[5])      if (ranges[2] + 1 != ranges[3])
4304        {        {
4305        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
4306        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
4307        }        }
4308      else      else
4309        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
4310      return TRUE;      return TRUE;
4311      }      }
4312    
4313    if (ranges[1] != 0)    if (bit != 0)
4314      {      {
4315      offset = 0;      i = 0;
4316      if (ranges[2] + 1 != ranges[3])      if (ranges[0] + 1 != ranges[1])
4317        {        {
4318        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4319        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4320        offset = ranges[2];        i = ranges[0];
4321        }        }
4322      else      else
4323        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[0]));
4324    
4325      if (ranges[4] + 1 != ranges[5])      if (ranges[2] + 1 != ranges[3])
4326        {        {
4327        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - offset);        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - i);
4328        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
4329        }        }
4330      else      else
4331        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4] - offset));        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2] - i));
4332      return TRUE;      return TRUE;
4333      }      }
4334    
4335    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4336    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[2]));    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[0]));
4337    if (ranges[3] + 1 != ranges[4])    if (ranges[1] + 1 != ranges[2])
4338      {      {
4339      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]);      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]);
4340      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[3]));      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
4341      }      }
4342    else    else
4343      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4344    return TRUE;    return TRUE;
4345    
4346    default:    default:
# Line 3885  switch(ranges[0]) Line 4349  switch(ranges[0])
4349    }    }
4350  }  }
4351    
 static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks)  
 {  
 int ranges[2 + MAX_RANGE_SIZE];  
 pcre_uint8 bit, cbit, all;  
 int i, byte, length = 0;  
   
 bit = bits[0] & 0x1;  
 ranges[1] = !invert ? bit : (bit ^ 0x1);  
 /* All bits will be zero or one (since bit is zero or one). */  
 all = -bit;  
   
 for (i = 0; i < 256; )  
   {  
   byte = i >> 3;  
   if ((i & 0x7) == 0 && bits[byte] == all)  
     i += 8;  
   else  
     {  
     cbit = (bits[byte] >> (i & 0x7)) & 0x1;  
     if (cbit != bit)  
       {  
       if (length >= MAX_RANGE_SIZE)  
         return FALSE;  
       ranges[2 + length] = i;  
       length++;  
       bit = cbit;  
       all = -cbit;  
       }  
     i++;  
     }  
   }  
   
 if (((bit == 0) && nclass) || ((bit == 1) && !nclass))  
   {  
   if (length >= MAX_RANGE_SIZE)  
     return FALSE;  
   ranges[2 + length] = 256;  
   length++;  
   }  
 ranges[0] = length;  
   
 return check_ranges(common, ranges, backtracks, FALSE);  
 }  
   
4352  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
4353  {  {
4354  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
# Line 4288  while (utflength > 0); Line 4708  while (utflength > 0);
4708  return cc;  return cc;
4709  }  }
4710    
4711  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
   
 #define SET_TYPE_OFFSET(value) \  
   if ((value) != typeoffset) \  
     { \  
     if ((value) > typeoffset) \  
       OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \  
     else \  
       OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \  
     } \  
   typeoffset = (value);  
   
 #define SET_CHAR_OFFSET(value) \  
   if ((value) != charoffset) \  
     { \  
     if ((value) > charoffset) \  
       OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (value) - charoffset); \  
     else \  
       OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, charoffset - (value)); \  
     } \  
   charoffset = (value);  
   
 static void compile_xclass_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)  
 {  
 DEFINE_COMPILER;  
 jump_list *found = NULL;  
 jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;  
 pcre_int32 c, charoffset;  
 struct sljit_jump *jump = NULL;  
 pcre_uchar *ccbegin;  
 int compares, invertcmp, numberofcmps;  
   
 #ifdef SUPPORT_UCP  
 BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  
 BOOL charsaved = FALSE;  
 int typereg = TMP1, scriptreg = TMP1;  
 const pcre_uint32 *other_cases;  
 pcre_int32 typeoffset;  
 #endif  
   
 /* Although SUPPORT_UTF must be defined, we are  
    not necessary in utf mode even in 8 bit mode. */  
 detect_partial_match(common, backtracks);  
 read_char(common);  
   
 cc++;  
 if ((cc[-1] & XCL_HASPROP) == 0)  
   {  
   if ((cc[-1] & XCL_MAP) != 0)  
     {  
     OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  
 #ifdef SUPPORT_UCP  
     charsaved = TRUE;  
 #endif  
     if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, FALSE, backtracks))  
       {  
       jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
   
       OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);  
       OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);  
       OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);  
       OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);  
       OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);  
       add_jump(compiler, &found, JUMP(SLJIT_C_NOT_ZERO));  
       add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));  
   
       JUMPHERE(jump);  
       }  
     else  
       add_jump(compiler, &found, CMP(SLJIT_C_LESS_EQUAL, TMP3, 0, SLJIT_IMM, 0xff));  
   
     OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);  
     cc += 32 / sizeof(pcre_uchar);  
     }  
   else  
     add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0xff));  
   }  
 else if ((cc[-1] & XCL_MAP) != 0)  
   {  
   OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  
 #ifdef SUPPORT_UCP  
   charsaved = TRUE;  
 #endif  
   if (!check_class_ranges(common, (const pcre_uint8 *)cc, FALSE, TRUE, list))  
     {  
 #ifdef COMPILE_PCRE8  
     SLJIT_ASSERT(common->utf);  
 #endif  
     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
4712    
4713      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);  #define SET_TYPE_OFFSET(value) \
4714      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    if ((value) != typeoffset) \
4715      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);      { \
4716      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      if ((value) < typeoffset) \
4717      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \
4718      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      else \
4719          OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \
4720        } \
4721      typeoffset = (value);
4722    
4723      JUMPHERE(jump);  #define SET_CHAR_OFFSET(value) \
4724      }    if ((value) != charoffset) \
4725        { \
4726        if ((value) < charoffset) \
4727          OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(charoffset - (value))); \
4728        else \
4729          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)((value) - charoffset)); \
4730        } \
4731      charoffset = (value);
4732    
4733    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);  static void compile_xclass_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)
4734    cc += 32 / sizeof(pcre_uchar);  {
4735    }  DEFINE_COMPILER;
4736    jump_list *found = NULL;
4737    jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4738    sljit_uw c, charoffset, max = 256, min = READ_CHAR_MAX;
4739    struct sljit_jump *jump = NULL;
4740    pcre_uchar *ccbegin;
4741    int compares, invertcmp, numberofcmps;
4742    #if defined SUPPORT_UTF && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
4743    BOOL utf = common->utf;
4744    #endif
4745    
4746    #ifdef SUPPORT_UCP
4747    BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4748    BOOL charsaved = FALSE;
4749    int typereg = TMP1, scriptreg = TMP1;
4750    const pcre_uint32 *other_cases;
4751    sljit_uw typeoffset;
4752    #endif
4753    
4754  /* Scanning the necessary info. */  /* Scanning the necessary info. */
4755    cc++;
4756  ccbegin = cc;  ccbegin = cc;
4757  compares = 0;  compares = 0;
4758    if (cc[-1] & XCL_MAP)
4759      {
4760      min = 0;
4761      cc += 32 / sizeof(pcre_uchar);
4762      }
4763    
4764  while (*cc != XCL_END)  while (*cc != XCL_END)
4765    {    {
4766    compares++;    compares++;
4767    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
4768      {      {
4769      cc += 2;      cc ++;
4770  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4771      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (c > max) max = c;
4772  #endif      if (c < min) min = c;
4773  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4774      needschar = TRUE;      needschar = TRUE;
4775  #endif  #endif
4776      }      }
4777    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4778      {      {
4779      cc += 2;      cc ++;
4780  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4781      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (c < min) min = c;
4782  #endif      GETCHARINCTEST(c, cc);
4783      cc++;      if (c > max) max = c;
 #ifdef SUPPORT_UTF  
     if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
4784  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4785      needschar = TRUE;      needschar = TRUE;
4786  #endif  #endif
# Line 4427  while (*cc != XCL_END) Line 4790  while (*cc != XCL_END)
4790      {      {
4791      SLJIT_ASSERT(*cc == XCL_PROP || *cc == XCL_NOTPROP);      SLJIT_ASSERT(*cc == XCL_PROP || *cc == XCL_NOTPROP);
4792      cc++;      cc++;
4793        if (*cc == PT_CLIST)
4794          {
4795          other_cases = PRIV(ucd_caseless_sets) + cc[1];
4796          while (*other_cases != NOTACHAR)
4797            {
4798            if (*other_cases > max) max = *other_cases;
4799            if (*other_cases < min) min = *other_cases;
4800            other_cases++;
4801            }
4802          }
4803        else
4804          {
4805          max = READ_CHAR_MAX;
4806          min = 0;
4807          }
4808    
4809      switch(*cc)      switch(*cc)
4810        {        {
4811        case PT_ANY:        case PT_ANY:
# Line 4467  while (*cc != XCL_END) Line 4846  while (*cc != XCL_END)
4846  #endif  #endif
4847    }    }
4848    
4849    /* We are not necessary in utf mode even in 8 bit mode. */
4850    cc = ccbegin;
4851    detect_partial_match(common, backtracks);
4852    read_char_range(common, min, max, (cc[-1] & XCL_NOT) != 0);
4853    
4854    if ((cc[-1] & XCL_HASPROP) == 0)
4855      {
4856      if ((cc[-1] & XCL_MAP) != 0)
4857        {
4858        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4859        if (!check_class_ranges(common, (const pcre_uint8 *)cc, (((const pcre_uint8 *)cc)[31] & 0x80) != 0, TRUE, &found))
4860          {
4861          OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4862          OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4863          OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4864          OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4865          OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4866          add_jump(compiler, &found, JUMP(SLJIT_C_NOT_ZERO));
4867          }
4868    
4869        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4870        JUMPHERE(jump);
4871    
4872        cc += 32 / sizeof(pcre_uchar);
4873        }
4874      else
4875        {
4876        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, min);
4877        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, max - min));
4878        }
4879      }
4880    else if ((cc[-1] & XCL_MAP) != 0)
4881      {
4882      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4883    #ifdef SUPPORT_UCP
4884      charsaved = TRUE;
4885    #endif
4886      if (!check_class_ranges(common, (const pcre_uint8 *)cc, FALSE, TRUE, list))
4887        {
4888    #ifdef COMPILE_PCRE8
4889        SLJIT_ASSERT(common->utf);
4890    #endif
4891        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4892    
4893        OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4894        OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4895        OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4896        OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4897        OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4898        add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
4899    
4900        JUMPHERE(jump);
4901        }
4902    
4903      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
4904      cc += 32 / sizeof(pcre_uchar);
4905      }
4906    
4907  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4908  /* Simple register allocation. TMP1 is preferred if possible. */  /* Simple register allocation. TMP1 is preferred if possible. */
4909  if (needstype || needsscript)  if (needstype || needsscript)
# Line 4508  if (needstype || needsscript) Line 4945  if (needstype || needsscript)
4945  #endif  #endif
4946    
4947  /* Generating code. */  /* Generating code. */
 cc = ccbegin;  
4948  charoffset = 0;  charoffset = 0;
4949  numberofcmps = 0;  numberofcmps = 0;
4950  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4524  while (*cc != XCL_END) Line 4960  while (*cc != XCL_END)
4960    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
4961      {      {
4962      cc ++;      cc ++;
4963  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
     if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4964    
4965      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4966        {        {
4967        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(c - charoffset));
4968        OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_EQUAL);
4969        numberofcmps++;        numberofcmps++;
4970        }        }
4971      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4972        {        {
4973        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(c - charoffset));
4974        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_C_EQUAL);
4975        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4976        numberofcmps = 0;        numberofcmps = 0;
4977        }        }
4978      else      else
4979        {        {
4980        jump = CMP(SLJIT_C_EQUAL ^ invertcmp, TMP1, 0, SLJIT_IMM, c - charoffset);        jump = CMP(SLJIT_C_EQUAL ^ invertcmp, TMP1, 0, SLJIT_IMM, (sljit_sw)(c - charoffset));
4981        numberofcmps = 0;        numberofcmps = 0;
4982        }        }
4983      }      }
4984    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4985      {      {
4986      cc ++;      cc ++;
4987  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
     if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4988      SET_CHAR_OFFSET(c);      SET_CHAR_OFFSET(c);
4989  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4990      if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4991      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4992        {        {
4993        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(c - charoffset));
4994        OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_LESS_EQUAL);
4995        numberofcmps++;        numberofcmps++;
4996        }        }
4997      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4998        {        {
4999        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(c - charoffset));
5000        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
5001        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
5002        numberofcmps = 0;        numberofcmps = 0;
5003        }        }
5004      else      else
5005        {        {
5006        jump = CMP(SLJIT_C_LESS_EQUAL ^ invertcmp, TMP1, 0, SLJIT_IMM, c - charoffset);        jump = CMP(SLJIT_C_LESS_EQUAL ^ invertcmp, TMP1, 0, SLJIT_IMM, (sljit_sw)(c - charoffset));
5007        numberofcmps = 0;        numberofcmps = 0;
5008        }        }
5009      }      }
# Line 4653  while (*cc != XCL_END) Line 5069  while (*cc != XCL_END)
5069        break;        break;
5070    
5071        case PT_WORD:        case PT_WORD:
5072        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(CHAR_UNDERSCORE - charoffset));
5073        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
5074        /* Fall through. */        /* Fall through. */
5075    
# Line 4701  while (*cc != XCL_END) Line 5117  while (*cc != XCL_END)
5117          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[2]);          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[2]);
5118          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
5119    
5120          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, other_cases[0] - charoffset);          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(other_cases[0] - charoffset));
5121          OP_FLAGS(SLJIT_OR | ((other_cases[3] == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_OR | ((other_cases[3] == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
5122    
5123          other_cases += 3;          other_cases += 3;
5124          }          }
5125        else        else
5126          {          {
5127          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(*other_cases++ - charoffset));
5128          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
5129          }          }
5130    
5131        while (*other_cases != NOTACHAR)        while (*other_cases != NOTACHAR)
5132          {          {
5133          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(*other_cases++ - charoffset));
5134          OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
5135          }          }
5136        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
5137        break;        break;
5138    
5139        case PT_UCNC:        case PT_UCNC:
5140        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(CHAR_DOLLAR_SIGN - charoffset));
5141        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
5142        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(CHAR_COMMERCIAL_AT - charoffset));
5143        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
5144        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(CHAR_GRAVE_ACCENT - charoffset));
5145        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
5146    
5147        SET_CHAR_OFFSET(0xa0);        SET_CHAR_OFFSET(0xa0);
5148        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(0xd7ff - charoffset));
5149        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
5150        SET_CHAR_OFFSET(0);        SET_CHAR_OFFSET(0);
5151        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
# Line 4828  struct sljit_label *label; Line 5244  struct sljit_label *label;
5244  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
5245  pcre_uchar propdata[5];  pcre_uchar propdata[5];
5246  #endif  #endif
5247  #endif  #endif /* SUPPORT_UTF */
5248    
5249  switch(type)  switch(type)
5250    {    {
# Line 4854  switch(type) Line 5270  switch(type)
5270    case OP_DIGIT:    case OP_DIGIT:
5271    /* Digits are usually 0-9, so it is worth to optimize them. */    /* Digits are usually 0-9, so it is worth to optimize them. */
5272    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5273    /* Flip the starting bit in the negative case. */  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5274    read_char8_type(common);    if (common->utf && is_char7_bitset((const pcre_uint8*)common->ctypes - cbit_length + cbit_digit, FALSE))
5275        read_char7_type(common, type == OP_NOT_DIGIT);
5276      else
5277    #endif
5278        read_char8_type(common, type == OP_NOT_DIGIT);
5279        /* Flip the starting bit in the negative case. */
5280    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);
5281    add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
5282    return cc;    return cc;
# Line 4863  switch(type) Line 5284  switch(type)
5284    case OP_NOT_WHITESPACE:    case OP_NOT_WHITESPACE:
5285    case OP_WHITESPACE:    case OP_WHITESPACE:
5286    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5287    read_char8_type(common);  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5288      if (common->utf && is_char7_bitset((const pcre_uint8*)common->ctypes - cbit_length + cbit_space, FALSE))
5289        read_char7_type(common, type == OP_NOT_WHITESPACE);
5290      else
5291    #endif
5292        read_char8_type(common, type == OP_NOT_WHITESPACE);
5293    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_space);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_space);
5294    add_jump(compiler, backtracks, JUMP(type == OP_WHITESPACE ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_WHITESPACE ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
5295    return cc;    return cc;
# Line 4871  switch(type) Line 5297  switch(type)
5297    case OP_NOT_WORDCHAR:    case OP_NOT_WORDCHAR:
5298    case OP_WORDCHAR:    case OP_WORDCHAR:
5299    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5300    read_char8_type(common);  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5301      if (common->utf && is_char7_bitset((const pcre_uint8*)common->ctypes - cbit_length + cbit_word, FALSE))
5302        read_char7_type(common, type == OP_NOT_WORDCHAR);
5303      else
5304    #endif
5305        read_char8_type(common, type == OP_NOT_WORDCHAR);
5306    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_word);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_word);
5307    add_jump(compiler, backtracks, JUMP(type == OP_WORDCHAR ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_WORDCHAR ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
5308    return cc;    return cc;
5309    
5310    case OP_ANY:    case OP_ANY:
5311    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5312    read_char(common);    read_char_range(common, common->nlmin, common->nlmax, TRUE);
5313    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
5314      {      {
5315      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
# Line 4946  switch(type) Line 5377  switch(type)
5377    
5378    case OP_ANYNL:    case OP_ANYNL:
5379    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5380    read_char(common);    read_char_range(common, common->bsr_nlmin, common->bsr_nlmax, FALSE);
5381    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
5382    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
5383    end_list = NULL;    end_list = NULL;
# Line 4968  switch(type) Line 5399  switch(type)
5399    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
5400    case OP_HSPACE:    case OP_HSPACE:
5401    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5402    read_char(common);    read_char_range(common, 0x9, 0x3000, type == OP_NOT_HSPACE);
5403    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));
5404    add_jump(compiler, backtracks, JUMP(type == OP_NOT_HSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_NOT_HSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
5405    return cc;    return cc;
# Line 4976  switch(type) Line 5407  switch(type)
5407    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
5408    case OP_VSPACE:    case OP_VSPACE:
5409    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5410    read_char(common);    read_char_range(common, 0xa, 0x2029, type == OP_NOT_VSPACE);
5411    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));
5412    add_jump(compiler, backtracks, JUMP(type == OP_NOT_VSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_NOT_VSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
5413    return cc;    return cc;
# Line 5075  switch(type) Line 5506  switch(type)
5506      else      else
5507        {        {
5508        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);
5509        read_char(common);        read_char_range(common, common->nlmin, common->nlmax, TRUE);
5510        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, STR_END, 0));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, STR_END, 0));
5511        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
5512        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 5123  switch(type) Line 5554  switch(type)
5554    else    else
5555      {      {
5556      skip_char_back(common);      skip_char_back(common);
5557      read_char(common);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
5558      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5559      }      }
5560    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 5174  switch(type) Line 5605  switch(type)
5605      }      }
5606    else    else
5607      {      {
5608      peek_char(common);      peek_char(common, common->nlmax);
5609      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5610      }      }
5611    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 5198  switch(type) Line 5629  switch(type)
5629  #endif  #endif
5630      return byte_sequence_compare(common, type == OP_CHARI, cc, &context, backtracks);      return byte_sequence_compare(common, type == OP_CHARI, cc, &context, backtracks);
5631      }      }
5632    
5633    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
   read_char(common);  
5634  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
5635    if (common->utf)    if (common->utf)
5636      {      {
# Line 5208  switch(type) Line 5639  switch(type)
5639    else    else
5640  #endif  #endif
5641      c = *cc;      c = *cc;
5642    
5643    if (type == OP_CHAR || !char_has_othercase(common, cc))    if (type == OP_CHAR || !char_has_othercase(common, cc))
5644      {      {
5645        read_char_range(common, c, c, FALSE);
5646      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c));
5647      return cc + length;      return cc + length;
5648      }      }
5649    oc = char_othercase(common, c);    oc = char_othercase(common, c);
5650      read_char_range(common, c < oc ? c : oc, c > oc ? c : oc, FALSE);
5651    bit = c ^ oc;    bit = c ^ oc;
5652    if (is_powerof2(bit))    if (is_powerof2(bit))
5653      {      {
# Line 5221  switch(type) Line 5655  switch(type)
5655      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));
5656      return cc + length;      return cc + length;
5657      }      }
5658    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c);    jump[0] = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c);
5659    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);    add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, oc));
5660    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);    JUMPHERE(jump[0]);
   OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);  
   add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));  
5661    return cc + length;    return cc + length;
5662    
5663    case OP_NOT:    case OP_NOT:
# Line 5260  switch(type) Line 5692  switch(type)
5692  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
5693        {        {
5694        GETCHARLEN(c, cc, length);        GETCHARLEN(c, cc, length);
       read_char(common);  
5695        }        }
5696      }      }
5697    else    else
5698  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
     {  
     read_char(common);  
5699      c = *cc;      c = *cc;
     }  
5700    
5701    if (type == OP_NOT || !char_has_othercase(common, cc))    if (type == OP_NOT || !char_has_othercase(common, cc))
5702        {
5703        read_char_range(common, c, c, TRUE);
5704      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));
5705        }
5706    else    else
5707      {      {
5708      oc = char_othercase(common, c);      oc = char_othercase(common, c);
5709        read_char_range(common, c < oc ? c : oc, c > oc ? c : oc, TRUE);
5710      bit = c ^ oc;      bit = c ^ oc;
5711      if (is_powerof2(bit))      if (is_powerof2(bit))
5712        {        {
# Line 5292  switch(type) Line 5724  switch(type)
5724    case OP_CLASS:    case OP_CLASS:
5725    case OP_NCLASS:    case OP_NCLASS:
5726    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5727    read_char8(common);  
5728    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5729      bit = (common->utf && is_char7_bitset((const pcre_uint8 *)cc, type == OP_NCLASS)) ? 127 : 255;
5730      read_char_range(common, 0, bit, type == OP_NCLASS);
5731    #else
5732      read_char_range(common, 0, 255, type == OP_NCLASS);
5733    #endif
5734    
5735    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, FALSE, backtracks))    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, FALSE, backtracks))
5736      return cc + 32 / sizeof(pcre_uchar);      return cc + 32 / sizeof(pcre_uchar);
5737    
5738  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5739    jump[0] = NULL;    jump[0] = NULL;
 #ifdef COMPILE_PCRE8  
   /* This check only affects 8 bit mode. In other modes, we  
   always need to compare the value with 255. */  
5740    if (common->utf)    if (common->utf)
 #endif /* COMPILE_PCRE8 */  
5741      {      {
5742      jump[0] = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump[0] = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, bit);
5743      if (type == OP_CLASS)      if (type == OP_CLASS)
5744        {        {
5745        add_jump(compiler, backtracks, jump[0]);        add_jump(compiler, backtracks, jump[0]);
5746        jump[0] = NULL;        jump[0] = NULL;
5747        }        }
5748      }      }
5749  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #elif !defined COMPILE_PCRE8
5750      jump[0] = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
5751      if (type == OP_CLASS)
5752        {
5753        add_jump(compiler, backtracks, jump[0]);
5754        jump[0] = NULL;
5755        }
5756    #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
5757    
5758    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
5759    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
5760    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
5761    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
5762    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);
5763    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
5764    
5765  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
5766    if (jump[0] != NULL)    if (jump[0] != NULL)
5767      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
5768  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif
5769    
5770    return cc + 32 / sizeof(pcre_uchar);    return cc + 32 / sizeof(pcre_uchar);
5771    
5772  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
# Line 6971  if (ket == OP_KETRMAX) Line 7416  if (ket == OP_KETRMAX)
7416    
7417  if (repeat_type == OP_EXACT)  if (repeat_type == OP_EXACT)
7418    {    {
7419      count_match(common);
7420    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
7421    JUMPTO(SLJIT_C_NOT_ZERO, rmax_label);    JUMPTO(SLJIT_C_NOT_ZERO, rmax_label);
7422    }    }
# Line 7655  if (*cc == OP_FAIL) Line 8101  if (*cc == OP_FAIL)
8101    return cc + 1;    return cc + 1;
8102    }    }
8103    
8104  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL || !common->might_be_empty)
8105    {    {
8106    /* No need to check notempty conditions. */    /* No need to check notempty conditions. */
8107    if (common->accept_label == NULL)    if (common->accept_label == NULL)
# Line 8357  if (bra == OP_BRAZERO) Line 8803  if (bra == OP_BRAZERO)
8803  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8804  {  {
8805  DEFINE_COMPILER;  DEFINE_COMPILER;
8806  int opcode, stacksize, count;  int opcode, stacksize, alt_count, alt_max;
8807  int offset = 0;  int offset = 0;
8808  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;
8809  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;
8810  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
8811  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
8812  pcre_uchar *ccprev;  pcre_uchar *ccprev;
 jump_list *jumplist = NULL;  
 jump_list *jumplistitem = NULL;  
8813  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
8814  pcre_uchar ket;  pcre_uchar ket;
8815  assert_backtrack *assert;  assert_backtrack *assert;
8816  BOOL has_alternatives;  BOOL has_alternatives;
8817  BOOL needs_control_head = FALSE;  BOOL needs_control_head = FALSE;
8818  struct sljit_jump *brazero = NULL;  struct sljit_jump *brazero = NULL;
8819    struct sljit_jump *alt1 = NULL;
8820    struct sljit_jump *alt2 = NULL;
8821  struct sljit_jump *once = NULL;  struct sljit_jump *once = NULL;
8822  struct sljit_jump *cond = NULL;  struct sljit_jump *cond = NULL;
8823  struct sljit_label *rmin_label = NULL;  struct sljit_label *rmin_label = NULL;
# Line 8409  if (SLJIT_UNLIKELY(opcode == OP_COND) && Line 8855  if (SLJIT_UNLIKELY(opcode == OP_COND) &&
8855  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))
8856    opcode = OP_ONCE;    opcode = OP_ONCE;
8857    
8858    alt_max = has_alternatives ? no_alternatives(ccbegin) : 0;
8859    
8860  /* Decoding the needs_control_head in framesize. */  /* Decoding the needs_control_head in framesize. */
8861  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
8862    {    {
# Line 8522  else if (SLJIT_UNLIKELY(opcode == OP_CON Line 8970  else if (SLJIT_UNLIKELY(opcode == OP_CON
8970      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8971      free_stack(common, 1);      free_stack(common, 1);
8972    
8973      jumplistitem = sljit_alloc_memory(compiler, sizeof(jump_list));      alt_max = 2;
8974      if (SLJIT_UNLIKELY(!jumplistitem))      alt1 = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, sizeof(sljit_uw));
       return;  
     jumplist = jumplistitem;  
     jumplistitem->next = NULL;  
     jumplistitem->jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 1);  
8975      }      }
8976    }    }
8977  else if (*cc == OP_ALT)  else if (has_alternatives)
8978    {    {
   /* Build a jump list. Get the last successfully matched branch index. */  
8979    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8980    free_stack(common, 1);    free_stack(common, 1);
   count = 1;  
   do  
     {  
     /* Append as the last item. */  
     if (jumplist != NULL)  
       {  
       jumplistitem->next = sljit_alloc_memory(compiler, sizeof(jump_list));  
       jumplistitem = jumplistitem->next;  
       }  
     else  
       {  
       jumplistitem = sljit_alloc_memory(compiler, sizeof(jump_list));  
       jumplist = jumplistitem;  
       }  
   
     if (SLJIT_UNLIKELY(!jumplistitem))  
       return;  
8981    
8982      jumplistitem->next = NULL;    if (alt_max > 4)
8983      jumplistitem->jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, count++);      {
8984      cc += GET(cc, 1);      /* Table jump if alt_max is greater than 4. */
8985        sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM1(TMP1), (sljit_sw)common->read_only_data_ptr);
8986        add_label_addr(common);
8987        }
8988      else
8989        {
8990        if (alt_max == 4)
8991          alt2 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_uw));
8992        alt1 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, sizeof(sljit_uw));
8993      }      }
   while (*cc == OP_ALT);  
   
   cc = ccbegin + GET(ccbegin, 1);  
8994    }    }
8995    
8996  COMPILE_BACKTRACKINGPATH(current->top);  COMPILE_BACKTRACKINGPATH(current->top);
# Line 8594  if (SLJIT_UNLIKELY(opcode == OP_COND) || Line 9025  if (SLJIT_UNLIKELY(opcode == OP_COND) ||
9025    
9026  if (has_alternatives)  if (has_alternatives)
9027    {    {
9028    count = 1;    alt_count = sizeof(sljit_uw);
9029    do    do
9030      {      {
9031      current->top = NULL;      current->top = NULL;
# Line 8670  if (has_alternatives) Line 9101  if (has_alternatives)
9101        stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);        stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);
9102    
9103      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
9104        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, count++);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, alt_count);
9105    
9106      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)
9107        {        {
# Line 8683  if (has_alternatives) Line 9114  if (has_alternatives)
9114    
9115      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
9116        {        {
9117        SLJIT_ASSERT(jumplist);        if (alt_max > 4)
9118        JUMPHERE(jumplist->jump);          add_label_addr(common);
9119        jumplist = jumplist->next;        else
9120            {
9121            if (alt_count != 2 * sizeof(sljit_uw))
9122              {
9123              JUMPHERE(alt1);
9124              if (alt_max == 3 && alt_count == sizeof(sljit_uw))
9125                alt2 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_uw));
9126              }
9127            else
9128              {
9129              JUMPHERE(alt2);
9130              if (alt_max == 4)
9131                alt1 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_uw));
9132              }
9133            }
9134          alt_count += sizeof(sljit_uw);
9135        }        }
9136    
9137      COMPILE_BACKTRACKINGPATH(current->top);      COMPILE_BACKTRACKINGPATH(current->top);
# Line 8694  if (has_alternatives) Line 9140  if (has_alternatives)
9140      SLJIT_ASSERT(!current->nextbacktracks);      SLJIT_ASSERT(!current->nextbacktracks);
9141      }      }
9142    while (*cc == OP_ALT);    while (*cc == OP_ALT);
   SLJIT_ASSERT(!jumplist);  
9143    
9144    if (cond != NULL)    if (cond != NULL)
9145      {      {
# Line 9295  pcre_uchar *ccend; Line 9740  pcre_uchar *ccend;
9740  executable_functions *functions;  executable_functions *functions;
9741  void *executable_func;  void *executable_func;
9742  sljit_uw executable_size;  sljit_uw executable_size;
9743    sljit_uw total_length;
9744    label_addr_list *label_addr;
9745  struct sljit_label *mainloop_label = NULL;  struct sljit_label *mainloop_label = NULL;
9746  struct sljit_label *continue_match_label;  struct sljit_label *continue_match_label;
9747  struct sljit_label *empty_match_found_label;  struct sljit_label *empty_match_found_label = NULL;
9748  struct sljit_label *empty_match_backtrack_label;  struct sljit_label *empty_match_backtrack_label = NULL;
9749  struct sljit_label *reset_match_label;  struct sljit_label *reset_match_label;
9750    struct sljit_label *quit_label;
9751  struct sljit_jump *jump;  struct sljit_jump *jump;
9752  struct sljit_jump *minlength_check_failed = NULL;  struct sljit_jump *minlength_check_failed = NULL;
9753  struct sljit_jump *reqbyte_notfound = NULL;  struct sljit_jump *reqbyte_notfound = NULL;
9754  struct sljit_jump *empty_match;  struct sljit_jump *empty_match = NULL;
 struct sljit_label *quit_label;  
9755    
9756  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);
9757  study = extra->study_data;  study = extra->study_data;
# Line 9317  memset(common, 0, sizeof(compiler_common Line 9764  memset(common, 0, sizeof(compiler_common
9764  rootbacktrack.cc = (pcre_uchar *)re + re->name_table_offset + re->name_count * re->name_entry_size;  rootbacktrack.cc = (pcre_uchar *)re + re->name_table_offset + re->name_count * re->name_entry_size;
9765    
9766  common->start = rootbacktrack.cc;  common->start = rootbacktrack.cc;
9767    common->read_only_data = NULL;
9768    common->read_only_data_size = 0;
9769    common->read_only_data_ptr = NULL;
9770  common->fcc = tables + fcc_offset;  common->fcc = tables + fcc_offset;
9771  common->lcc = (sljit_sw)(tables + lcc_offset);  common->lcc = (sljit_sw)(tables + lcc_offset);
9772  common->mode = mode;  common->mode = mode;
9773    common->might_be_empty = study->minlength == 0;
9774  common->nltype = NLTYPE_FIXED;  common->nltype = NLTYPE_FIXED;
9775  switch(re->options & PCRE_NEWLINE_BITS)  switch(re->options & PCRE_NEWLINE_BITS)
9776    {    {
# Line 9340  switch(re->options & PCRE_NEWLINE_BITS) Line 9791  switch(re->options & PCRE_NEWLINE_BITS)
9791    case PCRE_NEWLINE_ANYCRLF: common->newline = (CHAR_CR << 8) | CHAR_NL; common->nltype = NLTYPE_ANYCRLF; break;    case PCRE_NEWLINE_ANYCRLF: common->newline = (CHAR_CR << 8) | CHAR_NL; common->nltype = NLTYPE_ANYCRLF; break;
9792    default: return;    default: return;
9793    }    }
9794    common->nlmax = READ_CHAR_MAX;
9795    common->nlmin = 0;
9796  if ((re->options & PCRE_BSR_ANYCRLF) != 0)  if ((re->options & PCRE_BSR_ANYCRLF) != 0)
9797    common->bsr_nltype = NLTYPE_ANYCRLF;    common->bsr_nltype = NLTYPE_ANYCRLF;
9798  else if ((re->options & PCRE_BSR_UNICODE) != 0)  else if ((re->options & PCRE_BSR_UNICODE) != 0)
# Line 9352  else Line 9805  else
9805    common->bsr_nltype = NLTYPE_ANY;    common->bsr_nltype = NLTYPE_ANY;
9806  #endif  #endif
9807    }    }
9808    common->bsr_nlmax = READ_CHAR_MAX;
9809    common->bsr_nlmin = 0;
9810  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
9811  common->ctypes = (sljit_sw)(tables + ctypes_offset);  common->ctypes = (sljit_sw)(tables + ctypes_offset);
9812  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;
# Line 9364  common->utf = (re->options & PCRE_UTF8) Line 9819  common->utf = (re->options & PCRE_UTF8)
9819  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
9820  common->use_ucp = (re->options & PCRE_UCP) != 0;  common->use_ucp = (re->options & PCRE_UCP) != 0;
9821  #endif  #endif
9822    if (common->utf)
9823      {
9824      if (common->nltype == NLTYPE_ANY)
9825        common->nlmax = 0x2029;
9826      else if (common->nltype == NLTYPE_ANYCRLF)
9827        common->nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;
9828      else
9829        {
9830        /* We only care about the first newline character. */
9831        common->nlmax = common->newline & 0xff;
9832        }
9833    
9834      if (common->nltype == NLTYPE_FIXED)
9835        common->nlmin = common->newline & 0xff;
9836      else
9837        common->nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL;
9838    
9839      if (common->bsr_nltype == NLTYPE_ANY)
9840        common->bsr_nlmax = 0x2029;
9841      else
9842        common->bsr_nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;
9843      common->bsr_nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL;
9844      }
9845  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
9846  ccend = bracketend(rootbacktrack.cc);  ccend = bracketend(common->start);
9847    
9848  /* Calculate the local space size on the stack. */  /* Calculate the local space size on the stack. */
9849  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);
# Line 9378  memset(common->optimized_cbracket, 0, re Line 9856  memset(common->optimized_cbracket, 0, re
9856  memset(common->optimized_cbracket, 1, re->top_bracket + 1);  memset(common->optimized_cbracket, 1, re->top_bracket + 1);
9857  #endif  #endif
9858    
9859  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);  SLJIT_ASSERT(*common->start == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);
9860  #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2  #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2
9861  common->capture_last_ptr = common->ovector_start;  common->capture_last_ptr = common->ovector_start;
9862  common->ovector_start += sizeof(sljit_sw);  common->ovector_start += sizeof(sljit_sw);
9863  #endif  #endif
9864  if (!check_opcode_types(common, rootbacktrack.cc, ccend))  if (!check_opcode_types(common, common->start, ccend))
9865    {    {
9866    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9867    return;    return;
# Line 9446  if (common->capture_last_ptr != 0) Line 9924  if (common->capture_last_ptr != 0)
9924  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));
9925  common->cbra_ptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw);  common->cbra_ptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw);
9926    
9927  common->private_data_ptrs = (int *)SLJIT_MALLOC((ccend - rootbacktrack.cc) * sizeof(sljit_si));  total_length = ccend - common->start;
9928    common->private_data_ptrs = (sljit_si *)SLJIT_MALLOC(total_length * (sizeof(sljit_si) + (common->has_then ? 1 : 0)));
9929  if (!common->private_data_ptrs)  if (!common->private_data_ptrs)
9930    {    {
9931    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9932    return;    return;
9933    }    }
9934  memset(common->private_data_ptrs, 0, (ccend - rootbacktrack.cc) * sizeof(int));  memset(common->private_data_ptrs, 0, total_length * sizeof(sljit_si));
9935    
9936  private_data_size = common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw);  private_data_size = common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw);
9937  set_private_data_ptrs(common, &private_data_size, ccend);  set_private_data_ptrs(common, &private_data_size, ccend);
# Line 9465  if (private_data_size > SLJIT_MAX_LOCAL_ Line 9944  if (private_data_size > SLJIT_MAX_LOCAL_
9944    
9945  if (common->has_then)  if (common->has_then)
9946    {    {
9947    common->then_offsets = (pcre_uint8 *)SLJIT_MALLOC(ccend - rootbacktrack.cc);    common->then_offsets = (pcre_uint8 *)(common->private_data_ptrs + total_length);
9948    if (!common->then_offsets)    memset(common->then_offsets, 0, total_length);
9949      set_then_offsets(common, common->start, NULL);
9950      }
9951    
9952    if (common->read_only_data_size > 0)
9953      {
9954      common->read_only_data = (sljit_uw *)SLJIT_MALLOC(common->read_only_data_size);
9955      if (common->read_only_data == NULL)
9956      {      {
9957      SLJIT_FREE(common->optimized_cbracket);      SLJIT_FREE(common->optimized_cbracket);
9958      SLJIT_FREE(common->private_data_ptrs);      SLJIT_FREE(common->private_data_ptrs);
9959      return;      return;
9960      }      }
9961    memset(common->then_offsets, 0, ccend - rootbacktrack.cc);    common->read_only_data_ptr = common->read_only_data;
   set_then_offsets(common, rootbacktrack.cc, NULL);  
9962    }    }
9963    
9964  compiler = sljit_create_compiler();  compiler = sljit_create_compiler();
# Line 9481  if (!compiler) Line 9966  if (!compiler)
9966    {    {
9967    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9968    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9969    if (common->has_then)    if (common->read_only_data)
9970      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
9971    return;    return;
9972    }    }
9973  common->compiler = compiler;  common->compiler = compiler;
# Line 9521  if ((re->options & PCRE_ANCHORED) == 0) Line 10006  if ((re->options & PCRE_ANCHORED) == 0)
10006    if ((re->options & PCRE_NO_START_OPTIMIZE) == 0)    if ((re->options & PCRE_NO_START_OPTIMIZE) == 0)
10007      {      {
10008      if (mode == JIT_COMPILE && fast_forward_first_n_chars(common, (re->options & PCRE_FIRSTLINE) != 0))      if (mode == JIT_COMPILE && fast_forward_first_n_chars(common, (re->options & PCRE_FIRSTLINE) != 0))
10009        { /* Do nothing */ }        {
10010          /* If read_only_data is reallocated, we might have an allocation failure. */
10011          if (common->read_only_data_size > 0 && common->read_only_data == NULL)
10012            {
10013            sljit_free_compiler(compiler);
10014            SLJIT_FREE(common->optimized_cbracket);
10015            SLJIT_FREE(common->private_data_ptrs);
10016            return;
10017            }
10018          }
10019      else if ((re->flags & PCRE_FIRSTSET) != 0)      else if ((re->flags & PCRE_FIRSTSET) != 0)
10020        fast_forward_first_char(common, (pcre_uchar)re->first_char, (re->flags & PCRE_FCH_CASELESS) != 0, (re->options & PCRE_FIRSTLINE) != 0);        fast_forward_first_char(common, (pcre_uchar)re->first_char, (re->flags & PCRE_FCH_CASELESS) != 0, (re->options & PCRE_FIRSTLINE) != 0);
10021      else if ((re->flags & PCRE_STARTLINE) != 0)      else if ((re->flags & PCRE_STARTLINE) != 0)
# Line 9568  if (mode == JIT_PARTIAL_SOFT_COMPILE) Line 10062  if (mode == JIT_PARTIAL_SOFT_COMPILE)
10062  else if (mode == JIT_PARTIAL_HARD_COMPILE)  else if (mode == JIT_PARTIAL_HARD_COMPILE)
10063    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
10064    
10065  compile_matchingpath(common, rootbacktrack.cc, ccend, &rootbacktrack);  compile_matchingpath(common, common->start, ccend, &rootbacktrack);
10066  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
10067    {    {
10068    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
10069    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
10070    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
10071    if (common->has_then)    if (common->read_only_data)
10072      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
10073    return;    return;
10074    }    }
10075    
10076  empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));  if (common->might_be_empty)
10077  empty_match_found_label = LABEL();    {
10078      empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
10079      empty_match_found_label = LABEL();
10080      }
10081    
10082  common->accept_label = LABEL();  common->accept_label = LABEL();
10083  if (common->accept != NULL)  if (common->accept != NULL)
# Line 9604  if (mode != JIT_COMPILE) Line 10101  if (mode != JIT_COMPILE)
10101    return_with_partial_match(common, common->quit_label);    return_with_partial_match(common, common->quit_label);
10102    }    }
10103    
10104  empty_match_backtrack_label = LABEL();  if (common->might_be_empty)
10105      empty_match_backtrack_label = LABEL();
10106  compile_backtrackingpath(common, rootbacktrack.top);  compile_backtrackingpath(common, rootbacktrack.top);
10107  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
10108    {    {
10109    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
10110    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
10111    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
10112    if (common->has_then)    if (common->read_only_data)
10113      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
10114    return;    return;
10115    }    }
10116    
# Line 9640  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SL Line 10138  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SL
10138    
10139  if ((re->options & PCRE_ANCHORED) == 0)  if ((re->options & PCRE_ANCHORED) == 0)
10140    {    {
10141    if ((re->options & PCRE_FIRSTLINE) == 0)    if (common->ff_newline_shortcut != NULL)
10142      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop_label);      {
10143        if ((re->options & PCRE_FIRSTLINE) == 0)
10144          CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, common->ff_newline_shortcut);
10145        /* There cannot be more newlines here. */
10146        }
10147    else    else
10148      CMPTO(SLJIT_C_LESS, STR_PTR, 0, TMP1, 0, mainloop_label);      {
10149        if ((re->options & PCRE_FIRSTLINE) == 0)
10150          CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop_label);
10151        else
10152          CMPTO(SLJIT_C_LESS, STR_PTR, 0, TMP1, 0, mainloop_label);
10153        }
10154    }    }
10155    
10156  /* No more remaining characters. */  /* No more remaining characters. */
# Line 9658  JUMPTO(SLJIT_JUMP, common->quit_label); Line 10165  JUMPTO(SLJIT_JUMP, common->quit_label);
10165    
10166  flush_stubs(common);  flush_stubs(common);
10167    
10168  JUMPHERE(empty_match);  if (common->might_be_empty)
10169  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);    {
10170  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));    JUMPHERE(empty_match);
10171  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_backtrack_label);    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
10172  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));
10173  CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_found_label);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_backtrack_label);
10174  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));
10175  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, empty_match_found_label);    CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_found_label);
10176  JUMPTO(SLJIT_JUMP, empty_match_backtrack_label);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
10177      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, empty_match_found_label);
10178      JUMPTO(SLJIT_JUMP, empty_match_backtrack_label);
10179      }
10180    
10181  common->currententry = common->entries;  common->currententry = common->entries;
10182  common->local_exit = TRUE;  common->local_exit = TRUE;
# Line 9680  while (common->currententry != NULL) Line 10190  while (common->currententry != NULL)
10190      sljit_free_compiler(compiler);      sljit_free_compiler(compiler);
10191      SLJIT_FREE(common->optimized_cbracket);      SLJIT_FREE(common->optimized_cbracket);
10192      SLJIT_FREE(common->private_data_ptrs);      SLJIT_FREE(common->private_data_ptrs);
10193      if (common->has_then)      if (common->read_only_data)
10194        SLJIT_FREE(common->then_offsets);        SLJIT_FREE(common->read_only_data);
10195      return;      return;
10196      }      }
10197    flush_stubs(common);    flush_stubs(common);
# Line 9765  if (common->reset_match != NULL) Line 10275  if (common->reset_match != NULL)
10275    JUMPTO(SLJIT_JUMP, reset_match_label);    JUMPTO(SLJIT_JUMP, reset_match_label);
10276    }    }
10277  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
10278  #ifndef COMPILE_PCRE32  #ifdef COMPILE_PCRE8
10279  if (common->utfreadchar != NULL)  if (common->utfreadchar != NULL)
10280    {    {
10281    set_jumps(common->utfreadchar, LABEL());    set_jumps(common->utfreadchar, LABEL());
10282    do_utfreadchar(common);    do_utfreadchar(common);
10283    }    }
10284  #endif /* !COMPILE_PCRE32 */  if (common->utfreadchar16 != NULL)
 #ifdef COMPILE_PCRE8  
 if (common->utfreadchar8 != NULL)  
10285    {    {
10286    set_jumps(common->utfreadchar8, LABEL());    set_jumps(common->utfreadchar16, LABEL());
10287    do_utfreadchar8(common);    do_utfreadchar16(common);
10288    }    }
10289  if (common->utfreadtype8 != NULL)  if (common->utfreadtype8 != NULL)
10290    {    {
# Line 9793  if (common->getucd != NULL) Line 10301  if (common->getucd != NULL)
10301    }    }
10302  #endif  #endif
10303    
10304    SLJIT_ASSERT(common->read_only_data + (common->read_only_data_size >> SLJIT_WORD_SHIFT) == common->read_only_data_ptr);
10305  SLJIT_FREE(common->optimized_cbracket);  SLJIT_FREE(common->optimized_cbracket);
10306  SLJIT_FREE(common->private_data_ptrs);  SLJIT_FREE(common->private_data_ptrs);
 if (common->has_then)  
   SLJIT_FREE(common->then_offsets);  
10307    
10308  executable_func = sljit_generate_code(compiler);  executable_func = sljit_generate_code(compiler);
10309  executable_size = sljit_get_generated_code_size(compiler);  executable_size = sljit_get_generated_code_size(compiler);
10310    label_addr = common->label_addrs;
10311    while (label_addr != NULL)
10312      {
10313      *label_addr->addr = sljit_get_label_addr(label_addr->label);
10314      label_addr = label_addr->next;
10315      }
10316  sljit_free_compiler(compiler);  sljit_free_compiler(compiler);
10317  if (executable_func == NULL)  if (executable_func == NULL)
10318      {
10319      if (common->read_only_data)
10320        SLJIT_FREE(common->read_only_data);
10321    return;    return;
10322      }
10323    
10324  /* Reuse the function descriptor if possible. */  /* Reuse the function descriptor if possible. */
10325  if ((extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 && extra->executable_jit != NULL)  if ((extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 && extra->executable_jit != NULL)
# Line 9822  else Line 10339  else
10339    if (functions == NULL)    if (functions == NULL)
10340      {      {
10341      /* This case is highly unlikely since we just recently      /* This case is highly unlikely since we just recently
10342      freed a lot of memory. Although not impossible. */      freed a lot of memory. Not impossible though. */
10343      sljit_free_code(executable_func);      sljit_free_code(executable_func);
10344        if (common->read_only_data)
10345          SLJIT_FREE(common->read_only_data);
10346      return;      return;
10347      }      }
10348    memset(functions, 0, sizeof(executable_functions));    memset(functions, 0, sizeof(executable_functions));
# Line 9834  else Line 10353  else
10353    }    }
10354    
10355  functions->executable_funcs[mode] = executable_func;  functions->executable_funcs[mode] = executable_func;
10356    functions->read_only_data[mode] = common->read_only_data;
10357  functions->executable_sizes[mode] = executable_size;  functions->executable_sizes[mode] = executable_size;
10358  }  }
10359    
# Line 10020  for (i = 0; i < JIT_NUMBER_OF_COMPILE_MO Line 10540  for (i = 0; i < JIT_NUMBER_OF_COMPILE_MO
10540    {    {
10541    if (functions->executable_funcs[i] != NULL)    if (functions->executable_funcs[i] != NULL)
10542      sljit_free_code(functions->executable_funcs[i]);      sljit_free_code(functions->executable_funcs[i]);
10543      if (functions->read_only_data[i] != NULL)
10544        SLJIT_FREE(functions->read_only_data[i]);
10545    }    }
10546  SLJIT_FREE(functions);  SLJIT_FREE(functions);
10547  }  }

Legend:
Removed from v.1420  
changed lines
  Added in v.1474

  ViewVC Help
Powered by ViewVC 1.1.5