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

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

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

</
revision 1424 by zherczeg, Tue Dec 31 11:22:31 2013 UTC revision 1499 by zherczeg, Mon Aug 11 06:42:28 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 *update_addr;
204      struct label_addr_list *next;
205    } label_addr_list;
206    
207  enum frame_types {  enum frame_types {
208    no_frame = -1,    no_frame = -1,
209    no_stack = -2    no_stack = -2
# Line 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 364  typedef struct compiler_common { Line 379  typedef struct compiler_common {
379    /* Newline control. */    /* Newline control. */
380    int nltype;    int nltype;
381    pcre_uint32 nlmax;    pcre_uint32 nlmax;
382      pcre_uint32 nlmin;
383    int newline;    int newline;
384    int bsr_nltype;    int bsr_nltype;
385    pcre_uint32 bsr_nlmax;    pcre_uint32 bsr_nlmax;
386      pcre_uint32 bsr_nlmin;
387    /* Dollar endonly. */    /* Dollar endonly. */
388    int endonly;    int endonly;
389    /* Tables. */    /* Tables. */
# Line 381  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 456  typedef struct compare_context { Line 475  typedef struct compare_context {
475  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
476  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
477    
478  #define TMP1          SLJIT_SCRATCH_REG1  #define TMP1          SLJIT_R0
479  #define TMP2          SLJIT_SCRATCH_REG3  #define TMP2          SLJIT_R2
480  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_R3
481  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_S0
482  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_S1
483  #define STACK_TOP     SLJIT_SCRATCH_REG2  #define STACK_TOP     SLJIT_R1
484  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_S2
485  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define COUNT_MATCH   SLJIT_S3
486  #define COUNT_MATCH   SLJIT_SAVED_EREG2  #define ARGUMENTS     SLJIT_S4
487  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_R4
488    
489  /* Local space layout. */  /* Local space layout. */
490  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
# 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_ANY 0x7fffffff  #define READ_CHAR_MAX 0x7fffffff
547    
548  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
549  {  {
# Line 535  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 759  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 768  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 1397  while (cc < ccend) Line 1441  while (cc < ccend)
1441      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1442      if (!setsom_found)      if (!setsom_found)
1443        {        {
1444        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0));
1445        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1446        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1447        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
# Line 1413  while (cc < ccend) Line 1457  while (cc < ccend)
1457      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1458      if (!setmark_found)      if (!setmark_found)
1459        {        {
1460        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr);
1461        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1462        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1463        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
# Line 1426  while (cc < ccend) Line 1470  while (cc < ccend)
1470      case OP_RECURSE:      case OP_RECURSE:
1471      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1472        {        {
1473        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0));
1474        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1475        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1476        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
# Line 1435  while (cc < ccend) Line 1479  while (cc < ccend)
1479        }        }
1480      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1481        {        {
1482        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr);
1483        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1484        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1485        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
# Line 1444  while (cc < ccend) Line 1488  while (cc < ccend)
1488        }        }
1489      if (common->capture_last_ptr != 0 && !capture_last_found)      if (common->capture_last_ptr != 0 && !capture_last_found)
1490        {        {
1491        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr);
1492        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1493        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1494        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
# Line 1460  while (cc < ccend) Line 1504  while (cc < ccend)
1504      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1505      if (common->capture_last_ptr != 0 && !capture_last_found)      if (common->capture_last_ptr != 0 && !capture_last_found)
1506        {        {
1507        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr);
1508        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1509        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1510        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
# Line 1470  while (cc < ccend) Line 1514  while (cc < ccend)
1514      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1515      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1516      stackpos += (int)sizeof(sljit_sw);      stackpos += (int)sizeof(sljit_sw);
1517      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset));
1518      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1));
1519      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1520      stackpos += (int)sizeof(sljit_sw);      stackpos += (int)sizeof(sljit_sw);
1521      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
# Line 1851  do Line 1895  do
1895            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1896            stackptr += sizeof(sljit_sw);            stackptr += sizeof(sljit_sw);
1897            }            }
1898          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), srcw[count]);
1899          tmp1empty = FALSE;          tmp1empty = FALSE;
1900          tmp1next = FALSE;          tmp1next = FALSE;
1901          }          }
# Line 1862  do Line 1906  do
1906            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1907            stackptr += sizeof(sljit_sw);            stackptr += sizeof(sljit_sw);
1908            }            }
1909          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), srcw[count]);
1910          tmp2empty = FALSE;          tmp2empty = FALSE;
1911          tmp1next = TRUE;          tmp1next = TRUE;
1912          }          }
# Line 1872  do Line 1916  do
1916        if (tmp1next)        if (tmp1next)
1917          {          {
1918          SLJIT_ASSERT(!tmp1empty);          SLJIT_ASSERT(!tmp1empty);
1919          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count], TMP1, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), srcw[count], TMP1, 0);
1920          tmp1empty = stackptr >= stacktop;          tmp1empty = stackptr >= stacktop;
1921          if (!tmp1empty)          if (!tmp1empty)
1922            {            {
# Line 1884  do Line 1928  do
1928        else        else
1929          {          {
1930          SLJIT_ASSERT(!tmp2empty);          SLJIT_ASSERT(!tmp2empty);
1931          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count], TMP2, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), srcw[count], TMP2, 0);
1932          tmp2empty = stackptr >= stacktop;          tmp2empty = stackptr >= stacktop;
1933          if (!tmp2empty)          if (!tmp2empty)
1934            {            {
# Line 2026  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, sljit_uw *update_addr)
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->update_addr = update_addr;
2083    label_addr->next = common->label_addrs;
2084    common->label_addrs = label_addr;
2085    }
2086    
2087  static SLJIT_INLINE void count_match(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2088  {  {
2089  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2044  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, Line 2102  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP,
2102  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2103  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
2104  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2105  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS0, TMP1, 0);
2106  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, TMP1, 0);
2107  #endif  #endif
2108  add_stub(common, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));  add_stub(common, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));
2109  }  }
# Line 2065  int i; Line 2123  int i;
2123  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2124  SLJIT_ASSERT(length > 1);  SLJIT_ASSERT(length > 1);
2125  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2126  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
2127  if (length < 8)  if (length < 8)
2128    {    {
2129    for (i = 1; i < length; i++)    for (i = 1; i < length; i++)
2130      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(i), SLJIT_R0, 0);
2131    }    }
2132  else  else
2133    {    {
2134    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);    GET_LOCAL_BASE(SLJIT_R1, 0, OVECTOR_START);
2135    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);    OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, length - 1);
2136    loop = LABEL();    loop = LABEL();
2137    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_sw), SLJIT_R0, 0);
2138    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, 1);
2139    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2140    }    }
2141  }  }
# Line 2091  int i; Line 2149  int i;
2149  SLJIT_ASSERT(length > 1);  SLJIT_ASSERT(length > 1);
2150  /* OVECTOR(1) contains the "string begin - 1" constant. */  /* OVECTOR(1) contains the "string begin - 1" constant. */
2151  if (length > 2)  if (length > 2)
2152    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1));
2153  if (length < 8)  if (length < 8)
2154    {    {
2155    for (i = 2; i < length; i++)    for (i = 2; i < length; i++)
2156      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(i), TMP1, 0);
2157    }    }
2158  else  else
2159    {    {
# Line 2109  else Line 2167  else
2167    
2168  OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2169  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2170    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->mark_ptr, SLJIT_IMM, 0);
2171  if (common->control_head_ptr != 0)  if (common->control_head_ptr != 0)
2172    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_IMM, 0);
2173  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2174  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->start_ptr);
2175  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2176  }  }
2177    
# Line 2147  struct sljit_label *loop; Line 2205  struct sljit_label *loop;
2205  struct sljit_jump *early_quit;  struct sljit_jump *early_quit;
2206    
2207  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2208  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  OP1(SLJIT_MOV, SLJIT_S2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1));
2209  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(1), STR_PTR, 0);
2210    
2211  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_R0, 0, ARGUMENTS, 0);
2212  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2213    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);    OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr);
2214  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offset_count));  OP1(SLJIT_MOV_SI, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, offset_count));
2215  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2216    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_R2, 0);
2217  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));  OP2(SLJIT_SUB, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
2218  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, begin));
2219  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_S0, 0, OVECTOR_START);
2220  /* Unlikely, but possible */  /* Unlikely, but possible */
2221  early_quit = CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);  early_quit = CMP(SLJIT_C_EQUAL, SLJIT_R1, 0, SLJIT_IMM, 0);
2222  loop = LABEL();  loop = LABEL();
2223  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);  OP2(SLJIT_SUB, SLJIT_S1, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
2224  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));  OP2(SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, sizeof(sljit_sw));
2225  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2226  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2227  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, UCHAR_SHIFT);
2228  #endif  #endif
2229  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_R2), sizeof(int), SLJIT_S1, 0);
2230  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1);
2231  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2232  JUMPHERE(early_quit);  JUMPHERE(early_quit);
2233    
2234  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2235  if (topbracket > 1)  if (topbracket > 1)
2236    {    {
2237    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));    GET_LOCAL_BASE(SLJIT_R0, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
2238    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, topbracket + 1);
2239    
2240    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_S2. */
2241    loop = LABEL();    loop = LABEL();
2242    OP1(SLJIT_MOVU, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -(2 * (sljit_sw)sizeof(sljit_sw)));    OP1(SLJIT_MOVU, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R0), -(2 * (sljit_sw)sizeof(sljit_sw)));
2243    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1);
2244    CMPTO(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG3, 0, loop);    CMPTO(SLJIT_C_EQUAL, SLJIT_R2, 0, SLJIT_S2, 0, loop);
2245    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_R1, 0);
2246    }    }
2247  else  else
2248    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 2195  static SLJIT_INLINE void return_with_par Line 2253  static SLJIT_INLINE void return_with_par
2253  DEFINE_COMPILER;  DEFINE_COMPILER;
2254  struct sljit_jump *jump;  struct sljit_jump *jump;
2255    
2256  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_S1, str_end_must_be_saved_reg2);
2257  SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0  SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0
2258    && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));    && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2259    
2260  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_R1, 0, ARGUMENTS, 0);
2261  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2262  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count));  OP1(SLJIT_MOV_SI, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R1), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
2263  CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);  CMPTO(SLJIT_C_SIG_LESS, SLJIT_R2, 0, SLJIT_IMM, 2, quit);
2264    
2265  /* Store match begin and end. */  /* Store match begin and end. */
2266  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_S0, 0, SLJIT_MEM1(SLJIT_R1), SLJIT_OFFSETOF(jit_arguments, begin));
2267  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));  OP1(SLJIT_MOV, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R1), SLJIT_OFFSETOF(jit_arguments, offsets));
2268    
2269  jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);  jump = CMP(SLJIT_C_SIG_LESS, SLJIT_R2, 0, SLJIT_IMM, 3);
2270  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_S0, 0);
2271  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2272  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, UCHAR_SHIFT);
2273  #endif  #endif
2274  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_R1), 2 * sizeof(int), SLJIT_R2, 0);
2275  JUMPHERE(jump);  JUMPHERE(jump);
2276    
2277  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);  OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);
2278  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_S1, 0, STR_END, 0, SLJIT_S0, 0);
2279  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2280  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, UCHAR_SHIFT);
2281  #endif  #endif
2282  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_R1), sizeof(int), SLJIT_S1, 0);
2283    
2284  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_S0, 0);
2285  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2286  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, UCHAR_SHIFT);
2287  #endif  #endif
2288  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_R1), 0, SLJIT_R2, 0);
2289    
2290  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2291  }  }
# Line 2241  struct sljit_jump *jump; Line 2299  struct sljit_jump *jump;
2299  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2300    {    {
2301    /* The value of -1 must be kept for start_used_ptr! */    /* The value of -1 must be kept for start_used_ptr! */
2302    OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, SLJIT_IMM, 1);
2303    /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting    /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting
2304    is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */    is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */
2305    jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_PTR, 0);    jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_PTR, 0);
2306    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0);
2307    JUMPHERE(jump);    JUMPHERE(jump);
2308    }    }
2309  else if (common->mode == JIT_PARTIAL_HARD_COMPILE)  else if (common->mode == JIT_PARTIAL_HARD_COMPILE)
2310    {    {
2311    jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0);
2312    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0);
2313    JUMPHERE(jump);    JUMPHERE(jump);
2314    }    }
2315  }  }
# Line 2387  if (common->mode == JIT_COMPILE) Line 2445  if (common->mode == JIT_COMPILE)
2445    return;    return;
2446    
2447  if (!force)  if (!force)
2448    jump = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    jump = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0);
2449  else if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  else if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2450    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, SLJIT_IMM, -1);
2451    
2452  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2453    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0);
2454  else  else
2455    {    {
2456    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2420  if (common->mode == JIT_COMPILE) Line 2478  if (common->mode == JIT_COMPILE)
2478  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2479  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2480    {    {
2481    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0));
2482    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0);
2483    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
2484    }    }
2485  else  else
2486    {    {
2487    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0));
2488    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2489      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2490    else    else
# Line 2448  if (common->mode == JIT_COMPILE) Line 2506  if (common->mode == JIT_COMPILE)
2506    
2507  /* Partial matching mode. */  /* Partial matching mode. */
2508  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2509  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0));
2510  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2511    {    {
2512    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0);
2513    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2514    }    }
2515  else  else
# Line 2464  else Line 2522  else
2522  JUMPHERE(jump);  JUMPHERE(jump);
2523  }  }
2524    
2525  static void peek_char(compiler_common *common)  static void peek_char(compiler_common *common, pcre_uint32 max)
2526  {  {
2527  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2528  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
# Line 2473  DEFINE_COMPILER; Line 2531  DEFINE_COMPILER;
2531  struct sljit_jump *jump;  struct sljit_jump *jump;
2532  #endif  #endif
2533    
2534    SLJIT_UNUSED_ARG(max);
2535    
2536  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2537  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2538  if (common->utf)  if (common->utf)
2539    {    {
2540      if (max < 128) return;
2541    
2542    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2543    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));
2544    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
# Line 2488  if (common->utf) Line 2550  if (common->utf)
2550  #if defined SUPPORT_UTF && defined COMPILE_PCRE16  #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2551  if (common->utf)  if (common->utf)
2552    {    {
2553      if (max < 0xd800) return;
2554    
2555    OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2556    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2557    /* TMP2 contains the high surrogate. */    /* TMP2 contains the high surrogate. */
# Line 2503  if (common->utf) Line 2567  if (common->utf)
2567    
2568  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2569    
2570  static BOOL is_char7_bitset(const pcre_uint8* bitset, BOOL nclass)  static BOOL is_char7_bitset(const pcre_uint8 *bitset, BOOL nclass)
2571  {  {
2572  /* Tells whether the character codes below 128 are enough  /* Tells whether the character codes below 128 are enough
2573  to determine a match. */  to determine a match. */
# Line 2546  if (full_read) Line 2610  if (full_read)
2610    
2611  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2612    
2613  static void read_char_max(compiler_common *common, pcre_uint32 max, BOOL full_read)  static void read_char_range(compiler_common *common, pcre_uint32 min, pcre_uint32 max, BOOL update_str_ptr)
2614  {  {
2615  /* 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
2616  less than or equal to max. Otherwise it returns with a value greater than max.  between min and max (c >= min && c <= max). Otherwise it returns with a value
2617  Does not check STR_END. The full_read argument tells whether characters above  outside the range. Does not check STR_END. */
 max are accepted or not. */  
2618  DEFINE_COMPILER;  DEFINE_COMPILER;
2619  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2620  struct sljit_jump *jump;  struct sljit_jump *jump;
2621  #endif  #endif
2622    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2623    struct sljit_jump *jump2;
2624    #endif
2625    
2626  SLJIT_UNUSED_ARG(full_read);  SLJIT_UNUSED_ARG(update_str_ptr);
2627    SLJIT_UNUSED_ARG(min);
2628  SLJIT_UNUSED_ARG(max);  SLJIT_UNUSED_ARG(max);
2629    SLJIT_ASSERT(min <= max);
2630    
2631  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2632  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));
2633    
2634  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2635  if (common->utf)  if (common->utf)
2636    {    {
2637    if (max < 128 && !full_read)    if (max < 128 && !update_str_ptr) return;
     return;  
2638    
2639    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2640    if (max >= 0x800)    if (min >= 0x10000)
2641        {
2642        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xf0);
2643        if (update_str_ptr)
2644          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2645        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2646        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x7);
2647        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2648        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2649        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2650        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2651        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2652        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2653        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2654        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2655        if (!update_str_ptr)
2656          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2657        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2658        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2659        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2660        JUMPHERE(jump2);
2661        if (update_str_ptr)
2662          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2663        }
2664      else if (min >= 0x800 && max <= 0xffff)
2665        {
2666        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xe0);
2667        if (update_str_ptr)
2668          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2669        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2670        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xf);
2671        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2672        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2673        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2674        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2675        if (!update_str_ptr)
2676          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2677        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2678        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2679        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2680        JUMPHERE(jump2);
2681        if (update_str_ptr)
2682          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2683        }
2684      else if (max >= 0x800)
2685      add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));      add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2686    else if (max < 128)    else if (max < 128)
2687      {      {
# Line 2580  if (common->utf) Line 2691  if (common->utf)
2691    else    else
2692      {      {
2693      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2694      if (!full_read)      if (!update_str_ptr)
2695        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));
2696      else      else
2697        OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);        OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
# Line 2588  if (common->utf) Line 2699  if (common->utf)
2699      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2700      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2701      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2702      if (full_read)      if (update_str_ptr)
2703        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2704      }      }
2705    JUMPHERE(jump);    JUMPHERE(jump);
# Line 2613  if (common->utf) Line 2724  if (common->utf)
2724      return;      return;
2725      }      }
2726    
2727    if (max < 0xd800 && !full_read)    if (max < 0xd800 && !update_str_ptr) return;
     return;  
2728    
2729    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2730    OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2731    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2732    if (full_read)    if (update_str_ptr)
2733      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));
2734    if (max >= 0xd800)    if (max >= 0xd800)
2735      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
# Line 2630  if (common->utf) Line 2740  if (common->utf)
2740    
2741  static SLJIT_INLINE void read_char(compiler_common *common)  static SLJIT_INLINE void read_char(compiler_common *common)
2742  {  {
2743  read_char_max(common, READ_CHAR_ANY, TRUE);  read_char_range(common, 0, READ_CHAR_MAX, TRUE);
2744  }  }
2745    
2746  static void read_char8_type(compiler_common *common, BOOL full_read)  static void read_char8_type(compiler_common *common, BOOL update_str_ptr)
2747  {  {
2748  /* 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. */
 The full_read argument tells whether characters above max are accepted or not. */  
2749  DEFINE_COMPILER;  DEFINE_COMPILER;
2750  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2751  struct sljit_jump *jump;  struct sljit_jump *jump;
# Line 2645  struct sljit_jump *jump; Line 2754  struct sljit_jump *jump;
2754  struct sljit_jump *jump2;  struct sljit_jump *jump2;
2755  #endif  #endif
2756    
2757  SLJIT_UNUSED_ARG(full_read);  SLJIT_UNUSED_ARG(update_str_ptr);
2758    
2759  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2760  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));
# Line 2657  if (common->utf) Line 2766  if (common->utf)
2766    it is needed in most cases. */    it is needed in most cases. */
2767    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2768    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2769    if (!full_read)    if (!update_str_ptr)
2770      {      {
2771      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2772      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
# Line 2688  JUMPHERE(jump); Line 2797  JUMPHERE(jump);
2797  #endif  #endif
2798    
2799  #if defined SUPPORT_UTF && defined COMPILE_PCRE16  #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2800  if (common->utf && full_read)  if (common->utf && update_str_ptr)
2801    {    {
2802    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2803    OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
# Line 2956  if (firstline) Line 3065  if (firstline)
3065      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);
3066      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);
3067      JUMPHERE(end);      JUMPHERE(end);
3068      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_SP), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3069      }      }
3070    else    else
3071      {      {
3072      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3073      mainloop = LABEL();      mainloop = LABEL();
3074      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
3075      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->first_line_end, STR_PTR, 0);
3076      read_char_max(common, common->nlmax, TRUE);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
3077      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
3078      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
3079      JUMPHERE(end);      JUMPHERE(end);
3080      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->first_line_end, STR_PTR, 0);
3081      set_jumps(newline, LABEL());      set_jumps(newline, LABEL());
3082      }      }
3083    
# Line 3040  if (newlinecheck) Line 3149  if (newlinecheck)
3149  return mainloop;  return mainloop;
3150  }  }
3151    
3152  static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, int max_chars)  #define MAX_N_CHARS 16
3153    #define MAX_N_BYTES 8
3154    
3155    static SLJIT_INLINE void add_prefix_byte(pcre_uint8 byte, pcre_uint8 *bytes)
3156    {
3157    pcre_uint8 len = bytes[0];
3158    int i;
3159    
3160    if (len == 255)
3161      return;
3162    
3163    if (len == 0)
3164      {
3165      bytes[0] = 1;
3166      bytes[1] = byte;
3167      return;
3168      }
3169    
3170    for (i = len; i > 0; i--)
3171      if (bytes[i] == byte)
3172        return;
3173    
3174    if (len >= MAX_N_BYTES - 1)
3175      {
3176      bytes[0] = 255;
3177      return;
3178      }
3179    
3180    len++;
3181    bytes[len] = byte;
3182    bytes[0] = len;
3183    }
3184    
3185    static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, pcre_uint8 *bytes, int max_chars)
3186  {  {
3187  /* Recursive function, which scans prefix literals. */  /* Recursive function, which scans prefix literals. */
3188    BOOL last, any, caseless;
3189  int len, repeat, len_save, consumed = 0;  int len, repeat, len_save, consumed = 0;
3190  pcre_uint32 caseless, chr, mask;  pcre_uint32 chr, mask;
3191  pcre_uchar *alternative, *cc_save;  pcre_uchar *alternative, *cc_save, *oc;
3192  BOOL last, any;  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3193    pcre_uchar othercase[8];
3194    #elif defined SUPPORT_UTF && defined COMPILE_PCRE16
3195    pcre_uchar othercase[2];
3196    #else
3197    pcre_uchar othercase[1];
3198    #endif
3199    
3200  repeat = 1;  repeat = 1;
3201  while (TRUE)  while (TRUE)
3202    {    {
3203    last = TRUE;    last = TRUE;
3204    any = FALSE;    any = FALSE;
3205    caseless = 0;    caseless = FALSE;
3206    switch (*cc)    switch (*cc)
3207      {      {
3208      case OP_CHARI:      case OP_CHARI:
3209      caseless = 1;      caseless = TRUE;
3210      case OP_CHAR:      case OP_CHAR:
3211      last = FALSE;      last = FALSE;
3212      cc++;      cc++;
# Line 3078  while (TRUE) Line 3227  while (TRUE)
3227      cc++;      cc++;
3228      continue;      continue;
3229    
3230        case OP_ASSERT:
3231        case OP_ASSERT_NOT:
3232        case OP_ASSERTBACK:
3233        case OP_ASSERTBACK_NOT:
3234        cc = bracketend(cc);
3235        continue;
3236    
3237        case OP_PLUSI:
3238        case OP_MINPLUSI:
3239        case OP_POSPLUSI:
3240        caseless = TRUE;
3241      case OP_PLUS:      case OP_PLUS:
3242      case OP_MINPLUS:      case OP_MINPLUS:
3243      case OP_POSPLUS:      case OP_POSPLUS:
# Line 3085  while (TRUE) Line 3245  while (TRUE)
3245      break;      break;
3246    
3247      case OP_EXACTI:      case OP_EXACTI:
3248      caseless = 1;      caseless = TRUE;
3249      case OP_EXACT:      case OP_EXACT:
3250      repeat = GET2(cc, 1);      repeat = GET2(cc, 1);
3251      last = FALSE;      last = FALSE;
3252      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3253      break;      break;
3254    
3255      case OP_PLUSI:      case OP_QUERYI:
3256      case OP_MINPLUSI:      case OP_MINQUERYI:
3257      case OP_POSPLUSI:      case OP_POSQUERYI:
3258      caseless = 1;      caseless = TRUE;
3259        case OP_QUERY:
3260        case OP_MINQUERY:
3261        case OP_POSQUERY:
3262        len = 1;
3263      cc++;      cc++;
3264    #ifdef SUPPORT_UTF
3265        if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3266    #endif
3267        max_chars = scan_prefix(common, cc + len, chars, bytes, max_chars);
3268        if (max_chars == 0)
3269          return consumed;
3270        last = FALSE;
3271      break;      break;
3272    
3273      case OP_KET:      case OP_KET:
# Line 3116  while (TRUE) Line 3287  while (TRUE)
3287      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
3288      while (*alternative == OP_ALT)      while (*alternative == OP_ALT)
3289        {        {
3290        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);
3291        if (max_chars == 0)        if (max_chars == 0)
3292          return consumed;          return consumed;
3293        alternative += GET(alternative, 1);        alternative += GET(alternative, 1);
# Line 3128  while (TRUE) Line 3299  while (TRUE)
3299      continue;      continue;
3300    
3301      case OP_CLASS:      case OP_CLASS:
3302    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3303        if (common->utf && !is_char7_bitset((const pcre_uint8 *)(cc + 1), FALSE)) return consumed;
3304    #endif
3305        any = TRUE;
3306        cc += 1 + 32 / sizeof(pcre_uchar);
3307        break;
3308    
3309      case OP_NCLASS:      case OP_NCLASS:
3310    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3311        if (common->utf) return consumed;
3312    #endif
3313      any = TRUE;      any = TRUE;
3314      cc += 1 + 32 / sizeof(pcre_uchar);      cc += 1 + 32 / sizeof(pcre_uchar);
3315      break;      break;
3316    
3317  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3318      case OP_XCLASS:      case OP_XCLASS:
3319    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3320        if (common->utf) return consumed;
3321    #endif
3322      any = TRUE;      any = TRUE;
3323      cc += GET(cc, 1);      cc += GET(cc, 1);
3324      break;      break;
3325  #endif  #endif
3326    
     case OP_NOT_DIGIT:  
3327      case OP_DIGIT:      case OP_DIGIT:
3328      case OP_NOT_WHITESPACE:  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3329        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_digit, FALSE))
3330          return consumed;
3331    #endif
3332        any = TRUE;
3333        cc++;
3334        break;
3335    
3336      case OP_WHITESPACE:      case OP_WHITESPACE:
3337      case OP_NOT_WORDCHAR:  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3338        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_space, FALSE))
3339          return consumed;
3340    #endif
3341        any = TRUE;
3342        cc++;
3343        break;
3344    
3345      case OP_WORDCHAR:      case OP_WORDCHAR:
3346    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3347        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_word, FALSE))
3348          return consumed;
3349    #endif
3350        any = TRUE;
3351        cc++;
3352        break;
3353    
3354        case OP_NOT:
3355        case OP_NOTI:
3356        cc++;
3357        /* Fall through. */
3358        case OP_NOT_DIGIT:
3359        case OP_NOT_WHITESPACE:
3360        case OP_NOT_WORDCHAR:
3361      case OP_ANY:      case OP_ANY:
3362      case OP_ALLANY:      case OP_ALLANY:
3363    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3364        if (common->utf) return consumed;
3365    #endif
3366      any = TRUE;      any = TRUE;
3367      cc++;      cc++;
3368      break;      break;
# Line 3155  while (TRUE) Line 3370  while (TRUE)
3370  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3371      case OP_NOTPROP:      case OP_NOTPROP:
3372      case OP_PROP:      case OP_PROP:
3373    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3374        if (common->utf) return consumed;
3375    #endif
3376      any = TRUE;      any = TRUE;
3377      cc += 1 + 2;      cc += 1 + 2;
3378      break;      break;
# Line 3165  while (TRUE) Line 3383  while (TRUE)
3383      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3384      continue;      continue;
3385    
3386        case OP_NOTEXACT:
3387        case OP_NOTEXACTI:
3388    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3389        if (common->utf) return consumed;
3390    #endif
3391        any = TRUE;
3392        repeat = GET2(cc, 1);
3393        cc += 1 + IMM2_SIZE + 1;
3394        break;
3395    
3396      default:      default:
3397      return consumed;      return consumed;
3398      }      }
3399    
3400    if (any)    if (any)
3401      {      {
 #ifdef SUPPORT_UTF  
     if (common->utf) return consumed;  
 #endif  
3402  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
3403      mask = 0xff;      mask = 0xff;
3404  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
# Line 3188  while (TRUE) Line 3413  while (TRUE)
3413        {        {
3414        chars[0] = mask;        chars[0] = mask;
3415        chars[1] = mask;        chars[1] = mask;
3416          bytes[0] = 255;
3417    
3418          consumed++;
3419        if (--max_chars == 0)        if (--max_chars == 0)
3420          return consumed;          return consumed;
       consumed++;  
3421        chars += 2;        chars += 2;
3422          bytes += MAX_N_BYTES;
3423        }        }
3424      while (--repeat > 0);      while (--repeat > 0);
3425    
# Line 3205  while (TRUE) Line 3432  while (TRUE)
3432    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3433  #endif  #endif
3434    
3435    if (caseless != 0 && char_has_othercase(common, cc))    if (caseless && char_has_othercase(common, cc))
3436      {      {
3437      caseless = char_get_othercase_bit(common, cc);  #ifdef SUPPORT_UTF
3438      if (caseless == 0)      if (common->utf)
3439        return consumed;        {
3440  #ifdef COMPILE_PCRE8        GETCHAR(chr, cc);
3441      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));        if ((int)PRIV(ord2utf)(char_othercase(common, chr), othercase) != len)
3442  #else          return consumed;
3443      if ((caseless & 0x100) != 0)        }
       caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));  
3444      else      else
       caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));  
3445  #endif  #endif
3446          {
3447          chr = *cc;
3448          othercase[0] = TABLE_GET(chr, common->fcc, chr);
3449          }
3450      }      }
3451    else    else
3452      caseless = 0;      caseless = FALSE;
3453    
3454    len_save = len;    len_save = len;
3455    cc_save = cc;    cc_save = cc;
3456    while (TRUE)    while (TRUE)
3457      {      {
3458        oc = othercase;
3459      do      do
3460        {        {
3461        chr = *cc;        chr = *cc;
# Line 3233  while (TRUE) Line 3463  while (TRUE)
3463        if (SLJIT_UNLIKELY(chr == NOTACHAR))        if (SLJIT_UNLIKELY(chr == NOTACHAR))
3464          return consumed;          return consumed;
3465  #endif  #endif
3466          add_prefix_byte((pcre_uint8)chr, bytes);
3467    
3468        mask = 0;        mask = 0;
3469        if ((pcre_uint32)len == (caseless & 0xff))        if (caseless)
3470          {          {
3471          mask = caseless >> 8;          add_prefix_byte((pcre_uint8)*oc, bytes);
3472            mask = *cc ^ *oc;
3473          chr |= mask;          chr |= mask;
3474          }          }
3475    
3476    #ifdef COMPILE_PCRE32
3477          if (chars[0] == NOTACHAR && chars[1] == 0)
3478    #else
3479        if (chars[0] == NOTACHAR)        if (chars[0] == NOTACHAR)
3480    #endif
3481          {          {
3482          chars[0] = chr;          chars[0] = chr;
3483          chars[1] = mask;          chars[1] = mask;
# Line 3254  while (TRUE) Line 3491  while (TRUE)
3491          }          }
3492    
3493        len--;        len--;
3494          consumed++;
3495        if (--max_chars == 0)        if (--max_chars == 0)
3496          return consumed;          return consumed;
       consumed++;  
3497        chars += 2;        chars += 2;
3498          bytes += MAX_N_BYTES;
3499        cc++;        cc++;
3500          oc++;
3501        }        }
3502      while (len > 0);      while (len > 0);
3503    
# Line 3275  while (TRUE) Line 3514  while (TRUE)
3514    }    }
3515  }  }
3516    
 #define MAX_N_CHARS 16  
   
3517  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)
3518  {  {
3519  DEFINE_COMPILER;  DEFINE_COMPILER;
3520  struct sljit_label *start;  struct sljit_label *start;
3521  struct sljit_jump *quit;  struct sljit_jump *quit;
3522  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uint32 chars[MAX_N_CHARS * 2];
3523    pcre_uint8 bytes[MAX_N_CHARS * MAX_N_BYTES];
3524  pcre_uint8 ones[MAX_N_CHARS];  pcre_uint8 ones[MAX_N_CHARS];
 pcre_uint32 mask;  
 int i, max;  
3525  int offsets[3];  int offsets[3];
3526    pcre_uint32 mask;
3527    pcre_uint8 *byte_set, *byte_set_end;
3528    int i, max, from;
3529    int range_right = -1, range_len = 3 - 1;
3530    sljit_ub *update_table = NULL;
3531    BOOL in_range;
3532    
3533    /* This is even TRUE, if both are NULL. */
3534    SLJIT_ASSERT(common->read_only_data_ptr == common->read_only_data);
3535    
3536  for (i = 0; i < MAX_N_CHARS; i++)  for (i = 0; i < MAX_N_CHARS; i++)
3537    {    {
3538    chars[i << 1] = NOTACHAR;    chars[i << 1] = NOTACHAR;
3539    chars[(i << 1) + 1] = 0;    chars[(i << 1) + 1] = 0;
3540      bytes[i * MAX_N_BYTES] = 0;
3541    }    }
3542    
3543  max = scan_prefix(common, common->start, chars, MAX_N_CHARS);  max = scan_prefix(common, common->start, chars, bytes, MAX_N_CHARS);
3544    
3545  if (max <= 1)  if (max <= 1)
3546    return FALSE;    return FALSE;
# Line 3311  for (i = 0; i < max; i++) Line 3557  for (i = 0; i < max; i++)
3557      }      }
3558    }    }
3559    
3560    in_range = FALSE;
3561    from = 0;   /* Prevent compiler "uninitialized" warning */
3562    for (i = 0; i <= max; i++)
3563      {
3564      if (in_range && (i - from) > range_len && (bytes[(i - 1) * MAX_N_BYTES] <= 4))
3565        {
3566        range_len = i - from;
3567        range_right = i - 1;
3568        }
3569    
3570      if (i < max && bytes[i * MAX_N_BYTES] < 255)
3571        {
3572        if (!in_range)
3573          {
3574          in_range = TRUE;
3575          from = i;
3576          }
3577        }
3578      else if (in_range)
3579        in_range = FALSE;
3580      }
3581    
3582    if (range_right >= 0)
3583      {
3584      /* Since no data is consumed (see the assert in the beginning
3585      of this function), this space can be reallocated. */
3586      if (common->read_only_data)
3587        SLJIT_FREE(common->read_only_data);
3588    
3589      common->read_only_data_size += 256;
3590      common->read_only_data = (sljit_uw *)SLJIT_MALLOC(common->read_only_data_size);
3591      if (common->read_only_data == NULL)
3592        return TRUE;
3593    
3594      update_table = (sljit_ub *)common->read_only_data;
3595      common->read_only_data_ptr = (sljit_uw *)(update_table + 256);
3596      memset(update_table, IN_UCHARS(range_len), 256);
3597    
3598      for (i = 0; i < range_len; i++)
3599        {
3600        byte_set = bytes + ((range_right - i) * MAX_N_BYTES);
3601        SLJIT_ASSERT(byte_set[0] > 0 && byte_set[0] < 255);
3602        byte_set_end = byte_set + byte_set[0];
3603        byte_set++;
3604        while (byte_set <= byte_set_end)
3605          {
3606          if (update_table[*byte_set] > IN_UCHARS(i))
3607            update_table[*byte_set] = IN_UCHARS(i);
3608          byte_set++;
3609          }
3610        }
3611      }
3612    
3613  offsets[0] = -1;  offsets[0] = -1;
3614  /* Scan forward. */  /* Scan forward. */
3615  for (i = 0; i < max; i++)  for (i = 0; i < max; i++)
# Line 3319  for (i = 0; i < max; i++) Line 3618  for (i = 0; i < max; i++)
3618      break;      break;
3619    }    }
3620    
3621  if (offsets[0] == -1)  if (offsets[0] < 0 && range_right < 0)
3622    return FALSE;    return FALSE;
3623    
3624  /* 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)  
3625    {    {
3626    /* Scan from middle. */    /* Scan backward. */
3627    for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)    offsets[1] = -1;
3628      if (ones[i] <= 2)    for (i = max - 1; i > offsets[0]; i--)
3629        if (ones[i] <= 2 && i != range_right)
3630        {        {
3631        offsets[2] = i;        offsets[1] = i;
3632        break;        break;
3633        }        }
3634    
3635    if (offsets[2] == -1)    /* This case is handled better by fast_forward_first_char. */
3636      if (offsets[1] == -1 && offsets[0] == 0 && range_right < 0)
3637        return FALSE;
3638    
3639      offsets[2] = -1;
3640      /* We only search for a middle character if there is no range check. */
3641      if (offsets[1] >= 0 && range_right == -1)
3642      {      {
3643      for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)      /* Scan from middle. */
3644        for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3645        if (ones[i] <= 2)        if (ones[i] <= 2)
3646          {          {
3647          offsets[2] = i;          offsets[2] = i;
3648          break;          break;
3649          }          }
3650    
3651        if (offsets[2] == -1)
3652          {
3653          for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3654            if (ones[i] <= 2)
3655              {
3656              offsets[2] = i;
3657              break;
3658              }
3659          }
3660      }      }
   }  
3661    
3662  SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));    SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3663  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]));
3664    
3665  chars[0] = chars[offsets[0] << 1];    chars[0] = chars[offsets[0] << 1];
3666  chars[1] = chars[(offsets[0] << 1) + 1];    chars[1] = chars[(offsets[0] << 1) + 1];
3667  if (offsets[2] >= 0)    if (offsets[2] >= 0)
3668    {      {
3669    chars[2] = chars[offsets[2] << 1];      chars[2] = chars[offsets[2] << 1];
3670    chars[3] = chars[(offsets[2] << 1) + 1];      chars[3] = chars[(offsets[2] << 1) + 1];
3671    }      }
3672  if (offsets[1] >= 0)    if (offsets[1] >= 0)
3673    {      {
3674    chars[4] = chars[offsets[1] << 1];      chars[4] = chars[offsets[1] << 1];
3675    chars[5] = chars[(offsets[1] << 1) + 1];      chars[5] = chars[(offsets[1] << 1) + 1];
3676        }
3677    }    }
3678    
3679  max -= 1;  max -= 1;
3680  if (firstline)  if (firstline)
3681    {    {
3682    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3683      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end);
3684    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3685    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));
3686      quit = CMP(SLJIT_C_LESS_EQUAL, STR_END, 0, TMP1, 0);
3687      OP1(SLJIT_MOV, STR_END, 0, TMP1, 0);
3688      JUMPHERE(quit);
3689    }    }
3690  else  else
3691    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));
3692    
3693    #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3694    if (range_right >= 0)
3695      OP1(SLJIT_MOV, RETURN_ADDR, 0, SLJIT_IMM, (sljit_sw)update_table);
3696    #endif
3697    
3698  start = LABEL();  start = LABEL();
3699  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3700    
3701  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));  
3702    
3703  if (offsets[1] >= 0)  if (range_right >= 0)
3704    {    {
3705    if (chars[5] != 0)  #if defined COMPILE_PCRE8 || (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
3706      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));
3707    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);  #else
3708      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right + 1) - 1);
3709    #endif
3710    
3711    #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3712      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(RETURN_ADDR, TMP1), 0);
3713    #else
3714      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)update_table);
3715    #endif
3716      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3717      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, start);
3718    }    }
3719    
3720  if (offsets[2] >= 0)  if (offsets[0] >= 0)
3721    {    {
3722    if (chars[3] != 0)    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3723      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);    if (offsets[1] >= 0)
3724    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]));
3725      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3726    
3727      if (chars[1] != 0)
3728        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3729      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3730      if (offsets[2] >= 0)
3731        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3732    
3733      if (offsets[1] >= 0)
3734        {
3735        if (chars[5] != 0)
3736          OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3737        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3738        }
3739    
3740      if (offsets[2] >= 0)
3741        {
3742        if (chars[3] != 0)
3743          OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3744        CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3745        }
3746      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3747    }    }
 OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
3748    
3749  JUMPHERE(quit);  JUMPHERE(quit);
3750    
3751  if (firstline)  if (firstline)
3752      {
3753      if (range_right >= 0)
3754        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end);
3755    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3756      if (range_right >= 0)
3757        {
3758        quit = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3759        OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
3760        JUMPHERE(quit);
3761        }
3762      }
3763  else  else
3764    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));
3765  return TRUE;  return TRUE;
3766  }  }
3767    
3768  #undef MAX_N_CHARS  #undef MAX_N_CHARS
3769    #undef MAX_N_BYTES
3770    
3771  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)
3772  {  {
# Line 3430  if (firstline) Line 3780  if (firstline)
3780    {    {
3781    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3782    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3783    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end);
3784    }    }
3785    
3786  start = LABEL();  start = LABEL();
# Line 3490  if (firstline) Line 3840  if (firstline)
3840    {    {
3841    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3842    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3843    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end);
3844    }    }
3845    
3846  if (common->nltype == NLTYPE_FIXED && common->newline > 255)  if (common->nltype == NLTYPE_FIXED && common->newline > 255)
# Line 3522  if (common->nltype == NLTYPE_FIXED && co Line 3872  if (common->nltype == NLTYPE_FIXED && co
3872    JUMPHERE(lastchar);    JUMPHERE(lastchar);
3873    
3874    if (firstline)    if (firstline)
3875      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3876    return;    return;
3877    }    }
3878    
# Line 3532  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3882  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3882  skip_char_back(common);  skip_char_back(common);
3883    
3884  loop = LABEL();  loop = LABEL();
3885  read_char_max(common, common->nlmax, TRUE);  common->ff_newline_shortcut = loop;
3886    
3887    read_char_range(common, common->nlmin, common->nlmax, TRUE);
3888  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3889  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3890    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
# Line 3578  if (firstline) Line 3930  if (firstline)
3930    {    {
3931    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3932    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
3933    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end);
3934    }    }
3935    
3936  start = LABEL();  start = LABEL();
# Line 3652  struct sljit_jump *notfound; Line 4004  struct sljit_jump *notfound;
4004  pcre_uint32 oc, bit;  pcre_uint32 oc, bit;
4005    
4006  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
4007  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->req_char_ptr);
4008  OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, REQ_BYTE_MAX);  OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, REQ_BYTE_MAX);
4009  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);
4010  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);
# Line 3697  JUMPTO(SLJIT_JUMP, loop); Line 4049  JUMPTO(SLJIT_JUMP, loop);
4049  JUMPHERE(found);  JUMPHERE(found);
4050  if (foundoc)  if (foundoc)
4051    JUMPHERE(foundoc);    JUMPHERE(foundoc);
4052  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->req_char_ptr, TMP1, 0);
4053  JUMPHERE(alreadyfound);  JUMPHERE(alreadyfound);
4054  JUMPHERE(toolong);  JUMPHERE(toolong);
4055  return notfound;  return notfound;
# Line 3749  struct sljit_jump *jump; Line 4101  struct sljit_jump *jump;
4101    
4102  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
4103    
4104  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), LOCALS0);
4105  /* Get type of the previous char, and put it to LOCALS1. */  /* Get type of the previous char, and put it to LOCALS1. */
4106  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
4107  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
4108  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, SLJIT_IMM, 0);
4109  skipread = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);  skipread = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
4110  skip_char_back(common);  skip_char_back(common);
4111  check_start_used_ptr(common);  check_start_used_ptr(common);
# Line 3773  if (common->use_ucp) Line 4125  if (common->use_ucp)
4125    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
4126    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4127    JUMPHERE(jump);    JUMPHERE(jump);
4128    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, TMP2, 0);
4129    }    }
4130  else  else
4131  #endif  #endif
# Line 3789  else Line 4141  else
4141    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);
4142    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);
4143    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4144    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, TMP1, 0);
4145  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
4146    JUMPHERE(jump);    JUMPHERE(jump);
4147  #elif defined SUPPORT_UTF  #elif defined SUPPORT_UTF
# Line 3801  JUMPHERE(skipread); Line 4153  JUMPHERE(skipread);
4153    
4154  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
4155  check_str_end(common, &skipread_list);  check_str_end(common, &skipread_list);
4156  peek_char(common);  peek_char(common, READ_CHAR_MAX);
4157    
4158  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
4159  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3843  else Line 4195  else
4195    }    }
4196  set_jumps(skipread_list, LABEL());  set_jumps(skipread_list, LABEL());
4197    
4198  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_SP), LOCALS1);
4199  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_SP), LOCALS0);
4200  }  }
4201    
4202  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks)  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks)
# Line 4102  struct sljit_label *label; Line 4454  struct sljit_label *label;
4454  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
4455  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
4456  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);
4457  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS0, CHAR2, 0);
4458  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
4459  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));
4460    
# Line 4116  JUMPTO(SLJIT_C_NOT_ZERO, label); Line 4468  JUMPTO(SLJIT_C_NOT_ZERO, label);
4468  JUMPHERE(jump);  JUMPHERE(jump);
4469  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));
4470  OP1(SLJIT_MOV, CHAR1, 0, TMP3, 0);  OP1(SLJIT_MOV, CHAR1, 0, TMP3, 0);
4471  OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0);
4472  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
4473  }  }
4474    
# Line 4132  sljit_emit_fast_enter(compiler, RETURN_A Line 4484  sljit_emit_fast_enter(compiler, RETURN_A
4484  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
4485    
4486  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);
4487  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS0, CHAR1, 0);
4488  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, CHAR2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, CHAR2, 0);
4489  OP1(SLJIT_MOV, LCC_TABLE, 0, SLJIT_IMM, common->lcc);  OP1(SLJIT_MOV, LCC_TABLE, 0, SLJIT_IMM, common->lcc);
4490  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
4491  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));
# Line 4160  JUMPTO(SLJIT_C_NOT_ZERO, label); Line 4512  JUMPTO(SLJIT_C_NOT_ZERO, label);
4512  JUMPHERE(jump);  JUMPHERE(jump);
4513  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));
4514  OP1(SLJIT_MOV, LCC_TABLE, 0, TMP3, 0);  OP1(SLJIT_MOV, LCC_TABLE, 0, TMP3, 0);
4515  OP1(SLJIT_MOV, CHAR1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  OP1(SLJIT_MOV, CHAR1, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0);
4516  OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_SP), LOCALS1);
4517  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
4518  }  }
4519    
# Line 4360  return cc; Line 4712  return cc;
4712  #define SET_TYPE_OFFSET(value) \  #define SET_TYPE_OFFSET(value) \
4713    if ((value) != typeoffset) \    if ((value) != typeoffset) \
4714      { \      { \
4715      if ((value) > typeoffset) \      if ((value) < typeoffset) \
       OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \  
     else \  
4716        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \
4717        else \
4718          OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \
4719      } \      } \
4720    typeoffset = (value);    typeoffset = (value);
4721    
4722  #define SET_CHAR_OFFSET(value) \  #define SET_CHAR_OFFSET(value) \
4723    if ((value) != charoffset) \    if ((value) != charoffset) \
4724      { \      { \
4725      if ((value) > charoffset) \      if ((value) < charoffset) \
       OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)((value) - charoffset)); \  
     else \  
4726        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(charoffset - (value))); \        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(charoffset - (value))); \
4727        else \
4728          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)((value) - charoffset)); \
4729      } \      } \
4730    charoffset = (value);    charoffset = (value);
4731    
# Line 4382  static void compile_xclass_matchingpath( Line 4734  static void compile_xclass_matchingpath(
4734  DEFINE_COMPILER;  DEFINE_COMPILER;
4735  jump_list *found = NULL;  jump_list *found = NULL;
4736  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4737  sljit_uw c, charoffset, max = 0;  sljit_uw c, charoffset, max = 256, min = READ_CHAR_MAX;
4738  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4739  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4740  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
# Line 4395  BOOL needstype = FALSE, needsscript = FA Line 4747  BOOL needstype = FALSE, needsscript = FA
4747  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4748  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4749  const pcre_uint32 *other_cases;  const pcre_uint32 *other_cases;
4750  pcre_int32 typeoffset;  sljit_uw typeoffset;
4751  #endif  #endif
4752    
4753  /* Scanning the necessary info. */  /* Scanning the necessary info. */
4754  cc++;  cc++;
4755  ccbegin = cc;  ccbegin = cc;
4756  compares = 0;  compares = 0;
4757  if (cc[-1] & XCL_MAP) cc += 32 / sizeof(pcre_uchar);  if (cc[-1] & XCL_MAP)
4758      {
4759      min = 0;
4760      cc += 32 / sizeof(pcre_uchar);
4761      }
4762    
4763  while (*cc != XCL_END)  while (*cc != XCL_END)
4764    {    {
# Line 4412  while (*cc != XCL_END) Line 4768  while (*cc != XCL_END)
4768      cc ++;      cc ++;
4769      GETCHARINCTEST(c, cc);      GETCHARINCTEST(c, cc);
4770      if (c > max) max = c;      if (c > max) max = c;
4771        if (c < min) min = c;
4772  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4773      needschar = TRUE;      needschar = TRUE;
4774  #endif  #endif
4775      }      }
4776    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4777      {      {
4778      cc += 2;      cc ++;
4779  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4780      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (c < min) min = c;
 #endif  
4781      GETCHARINCTEST(c, cc);      GETCHARINCTEST(c, cc);
4782      if (c > max) max = c;      if (c > max) max = c;
4783  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4439  while (*cc != XCL_END) Line 4795  while (*cc != XCL_END)
4795        while (*other_cases != NOTACHAR)        while (*other_cases != NOTACHAR)
4796          {          {
4797          if (*other_cases > max) max = *other_cases;          if (*other_cases > max) max = *other_cases;
4798            if (*other_cases < min) min = *other_cases;
4799          other_cases++;          other_cases++;
4800          }          }
4801        }        }
4802      else      else
4803        max = READ_CHAR_ANY;        {
4804          max = READ_CHAR_MAX;
4805          min = 0;
4806          }
4807    
4808      switch(*cc)      switch(*cc)
4809        {        {
# Line 4488  while (*cc != XCL_END) Line 4848  while (*cc != XCL_END)
4848  /* We are not necessary in utf mode even in 8 bit mode. */  /* We are not necessary in utf mode even in 8 bit mode. */
4849  cc = ccbegin;  cc = ccbegin;
4850  detect_partial_match(common, backtracks);  detect_partial_match(common, backtracks);
4851  read_char_max(common, max, (cc[0] & XCL_NOT) != 0);  read_char_range(common, min, max, (cc[-1] & XCL_NOT) != 0);
4852    
4853  if ((cc[-1] & XCL_HASPROP) == 0)  if ((cc[-1] & XCL_HASPROP) == 0)
4854    {    {
# Line 4511  if ((cc[-1] & XCL_HASPROP) == 0) Line 4871  if ((cc[-1] & XCL_HASPROP) == 0)
4871      cc += 32 / sizeof(pcre_uchar);      cc += 32 / sizeof(pcre_uchar);
4872      }      }
4873    else    else
4874      add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0xff));      {
4875        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, min);
4876        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, max - min));
4877        }
4878    }    }
4879  else if ((cc[-1] & XCL_MAP) != 0)  else if ((cc[-1] & XCL_MAP) != 0)
4880    {    {
# Line 4945  switch(type) Line 5308  switch(type)
5308    
5309    case OP_ANY:    case OP_ANY:
5310    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5311    read_char_max(common, common->nlmax, TRUE);    read_char_range(common, common->nlmin, common->nlmax, TRUE);
5312    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
5313      {      {
5314      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 5013  switch(type) Line 5376  switch(type)
5376    
5377    case OP_ANYNL:    case OP_ANYNL:
5378    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5379    read_char_max(common, common->bsr_nlmax, FALSE);    read_char_range(common, common->bsr_nlmin, common->bsr_nlmax, FALSE);
5380    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);
5381    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
5382    end_list = NULL;    end_list = NULL;
# Line 5035  switch(type) Line 5398  switch(type)
5398    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
5399    case OP_HSPACE:    case OP_HSPACE:
5400    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5401    read_char_max(common, 0x3000, type == OP_NOT_HSPACE);    read_char_range(common, 0x9, 0x3000, type == OP_NOT_HSPACE);
5402    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));
5403    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));
5404    return cc;    return cc;
# Line 5043  switch(type) Line 5406  switch(type)
5406    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
5407    case OP_VSPACE:    case OP_VSPACE:
5408    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5409    read_char_max(common, 0x2029, type == OP_NOT_VSPACE);    read_char_range(common, 0xa, 0x2029, type == OP_NOT_VSPACE);
5410    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));
5411    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));
5412    return cc;    return cc;
# Line 5055  switch(type) Line 5418  switch(type)
5418    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
5419    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));
5420    /* Optimize register allocation: use a real register. */    /* Optimize register allocation: use a real register. */
5421    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS0, STACK_TOP, 0);
5422    OP1(SLJIT_MOV_UB, STACK_TOP, 0, SLJIT_MEM2(TMP1, TMP2), 3);    OP1(SLJIT_MOV_UB, STACK_TOP, 0, SLJIT_MEM2(TMP1, TMP2), 3);
5423    
5424    label = LABEL();    label = LABEL();
# Line 5075  switch(type) Line 5438  switch(type)
5438    
5439    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
5440    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
5441    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0);
5442    
5443    if (common->mode == JIT_PARTIAL_HARD_COMPILE)    if (common->mode == JIT_PARTIAL_HARD_COMPILE)
5444      {      {
# Line 5141  switch(type) Line 5504  switch(type)
5504        }        }
5505      else      else
5506        {        {
5507        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, STR_PTR, 0);
5508        read_char_max(common, common->nlmax, TRUE);        read_char_range(common, common->nlmin, common->nlmax, TRUE);
5509        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));
5510        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
5511        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
5512        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), LOCALS1);
5513        }        }
5514      JUMPHERE(jump[2]);      JUMPHERE(jump[2]);
5515      JUMPHERE(jump[3]);      JUMPHERE(jump[3]);
# Line 5190  switch(type) Line 5553  switch(type)
5553    else    else
5554      {      {
5555      skip_char_back(common);      skip_char_back(common);
5556      read_char_max(common, common->nlmax, TRUE);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
5557      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5558      }      }
5559    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 5241  switch(type) Line 5604  switch(type)
5604      }      }
5605    else    else
5606      {      {
5607      peek_char(common);      peek_char(common, common->nlmax);
5608      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5609      }      }
5610    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 5278  switch(type) Line 5641  switch(type)
5641    
5642    if (type == OP_CHAR || !char_has_othercase(common, cc))    if (type == OP_CHAR || !char_has_othercase(common, cc))
5643      {      {
5644      read_char_max(common, c, FALSE);      read_char_range(common, c, c, FALSE);
5645      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));
5646      return cc + length;      return cc + length;
5647      }      }
5648    oc = char_othercase(common, c);    oc = char_othercase(common, c);
5649    read_char_max(common, c > oc ? c : oc, FALSE);    read_char_range(common, c < oc ? c : oc, c > oc ? c : oc, FALSE);
5650    bit = c ^ oc;    bit = c ^ oc;
5651    if (is_powerof2(bit))    if (is_powerof2(bit))
5652      {      {
# Line 5336  switch(type) Line 5699  switch(type)
5699    
5700    if (type == OP_NOT || !char_has_othercase(common, cc))    if (type == OP_NOT || !char_has_othercase(common, cc))
5701      {      {
5702      read_char_max(common, c, TRUE);      read_char_range(common, c, c, TRUE);
5703      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));
5704      }      }
5705    else    else
5706      {      {
5707      oc = char_othercase(common, c);      oc = char_othercase(common, c);
5708      read_char_max(common, c > oc ? c : oc, TRUE);      read_char_range(common, c < oc ? c : oc, c > oc ? c : oc, TRUE);
5709      bit = c ^ oc;      bit = c ^ oc;
5710      if (is_powerof2(bit))      if (is_powerof2(bit))
5711        {        {
# Line 5363  switch(type) Line 5726  switch(type)
5726    
5727  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5728    bit = (common->utf && is_char7_bitset((const pcre_uint8 *)cc, type == OP_NCLASS)) ? 127 : 255;    bit = (common->utf && is_char7_bitset((const pcre_uint8 *)cc, type == OP_NCLASS)) ? 127 : 255;
5729    read_char_max(common, bit, type == OP_NCLASS);    read_char_range(common, 0, bit, type == OP_NCLASS);
5730  #else  #else
5731    read_char_max(common, 255, type == OP_NCLASS);    read_char_range(common, 0, 255, type == OP_NCLASS);
5732  #endif  #endif
5733    
5734    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))
# Line 5550  jump_list *found = NULL; Line 5913  jump_list *found = NULL;
5913    
5914  SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI);  SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI);
5915    
5916  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1));
5917    
5918  count--;  count--;
5919  while (count-- > 0)  while (count-- > 0)
5920    {    {
5921    offset = GET2(slot, 0) << 1;    offset = GET2(slot, 0) << 1;
5922    GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));    GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5923    add_jump(compiler, &found, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));    add_jump(compiler, &found, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0));
5924    slot += common->name_entry_size;    slot += common->name_entry_size;
5925    }    }
5926    
5927  offset = GET2(slot, 0) << 1;  offset = GET2(slot, 0) << 1;
5928  GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));  GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5929  if (backtracks != NULL && !common->jscript_compat)  if (backtracks != NULL && !common->jscript_compat)
5930    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0));
5931    
5932  set_jumps(found, LABEL());  set_jumps(found, LABEL());
5933  }  }
# Line 5581  struct sljit_jump *nopartial; Line 5944  struct sljit_jump *nopartial;
5944  if (ref)  if (ref)
5945    {    {
5946    offset = GET2(cc, 1) << 1;    offset = GET2(cc, 1) << 1;
5947    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset));
5948    /* OVECTOR(1) contains the "string begin - 1" constant. */    /* OVECTOR(1) contains the "string begin - 1" constant. */
5949    if (withchecks && !common->jscript_compat)    if (withchecks && !common->jscript_compat)
5950      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1)));
5951    }    }
5952  else  else
5953    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
# Line 5592  else Line 5955  else
5955  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5956  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5957    {    {
5958    SLJIT_ASSERT(TMP1 == SLJIT_SCRATCH_REG1 && STACK_TOP == SLJIT_SCRATCH_REG2 && TMP2 == SLJIT_SCRATCH_REG3);    SLJIT_ASSERT(TMP1 == SLJIT_R0 && STACK_TOP == SLJIT_R1 && TMP2 == SLJIT_R2);
5959    if (ref)    if (ref)
5960      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1));
5961    else    else
5962      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5963    
# Line 5602  if (common->utf && *cc == OP_REFI) Line 5965  if (common->utf && *cc == OP_REFI)
5965      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5966    
5967    /* Needed to save important temporary registers. */    /* Needed to save important temporary registers. */
5968    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS0, STACK_TOP, 0);
5969    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, SLJIT_R1, 0, ARGUMENTS, 0);
5970    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, uchar_ptr), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), SLJIT_OFFSETOF(jit_arguments, uchar_ptr), STR_PTR, 0);
5971    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_utf_caselesscmp));    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_utf_caselesscmp));
5972    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0);
5973    if (common->mode == JIT_COMPILE)    if (common->mode == JIT_COMPILE)
5974      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1));      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1));
5975    else    else
# Line 5623  else Line 5986  else
5986  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
5987    {    {
5988    if (ref)    if (ref)
5989      OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);      OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), TMP1, 0);
5990    else    else
5991      OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);      OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
5992    
# Line 5726  if (!minimize) Line 6089  if (!minimize)
6089      {      {
6090      allocate_stack(common, 2);      allocate_stack(common, 2);
6091      if (ref)      if (ref)
6092        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset));
6093      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6094      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
6095      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
# Line 5734  if (!minimize) Line 6097  if (!minimize)
6097      /* Handles both invalid and empty cases. Since the minimum repeat,      /* Handles both invalid and empty cases. Since the minimum repeat,
6098      is zero the invalid case is basically the same as an empty case. */      is zero the invalid case is basically the same as an empty case. */
6099      if (ref)      if (ref)
6100        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1));
6101      else      else
6102        {        {
6103        compile_dnref_search(common, ccbegin, NULL);        compile_dnref_search(common, ccbegin, NULL);
6104        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
6105        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), POSSESSIVE1, TMP2, 0);
6106        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
6107        }        }
6108      /* Restore if not zero length. */      /* Restore if not zero length. */
# Line 5749  if (!minimize) Line 6112  if (!minimize)
6112      {      {
6113      allocate_stack(common, 1);      allocate_stack(common, 1);
6114      if (ref)      if (ref)
6115        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset));
6116      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6117      if (ref)      if (ref)
6118        {        {
6119        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1)));
6120        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1));
6121        }        }
6122      else      else
6123        {        {
6124        compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);        compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
6125        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
6126        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), POSSESSIVE1, TMP2, 0);
6127        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
6128        }        }
6129      }      }
6130    
6131    if (min > 1 || max > 1)    if (min > 1 || max > 1)
6132      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), POSSESSIVE0, SLJIT_IMM, 0);
6133    
6134    label = LABEL();    label = LABEL();
6135    if (!ref)    if (!ref)
6136      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), POSSESSIVE1);
6137    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
6138    
6139    if (min > 1 || max > 1)    if (min > 1 || max > 1)
6140      {      {
6141      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), POSSESSIVE0);
6142      OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
6143      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), POSSESSIVE0, TMP1, 0);
6144      if (min > 1)      if (min > 1)
6145        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, label);        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, label);
6146      if (max > 1)      if (max > 1)
# Line 5807  if (!minimize) Line 6170  if (!minimize)
6170    
6171  allocate_stack(common, ref ? 2 : 3);  allocate_stack(common, ref ? 2 : 3);
6172  if (ref)  if (ref)
6173    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset));
6174  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6175  if (type != OP_CRMINSTAR)  if (type != OP_CRMINSTAR)
6176    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
# Line 5817  if (min == 0) Line 6180  if (min == 0)
6180    /* Handles both invalid and empty cases. Since the minimum repeat,    /* Handles both invalid and empty cases. Since the minimum repeat,
6181    is zero the invalid case is basically the same as an empty case. */    is zero the invalid case is basically the same as an empty case. */
6182    if (ref)    if (ref)
6183      zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1));
6184    else    else
6185      {      {
6186      compile_dnref_search(common, ccbegin, NULL);      compile_dnref_search(common, ccbegin, NULL);
# Line 5833  else Line 6196  else
6196    {    {
6197    if (ref)    if (ref)
6198      {      {
6199      add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));      add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1)));
6200      zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1));
6201      }      }
6202    else    else
6203      {      {
# Line 5919  if (entry == NULL) Line 6282  if (entry == NULL)
6282    
6283  if (common->has_set_som && common->mark_ptr != 0)  if (common->has_set_som && common->mark_ptr != 0)
6284    {    {
6285    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0));
6286    allocate_stack(common, 2);    allocate_stack(common, 2);
6287    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr);
6288    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6289    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
6290    }    }
6291  else if (common->has_set_som || common->mark_ptr != 0)  else if (common->has_set_som || common->mark_ptr != 0)
6292    {    {
6293    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->has_set_som ? (int)(OVECTOR(0)) : common->mark_ptr);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->has_set_som ? (int)(OVECTOR(0)) : common->mark_ptr);
6294    allocate_stack(common, 1);    allocate_stack(common, 1);
6295    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6296    }    }
# Line 6001  PUSH_BACKTRACK(sizeof(backtrack_common), Line 6364  PUSH_BACKTRACK(sizeof(backtrack_common),
6364    
6365  allocate_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));  allocate_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
6366    
6367  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr);
6368  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
6369  SLJIT_ASSERT(common->capture_last_ptr != 0);  SLJIT_ASSERT(common->capture_last_ptr != 0);
6370  OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
6371  OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
6372    
6373  /* These pointer sized fields temporarly stores internal variables. */  /* These pointer sized fields temporarly stores internal variables. */
6374  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0));
6375  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0);
6376  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(subject), TMP2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(subject), TMP2, 0);
6377    
# Line 6019  OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), Line 6382  OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP),
6382  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
6383    
6384  /* Needed to save important temporary registers. */  /* Needed to save important temporary registers. */
6385  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS0, STACK_TOP, 0);
6386  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, STACK_TOP, 0, SLJIT_IMM, CALLOUT_ARG_SIZE);  OP2(SLJIT_SUB, SLJIT_R1, 0, STACK_TOP, 0, SLJIT_IMM, CALLOUT_ARG_SIZE);
6387  GET_LOCAL_BASE(SLJIT_SCRATCH_REG3, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_R2, 0, OVECTOR_START);
6388  sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout));  sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout));
6389  OP1(SLJIT_MOV_SI, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0);  OP1(SLJIT_MOV_SI, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0);
6390  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0);
6391  free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));  free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
6392    
6393  /* Check return value. */  /* Check return value. */
# Line 6098  if (framesize < 0) Line 6461  if (framesize < 0)
6461    {    {
6462    extrasize = needs_control_head ? 2 : 1;    extrasize = needs_control_head ? 2 : 1;
6463    if (framesize == no_frame)    if (framesize == no_frame)
6464      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STACK_TOP, 0);
6465    allocate_stack(common, extrasize);    allocate_stack(common, extrasize);
6466    if (needs_control_head)    if (needs_control_head)
6467      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr);
6468    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6469    if (needs_control_head)    if (needs_control_head)
6470      {      {
6471      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_IMM, 0);
6472      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
6473      }      }
6474    }    }
# Line 6113  else Line 6476  else
6476    {    {
6477    extrasize = needs_control_head ? 3 : 2;    extrasize = needs_control_head ? 3 : 2;
6478    allocate_stack(common, framesize + extrasize);    allocate_stack(common, framesize + extrasize);
6479    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
6480    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
6481    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP2, 0);
6482    if (needs_control_head)    if (needs_control_head)
6483      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr);
6484    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6485    if (needs_control_head)    if (needs_control_head)
6486      {      {
6487      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
6488      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6489      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_IMM, 0);
6490      }      }
6491    else    else
6492      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
# Line 6178  while (1) Line 6541  while (1)
6541    if (framesize < 0)    if (framesize < 0)
6542      {      {
6543      if (framesize == no_frame)      if (framesize == no_frame)
6544        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
6545      else      else
6546        free_stack(common, extrasize);        free_stack(common, extrasize);
6547      if (needs_control_head)      if (needs_control_head)
6548        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
6549      }      }
6550    else    else
6551      {      {
6552      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
6553        {        {
6554        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
6555        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));
6556        if (needs_control_head)        if (needs_control_head)
6557          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
6558        }        }
6559      else      else
6560        {        {
6561        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
6562        if (needs_control_head)        if (needs_control_head)
6563          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));
6564        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
6565        }        }
6566      }      }
# Line 6215  while (1) Line 6578  while (1)
6578          {          {
6579          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));
6580          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + extrasize - 1) * sizeof(sljit_sw));          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + extrasize - 1) * sizeof(sljit_sw));
6581          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP1, 0);
6582          }          }
6583        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
6584        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
# Line 6223  while (1) Line 6586  while (1)
6586      else if (framesize >= 0)      else if (framesize >= 0)
6587        {        {
6588        /* For OP_BRA and OP_BRAMINZERO. */        /* For OP_BRA and OP_BRAMINZERO. */
6589        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));
6590        }        }
6591      }      }
6592    add_jump(compiler, found, JUMP(SLJIT_JUMP));    add_jump(compiler, found, JUMP(SLJIT_JUMP));
# Line 6267  if (common->positive_assert_quit != NULL Line 6630  if (common->positive_assert_quit != NULL
6630    set_jumps(common->positive_assert_quit, LABEL());    set_jumps(common->positive_assert_quit, LABEL());
6631    SLJIT_ASSERT(framesize != no_stack);    SLJIT_ASSERT(framesize != no_stack);
6632    if (framesize < 0)    if (framesize < 0)
6633      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
6634    else    else
6635      {      {
6636      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
6637      add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));      add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
6638      OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));      OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
6639      }      }
# Line 6278  if (common->positive_assert_quit != NULL Line 6641  if (common->positive_assert_quit != NULL
6641    }    }
6642    
6643  if (needs_control_head)  if (needs_control_head)
6644    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(1));    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(1));
6645    
6646  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)
6647    {    {
# Line 6309  if (opcode == OP_ASSERT || opcode == OP_ Line 6672  if (opcode == OP_ASSERT || opcode == OP_
6672        }        }
6673      else      else
6674        free_stack(common, framesize + extrasize);        free_stack(common, framesize + extrasize);
6675      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP1, 0);
6676      }      }
6677    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
6678    if (bra != OP_BRAZERO)    if (bra != OP_BRAZERO)
# Line 6339  if (opcode == OP_ASSERT || opcode == OP_ Line 6702  if (opcode == OP_ASSERT || opcode == OP_
6702      if (bra == OP_BRA)      if (bra == OP_BRA)
6703        {        {
6704        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
6705        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));
6706        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 2) * sizeof(sljit_sw));        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 2) * sizeof(sljit_sw));
6707        }        }
6708      else      else
6709        {        {
6710        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
6711        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_sw));
6712        if (extrasize == 2)        if (extrasize == 2)
6713          {          {
6714          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
# Line 6371  if (opcode == OP_ASSERT || opcode == OP_ Line 6734  if (opcode == OP_ASSERT || opcode == OP_
6734      JUMPHERE(brajump);      JUMPHERE(brajump);
6735      if (framesize >= 0)      if (framesize >= 0)
6736        {        {
6737        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
6738        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
6739        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));
6740        }        }
6741      set_jumps(backtrack->common.topbacktracks, LABEL());      set_jumps(backtrack->common.topbacktracks, LABEL());
6742      }      }
# Line 6405  else Line 6768  else
6768        }        }
6769      else      else
6770        free_stack(common, framesize + extrasize);        free_stack(common, framesize + extrasize);
6771      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP1, 0);
6772      }      }
6773    
6774    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
# Line 6446  int stacksize; Line 6809  int stacksize;
6809  if (framesize < 0)  if (framesize < 0)
6810    {    {
6811    if (framesize == no_frame)    if (framesize == no_frame)
6812      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
6813    else    else
6814      {      {
6815      stacksize = needs_control_head ? 1 : 0;      stacksize = needs_control_head ? 1 : 0;
# Line 6464  if (framesize < 0) Line 6827  if (framesize < 0)
6827    else if (ket == OP_KETRMIN)    else if (ket == OP_KETRMIN)
6828      {      {
6829      /* Move the STR_PTR to the private_data_ptr. */      /* Move the STR_PTR to the private_data_ptr. */
6830      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);
6831      }      }
6832    }    }
6833  else  else
6834    {    {
6835    stacksize = (ket != OP_KET || has_alternatives) ? 2 : 1;    stacksize = (ket != OP_KET || has_alternatives) ? 2 : 1;
6836    OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + stacksize) * sizeof(sljit_sw));    OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_IMM, (framesize + stacksize) * sizeof(sljit_sw));
6837    if (needs_control_head)    if (needs_control_head)
6838      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 0);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 0);
6839    
# Line 6481  else Line 6844  else
6844      }      }
6845    }    }
6846  if (needs_control_head)  if (needs_control_head)
6847    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, TMP1, 0);
6848  }  }
6849    
6850  static SLJIT_INLINE int match_capture_common(compiler_common *common, int stacksize, int offset, int private_data_ptr)  static SLJIT_INLINE int match_capture_common(compiler_common *common, int stacksize, int offset, int private_data_ptr)
# Line 6490  DEFINE_COMPILER; Line 6853  DEFINE_COMPILER;
6853    
6854  if (common->capture_last_ptr != 0)  if (common->capture_last_ptr != 0)
6855    {    {
6856    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr);
6857    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6858    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6859    stacksize++;    stacksize++;
6860    }    }
6861  if (common->optimized_cbracket[offset >> 1] == 0)  if (common->optimized_cbracket[offset >> 1] == 0)
6862    {    {
6863    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset));
6864    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1));
6865    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6866    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
6867    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6868    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), STR_PTR, 0);
6869    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0);
6870    stacksize += 2;    stacksize += 2;
6871    }    }
6872  return stacksize;  return stacksize;
# Line 6702  if (bra == OP_BRAMINZERO) Line 7065  if (bra == OP_BRAMINZERO)
7065        if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)        if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
7066          {          {
7067          /* When we come from outside, private_data_ptr contains the previous STR_PTR. */          /* When we come from outside, private_data_ptr contains the previous STR_PTR. */
7068          braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
7069          }          }
7070        else        else
7071          {          {
7072          /* Except when the whole stack frame must be saved. */          /* Except when the whole stack frame must be saved. */
7073          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
7074          braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (BACKTRACK_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw));          braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (BACKTRACK_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw));
7075          }          }
7076        JUMPHERE(skip);        JUMPHERE(skip);
# Line 6723  if (bra == OP_BRAMINZERO) Line 7086  if (bra == OP_BRAMINZERO)
7086    
7087  if (repeat_type != 0)  if (repeat_type != 0)
7088    {    {
7089    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, repeat_count);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_IMM, repeat_count);
7090    if (repeat_type == OP_EXACT)    if (repeat_type == OP_EXACT)
7091      rmax_label = LABEL();      rmax_label = LABEL();
7092    }    }
# Line 6744  if (opcode == OP_ONCE) Line 7107  if (opcode == OP_ONCE)
7107    stacksize = 0;    stacksize = 0;
7108    if (needs_control_head)    if (needs_control_head)
7109      {      {
7110      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr);
7111      stacksize++;      stacksize++;
7112      }      }
7113    
# Line 6755  if (opcode == OP_ONCE) Line 7118  if (opcode == OP_ONCE)
7118        {        {
7119        stacksize += 2;        stacksize += 2;
7120        if (!needs_control_head)        if (!needs_control_head)
7121          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
7122        }        }
7123      else      else
7124        {        {
7125        if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)        if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
7126          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STACK_TOP, 0);
7127        if (ket == OP_KETRMAX || has_alternatives)        if (ket == OP_KETRMAX || has_alternatives)
7128          stacksize++;          stacksize++;
7129        }        }
# Line 6778  if (opcode == OP_ONCE) Line 7141  if (opcode == OP_ONCE)
7141      if (ket == OP_KETRMIN)      if (ket == OP_KETRMIN)
7142        {        {
7143        if (needs_control_head)        if (needs_control_head)
7144          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
7145        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
7146        if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)        if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
7147          OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, needs_control_head ? (2 * sizeof(sljit_sw)) : sizeof(sljit_sw));          OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, needs_control_head ? (2 * sizeof(sljit_sw)) : sizeof(sljit_sw));
7148        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
7149        }        }
7150      else if (ket == OP_KETRMAX || has_alternatives)      else if (ket == OP_KETRMAX || has_alternatives)
# Line 6798  if (opcode == OP_ONCE) Line 7161  if (opcode == OP_ONCE)
7161      if (needs_control_head)      if (needs_control_head)
7162        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
7163    
7164      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
7165      OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, stacksize * sizeof(sljit_sw));      OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, stacksize * sizeof(sljit_sw));
7166    
7167      stacksize = needs_control_head ? 1 : 0;      stacksize = needs_control_head ? 1 : 0;
7168      if (ket != OP_KET || has_alternatives)      if (ket != OP_KET || has_alternatives)
7169        {        {
7170        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
7171        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP2, 0);
7172        stacksize++;        stacksize++;
7173        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
7174        }        }
7175      else      else
7176        {        {
7177        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP2, 0);
7178        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
7179        }        }
7180      init_frame(common, ccbegin, NULL, BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize, stacksize + 1, FALSE);      init_frame(common, ccbegin, NULL, BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize, stacksize + 1, FALSE);
# Line 6824  else if (opcode == OP_CBRA || opcode == Line 7187  else if (opcode == OP_CBRA || opcode ==
7187      {      {
7188      SLJIT_ASSERT(private_data_ptr == OVECTOR(offset));      SLJIT_ASSERT(private_data_ptr == OVECTOR(offset));
7189      allocate_stack(common, 2);      allocate_stack(common, 2);
7190      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
7191      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr + sizeof(sljit_sw));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw));
7192      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STR_PTR, 0);
7193      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
7194      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
7195      }      }
7196    else    else
7197      {      {
7198      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
7199      allocate_stack(common, 1);      allocate_stack(common, 1);
7200      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STR_PTR, 0);
7201      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
7202      }      }
7203    }    }
7204  else if (opcode == OP_SBRA || opcode == OP_SCOND)  else if (opcode == OP_SBRA || opcode == OP_SCOND)
7205    {    {
7206    /* Saving the previous value. */    /* Saving the previous value. */
7207    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
7208    allocate_stack(common, 1);    allocate_stack(common, 1);
7209    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STR_PTR, 0);
7210    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
7211    }    }
7212  else if (has_alternatives)  else if (has_alternatives)
# Line 6860  if (opcode == OP_COND || opcode == OP_SC Line 7223  if (opcode == OP_COND || opcode == OP_SC
7223      {      {
7224      SLJIT_ASSERT(has_alternatives);      SLJIT_ASSERT(has_alternatives);
7225      add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed),      add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed),
7226        CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(matchingpath, 1) << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));        CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_SP), OVECTOR(GET2(matchingpath, 1) << 1), SLJIT_MEM1(SLJIT_SP), OVECTOR(1)));
7227      matchingpath += 1 + IMM2_SIZE;      matchingpath += 1 + IMM2_SIZE;
7228      }      }
7229    else if (*matchingpath == OP_DNCREF)    else if (*matchingpath == OP_DNCREF)
# Line 6870  if (opcode == OP_COND || opcode == OP_SC Line 7233  if (opcode == OP_COND || opcode == OP_SC
7233      i = GET2(matchingpath, 1 + IMM2_SIZE);      i = GET2(matchingpath, 1 + IMM2_SIZE);
7234      slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;      slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
7235      OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);      OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
7236      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1));
7237      OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);      OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
7238      slot += common->name_entry_size;      slot += common->name_entry_size;
7239      i--;      i--;
7240      while (i-- > 0)      while (i-- > 0)
7241        {        {
7242        OP2(SLJIT_SUB, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);        OP2(SLJIT_SUB, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
7243        OP2(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, STR_PTR, 0);        OP2(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, STR_PTR, 0);
7244        slot += common->name_entry_size;        slot += common->name_entry_size;
7245        }        }
# Line 6964  stacksize = 0; Line 7327  stacksize = 0;
7327  if (repeat_type == OP_MINUPTO)  if (repeat_type == OP_MINUPTO)
7328    {    {
7329    /* We need to preserve the counter. TMP2 will be used below. */    /* We need to preserve the counter. TMP2 will be used below. */
7330    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), repeat_ptr);
7331    stacksize++;    stacksize++;
7332    }    }
7333  if (ket != OP_KET || bra != OP_BRA)  if (ket != OP_KET || bra != OP_BRA)
# Line 7014  if (has_alternatives) Line 7377  if (has_alternatives)
7377  if (offset != 0 && common->optimized_cbracket[offset >> 1] != 0)  if (offset != 0 && common->optimized_cbracket[offset >> 1] != 0)
7378    {    {
7379    SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0));    SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0));
7380    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), STR_PTR, 0);
7381    }    }
7382    
7383  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
# Line 7023  if (ket == OP_KETRMAX) Line 7386  if (ket == OP_KETRMAX)
7386      {      {
7387      if (has_alternatives)      if (has_alternatives)
7388        BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = LABEL();        BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = LABEL();
7389      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_SP), repeat_ptr, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_IMM, 1);
7390      JUMPTO(SLJIT_C_NOT_ZERO, rmax_label);      JUMPTO(SLJIT_C_NOT_ZERO, rmax_label);
7391      /* Drop STR_PTR for greedy plus quantifier. */      /* Drop STR_PTR for greedy plus quantifier. */
7392      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
# Line 7036  if (ket == OP_KETRMAX) Line 7399  if (ket == OP_KETRMAX)
7399      /* Checking zero-length iteration. */      /* Checking zero-length iteration. */
7400      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
7401        {        {
7402        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0, rmax_label);        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STR_PTR, 0, rmax_label);
7403        /* Drop STR_PTR for greedy plus quantifier. */        /* Drop STR_PTR for greedy plus quantifier. */
7404        if (bra != OP_BRAZERO)        if (bra != OP_BRAZERO)
7405          free_stack(common, 1);          free_stack(common, 1);
# Line 7052  if (ket == OP_KETRMAX) Line 7415  if (ket == OP_KETRMAX)
7415    
7416  if (repeat_type == OP_EXACT)  if (repeat_type == OP_EXACT)
7417    {    {
7418    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);    count_match(common);
7419      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_IMM, 1);
7420    JUMPTO(SLJIT_C_NOT_ZERO, rmax_label);    JUMPTO(SLJIT_C_NOT_ZERO, rmax_label);
7421    }    }
7422  else if (repeat_type == OP_UPTO)  else if (repeat_type == OP_UPTO)
7423    {    {
7424    /* We need to preserve the counter. */    /* We need to preserve the counter. */
7425    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), repeat_ptr);
7426    allocate_stack(common, 1);    allocate_stack(common, 1);
7427    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
7428    }    }
# Line 7078  if (bra == OP_BRAMINZERO) Line 7442  if (bra == OP_BRAMINZERO)
7442      framesize is < 0, OP_ONCE will do the release itself. */      framesize is < 0, OP_ONCE will do the release itself. */
7443      if (opcode == OP_ONCE && BACKTRACK_AS(bracket_backtrack)->u.framesize >= 0)      if (opcode == OP_ONCE && BACKTRACK_AS(bracket_backtrack)->u.framesize >= 0)
7444        {        {
7445        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
7446        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
7447        }        }
7448      else if (ket == OP_KETRMIN && opcode != OP_ONCE)      else if (ket == OP_KETRMIN && opcode != OP_ONCE)
# Line 7173  if (framesize < 0) Line 7537  if (framesize < 0)
7537    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
7538    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
7539    if (framesize == no_frame)    if (framesize == no_frame)
7540      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STACK_TOP, 0);
7541    
7542    stack = 0;    stack = 0;
7543    if (offset != 0)    if (offset != 0)
7544      {      {
7545      stack = 2;      stack = 2;
7546      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset));
7547      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1));
7548      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
7549      if (common->capture_last_ptr != 0)      if (common->capture_last_ptr != 0)
7550        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr);
7551      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
7552      if (needs_control_head)      if (needs_control_head)
7553        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr);
7554      if (common->capture_last_ptr != 0)      if (common->capture_last_ptr != 0)
7555        {        {
7556        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
# Line 7196  if (framesize < 0) Line 7560  if (framesize < 0)
7560    else    else
7561      {      {
7562      if (needs_control_head)      if (needs_control_head)
7563        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr);
7564      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
7565      stack = 1;      stack = 1;
7566      }      }
# Line 7223  else Line 7587  else
7587    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
7588    
7589    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
7590    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
7591    if (needs_control_head)    if (needs_control_head)
7592      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr);
7593    OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));    OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));
7594    
7595    stack = 0;    stack = 0;
7596    if (!zero)    if (!zero)
# Line 7250  else Line 7614  else
7614    }    }
7615    
7616  if (offset != 0)  if (offset != 0)
7617    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), cbraprivptr, STR_PTR, 0);
7618    
7619  loop = LABEL();  loop = LABEL();
7620  while (*cc != OP_KETRPOS)  while (*cc != OP_KETRPOS)
# Line 7266  while (*cc != OP_KETRPOS) Line 7630  while (*cc != OP_KETRPOS)
7630    if (framesize < 0)    if (framesize < 0)
7631      {      {
7632      if (framesize == no_frame)      if (framesize == no_frame)
7633        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
7634    
7635      if (offset != 0)      if (offset != 0)
7636        {        {
7637        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), cbraprivptr);
7638        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), STR_PTR, 0);
7639        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), cbraprivptr, STR_PTR, 0);
7640        if (common->capture_last_ptr != 0)        if (common->capture_last_ptr != 0)
7641          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
7642        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0);
7643        }        }
7644      else      else
7645        {        {
# Line 7294  while (*cc != OP_KETRPOS) Line 7658  while (*cc != OP_KETRPOS)
7658      {      {
7659      if (offset != 0)      if (offset != 0)
7660        {        {
7661        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, stacksize * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_IMM, stacksize * sizeof(sljit_sw));
7662        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), cbraprivptr);
7663        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), STR_PTR, 0);
7664        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), cbraprivptr, STR_PTR, 0);
7665        if (common->capture_last_ptr != 0)        if (common->capture_last_ptr != 0)
7666          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
7667        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0);
7668        }        }
7669      else      else
7670        {        {
7671        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
7672        OP2(SLJIT_ADD, STACK_TOP, 0, TMP2, 0, SLJIT_IMM, stacksize * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, TMP2, 0, SLJIT_IMM, stacksize * sizeof(sljit_sw));
7673        if (opcode == OP_SBRAPOS)        if (opcode == OP_SBRAPOS)
7674          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), (framesize + 1) * sizeof(sljit_sw));          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), (framesize + 1) * sizeof(sljit_sw));
# Line 7324  while (*cc != OP_KETRPOS) Line 7688  while (*cc != OP_KETRPOS)
7688      }      }
7689    
7690    if (needs_control_head)    if (needs_control_head)
7691      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(stack));      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(stack));
7692    
7693    JUMPTO(SLJIT_JUMP, loop);    JUMPTO(SLJIT_JUMP, loop);
7694    flush_stubs(common);    flush_stubs(common);
# Line 7337  while (*cc != OP_KETRPOS) Line 7701  while (*cc != OP_KETRPOS)
7701    if (framesize < 0)    if (framesize < 0)
7702      {      {
7703      if (offset != 0)      if (offset != 0)
7704        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), cbraprivptr);
7705      else      else
7706        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7707      }      }
# Line 7347  while (*cc != OP_KETRPOS) Line 7711  while (*cc != OP_KETRPOS)
7711        {        {
7712        /* Last alternative. */        /* Last alternative. */
7713        if (*cc == OP_KETRPOS)        if (*cc == OP_KETRPOS)
7714          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
7715        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), cbraprivptr);
7716        }        }
7717      else      else
7718        {        {
7719        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
7720        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP2), (framesize + 1) * sizeof(sljit_sw));        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP2), (framesize + 1) * sizeof(sljit_sw));
7721        }        }
7722      }      }
# Line 7489  jump_list *nomatch = NULL; Line 7853  jump_list *nomatch = NULL;
7853  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
7854  struct sljit_label *label;  struct sljit_label *label;
7855  int private_data_ptr = PRIVATE_DATA(cc);  int private_data_ptr = PRIVATE_DATA(cc);
7856  int base = (private_data_ptr == 0) ? SLJIT_MEM1(STACK_TOP) : SLJIT_MEM1(SLJIT_LOCALS_REG);  int base = (private_data_ptr == 0) ? SLJIT_MEM1(STACK_TOP) : SLJIT_MEM1(SLJIT_SP);
7857  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;
7858  int offset1 = (private_data_ptr == 0) ? STACK(1) : private_data_ptr + (int)sizeof(sljit_sw);  int offset1 = (private_data_ptr == 0) ? STACK(1) : private_data_ptr + (int)sizeof(sljit_sw);
7859  int tmp_base, tmp_offset;  int tmp_base, tmp_offset;
# Line 7532  switch(type) Line 7896  switch(type)
7896    case OP_XCLASS:    case OP_XCLASS:
7897    case OP_NOTPROP:    case OP_NOTPROP:
7898    case OP_PROP:    case OP_PROP:
7899    tmp_base = SLJIT_MEM1(SLJIT_LOCALS_REG);    tmp_base = SLJIT_MEM1(SLJIT_SP);
7900    tmp_offset = POSSESSIVE0;    tmp_offset = POSSESSIVE0;
7901    break;    break;
7902    }    }
# Line 7559  switch(opcode) Line 7923  switch(opcode)
7923        }        }
7924    
7925      if (opcode == OP_UPTO || opcode == OP_CRRANGE)      if (opcode == OP_UPTO || opcode == OP_CRRANGE)
7926        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), POSSESSIVE0, SLJIT_IMM, 0);
7927    
7928      label = LABEL();      label = LABEL();
7929      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7930      if (opcode == OP_UPTO || opcode == OP_CRRANGE)      if (opcode == OP_UPTO || opcode == OP_CRRANGE)
7931        {        {
7932        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), POSSESSIVE0);
7933        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7934        if (opcode == OP_CRRANGE && min > 0)        if (opcode == OP_CRRANGE && min > 0)
7935          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, label);          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, label);
7936        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && max > 0))        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && max > 0))
7937          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, max);          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, max);
7938        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), POSSESSIVE0, TMP1, 0);
7939        }        }
7940    
7941      /* We cannot use TMP3 because of this allocate_stack. */      /* We cannot use TMP3 because of this allocate_stack. */
# Line 7662  switch(opcode) Line 8026  switch(opcode)
8026    if (opcode == OP_POSPLUS)    if (opcode == OP_POSPLUS)
8027      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
8028    if (opcode == OP_POSUPTO)    if (opcode == OP_POSUPTO)
8029      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), POSSESSIVE1, SLJIT_IMM, max);
8030    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
8031    label = LABEL();    label = LABEL();
8032    compile_char1_matchingpath(common, type, cc, &nomatch);    compile_char1_matchingpath(common, type, cc, &nomatch);
# Line 7671  switch(opcode) Line 8035  switch(opcode)
8035      JUMPTO(SLJIT_JUMP, label);      JUMPTO(SLJIT_JUMP, label);
8036    else    else
8037      {      {
8038      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, 1);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_SP), POSSESSIVE1, SLJIT_MEM1(SLJIT_SP), POSSESSIVE1, SLJIT_IMM, 1);
8039      JUMPTO(SLJIT_C_NOT_ZERO, label);      JUMPTO(SLJIT_C_NOT_ZERO, label);
8040      }      }
8041    set_jumps(nomatch, LABEL());    set_jumps(nomatch, LABEL());
# Line 7697  switch(opcode) Line 8061  switch(opcode)
8061    if (max != 0)    if (max != 0)
8062      {      {
8063      SLJIT_ASSERT(max - min > 0);      SLJIT_ASSERT(max - min > 0);
8064      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max - min);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), POSSESSIVE1, SLJIT_IMM, max - min);
8065      }      }
8066    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
8067    label = LABEL();    label = LABEL();
# Line 7707  switch(opcode) Line 8071  switch(opcode)
8071      JUMPTO(SLJIT_JUMP, label);      JUMPTO(SLJIT_JUMP, label);
8072    else    else
8073      {      {
8074      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, 1);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_SP), POSSESSIVE1, SLJIT_MEM1(SLJIT_SP), POSSESSIVE1, SLJIT_IMM, 1);
8075      JUMPTO(SLJIT_C_NOT_ZERO, label);      JUMPTO(SLJIT_C_NOT_ZERO, label);
8076      }      }
8077    set_jumps(nomatch, LABEL());    set_jumps(nomatch, LABEL());
# Line 7736  if (*cc == OP_FAIL) Line 8100  if (*cc == OP_FAIL)
8100    return cc + 1;    return cc + 1;
8101    }    }
8102    
8103  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL || !common->might_be_empty)
8104    {    {
8105    /* No need to check notempty conditions. */    /* No need to check notempty conditions. */
8106    if (common->accept_label == NULL)    if (common->accept_label == NULL)
# Line 7747  if (*cc == OP_ASSERT_ACCEPT || common->c Line 8111  if (*cc == OP_ASSERT_ACCEPT || common->c
8111    }    }
8112    
8113  if (common->accept_label == NULL)  if (common->accept_label == NULL)
8114    add_jump(compiler, &common->accept, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0)));    add_jump(compiler, &common->accept, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0)));
8115  else  else
8116    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), common->accept_label);    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0), common->accept_label);
8117  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
8118  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));
8119  add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));  add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
# Line 7778  if (common->currententry != NULL) Line 8142  if (common->currententry != NULL)
8142    return cc + 1 + IMM2_SIZE;    return cc + 1 + IMM2_SIZE;
8143    
8144  if (!optimized_cbracket)  if (!optimized_cbracket)
8145    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR_PRIV(offset));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR_PRIV(offset));
8146  offset <<= 1;  offset <<= 1;
8147  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), STR_PTR, 0);
8148  if (!optimized_cbracket)  if (!optimized_cbracket)
8149    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0);
8150  return cc + 1 + IMM2_SIZE;  return cc + 1 + IMM2_SIZE;
8151  }  }
8152    
# Line 7809  if (opcode == OP_PRUNE_ARG || opcode == Line 8173  if (opcode == OP_PRUNE_ARG || opcode ==
8173    {    {
8174    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
8175    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));
8176    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->mark_ptr, TMP2, 0);
8177    OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);
8178    }    }
8179    
# Line 7834  BACKTRACK_AS(then_trap_backtrack)->frame Line 8198  BACKTRACK_AS(then_trap_backtrack)->frame
8198  size = BACKTRACK_AS(then_trap_backtrack)->framesize;  size = BACKTRACK_AS(then_trap_backtrack)->framesize;
8199  size = 3 + (size < 0 ? 0 : size);  size = 3 + (size < 0 ? 0 : size);
8200    
8201  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr);
8202  allocate_stack(common, size);  allocate_stack(common, size);
8203  if (size > 3)  if (size > 3)
8204    OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0, SLJIT_IMM, (size - 3) * sizeof(sljit_sw));    OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, STACK_TOP, 0, SLJIT_IMM, (size - 3) * sizeof(sljit_sw));
8205  else  else
8206    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, STACK_TOP, 0);
8207  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 1), SLJIT_IMM, BACKTRACK_AS(then_trap_backtrack)->start);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 1), SLJIT_IMM, BACKTRACK_AS(then_trap_backtrack)->start);
8208  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 2), SLJIT_IMM, type_then_trap);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 2), SLJIT_IMM, type_then_trap);
8209  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 3), TMP2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 3), TMP2, 0);
# Line 7906  while (cc < ccend) Line 8270  while (cc < ccend)
8270    
8271      case OP_SET_SOM:      case OP_SET_SOM:
8272      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);
8273      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0));
8274      allocate_stack(common, 1);      allocate_stack(common, 1);
8275      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(0), STR_PTR, 0);
8276      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
8277      cc++;      cc++;
8278      break;      break;
# Line 8096  while (cc < ccend) Line 8460  while (cc < ccend)
8460      case OP_MARK:      case OP_MARK:
8461      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);
8462      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
8463      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr);
8464      allocate_stack(common, common->has_skip_arg ? 5 : 1);      allocate_stack(common, common->has_skip_arg ? 5 : 1);
8465      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
8466      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(common->has_skip_arg ? 4 : 0), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(common->has_skip_arg ? 4 : 0), TMP2, 0);
8467      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));
8468      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->mark_ptr, TMP2, 0);
8469      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);
8470      if (common->has_skip_arg)      if (common->has_skip_arg)
8471        {        {
8472        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr);
8473        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, STACK_TOP, 0);
8474        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, type_mark);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, type_mark);
8475        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), SLJIT_IMM, (sljit_sw)(cc + 2));        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), SLJIT_IMM, (sljit_sw)(cc + 2));
8476        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(3), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(3), STR_PTR, 0);
# Line 8184  struct sljit_label *label = NULL; Line 8548  struct sljit_label *label = NULL;
8548  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
8549  jump_list *jumplist = NULL;  jump_list *jumplist = NULL;
8550  int private_data_ptr = PRIVATE_DATA(cc);  int private_data_ptr = PRIVATE_DATA(cc);
8551  int base = (private_data_ptr == 0) ? SLJIT_MEM1(STACK_TOP) : SLJIT_MEM1(SLJIT_LOCALS_REG);  int base = (private_data_ptr == 0) ? SLJIT_MEM1(STACK_TOP) : SLJIT_MEM1(SLJIT_SP);
8552  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;
8553  int offset1 = (private_data_ptr == 0) ? STACK(1) : private_data_ptr + (int)sizeof(sljit_sw);  int offset1 = (private_data_ptr == 0) ? STACK(1) : private_data_ptr + (int)sizeof(sljit_sw);
8554    
# Line 8357  if (common->has_set_som && common->mark_ Line 8721  if (common->has_set_som && common->mark_
8721    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8722    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
8723    free_stack(common, 2);    free_stack(common, 2);
8724    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(0), TMP2, 0);
8725    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->mark_ptr, TMP1, 0);
8726    }    }
8727  else if (common->has_set_som || common->mark_ptr != 0)  else if (common->has_set_som || common->mark_ptr != 0)
8728    {    {
8729    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8730    free_stack(common, 1);    free_stack(common, 1);
8731    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->has_set_som ? (int)(OVECTOR(0)) : common->mark_ptr, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->has_set_som ? (int)(OVECTOR(0)) : common->mark_ptr, TMP2, 0);
8732    }    }
8733  }  }
8734    
# Line 8416  if (bra == OP_BRAZERO) Line 8780  if (bra == OP_BRAZERO)
8780    
8781  if (*cc == OP_ASSERT || *cc == OP_ASSERTBACK)  if (*cc == OP_ASSERT || *cc == OP_ASSERTBACK)
8782    {    {
8783    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(assert_backtrack)->private_data_ptr);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), CURRENT_AS(assert_backtrack)->private_data_ptr);
8784    add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
8785    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(assert_backtrack)->private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(assert_backtrack)->framesize * sizeof(sljit_sw));    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), CURRENT_AS(assert_backtrack)->private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(assert_backtrack)->framesize * sizeof(sljit_sw));
8786    
8787    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
8788    }    }
# Line 8438  if (bra == OP_BRAZERO) Line 8802  if (bra == OP_BRAZERO)
8802  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8803  {  {
8804  DEFINE_COMPILER;  DEFINE_COMPILER;
8805  int opcode, stacksize, count;  int opcode, stacksize, alt_count, alt_max;
8806  int offset = 0;  int offset = 0;
8807  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;
8808  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;
8809  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
8810  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
8811  pcre_uchar *ccprev;  pcre_uchar *ccprev;
 jump_list *jumplist = NULL;  
 jump_list *jumplistitem = NULL;  
8812  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
8813  pcre_uchar ket;  pcre_uchar ket;
8814  assert_backtrack *assert;  assert_backtrack *assert;
8815    sljit_uw *next_update_addr = NULL;
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 8490  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 8503  if (ket != OP_KET && repeat_type != 0) Line 8870  if (ket != OP_KET && repeat_type != 0)
8870    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8871    free_stack(common, 1);    free_stack(common, 1);
8872    if (repeat_type == OP_UPTO)    if (repeat_type == OP_UPTO)
8873      OP2(SLJIT_ADD, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_ADD, SLJIT_MEM1(SLJIT_SP), repeat_ptr, TMP1, 0, SLJIT_IMM, 1);
8874    else    else
8875      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), repeat_ptr, TMP1, 0);
8876    }    }
8877    
8878  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
# Line 8534  else if (ket == OP_KETRMIN) Line 8901  else if (ket == OP_KETRMIN)
8901        {        {
8902        /* Checking zero-length iteration. */        /* Checking zero-length iteration. */
8903        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize < 0)        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize < 0)
8904          CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, CURRENT_AS(bracket_backtrack)->recursive_matchingpath);          CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr, CURRENT_AS(bracket_backtrack)->recursive_matchingpath);
8905        else        else
8906          {          {
8907          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
8908          CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (CURRENT_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw), CURRENT_AS(bracket_backtrack)->recursive_matchingpath);          CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (CURRENT_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw), CURRENT_AS(bracket_backtrack)->recursive_matchingpath);
8909          }          }
8910        /* Drop STR_PTR for non-greedy plus quantifier. */        /* Drop STR_PTR for non-greedy plus quantifier. */
# Line 8549  else if (ket == OP_KETRMIN) Line 8916  else if (ket == OP_KETRMIN)
8916      }      }
8917    rmin_label = LABEL();    rmin_label = LABEL();
8918    if (repeat_type != 0)    if (repeat_type != 0)
8919      OP2(SLJIT_ADD, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);      OP2(SLJIT_ADD, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_IMM, 1);
8920    }    }
8921  else if (bra == OP_BRAZERO)  else if (bra == OP_BRAZERO)
8922    {    {
# Line 8559  else if (bra == OP_BRAZERO) Line 8926  else if (bra == OP_BRAZERO)
8926    }    }
8927  else if (repeat_type == OP_EXACT)  else if (repeat_type == OP_EXACT)
8928    {    {
8929    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_IMM, 1);
8930    exact_label = LABEL();    exact_label = LABEL();
8931    }    }
8932    
# Line 8570  if (offset != 0) Line 8937  if (offset != 0)
8937      SLJIT_ASSERT(common->optimized_cbracket[offset >> 1] == 0);      SLJIT_ASSERT(common->optimized_cbracket[offset >> 1] == 0);
8938      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8939      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
8940      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr, TMP1, 0);
8941      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
8942      free_stack(common, 3);      free_stack(common, 3);
8943      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP2, 0);
8944      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), TMP1, 0);
8945      }      }
8946    else if (common->optimized_cbracket[offset >> 1] == 0)    else if (common->optimized_cbracket[offset >> 1] == 0)
8947      {      {
8948      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8949      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
8950      free_stack(common, 2);      free_stack(common, 2);
8951      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0);
8952      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), TMP2, 0);
8953      }      }
8954    }    }
8955    
# Line 8590  if (SLJIT_UNLIKELY(opcode == OP_ONCE)) Line 8957  if (SLJIT_UNLIKELY(opcode == OP_ONCE))
8957    {    {
8958    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
8959      {      {
8960      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
8961      add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));      add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
8962      }      }
8963    once = JUMP(SLJIT_JUMP);    once = JUMP(SLJIT_JUMP);
# Line 8603  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;  
       }  
8981    
8982      if (SLJIT_UNLIKELY(!jumplistitem))    if (alt_max > 4)
8983        return;      {
8984        /* Table jump if alt_max is greater than 4. */
8985      jumplistitem->next = NULL;      next_update_addr = common->read_only_data_ptr;
8986      jumplistitem->jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, count++);      common->read_only_data_ptr += alt_max;
8987      cc += GET(cc, 1);      sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM1(TMP1), (sljit_sw)next_update_addr);
8988        add_label_addr(common, next_update_addr++);
8989        }
8990      else
8991        {
8992        if (alt_max == 4)
8993          alt2 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_uw));
8994        alt1 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, sizeof(sljit_uw));
8995      }      }
   while (*cc == OP_ALT);  
   
   cc = ccbegin + GET(ccbegin, 1);  
8996    }    }
8997    
8998  COMPILE_BACKTRACKINGPATH(current->top);  COMPILE_BACKTRACKINGPATH(current->top);
# Line 8656  if (SLJIT_UNLIKELY(opcode == OP_COND) || Line 9008  if (SLJIT_UNLIKELY(opcode == OP_COND) ||
9008      assert = CURRENT_AS(bracket_backtrack)->u.assert;      assert = CURRENT_AS(bracket_backtrack)->u.assert;
9009      if (assert->framesize >= 0 && (ccbegin[1 + LINK_SIZE] == OP_ASSERT || ccbegin[1 + LINK_SIZE] == OP_ASSERTBACK))      if (assert->framesize >= 0 && (ccbegin[1 + LINK_SIZE] == OP_ASSERT || ccbegin[1 + LINK_SIZE] == OP_ASSERTBACK))
9010        {        {
9011        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), assert->private_data_ptr);
9012        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
9013        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->private_data_ptr, SLJIT_MEM1(STACK_TOP), assert->framesize * sizeof(sljit_sw));        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), assert->private_data_ptr, SLJIT_MEM1(STACK_TOP), assert->framesize * sizeof(sljit_sw));
9014        }        }
9015      cond = JUMP(SLJIT_JUMP);      cond = JUMP(SLJIT_JUMP);
9016      set_jumps(CURRENT_AS(bracket_backtrack)->u.assert->condfailed, LABEL());      set_jumps(CURRENT_AS(bracket_backtrack)->u.assert->condfailed, LABEL());
# Line 8675  if (SLJIT_UNLIKELY(opcode == OP_COND) || Line 9027  if (SLJIT_UNLIKELY(opcode == OP_COND) ||
9027    
9028  if (has_alternatives)  if (has_alternatives)
9029    {    {
9030    count = 1;    alt_count = sizeof(sljit_uw);
9031    do    do
9032      {      {
9033      current->top = NULL;      current->top = NULL;
# Line 8691  if (has_alternatives) Line 9043  if (has_alternatives)
9043          if (opcode != OP_ONCE)          if (opcode != OP_ONCE)
9044            {            {
9045            if (private_data_ptr != 0)            if (private_data_ptr != 0)
9046              OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);              OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr);
9047            else            else
9048              OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));              OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
9049            }            }
# Line 8712  if (has_alternatives) Line 9064  if (has_alternatives)
9064      if (repeat_type == OP_MINUPTO)      if (repeat_type == OP_MINUPTO)
9065        {        {
9066        /* We need to preserve the counter. TMP2 will be used below. */        /* We need to preserve the counter. TMP2 will be used below. */
9067        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr);        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), repeat_ptr);
9068        stacksize++;        stacksize++;
9069        }        }
9070      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
# Line 8751  if (has_alternatives) Line 9103  if (has_alternatives)
9103        stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);        stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);
9104    
9105      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
9106        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);
9107    
9108      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)
9109        {        {
9110        /* If ket is not OP_KETRMAX, this code path is executed after the jump to alternative_matchingpath. */        /* If ket is not OP_KETRMAX, this code path is executed after the jump to alternative_matchingpath. */
9111        SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0));        SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0));
9112        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), STR_PTR, 0);
9113        }        }
9114    
9115      JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->alternative_matchingpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->alternative_matchingpath);
9116    
9117      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
9118        {        {
9119        SLJIT_ASSERT(jumplist);        if (alt_max > 4)
9120        JUMPHERE(jumplist->jump);          add_label_addr(common, next_update_addr++);
9121        jumplist = jumplist->next;        else
9122            {
9123            if (alt_count != 2 * sizeof(sljit_uw))
9124              {
9125              JUMPHERE(alt1);
9126              if (alt_max == 3 && alt_count == sizeof(sljit_uw))
9127                alt2 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_uw));
9128              }
9129            else
9130              {
9131              JUMPHERE(alt2);
9132              if (alt_max == 4)
9133                alt1 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_uw));
9134              }
9135            }
9136          alt_count += sizeof(sljit_uw);
9137        }        }
9138    
9139      COMPILE_BACKTRACKINGPATH(current->top);      COMPILE_BACKTRACKINGPATH(current->top);
# Line 8775  if (has_alternatives) Line 9142  if (has_alternatives)
9142      SLJIT_ASSERT(!current->nextbacktracks);      SLJIT_ASSERT(!current->nextbacktracks);
9143      }      }
9144    while (*cc == OP_ALT);    while (*cc == OP_ALT);
   SLJIT_ASSERT(!jumplist);  
9145    
9146    if (cond != NULL)    if (cond != NULL)
9147      {      {
# Line 8783  if (has_alternatives) Line 9149  if (has_alternatives)
9149      assert = CURRENT_AS(bracket_backtrack)->u.assert;      assert = CURRENT_AS(bracket_backtrack)->u.assert;
9150      if ((ccbegin[1 + LINK_SIZE] == OP_ASSERT_NOT || ccbegin[1 + LINK_SIZE] == OP_ASSERTBACK_NOT) && assert->framesize >= 0)      if ((ccbegin[1 + LINK_SIZE] == OP_ASSERT_NOT || ccbegin[1 + LINK_SIZE] == OP_ASSERTBACK_NOT) && assert->framesize >= 0)
9151        {        {
9152        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), assert->private_data_ptr);
9153        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
9154        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->private_data_ptr, SLJIT_MEM1(STACK_TOP), assert->framesize * sizeof(sljit_sw));        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), assert->private_data_ptr, SLJIT_MEM1(STACK_TOP), assert->framesize * sizeof(sljit_sw));
9155        }        }
9156      JUMPHERE(cond);      JUMPHERE(cond);
9157      }      }
# Line 8803  if (offset != 0) Line 9169  if (offset != 0)
9169      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
9170      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
9171      free_stack(common, 2);      free_stack(common, 2);
9172      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0);
9173      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), TMP2, 0);
9174      }      }
9175    else    else
9176      {      {
9177      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
9178      free_stack(common, 1);      free_stack(common, 1);
9179      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP1, 0);
9180      }      }
9181    }    }
9182  else if (opcode == OP_SBRA || opcode == OP_SCOND)  else if (opcode == OP_SBRA || opcode == OP_SCOND)
9183    {    {
9184    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_MEM1(STACK_TOP), STACK(0));
9185    free_stack(common, 1);    free_stack(common, 1);
9186    }    }
9187  else if (opcode == OP_ONCE)  else if (opcode == OP_ONCE)
# Line 8838  else if (opcode == OP_ONCE) Line 9204  else if (opcode == OP_ONCE)
9204    JUMPHERE(once);    JUMPHERE(once);
9205    /* Restore previous private_data_ptr */    /* Restore previous private_data_ptr */
9206    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
9207      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracket_backtrack)->u.framesize * sizeof(sljit_sw));      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracket_backtrack)->u.framesize * sizeof(sljit_sw));
9208    else if (ket == OP_KETRMIN)    else if (ket == OP_KETRMIN)
9209      {      {
9210      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
9211      /* See the comment below. */      /* See the comment below. */
9212      free_stack(common, 2);      free_stack(common, 2);
9213      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP1, 0);
9214      }      }
9215    }    }
9216    
9217  if (repeat_type == OP_EXACT)  if (repeat_type == OP_EXACT)
9218    {    {
9219    OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_IMM, 1);
9220    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), repeat_ptr, TMP1, 0);
9221    CMPTO(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, repeat_count, exact_label);    CMPTO(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, repeat_count, exact_label);
9222    }    }
9223  else if (ket == OP_KETRMAX)  else if (ket == OP_KETRMAX)
# Line 8905  if (CURRENT_AS(bracketpos_backtrack)->fr Line 9271  if (CURRENT_AS(bracketpos_backtrack)->fr
9271      offset = (GET2(current->cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(current->cc, 1 + LINK_SIZE)) << 1;
9272      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
9273      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
9274      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0);
9275      if (common->capture_last_ptr != 0)      if (common->capture_last_ptr != 0)
9276        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
9277      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), TMP2, 0);
9278      if (common->capture_last_ptr != 0)      if (common->capture_last_ptr != 0)
9279        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr, TMP1, 0);
9280      }      }
9281    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
9282    free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize);    free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize);
9283    return;    return;
9284    }    }
9285    
9286  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(bracketpos_backtrack)->private_data_ptr);  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), CURRENT_AS(bracketpos_backtrack)->private_data_ptr);
9287  add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));  add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
9288    
9289  if (current->topbacktracks)  if (current->topbacktracks)
# Line 8928  if (current->topbacktracks) Line 9294  if (current->topbacktracks)
9294    free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize);    free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize);
9295    JUMPHERE(jump);    JUMPHERE(jump);
9296    }    }
9297  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(bracketpos_backtrack)->private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracketpos_backtrack)->framesize * sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), CURRENT_AS(bracketpos_backtrack)->private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracketpos_backtrack)->framesize * sizeof(sljit_sw));
9298  }  }
9299    
9300  static SLJIT_INLINE void compile_braminzero_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static SLJIT_INLINE void compile_braminzero_backtrackingpath(compiler_common *common, struct backtrack_common *current)
# Line 8968  if (opcode == OP_THEN || opcode == OP_TH Line 9334  if (opcode == OP_THEN || opcode == OP_TH
9334      {      {
9335      SLJIT_ASSERT(common->control_head_ptr != 0);      SLJIT_ASSERT(common->control_head_ptr != 0);
9336    
9337      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr);
9338      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, type_then_trap);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, type_then_trap);
9339      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, common->then_trap->start);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, common->then_trap->start);
9340      jump = JUMP(SLJIT_JUMP);      jump = JUMP(SLJIT_JUMP);
# Line 9000  if (common->local_exit) Line 9366  if (common->local_exit)
9366  if (opcode == OP_SKIP_ARG)  if (opcode == OP_SKIP_ARG)
9367    {    {
9368    SLJIT_ASSERT(common->control_head_ptr != 0);    SLJIT_ASSERT(common->control_head_ptr != 0);
9369    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr);
9370    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS0, STACK_TOP, 0);
9371    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, (sljit_sw)(current->cc + 2));    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, (sljit_sw)(current->cc + 2));
9372    sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_search_mark));    sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_search_mark));
9373    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0);
9374    
9375    OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);    OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
9376    add_jump(compiler, &common->reset_match, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, -1));    add_jump(compiler, &common->reset_match, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, -1));
# Line 9045  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK Line 9411  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK
9411  free_stack(common, 3);  free_stack(common, 3);
9412    
9413  JUMPHERE(jump);  JUMPHERE(jump);
9414  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, TMP1, 0);
9415  }  }
9416    
9417  static void compile_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_backtrackingpath(compiler_common *common, struct backtrack_common *current)
# Line 9062  while (current) Line 9428  while (current)
9428      case OP_SET_SOM:      case OP_SET_SOM:
9429      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
9430      free_stack(common, 1);      free_stack(common, 1);
9431      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(0), TMP1, 0);
9432      break;      break;
9433    
9434      case OP_STAR:      case OP_STAR:
# Line 9191  while (current) Line 9557  while (current)
9557      if (common->has_skip_arg)      if (common->has_skip_arg)
9558        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
9559      free_stack(common, common->has_skip_arg ? 5 : 1);      free_stack(common, common->has_skip_arg ? 5 : 1);
9560      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->mark_ptr, TMP1, 0);
9561      if (common->has_skip_arg)      if (common->has_skip_arg)
9562        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, TMP2, 0);
9563      break;      break;
9564    
9565      case OP_THEN:      case OP_THEN:
# Line 9267  allocate_stack(common, private_data_size Line 9633  allocate_stack(common, private_data_size
9633  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(private_data_size + framesize + alternativesize - 1), TMP2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(private_data_size + framesize + alternativesize - 1), TMP2, 0);
9634  copy_private_data(common, ccbegin, ccend, TRUE, private_data_size + framesize + alternativesize, framesize + alternativesize, needs_control_head);  copy_private_data(common, ccbegin, ccend, TRUE, private_data_size + framesize + alternativesize, framesize + alternativesize, needs_control_head);
9635  if (needs_control_head)  if (needs_control_head)
9636    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_IMM, 0);
9637  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, STACK_TOP, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->recursive_head_ptr, STACK_TOP, 0);
9638  if (needs_frame)  if (needs_frame)
9639    init_frame(common, cc, NULL, framesize + alternativesize - 1, alternativesize, TRUE);    init_frame(common, cc, NULL, framesize + alternativesize - 1, alternativesize, TRUE);
9640    
# Line 9315  jump = JUMP(SLJIT_JUMP); Line 9681  jump = JUMP(SLJIT_JUMP);
9681  if (common->quit != NULL)  if (common->quit != NULL)
9682    {    {
9683    set_jumps(common->quit, LABEL());    set_jumps(common->quit, LABEL());
9684    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), common->recursive_head_ptr);
9685    if (needs_frame)    if (needs_frame)
9686      {      {
9687      OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + alternativesize) * sizeof(sljit_sw));      OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + alternativesize) * sizeof(sljit_sw));
# Line 9328  if (common->quit != NULL) Line 9694  if (common->quit != NULL)
9694    }    }
9695    
9696  set_jumps(common->accept, LABEL());  set_jumps(common->accept, LABEL());
9697  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr);  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), common->recursive_head_ptr);
9698  if (needs_frame)  if (needs_frame)
9699    {    {
9700    OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + alternativesize) * sizeof(sljit_sw));    OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + alternativesize) * sizeof(sljit_sw));
# Line 9346  if (needs_control_head) Line 9712  if (needs_control_head)
9712    {    {
9713    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 2 * sizeof(sljit_sw));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 2 * sizeof(sljit_sw));
9714    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), sizeof(sljit_sw));    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), sizeof(sljit_sw));
9715    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->recursive_head_ptr, TMP1, 0);
9716    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
9717    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, TMP2, 0);
9718    }    }
9719  else  else
9720    {    {
9721    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), sizeof(sljit_sw));    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), sizeof(sljit_sw));
9722    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
9723    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->recursive_head_ptr, TMP2, 0);
9724    }    }
9725  sljit_emit_fast_return(compiler, SLJIT_MEM1(STACK_TOP), 0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(STACK_TOP), 0);
9726  }  }
# Line 9376  pcre_uchar *ccend; Line 9742  pcre_uchar *ccend;
9742  executable_functions *functions;  executable_functions *functions;
9743  void *executable_func;  void *executable_func;
9744  sljit_uw executable_size;  sljit_uw executable_size;
9745    sljit_uw total_length;
9746    label_addr_list *label_addr;
9747  struct sljit_label *mainloop_label = NULL;  struct sljit_label *mainloop_label = NULL;
9748  struct sljit_label *continue_match_label;  struct sljit_label *continue_match_label;
9749  struct sljit_label *empty_match_found_label;  struct sljit_label *empty_match_found_label = NULL;
9750  struct sljit_label *empty_match_backtrack_label;  struct sljit_label *empty_match_backtrack_label = NULL;
9751  struct sljit_label *reset_match_label;  struct sljit_label *reset_match_label;
9752    struct sljit_label *quit_label;
9753  struct sljit_jump *jump;  struct sljit_jump *jump;
9754  struct sljit_jump *minlength_check_failed = NULL;  struct sljit_jump *minlength_check_failed = NULL;
9755  struct sljit_jump *reqbyte_notfound = NULL;  struct sljit_jump *reqbyte_notfound = NULL;
9756  struct sljit_jump *empty_match;  struct sljit_jump *empty_match = NULL;
 struct sljit_label *quit_label;  
9757    
9758  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);
9759  study = extra->study_data;  study = extra->study_data;
# Line 9398  memset(common, 0, sizeof(compiler_common Line 9766  memset(common, 0, sizeof(compiler_common
9766  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;
9767    
9768  common->start = rootbacktrack.cc;  common->start = rootbacktrack.cc;
9769    common->read_only_data = NULL;
9770    common->read_only_data_size = 0;
9771    common->read_only_data_ptr = NULL;
9772  common->fcc = tables + fcc_offset;  common->fcc = tables + fcc_offset;
9773  common->lcc = (sljit_sw)(tables + lcc_offset);  common->lcc = (sljit_sw)(tables + lcc_offset);
9774  common->mode = mode;  common->mode = mode;
9775    common->might_be_empty = study->minlength == 0;
9776  common->nltype = NLTYPE_FIXED;  common->nltype = NLTYPE_FIXED;
9777  switch(re->options & PCRE_NEWLINE_BITS)  switch(re->options & PCRE_NEWLINE_BITS)
9778    {    {
# Line 9421  switch(re->options & PCRE_NEWLINE_BITS) Line 9793  switch(re->options & PCRE_NEWLINE_BITS)
9793    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;
9794    default: return;    default: return;
9795    }    }
9796  common->nlmax = READ_CHAR_ANY;  common->nlmax = READ_CHAR_MAX;
9797    common->nlmin = 0;
9798  if ((re->options & PCRE_BSR_ANYCRLF) != 0)  if ((re->options & PCRE_BSR_ANYCRLF) != 0)
9799    common->bsr_nltype = NLTYPE_ANYCRLF;    common->bsr_nltype = NLTYPE_ANYCRLF;
9800  else if ((re->options & PCRE_BSR_UNICODE) != 0)  else if ((re->options & PCRE_BSR_UNICODE) != 0)
# Line 9434  else Line 9807  else
9807    common->bsr_nltype = NLTYPE_ANY;    common->bsr_nltype = NLTYPE_ANY;
9808  #endif  #endif
9809    }    }
9810  common->bsr_nlmax = READ_CHAR_ANY;  common->bsr_nlmax = READ_CHAR_MAX;
9811    common->bsr_nlmin = 0;
9812  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
9813  common->ctypes = (sljit_sw)(tables + ctypes_offset);  common->ctypes = (sljit_sw)(tables + ctypes_offset);
9814  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;
# Line 9459  if (common->utf) Line 9833  if (common->utf)
9833      common->nlmax = common->newline & 0xff;      common->nlmax = common->newline & 0xff;
9834      }      }
9835    
9836      if (common->nltype == NLTYPE_FIXED)
9837        common->nlmin = common->newline & 0xff;
9838      else
9839        common->nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL;
9840    
9841    if (common->bsr_nltype == NLTYPE_ANY)    if (common->bsr_nltype == NLTYPE_ANY)
9842      common->bsr_nlmax = 0x2029;      common->bsr_nlmax = 0x2029;
9843    else    else
9844      common->bsr_nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;      common->bsr_nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;
9845      common->bsr_nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL;
9846    }    }
9847  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
9848  ccend = bracketend(rootbacktrack.cc);  ccend = bracketend(common->start);
9849    
9850  /* Calculate the local space size on the stack. */  /* Calculate the local space size on the stack. */
9851  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);
# Line 9478  memset(common->optimized_cbracket, 0, re Line 9858  memset(common->optimized_cbracket, 0, re
9858  memset(common->optimized_cbracket, 1, re->top_bracket + 1);  memset(common->optimized_cbracket, 1, re->top_bracket + 1);
9859  #endif  #endif
9860    
9861  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);  SLJIT_ASSERT(*common->start == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);
9862  #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2  #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2
9863  common->capture_last_ptr = common->ovector_start;  common->capture_last_ptr = common->ovector_start;
9864  common->ovector_start += sizeof(sljit_sw);  common->ovector_start += sizeof(sljit_sw);
9865  #endif  #endif
9866  if (!check_opcode_types(common, rootbacktrack.cc, ccend))  if (!check_opcode_types(common, common->start, ccend))
9867    {    {
9868    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9869    return;    return;
# Line 9546  if (common->capture_last_ptr != 0) Line 9926  if (common->capture_last_ptr != 0)
9926  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));
9927  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);
9928    
9929  common->private_data_ptrs = (int *)SLJIT_MALLOC((ccend - rootbacktrack.cc) * sizeof(sljit_si));  total_length = ccend - common->start;
9930    common->private_data_ptrs = (sljit_si *)SLJIT_MALLOC(total_length * (sizeof(sljit_si) + (common->has_then ? 1 : 0)));
9931  if (!common->private_data_ptrs)  if (!common->private_data_ptrs)
9932    {    {
9933    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9934    return;    return;
9935    }    }
9936  memset(common->private_data_ptrs, 0, (ccend - rootbacktrack.cc) * sizeof(int));  memset(common->private_data_ptrs, 0, total_length * sizeof(sljit_si));
9937    
9938  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);
9939  set_private_data_ptrs(common, &private_data_size, ccend);  set_private_data_ptrs(common, &private_data_size, ccend);
# Line 9565  if (private_data_size > SLJIT_MAX_LOCAL_ Line 9946  if (private_data_size > SLJIT_MAX_LOCAL_
9946    
9947  if (common->has_then)  if (common->has_then)
9948    {    {
9949    common->then_offsets = (pcre_uint8 *)SLJIT_MALLOC(ccend - rootbacktrack.cc);    common->then_offsets = (pcre_uint8 *)(common->private_data_ptrs + total_length);
9950    if (!common->then_offsets)    memset(common->then_offsets, 0, total_length);
9951      set_then_offsets(common, common->start, NULL);
9952      }
9953    
9954    if (common->read_only_data_size > 0)
9955      {
9956      common->read_only_data = (sljit_uw *)SLJIT_MALLOC(common->read_only_data_size);
9957      if (common->read_only_data == NULL)
9958      {      {
9959      SLJIT_FREE(common->optimized_cbracket);      SLJIT_FREE(common->optimized_cbracket);
9960      SLJIT_FREE(common->private_data_ptrs);      SLJIT_FREE(common->private_data_ptrs);
9961      return;      return;
9962      }      }
9963    memset(common->then_offsets, 0, ccend - rootbacktrack.cc);    common->read_only_data_ptr = common->read_only_data;
   set_then_offsets(common, rootbacktrack.cc, NULL);  
9964    }    }
9965    
9966  compiler = sljit_create_compiler();  compiler = sljit_create_compiler();
# Line 9581  if (!compiler) Line 9968  if (!compiler)
9968    {    {
9969    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9970    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9971    if (common->has_then)    if (common->read_only_data)
9972      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
9973    return;    return;
9974    }    }
9975  common->compiler = compiler;  common->compiler = compiler;
9976    
9977  /* Main pcre_jit_exec entry. */  /* Main pcre_jit_exec entry. */
9978  sljit_emit_enter(compiler, 1, 5, 5, private_data_size);  sljit_emit_enter(compiler, 0, 1, 5, 5, 0, 0, private_data_size);
9979    
9980  /* Register init. */  /* Register init. */
9981  reset_ovector(common, (re->top_bracket + 1) * 2);  reset_ovector(common, (re->top_bracket + 1) * 2);
9982  if (common->req_char_ptr != 0)  if (common->req_char_ptr != 0)
9983    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr, SLJIT_SCRATCH_REG1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->req_char_ptr, SLJIT_R0, 0);
9984    
9985  OP1(SLJIT_MOV, ARGUMENTS, 0, SLJIT_SAVED_REG1, 0);  OP1(SLJIT_MOV, ARGUMENTS, 0, SLJIT_S0, 0);
9986  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_S0, 0);
9987  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
9988  OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, end));  OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, end));
9989  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, stack));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, stack));
9990  OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, limit_match));  OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, limit_match));
9991  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, base));  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, base));
9992  OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, limit));  OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, limit));
9993  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LIMIT_MATCH, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LIMIT_MATCH, TMP1, 0);
9994    
9995  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
9996    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, -1);
9997  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
9998    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->mark_ptr, SLJIT_IMM, 0);
9999  if (common->control_head_ptr != 0)  if (common->control_head_ptr != 0)
10000    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_IMM, 0);
10001    
10002  /* Main part of the matching */  /* Main part of the matching */
10003  if ((re->options & PCRE_ANCHORED) == 0)  if ((re->options & PCRE_ANCHORED) == 0)
# Line 9621  if ((re->options & PCRE_ANCHORED) == 0) Line 10008  if ((re->options & PCRE_ANCHORED) == 0)
10008    if ((re->options & PCRE_NO_START_OPTIMIZE) == 0)    if ((re->options & PCRE_NO_START_OPTIMIZE) == 0)
10009      {      {
10010      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))
10011        { /* Do nothing */ }        {
10012          /* If read_only_data is reallocated, we might have an allocation failure. */
10013          if (common->read_only_data_size > 0 && common->read_only_data == NULL)
10014            {
10015            sljit_free_compiler(compiler);
10016            SLJIT_FREE(common->optimized_cbracket);
10017            SLJIT_FREE(common->private_data_ptrs);
10018            return;
10019            }
10020          }
10021      else if ((re->flags & PCRE_FIRSTSET) != 0)      else if ((re->flags & PCRE_FIRSTSET) != 0)
10022        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);
10023      else if ((re->flags & PCRE_STARTLINE) != 0)      else if ((re->flags & PCRE_STARTLINE) != 0)
# Line 9643  if (common->req_char_ptr != 0) Line 10039  if (common->req_char_ptr != 0)
10039    reqbyte_notfound = search_requested_char(common, (pcre_uchar)re->req_char, (re->flags & PCRE_RCH_CASELESS) != 0, (re->flags & PCRE_FIRSTSET) != 0);    reqbyte_notfound = search_requested_char(common, (pcre_uchar)re->req_char, (re->flags & PCRE_RCH_CASELESS) != 0, (re->flags & PCRE_FIRSTSET) != 0);
10040    
10041  /* Store the current STR_PTR in OVECTOR(0). */  /* Store the current STR_PTR in OVECTOR(0). */
10042  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(0), STR_PTR, 0);
10043  /* Copy the limit of allowed recursions. */  /* Copy the limit of allowed recursions. */
10044  OP1(SLJIT_MOV, COUNT_MATCH, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LIMIT_MATCH);  OP1(SLJIT_MOV, COUNT_MATCH, 0, SLJIT_MEM1(SLJIT_SP), LIMIT_MATCH);
10045  if (common->capture_last_ptr != 0)  if (common->capture_last_ptr != 0)
10046    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr, SLJIT_IMM, -1);
10047    
10048  if (common->needs_start_ptr)  if (common->needs_start_ptr)
10049    {    {
10050    SLJIT_ASSERT(common->start_ptr != OVECTOR(0));    SLJIT_ASSERT(common->start_ptr != OVECTOR(0));
10051    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_ptr, STR_PTR, 0);
10052    }    }
10053  else  else
10054    SLJIT_ASSERT(common->start_ptr == OVECTOR(0));    SLJIT_ASSERT(common->start_ptr == OVECTOR(0));
# Line 9660  else Line 10056  else
10056  /* Copy the beginning of the string. */  /* Copy the beginning of the string. */
10057  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
10058    {    {
10059    jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, -1);
10060    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0);
10061    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start + sizeof(sljit_sw), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start + sizeof(sljit_sw), STR_PTR, 0);
10062    JUMPHERE(jump);    JUMPHERE(jump);
10063    }    }
10064  else if (mode == JIT_PARTIAL_HARD_COMPILE)  else if (mode == JIT_PARTIAL_HARD_COMPILE)
10065    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0);
10066    
10067  compile_matchingpath(common, rootbacktrack.cc, ccend, &rootbacktrack);  compile_matchingpath(common, common->start, ccend, &rootbacktrack);
10068  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
10069    {    {
10070    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
10071    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
10072    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
10073    if (common->has_then)    if (common->read_only_data)
10074      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
10075    return;    return;
10076    }    }
10077    
10078  empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));  if (common->might_be_empty)
10079  empty_match_found_label = LABEL();    {
10080      empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0));
10081      empty_match_found_label = LABEL();
10082      }
10083    
10084  common->accept_label = LABEL();  common->accept_label = LABEL();
10085  if (common->accept != NULL)  if (common->accept != NULL)
# Line 9704  if (mode != JIT_COMPILE) Line 10103  if (mode != JIT_COMPILE)
10103    return_with_partial_match(common, common->quit_label);    return_with_partial_match(common, common->quit_label);
10104    }    }
10105    
10106  empty_match_backtrack_label = LABEL();  if (common->might_be_empty)
10107      empty_match_backtrack_label = LABEL();
10108  compile_backtrackingpath(common, rootbacktrack.top);  compile_backtrackingpath(common, rootbacktrack.top);
10109  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
10110    {    {
10111    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
10112    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
10113    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
10114    if (common->has_then)    if (common->read_only_data)
10115      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
10116    return;    return;
10117    }    }
10118    
# Line 9722  reset_match_label = LABEL(); Line 10122  reset_match_label = LABEL();
10122  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
10123    {    {
10124    /* Update hit_start only in the first time. */    /* Update hit_start only in the first time. */
10125    jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);    jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0);
10126    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr);
10127    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, SLJIT_IMM, -1);
10128    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, TMP1, 0);
10129    JUMPHERE(jump);    JUMPHERE(jump);
10130    }    }
10131    
# Line 9733  if (mode == JIT_PARTIAL_SOFT_COMPILE) Line 10133  if (mode == JIT_PARTIAL_SOFT_COMPILE)
10133  if ((re->options & PCRE_ANCHORED) == 0 && (re->options & PCRE_FIRSTLINE) != 0)  if ((re->options & PCRE_ANCHORED) == 0 && (re->options & PCRE_FIRSTLINE) != 0)
10134    {    {
10135    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
10136    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end);
10137    }    }
10138    
10139  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), common->start_ptr);
10140    
10141  if ((re->options & PCRE_ANCHORED) == 0)  if ((re->options & PCRE_ANCHORED) == 0)
10142    {    {
10143    if ((re->options & PCRE_FIRSTLINE) == 0)    if (common->ff_newline_shortcut != NULL)
10144      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop_label);      {
10145        if ((re->options & PCRE_FIRSTLINE) == 0)
10146          CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, common->ff_newline_shortcut);