"Fossies" - the Fresh Open Source Software Archive

Member "AutoHotkey_L-1.1.33.09/source/lib_pcre/pcre/pcre_jit_compile.c" (8 May 2021, 213739 Bytes) of package /windows/misc/AutoHotkey_L-1.1.33.09.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "pcre_jit_compile.c" see the Fossies "Dox" file reference documentation.

    1 /*************************************************
    2 *      Perl-Compatible Regular Expressions       *
    3 *************************************************/
    4 
    5 /* PCRE is a library of functions to support regular expressions whose syntax
    6 and semantics are as close as possible to those of the Perl 5 language.
    7 
    8                        Written by Philip Hazel
    9            Copyright (c) 1997-2012 University of Cambridge
   10 
   11   The machine code generator part (this module) was written by Zoltan Herczeg
   12                       Copyright (c) 2010-2012
   13 
   14 -----------------------------------------------------------------------------
   15 Redistribution and use in source and binary forms, with or without
   16 modification, are permitted provided that the following conditions are met:
   17 
   18     * Redistributions of source code must retain the above copyright notice,
   19       this list of conditions and the following disclaimer.
   20 
   21     * Redistributions in binary form must reproduce the above copyright
   22       notice, this list of conditions and the following disclaimer in the
   23       documentation and/or other materials provided with the distribution.
   24 
   25     * Neither the name of the University of Cambridge nor the names of its
   26       contributors may be used to endorse or promote products derived from
   27       this software without specific prior written permission.
   28 
   29 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   30 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   31 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   32 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
   33 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   34 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   35 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   36 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   37 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   38 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   39 POSSIBILITY OF SUCH DAMAGE.
   40 -----------------------------------------------------------------------------
   41 */
   42 
   43 #ifdef HAVE_CONFIG_H
   44 #include "config.h"
   45 #endif
   46 
   47 #include "pcre_internal.h"
   48 
   49 #ifdef SUPPORT_JIT
   50 
   51 /* All-in-one: Since we use the JIT compiler only from here,
   52 we just include it. This way we don't need to touch the build
   53 system files. */
   54 
   55 #define SLJIT_MALLOC(size) (PUBL(malloc))(size)
   56 #define SLJIT_FREE(ptr) (PUBL(free))(ptr)
   57 #define SLJIT_CONFIG_AUTO 1
   58 #define SLJIT_CONFIG_STATIC 1
   59 #define SLJIT_VERBOSE 0
   60 #define SLJIT_DEBUG 0
   61 
   62 #include "sljit/sljitLir.c"
   63 
   64 #if defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED
   65 #error Unsupported architecture
   66 #endif
   67 
   68 /* Allocate memory on the stack. Fast, but limited size. */
   69 #define LOCAL_SPACE_SIZE 32768
   70 
   71 #define STACK_GROWTH_RATE 8192
   72 
   73 /* Enable to check that the allocation could destroy temporaries. */
   74 #if defined SLJIT_DEBUG && SLJIT_DEBUG
   75 #define DESTROY_REGISTERS 1
   76 #endif
   77 
   78 /*
   79 Short summary about the backtracking mechanism empolyed by the jit code generator:
   80 
   81 The code generator follows the recursive nature of the PERL compatible regular
   82 expressions. The basic blocks of regular expressions are condition checkers
   83 whose execute different commands depending on the result of the condition check.
   84 The relationship between the operators can be horizontal (concatenation) and
   85 vertical (sub-expression) (See struct fallback_common for more details).
   86 
   87   'ab' - 'a' and 'b' regexps are concatenated
   88   'a+' - 'a' is the sub-expression of the '+' operator
   89 
   90 The condition checkers are boolean (true/false) checkers. Machine code is generated
   91 for the checker itself and for the actions depending on the result of the checker.
   92 The 'true' case is called as the hot path (expected path), and the other is called as
   93 the 'fallback' path. Branch instructions are expesive for all CPUs, so we avoid taken
   94 branches on the hot path.
   95 
   96  Greedy star operator (*) :
   97    Hot path: match happens.
   98    Fallback path: match failed.
   99  Non-greedy star operator (*?) :
  100    Hot path: no need to perform a match.
  101    Fallback path: match is required.
  102 
  103 The following example shows how the code generated for a capturing bracket
  104 with two alternatives. Let A, B, C, D are arbirary regular expressions, and
  105 we have the following regular expression:
  106 
  107    A(B|C)D
  108 
  109 The generated code will be the following:
  110 
  111  A hot path
  112  '(' hot path (pushing arguments to the stack)
  113  B hot path
  114  ')' hot path (pushing arguments to the stack)
  115  D hot path
  116  return with successful match
  117 
  118  D fallback path
  119  ')' fallback path (If we arrived from "C" jump to the fallback of "C")
  120  B fallback path
  121  C expected path
  122  jump to D hot path
  123  C fallback path
  124  A fallback path
  125 
  126  Notice, that the order of fallback code paths are the opposite of the fast
  127  code paths. In this way the topmost value on the stack is always belong
  128  to the current fallback code path. The fallback code path must check
  129  whether there is a next alternative. If so, it needs to jump back to
  130  the hot path eventually. Otherwise it needs to clear out its own stack
  131  frame and continue the execution on the fallback code paths.
  132 */
  133 
  134 /*
  135 Saved stack frames:
  136 
  137 Atomic blocks and asserts require reloading the values of local variables
  138 when the fallback mechanism performed. Because of OP_RECURSE, the locals
  139 are not necessarly known in compile time, thus we need a dynamic restore
  140 mechanism.
  141 
  142 The stack frames are stored in a chain list, and have the following format:
  143 ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]
  144 
  145 Thus we can restore the locals to a particular point in the stack.
  146 */
  147 
  148 typedef struct jit_arguments {
  149   /* Pointers first. */
  150   struct sljit_stack *stack;
  151   const pcre_uchar *str;
  152   const pcre_uchar *begin;
  153   const pcre_uchar *end;
  154   int *offsets;
  155   pcre_uchar *ptr;
  156   /* Everything else after. */
  157   int offsetcount;
  158   int calllimit;
  159   pcre_uint8 notbol;
  160   pcre_uint8 noteol;
  161   pcre_uint8 notempty;
  162   pcre_uint8 notempty_atstart;
  163 } jit_arguments;
  164 
  165 typedef struct executable_function {
  166   void *executable_func;
  167   PUBL(jit_callback) callback;
  168   void *userdata;
  169   sljit_uw executable_size;
  170 } executable_function;
  171 
  172 typedef struct jump_list {
  173   struct sljit_jump *jump;
  174   struct jump_list *next;
  175 } jump_list;
  176 
  177 enum stub_types { stack_alloc };
  178 
  179 typedef struct stub_list {
  180   enum stub_types type;
  181   int data;
  182   struct sljit_jump *start;
  183   struct sljit_label *leave;
  184   struct stub_list *next;
  185 } stub_list;
  186 
  187 typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
  188 
  189 /* The following structure is the key data type for the recursive
  190 code generator. It is allocated by compile_hotpath, and contains
  191 the aguments for compile_fallbackpath. Must be the first member
  192 of its descendants. */
  193 typedef struct fallback_common {
  194   /* Concatenation stack. */
  195   struct fallback_common *prev;
  196   jump_list *nextfallbacks;
  197   /* Internal stack (for component operators). */
  198   struct fallback_common *top;
  199   jump_list *topfallbacks;
  200   /* Opcode pointer. */
  201   pcre_uchar *cc;
  202 } fallback_common;
  203 
  204 typedef struct assert_fallback {
  205   fallback_common common;
  206   jump_list *condfailed;
  207   /* Less than 0 (-1) if a frame is not needed. */
  208   int framesize;
  209   /* Points to our private memory word on the stack. */
  210   int localptr;
  211   /* For iterators. */
  212   struct sljit_label *hotpath;
  213 } assert_fallback;
  214 
  215 typedef struct bracket_fallback {
  216   fallback_common common;
  217   /* Where to coninue if an alternative is successfully matched. */
  218   struct sljit_label *althotpath;
  219   /* For rmin and rmax iterators. */
  220   struct sljit_label *recursivehotpath;
  221   /* For greedy ? operator. */
  222   struct sljit_label *zerohotpath;
  223   /* Contains the branches of a failed condition. */
  224   union {
  225     /* Both for OP_COND, OP_SCOND. */
  226     jump_list *condfailed;
  227     assert_fallback *assert;
  228     /* For OP_ONCE. -1 if not needed. */
  229     int framesize;
  230   } u;
  231   /* Points to our private memory word on the stack. */
  232   int localptr;
  233 } bracket_fallback;
  234 
  235 typedef struct bracketpos_fallback {
  236   fallback_common common;
  237   /* Points to our private memory word on the stack. */
  238   int localptr;
  239   /* Reverting stack is needed. */
  240   int framesize;
  241   /* Allocated stack size. */
  242   int stacksize;
  243 } bracketpos_fallback;
  244 
  245 typedef struct braminzero_fallback {
  246   fallback_common common;
  247   struct sljit_label *hotpath;
  248 } braminzero_fallback;
  249 
  250 typedef struct iterator_fallback {
  251   fallback_common common;
  252   /* Next iteration. */
  253   struct sljit_label *hotpath;
  254 } iterator_fallback;
  255 
  256 typedef struct recurse_entry {
  257   struct recurse_entry *next;
  258   /* Contains the function entry. */
  259   struct sljit_label *entry;
  260   /* Collects the calls until the function is not created. */
  261   jump_list *calls;
  262   /* Points to the starting opcode. */
  263   int start;
  264 } recurse_entry;
  265 
  266 typedef struct recurse_fallback {
  267   fallback_common common;
  268 } recurse_fallback;
  269 
  270 typedef struct compiler_common {
  271   struct sljit_compiler *compiler;
  272   pcre_uchar *start;
  273   int localsize;
  274   int *localptrs;
  275   const pcre_uint8 *fcc;
  276   sljit_w lcc;
  277   int cbraptr;
  278   int nltype;
  279   int newline;
  280   int bsr_nltype;
  281   int endonly;
  282   sljit_w ctypes;
  283   sljit_uw name_table;
  284   sljit_w name_count;
  285   sljit_w name_entry_size;
  286   struct sljit_label *acceptlabel;
  287   stub_list *stubs;
  288   recurse_entry *entries;
  289   recurse_entry *currententry;
  290   jump_list *accept;
  291   jump_list *calllimit;
  292   jump_list *stackalloc;
  293   jump_list *revertframes;
  294   jump_list *wordboundary;
  295   jump_list *anynewline;
  296   jump_list *hspace;
  297   jump_list *vspace;
  298   jump_list *casefulcmp;
  299   jump_list *caselesscmp;
  300   BOOL jscript_compat;
  301 #ifdef SUPPORT_UTF
  302 #ifdef SUPPORT_UTF_OPTION /* AutoHotkey: Helps detect any usages which aren't macro'd out. */
  303   BOOL utf;
  304 #endif
  305 #ifdef SUPPORT_UCP
  306   BOOL use_ucp;
  307 #endif
  308   jump_list *utfreadchar;
  309 #ifdef COMPILE_PCRE8
  310   jump_list *utfreadtype8;
  311 #endif
  312 #endif /* SUPPORT_UTF */
  313 #ifdef SUPPORT_UCP
  314   jump_list *getucd;
  315 #endif
  316 } compiler_common;
  317 
  318 /* For byte_sequence_compare. */
  319 
  320 typedef struct compare_context {
  321   int length;
  322   int sourcereg;
  323 #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
  324   int ucharptr;
  325   union {
  326     sljit_i asint;
  327     sljit_uh asushort;
  328 #ifdef COMPILE_PCRE8
  329     sljit_ub asbyte;
  330     sljit_ub asuchars[4];
  331 #else
  332 #ifdef COMPILE_PCRE16
  333     sljit_uh asuchars[2];
  334 #endif
  335 #endif
  336   } c;
  337   union {
  338     sljit_i asint;
  339     sljit_uh asushort;
  340 #ifdef COMPILE_PCRE8
  341     sljit_ub asbyte;
  342     sljit_ub asuchars[4];
  343 #else
  344 #ifdef COMPILE_PCRE16
  345     sljit_uh asuchars[2];
  346 #endif
  347 #endif
  348   } oc;
  349 #endif
  350 } compare_context;
  351 
  352 enum {
  353   frame_end = 0,
  354   frame_setstrbegin = -1
  355 };
  356 
  357 /* Undefine sljit macros. */
  358 #undef CMP
  359 
  360 /* Used for accessing the elements of the stack. */
  361 #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))
  362 
  363 #define TMP1          SLJIT_TEMPORARY_REG1
  364 #define TMP2          SLJIT_TEMPORARY_REG3
  365 #define TMP3          SLJIT_TEMPORARY_EREG2
  366 #define STR_PTR       SLJIT_SAVED_REG1
  367 #define STR_END       SLJIT_SAVED_REG2
  368 #define STACK_TOP     SLJIT_TEMPORARY_REG2
  369 #define STACK_LIMIT   SLJIT_SAVED_REG3
  370 #define ARGUMENTS     SLJIT_SAVED_EREG1
  371 #define CALL_COUNT    SLJIT_SAVED_EREG2
  372 #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
  373 
  374 /* Locals layout. */
  375 /* These two locals can be used by the current opcode. */
  376 #define LOCALS0          (0 * sizeof(sljit_w))
  377 #define LOCALS1          (1 * sizeof(sljit_w))
  378 /* Two local variables for possessive quantifiers (char1 cannot use them). */
  379 #define POSSESSIVE0      (2 * sizeof(sljit_w))
  380 #define POSSESSIVE1      (3 * sizeof(sljit_w))
  381 /* Head of the last recursion. */
  382 #define RECURSIVE_HEAD   (4 * sizeof(sljit_w))
  383 /* Max limit of recursions. */
  384 #define CALL_LIMIT       (5 * sizeof(sljit_w))
  385 /* Last known position of the requested byte. */
  386 #define REQ_CHAR_PTR     (6 * sizeof(sljit_w))
  387 /* End pointer of the first line. */
  388 #define FIRSTLINE_END    (7 * sizeof(sljit_w))
  389 /* The output vector is stored on the stack, and contains pointers
  390 to characters. The vector data is divided into two groups: the first
  391 group contains the start / end character pointers, and the second is
  392 the start pointers when the end of the capturing group has not yet reached. */
  393 #define OVECTOR_START    (8 * sizeof(sljit_w))
  394 #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))
  395 #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))
  396 #define PRIV_DATA(cc)    (common->localptrs[(cc) - common->start])
  397 
  398 #ifdef COMPILE_PCRE8
  399 #define MOV_UCHAR  SLJIT_MOV_UB
  400 #define MOVU_UCHAR SLJIT_MOVU_UB
  401 #else
  402 #ifdef COMPILE_PCRE16
  403 #define MOV_UCHAR  SLJIT_MOV_UH
  404 #define MOVU_UCHAR SLJIT_MOVU_UH
  405 #else
  406 #error Unsupported compiling mode
  407 #endif
  408 #endif
  409 
  410 /* Shortcuts. */
  411 #define DEFINE_COMPILER \
  412   struct sljit_compiler *compiler = common->compiler
  413 #define OP1(op, dst, dstw, src, srcw) \
  414   sljit_emit_op1(compiler, (op), (dst), (dstw), (src), (srcw))
  415 #define OP2(op, dst, dstw, src1, src1w, src2, src2w) \
  416   sljit_emit_op2(compiler, (op), (dst), (dstw), (src1), (src1w), (src2), (src2w))
  417 #define LABEL() \
  418   sljit_emit_label(compiler)
  419 #define JUMP(type) \
  420   sljit_emit_jump(compiler, (type))
  421 #define JUMPTO(type, label) \
  422   sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
  423 #define JUMPHERE(jump) \
  424   sljit_set_label((jump), sljit_emit_label(compiler))
  425 #define CMP(type, src1, src1w, src2, src2w) \
  426   sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
  427 #define CMPTO(type, src1, src1w, src2, src2w, label) \
  428   sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))
  429 #define COND_VALUE(op, dst, dstw, type) \
  430   sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))
  431 
  432 static pcre_uchar* bracketend(pcre_uchar* cc)
  433 {
  434 SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
  435 do cc += GET(cc, 1); while (*cc == OP_ALT);
  436 SLJIT_ASSERT(*cc >= OP_KET && *cc <= OP_KETRPOS);
  437 cc += 1 + LINK_SIZE;
  438 return cc;
  439 }
  440 
  441 /* Functions whose might need modification for all new supported opcodes:
  442  next_opcode
  443  get_localspace
  444  set_localptrs
  445  get_framesize
  446  init_frame
  447  get_localsize
  448  copy_locals
  449  compile_hotpath
  450  compile_fallbackpath
  451 */
  452 
  453 static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
  454 {
  455 SLJIT_UNUSED_ARG(common);
  456 switch(*cc)
  457   {
  458   case OP_SOD:
  459   case OP_SOM:
  460   case OP_SET_SOM:
  461   case OP_NOT_WORD_BOUNDARY:
  462   case OP_WORD_BOUNDARY:
  463   case OP_NOT_DIGIT:
  464   case OP_DIGIT:
  465   case OP_NOT_WHITESPACE:
  466   case OP_WHITESPACE:
  467   case OP_NOT_WORDCHAR:
  468   case OP_WORDCHAR:
  469   case OP_ANY:
  470   case OP_ALLANY:
  471   case OP_ANYNL:
  472   case OP_NOT_HSPACE:
  473   case OP_HSPACE:
  474   case OP_NOT_VSPACE:
  475   case OP_VSPACE:
  476   case OP_EXTUNI:
  477   case OP_EODN:
  478   case OP_EOD:
  479   case OP_CIRC:
  480   case OP_CIRCM:
  481   case OP_DOLL:
  482   case OP_DOLLM:
  483   case OP_TYPESTAR:
  484   case OP_TYPEMINSTAR:
  485   case OP_TYPEPLUS:
  486   case OP_TYPEMINPLUS:
  487   case OP_TYPEQUERY:
  488   case OP_TYPEMINQUERY:
  489   case OP_TYPEPOSSTAR:
  490   case OP_TYPEPOSPLUS:
  491   case OP_TYPEPOSQUERY:
  492   case OP_CRSTAR:
  493   case OP_CRMINSTAR:
  494   case OP_CRPLUS:
  495   case OP_CRMINPLUS:
  496   case OP_CRQUERY:
  497   case OP_CRMINQUERY:
  498   case OP_DEF:
  499   case OP_BRAZERO:
  500   case OP_BRAMINZERO:
  501   case OP_BRAPOSZERO:
  502   case OP_FAIL:
  503   case OP_ACCEPT:
  504   case OP_ASSERT_ACCEPT:
  505   case OP_SKIPZERO:
  506   return cc + 1;
  507 
  508   case OP_ANYBYTE:
  509 #ifdef SUPPORT_UTF
  510   if (UTF_ENABLED(common->utf)) return NULL;
  511 #endif
  512   return cc + 1;
  513 
  514   case OP_CHAR:
  515   case OP_CHARI:
  516   case OP_NOT:
  517   case OP_NOTI:
  518   case OP_STAR:
  519   case OP_MINSTAR:
  520   case OP_PLUS:
  521   case OP_MINPLUS:
  522   case OP_QUERY:
  523   case OP_MINQUERY:
  524   case OP_POSSTAR:
  525   case OP_POSPLUS:
  526   case OP_POSQUERY:
  527   case OP_STARI:
  528   case OP_MINSTARI:
  529   case OP_PLUSI:
  530   case OP_MINPLUSI:
  531   case OP_QUERYI:
  532   case OP_MINQUERYI:
  533   case OP_POSSTARI:
  534   case OP_POSPLUSI:
  535   case OP_POSQUERYI:
  536   case OP_NOTSTAR:
  537   case OP_NOTMINSTAR:
  538   case OP_NOTPLUS:
  539   case OP_NOTMINPLUS:
  540   case OP_NOTQUERY:
  541   case OP_NOTMINQUERY:
  542   case OP_NOTPOSSTAR:
  543   case OP_NOTPOSPLUS:
  544   case OP_NOTPOSQUERY:
  545   case OP_NOTSTARI:
  546   case OP_NOTMINSTARI:
  547   case OP_NOTPLUSI:
  548   case OP_NOTMINPLUSI:
  549   case OP_NOTQUERYI:
  550   case OP_NOTMINQUERYI:
  551   case OP_NOTPOSSTARI:
  552   case OP_NOTPOSPLUSI:
  553   case OP_NOTPOSQUERYI:
  554   cc += 2;
  555 #ifdef SUPPORT_UTF
  556   if (UTF_ENABLED(common->utf) && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
  557 #endif
  558   return cc;
  559 
  560   case OP_UPTO:
  561   case OP_MINUPTO:
  562   case OP_EXACT:
  563   case OP_POSUPTO:
  564   case OP_UPTOI:
  565   case OP_MINUPTOI:
  566   case OP_EXACTI:
  567   case OP_POSUPTOI:
  568   case OP_NOTUPTO:
  569   case OP_NOTMINUPTO:
  570   case OP_NOTEXACT:
  571   case OP_NOTPOSUPTO:
  572   case OP_NOTUPTOI:
  573   case OP_NOTMINUPTOI:
  574   case OP_NOTEXACTI:
  575   case OP_NOTPOSUPTOI:
  576   cc += 2 + IMM2_SIZE;
  577 #ifdef SUPPORT_UTF
  578   if (UTF_ENABLED(common->utf) && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
  579 #endif
  580   return cc;
  581 
  582   case OP_NOTPROP:
  583   case OP_PROP:
  584   return cc + 1 + 2;
  585 
  586   case OP_TYPEUPTO:
  587   case OP_TYPEMINUPTO:
  588   case OP_TYPEEXACT:
  589   case OP_TYPEPOSUPTO:
  590   case OP_REF:
  591   case OP_REFI:
  592   case OP_CREF:
  593   case OP_NCREF:
  594   case OP_RREF:
  595   case OP_NRREF:
  596   case OP_CLOSE:
  597   cc += 1 + IMM2_SIZE;
  598   return cc;
  599 
  600   case OP_CRRANGE:
  601   case OP_CRMINRANGE:
  602   return cc + 1 + 2 * IMM2_SIZE;
  603 
  604   case OP_CLASS:
  605   case OP_NCLASS:
  606   return cc + 1 + 32 / sizeof(pcre_uchar);
  607 
  608 #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
  609   case OP_XCLASS:
  610   return cc + GET(cc, 1);
  611 #endif
  612 
  613   case OP_RECURSE:
  614   case OP_ASSERT:
  615   case OP_ASSERT_NOT:
  616   case OP_ASSERTBACK:
  617   case OP_ASSERTBACK_NOT:
  618   case OP_REVERSE:
  619   case OP_ONCE:
  620   case OP_ONCE_NC:
  621   case OP_BRA:
  622   case OP_BRAPOS:
  623   case OP_COND:
  624   case OP_SBRA:
  625   case OP_SBRAPOS:
  626   case OP_SCOND:
  627   case OP_ALT:
  628   case OP_KET:
  629   case OP_KETRMAX:
  630   case OP_KETRMIN:
  631   case OP_KETRPOS:
  632   return cc + 1 + LINK_SIZE;
  633 
  634   case OP_CBRA:
  635   case OP_CBRAPOS:
  636   case OP_SCBRA:
  637   case OP_SCBRAPOS:
  638   return cc + 1 + LINK_SIZE + IMM2_SIZE;
  639 
  640   default:
  641   return NULL;
  642   }
  643 }
  644 
  645 static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
  646 {
  647 int localspace = 0;
  648 pcre_uchar *alternative;
  649 /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
  650 while (cc < ccend)
  651   {
  652   switch(*cc)
  653     {
  654     case OP_ASSERT:
  655     case OP_ASSERT_NOT:
  656     case OP_ASSERTBACK:
  657     case OP_ASSERTBACK_NOT:
  658     case OP_ONCE:
  659     case OP_ONCE_NC:
  660     case OP_BRAPOS:
  661     case OP_SBRA:
  662     case OP_SBRAPOS:
  663     case OP_SCOND:
  664     localspace += sizeof(sljit_w);
  665     cc += 1 + LINK_SIZE;
  666     break;
  667 
  668     case OP_CBRAPOS:
  669     case OP_SCBRAPOS:
  670     localspace += sizeof(sljit_w);
  671     cc += 1 + LINK_SIZE + IMM2_SIZE;
  672     break;
  673 
  674     case OP_COND:
  675     /* Might be a hidden SCOND. */
  676     alternative = cc + GET(cc, 1);
  677     if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
  678       localspace += sizeof(sljit_w);
  679     cc += 1 + LINK_SIZE;
  680     break;
  681 
  682     default:
  683     cc = next_opcode(common, cc);
  684     if (cc == NULL)
  685       return -1;
  686     break;
  687     }
  688   }
  689 return localspace;
  690 }
  691 
  692 static void set_localptrs(compiler_common *common, int localptr, pcre_uchar *ccend)
  693 {
  694 pcre_uchar *cc = common->start;
  695 pcre_uchar *alternative;
  696 while (cc < ccend)
  697   {
  698   switch(*cc)
  699     {
  700     case OP_ASSERT:
  701     case OP_ASSERT_NOT:
  702     case OP_ASSERTBACK:
  703     case OP_ASSERTBACK_NOT:
  704     case OP_ONCE:
  705     case OP_ONCE_NC:
  706     case OP_BRAPOS:
  707     case OP_SBRA:
  708     case OP_SBRAPOS:
  709     case OP_SCOND:
  710     common->localptrs[cc - common->start] = localptr;
  711     localptr += sizeof(sljit_w);
  712     cc += 1 + LINK_SIZE;
  713     break;
  714 
  715     case OP_CBRAPOS:
  716     case OP_SCBRAPOS:
  717     common->localptrs[cc - common->start] = localptr;
  718     localptr += sizeof(sljit_w);
  719     cc += 1 + LINK_SIZE + IMM2_SIZE;
  720     break;
  721 
  722     case OP_COND:
  723     /* Might be a hidden SCOND. */
  724     alternative = cc + GET(cc, 1);
  725     if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
  726       {
  727       common->localptrs[cc - common->start] = localptr;
  728       localptr += sizeof(sljit_w);
  729       }
  730     cc += 1 + LINK_SIZE;
  731     break;
  732 
  733     default:
  734     cc = next_opcode(common, cc);
  735     SLJIT_ASSERT(cc != NULL);
  736     break;
  737     }
  738   }
  739 }
  740 
  741 /* Returns with -1 if no need for frame. */
  742 static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)
  743 {
  744 pcre_uchar *ccend = bracketend(cc);
  745 int length = 0;
  746 BOOL possessive = FALSE;
  747 BOOL setsom_found = FALSE;
  748 
  749 if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
  750   {
  751   length = 3;
  752   possessive = TRUE;
  753   }
  754 
  755 cc = next_opcode(common, cc);
  756 SLJIT_ASSERT(cc != NULL);
  757 while (cc < ccend)
  758   switch(*cc)
  759     {
  760     case OP_SET_SOM:
  761     case OP_RECURSE:
  762     if (!setsom_found)
  763       {
  764       length += 2;
  765       setsom_found = TRUE;
  766       }
  767     cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;
  768     break;
  769 
  770     case OP_CBRA:
  771     case OP_CBRAPOS:
  772     case OP_SCBRA:
  773     case OP_SCBRAPOS:
  774     length += 3;
  775     cc += 1 + LINK_SIZE + IMM2_SIZE;
  776     break;
  777 
  778     default:
  779     cc = next_opcode(common, cc);
  780     SLJIT_ASSERT(cc != NULL);
  781     break;
  782     }
  783 
  784 /* Possessive quantifiers can use a special case. */
  785 if (SLJIT_UNLIKELY(possessive) && length == 3)
  786   return -1;
  787 
  788 if (length > 0)
  789   return length + 1;
  790 return -1;
  791 }
  792 
  793 static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)
  794 {
  795 DEFINE_COMPILER;
  796 pcre_uchar *ccend = bracketend(cc);
  797 BOOL setsom_found = FALSE;
  798 int offset;
  799 
  800 /* >= 1 + shortest item size (2) */
  801 SLJIT_UNUSED_ARG(stacktop);
  802 SLJIT_ASSERT(stackpos >= stacktop + 2);
  803 
  804 stackpos = STACK(stackpos);
  805 if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
  806   cc = next_opcode(common, cc);
  807 SLJIT_ASSERT(cc != NULL);
  808 while (cc < ccend)
  809   switch(*cc)
  810     {
  811     case OP_SET_SOM:
  812     case OP_RECURSE:
  813     if (!setsom_found)
  814       {
  815       OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
  816       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);
  817       stackpos += (int)sizeof(sljit_w);
  818       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
  819       stackpos += (int)sizeof(sljit_w);
  820       setsom_found = TRUE;
  821       }
  822     cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;
  823     break;
  824 
  825     case OP_CBRA:
  826     case OP_CBRAPOS:
  827     case OP_SCBRA:
  828     case OP_SCBRAPOS:
  829     offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
  830     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
  831     stackpos += (int)sizeof(sljit_w);
  832     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
  833     OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
  834     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
  835     stackpos += (int)sizeof(sljit_w);
  836     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
  837     stackpos += (int)sizeof(sljit_w);
  838 
  839     cc += 1 + LINK_SIZE + IMM2_SIZE;
  840     break;
  841 
  842     default:
  843     cc = next_opcode(common, cc);
  844     SLJIT_ASSERT(cc != NULL);
  845     break;
  846     }
  847 
  848 OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);
  849 SLJIT_ASSERT(stackpos == STACK(stacktop));
  850 }
  851 
  852 static SLJIT_INLINE int get_localsize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
  853 {
  854 int localsize = 2;
  855 pcre_uchar *alternative;
  856 /* Calculate the sum of the local variables. */
  857 while (cc < ccend)
  858   {
  859   switch(*cc)
  860     {
  861     case OP_ASSERT:
  862     case OP_ASSERT_NOT:
  863     case OP_ASSERTBACK:
  864     case OP_ASSERTBACK_NOT:
  865     case OP_ONCE:
  866     case OP_ONCE_NC:
  867     case OP_BRAPOS:
  868     case OP_SBRA:
  869     case OP_SBRAPOS:
  870     case OP_SCOND:
  871     localsize++;
  872     cc += 1 + LINK_SIZE;
  873     break;
  874 
  875     case OP_CBRA:
  876     case OP_SCBRA:
  877     localsize++;
  878     cc += 1 + LINK_SIZE + IMM2_SIZE;
  879     break;
  880 
  881     case OP_CBRAPOS:
  882     case OP_SCBRAPOS:
  883     localsize += 2;
  884     cc += 1 + LINK_SIZE + IMM2_SIZE;
  885     break;
  886 
  887     case OP_COND:
  888     /* Might be a hidden SCOND. */
  889     alternative = cc + GET(cc, 1);
  890     if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
  891       localsize++;
  892     cc += 1 + LINK_SIZE;
  893     break;
  894 
  895     default:
  896     cc = next_opcode(common, cc);
  897     SLJIT_ASSERT(cc != NULL);
  898     break;
  899     }
  900   }
  901 SLJIT_ASSERT(cc == ccend);
  902 return localsize;
  903 }
  904 
  905 static void copy_locals(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,
  906   BOOL save, int stackptr, int stacktop)
  907 {
  908 DEFINE_COMPILER;
  909 int srcw[2];
  910 int count;
  911 BOOL tmp1next = TRUE;
  912 BOOL tmp1empty = TRUE;
  913 BOOL tmp2empty = TRUE;
  914 pcre_uchar *alternative;
  915 enum {
  916   start,
  917   loop,
  918   end
  919 } status;
  920 
  921 status = save ? start : loop;
  922 stackptr = STACK(stackptr - 2);
  923 stacktop = STACK(stacktop - 1);
  924 
  925 if (!save)
  926   {
  927   stackptr += sizeof(sljit_w);
  928   if (stackptr < stacktop)
  929     {
  930     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
  931     stackptr += sizeof(sljit_w);
  932     tmp1empty = FALSE;
  933     }
  934   if (stackptr < stacktop)
  935     {
  936     OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
  937     stackptr += sizeof(sljit_w);
  938     tmp2empty = FALSE;
  939     }
  940   /* The tmp1next must be TRUE in either way. */
  941   }
  942 
  943 while (status != end)
  944   {
  945   count = 0;
  946   switch(status)
  947     {
  948     case start:
  949     SLJIT_ASSERT(save);
  950     count = 1;
  951     srcw[0] = RECURSIVE_HEAD;
  952     status = loop;
  953     break;
  954 
  955     case loop:
  956     if (cc >= ccend)
  957       {
  958       status = end;
  959       break;
  960       }
  961 
  962     switch(*cc)
  963       {
  964       case OP_ASSERT:
  965       case OP_ASSERT_NOT:
  966       case OP_ASSERTBACK:
  967       case OP_ASSERTBACK_NOT:
  968       case OP_ONCE:
  969       case OP_ONCE_NC:
  970       case OP_BRAPOS:
  971       case OP_SBRA:
  972       case OP_SBRAPOS:
  973       case OP_SCOND:
  974       count = 1;
  975       srcw[0] = PRIV_DATA(cc);
  976       SLJIT_ASSERT(srcw[0] != 0);
  977       cc += 1 + LINK_SIZE;
  978       break;
  979 
  980       case OP_CBRA:
  981       case OP_SCBRA:
  982       count = 1;
  983       srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
  984       cc += 1 + LINK_SIZE + IMM2_SIZE;
  985       break;
  986 
  987       case OP_CBRAPOS:
  988       case OP_SCBRAPOS:
  989       count = 2;
  990       srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
  991       srcw[0] = PRIV_DATA(cc);
  992       SLJIT_ASSERT(srcw[0] != 0);
  993       cc += 1 + LINK_SIZE + IMM2_SIZE;
  994       break;
  995 
  996       case OP_COND:
  997       /* Might be a hidden SCOND. */
  998       alternative = cc + GET(cc, 1);
  999       if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
 1000         {
 1001         count = 1;
 1002         srcw[0] = PRIV_DATA(cc);
 1003         SLJIT_ASSERT(srcw[0] != 0);
 1004         }
 1005       cc += 1 + LINK_SIZE;
 1006       break;
 1007 
 1008       default:
 1009       cc = next_opcode(common, cc);
 1010       SLJIT_ASSERT(cc != NULL);
 1011       break;
 1012       }
 1013     break;
 1014 
 1015     case end:
 1016     SLJIT_ASSERT_STOP();
 1017     break;
 1018     }
 1019 
 1020   while (count > 0)
 1021     {
 1022     count--;
 1023     if (save)
 1024       {
 1025       if (tmp1next)
 1026         {
 1027         if (!tmp1empty)
 1028           {
 1029           OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
 1030           stackptr += sizeof(sljit_w);
 1031           }
 1032         OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
 1033         tmp1empty = FALSE;
 1034         tmp1next = FALSE;
 1035         }
 1036       else
 1037         {
 1038         if (!tmp2empty)
 1039           {
 1040           OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
 1041           stackptr += sizeof(sljit_w);
 1042           }
 1043         OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
 1044         tmp2empty = FALSE;
 1045         tmp1next = TRUE;
 1046         }
 1047       }
 1048     else
 1049       {
 1050       if (tmp1next)
 1051         {
 1052         SLJIT_ASSERT(!tmp1empty);
 1053         OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count], TMP1, 0);
 1054         tmp1empty = stackptr >= stacktop;
 1055         if (!tmp1empty)
 1056           {
 1057           OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
 1058           stackptr += sizeof(sljit_w);
 1059           }
 1060         tmp1next = FALSE;
 1061         }
 1062       else
 1063         {
 1064         SLJIT_ASSERT(!tmp2empty);
 1065         OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count], TMP2, 0);
 1066         tmp2empty = stackptr >= stacktop;
 1067         if (!tmp2empty)
 1068           {
 1069           OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
 1070           stackptr += sizeof(sljit_w);
 1071           }
 1072         tmp1next = TRUE;
 1073         }
 1074       }
 1075     }
 1076   }
 1077 
 1078 if (save)
 1079   {
 1080   if (tmp1next)
 1081     {
 1082     if (!tmp1empty)
 1083       {
 1084       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
 1085       stackptr += sizeof(sljit_w);
 1086       }
 1087     if (!tmp2empty)
 1088       {
 1089       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
 1090       stackptr += sizeof(sljit_w);
 1091       }
 1092     }
 1093   else
 1094     {
 1095     if (!tmp2empty)
 1096       {
 1097       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
 1098       stackptr += sizeof(sljit_w);
 1099       }
 1100     if (!tmp1empty)
 1101       {
 1102       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
 1103       stackptr += sizeof(sljit_w);
 1104       }
 1105     }
 1106   }
 1107 SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
 1108 }
 1109 
 1110 static SLJIT_INLINE BOOL ispowerof2(unsigned int value)
 1111 {
 1112 return (value & (value - 1)) == 0;
 1113 }
 1114 
 1115 static SLJIT_INLINE void set_jumps(jump_list *list, struct sljit_label *label)
 1116 {
 1117 while (list)
 1118   {
 1119   /* sljit_set_label is clever enough to do nothing
 1120   if either the jump or the label is NULL */
 1121   sljit_set_label(list->jump, label);
 1122   list = list->next;
 1123   }
 1124 }
 1125 
 1126 static SLJIT_INLINE void add_jump(struct sljit_compiler *compiler, jump_list **list, struct sljit_jump* jump)
 1127 {
 1128 jump_list *list_item = sljit_alloc_memory(compiler, sizeof(jump_list));
 1129 if (list_item)
 1130   {
 1131   list_item->next = *list;
 1132   list_item->jump = jump;
 1133   *list = list_item;
 1134   }
 1135 }
 1136 
 1137 static void add_stub(compiler_common *common, enum stub_types type, int data, struct sljit_jump *start)
 1138 {
 1139 DEFINE_COMPILER;
 1140 stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
 1141 
 1142 if (list_item)
 1143   {
 1144   list_item->type = type;
 1145   list_item->data = data;
 1146   list_item->start = start;
 1147   list_item->leave = LABEL();
 1148   list_item->next = common->stubs;
 1149   common->stubs = list_item;
 1150   }
 1151 }
 1152 
 1153 static void flush_stubs(compiler_common *common)
 1154 {
 1155 DEFINE_COMPILER;
 1156 stub_list* list_item = common->stubs;
 1157 
 1158 while (list_item)
 1159   {
 1160   JUMPHERE(list_item->start);
 1161   switch(list_item->type)
 1162     {
 1163     case stack_alloc:
 1164     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
 1165     break;
 1166     }
 1167   JUMPTO(SLJIT_JUMP, list_item->leave);
 1168   list_item = list_item->next;
 1169   }
 1170 common->stubs = NULL;
 1171 }
 1172 
 1173 static SLJIT_INLINE void decrease_call_count(compiler_common *common)
 1174 {
 1175 DEFINE_COMPILER;
 1176 
 1177 OP2(SLJIT_SUB | SLJIT_SET_E, CALL_COUNT, 0, CALL_COUNT, 0, SLJIT_IMM, 1);
 1178 add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
 1179 }
 1180 
 1181 static SLJIT_INLINE void allocate_stack(compiler_common *common, int size)
 1182 {
 1183 /* May destroy all locals and registers except TMP2. */
 1184 DEFINE_COMPILER;
 1185 
 1186 OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));
 1187 #ifdef DESTROY_REGISTERS
 1188 OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
 1189 OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
 1190 OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
 1191 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
 1192 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
 1193 #endif
 1194 add_stub(common, stack_alloc, 0, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));
 1195 }
 1196 
 1197 static SLJIT_INLINE void free_stack(compiler_common *common, int size)
 1198 {
 1199 DEFINE_COMPILER;
 1200 OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));
 1201 }
 1202 
 1203 static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
 1204 {
 1205 DEFINE_COMPILER;
 1206 struct sljit_label *loop;
 1207 int i;
 1208 /* At this point we can freely use all temporary registers. */
 1209 /* TMP1 returns with begin - 1. */
 1210 OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
 1211 if (length < 8)
 1212   {
 1213   for (i = 0; i < length; i++)
 1214     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_TEMPORARY_REG1, 0);
 1215   }
 1216 else
 1217   {
 1218   OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START - sizeof(sljit_w));
 1219   OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);
 1220   loop = LABEL();
 1221   OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
 1222   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);
 1223   JUMPTO(SLJIT_C_NOT_ZERO, loop);
 1224   }
 1225 }
 1226 
 1227 static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
 1228 {
 1229 DEFINE_COMPILER;
 1230 struct sljit_label *loop;
 1231 struct sljit_jump *earlyexit;
 1232 
 1233 /* At this point we can freely use all registers. */
 1234 OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
 1235 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);
 1236 
 1237 OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);
 1238 OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));
 1239 OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
 1240 OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
 1241 OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START);
 1242 /* Unlikely, but possible */
 1243 earlyexit = CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0);
 1244 loop = LABEL();
 1245 OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0);
 1246 OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_w));
 1247 /* Copy the integer value to the output buffer */
 1248 #ifdef COMPILE_PCRE16
 1249 OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);
 1250 #endif
 1251 OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
 1252 OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);
 1253 JUMPTO(SLJIT_C_NOT_ZERO, loop);
 1254 JUMPHERE(earlyexit);
 1255 
 1256 /* Calculate the return value, which is the maximum ovector value. */
 1257 if (topbracket > 1)
 1258   {
 1259   OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START + topbracket * 2 * sizeof(sljit_w));
 1260   OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);
 1261 
 1262   /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
 1263   loop = LABEL();
 1264   OP1(SLJIT_MOVU, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), -(2 * (sljit_w)sizeof(sljit_w)));
 1265   OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);
 1266   CMPTO(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG3, 0, loop);
 1267   OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);
 1268   }
 1269 else
 1270   OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
 1271 }
 1272 
 1273 static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar* cc)
 1274 {
 1275 /* Detects if the character has an othercase. */
 1276 unsigned int c;
 1277 
 1278 #ifdef SUPPORT_UTF
 1279 if (UTF_ENABLED(common->utf))
 1280   {
 1281   GETCHAR(c, cc);
 1282   if (c > 127)
 1283     {
 1284 #ifdef SUPPORT_UCP
 1285     return c != UCD_OTHERCASE(c);
 1286 #else
 1287     return FALSE;
 1288 #endif
 1289     }
 1290 #ifndef COMPILE_PCRE8
 1291   return common->fcc[c] != c;
 1292 #endif
 1293   }
 1294 else
 1295 #endif
 1296   c = *cc;
 1297 return MAX_255(c) ? common->fcc[c] != c : FALSE;
 1298 }
 1299 
 1300 static SLJIT_INLINE unsigned int char_othercase(compiler_common *common, unsigned int c)
 1301 {
 1302 /* Returns with the othercase. */
 1303 #ifdef SUPPORT_UTF
 1304 if (UTF_ENABLED(common->utf) && c > 127)
 1305   {
 1306 #ifdef SUPPORT_UCP
 1307   return UCD_OTHERCASE(c);
 1308 #else
 1309   return c;
 1310 #endif
 1311   }
 1312 #endif
 1313 return TABLE_GET(c, common->fcc, c);
 1314 }
 1315 
 1316 static unsigned int char_get_othercase_bit(compiler_common *common, pcre_uchar* cc)
 1317 {
 1318 /* Detects if the character and its othercase has only 1 bit difference. */
 1319 unsigned int c, oc, bit;
 1320 #if defined SUPPORT_UTF && defined COMPILE_PCRE8
 1321 int n;
 1322 #endif
 1323 
 1324 #ifdef SUPPORT_UTF
 1325 if (UTF_ENABLED(common->utf))
 1326   {
 1327   GETCHAR(c, cc);
 1328   if (c <= 127)
 1329     oc = common->fcc[c];
 1330   else
 1331     {
 1332 #ifdef SUPPORT_UCP
 1333     oc = UCD_OTHERCASE(c);
 1334 #else
 1335     oc = c;
 1336 #endif
 1337     }
 1338   }
 1339 else
 1340   {
 1341   c = *cc;
 1342   oc = TABLE_GET(c, common->fcc, c);
 1343   }
 1344 #else
 1345 c = *cc;
 1346 oc = TABLE_GET(c, common->fcc, c);
 1347 #endif
 1348 
 1349 SLJIT_ASSERT(c != oc);
 1350 
 1351 bit = c ^ oc;
 1352 /* Optimized for English alphabet. */
 1353 if (c <= 127 && bit == 0x20)
 1354   return (0 << 8) | 0x20;
 1355 
 1356 /* Since c != oc, they must have at least 1 bit difference. */
 1357 if (!ispowerof2(bit))
 1358   return 0;
 1359 
 1360 #ifdef COMPILE_PCRE8
 1361 
 1362 #ifdef SUPPORT_UTF
 1363 if (UTF_ENABLED(common->utf) && c > 127)
 1364   {
 1365   n = GET_EXTRALEN(*cc);
 1366   while ((bit & 0x3f) == 0)
 1367     {
 1368     n--;
 1369     bit >>= 6;
 1370     }
 1371   return (n << 8) | bit;
 1372   }
 1373 #endif /* SUPPORT_UTF */
 1374 return (0 << 8) | bit;
 1375 
 1376 #else /* COMPILE_PCRE8 */
 1377 
 1378 #ifdef COMPILE_PCRE16
 1379 #ifdef SUPPORT_UTF
 1380 if (UTF_ENABLED(common->utf) && c > 65535)
 1381   {
 1382   if (bit >= (1 << 10))
 1383     bit >>= 10;
 1384   else
 1385     return (bit < 256) ? ((2 << 8) | bit) : ((3 << 8) | (bit >> 8));
 1386   }
 1387 #endif /* SUPPORT_UTF */
 1388 return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 1389 #endif /* COMPILE_PCRE16 */
 1390 
 1391 #endif /* COMPILE_PCRE8 */
 1392 }
 1393 
 1394 static SLJIT_INLINE void check_input_end(compiler_common *common, jump_list **fallbacks)
 1395 {
 1396 DEFINE_COMPILER;
 1397 add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
 1398 }
 1399 
 1400 static void read_char(compiler_common *common)
 1401 {
 1402 /* Reads the character into TMP1, updates STR_PTR.
 1403 Does not check STR_END. TMP2 Destroyed. */
 1404 DEFINE_COMPILER;
 1405 #ifdef SUPPORT_UTF
 1406 struct sljit_jump *jump;
 1407 #endif
 1408 
 1409 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
 1410 #ifdef SUPPORT_UTF
 1411 if (UTF_ENABLED(common->utf))
 1412   {
 1413 #ifdef COMPILE_PCRE8
 1414   jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
 1415 #else
 1416 #ifdef COMPILE_PCRE16
 1417   jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
 1418 #endif
 1419 #endif /* COMPILE_PCRE8 */
 1420   add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
 1421   JUMPHERE(jump);
 1422   }
 1423 #endif
 1424 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 1425 }
 1426 
 1427 static void peek_char(compiler_common *common)
 1428 {
 1429 /* Reads the character into TMP1, keeps STR_PTR.
 1430 Does not check STR_END. TMP2 Destroyed. */
 1431 DEFINE_COMPILER;
 1432 #ifdef SUPPORT_UTF
 1433 struct sljit_jump *jump;
 1434 #endif
 1435 
 1436 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
 1437 #ifdef SUPPORT_UTF
 1438 if (UTF_ENABLED(common->utf))
 1439   {
 1440 #ifdef COMPILE_PCRE8
 1441   jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
 1442 #else
 1443 #ifdef COMPILE_PCRE16
 1444   jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
 1445 #endif
 1446 #endif /* COMPILE_PCRE8 */
 1447   add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
 1448   OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
 1449   JUMPHERE(jump);
 1450   }
 1451 #endif
 1452 }
 1453 
 1454 static void read_char8_type(compiler_common *common)
 1455 {
 1456 /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */
 1457 DEFINE_COMPILER;
 1458 #if defined SUPPORT_UTF || defined COMPILE_PCRE16
 1459 struct sljit_jump *jump;
 1460 #endif
 1461 
 1462 #ifdef SUPPORT_UTF
 1463 if (UTF_ENABLED(common->utf))
 1464   {
 1465   OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
 1466   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 1467 #ifdef COMPILE_PCRE8
 1468   /* This can be an extra read in some situations, but hopefully
 1469   it is needed in most cases. */
 1470   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
 1471   jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
 1472   add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
 1473   JUMPHERE(jump);
 1474 #else
 1475 #ifdef COMPILE_PCRE16
 1476   OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
 1477   jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
 1478   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
 1479   JUMPHERE(jump);
 1480   /* Skip low surrogate if necessary. */
 1481   OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
 1482   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);
 1483   COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);
 1484   OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
 1485   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
 1486 #endif
 1487 #endif /* COMPILE_PCRE8 */
 1488   return;
 1489   }
 1490 #endif
 1491 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
 1492 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 1493 #ifdef COMPILE_PCRE16
 1494 /* The ctypes array contains only 256 values. */
 1495 OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
 1496 jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
 1497 #endif
 1498 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
 1499 #ifdef COMPILE_PCRE16
 1500 JUMPHERE(jump);
 1501 #endif
 1502 }
 1503 
 1504 static void skip_char_back(compiler_common *common)
 1505 {
 1506 /* Goes one character back. Affects STR_PTR and TMP1. Does not check begin. */
 1507 DEFINE_COMPILER;
 1508 #if defined SUPPORT_UTF && defined COMPILE_PCRE8
 1509 struct sljit_label *label;
 1510 
 1511 if (UTF_ENABLED(common->utf))
 1512   {
 1513   label = LABEL();
 1514   OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
 1515   OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 1516   OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);
 1517   CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
 1518   return;
 1519   }
 1520 #endif
 1521 #if defined SUPPORT_UTF && defined COMPILE_PCRE16
 1522 if (UTF_ENABLED(common->utf))
 1523   {
 1524   OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
 1525   OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 1526   /* Skip low surrogate if necessary. */
 1527   OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
 1528   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);
 1529   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);
 1530   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
 1531   OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
 1532   return;
 1533   }
 1534 #endif
 1535 OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 1536 }
 1537 
 1538 static void check_newlinechar(compiler_common *common, int nltype, jump_list **fallbacks, BOOL jumpiftrue)
 1539 {
 1540 /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */
 1541 DEFINE_COMPILER;
 1542 
 1543 if (nltype == NLTYPE_ANY)
 1544   {
 1545   add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
 1546   add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
 1547   }
 1548 else if (nltype == NLTYPE_ANYCRLF)
 1549   {
 1550   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);
 1551   COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);
 1552   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);
 1553   COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
 1554   add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
 1555   }
 1556 else
 1557   {
 1558   SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
 1559   add_jump(compiler, fallbacks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
 1560   }
 1561 }
 1562 
 1563 #ifdef SUPPORT_UTF
 1564 
 1565 #ifdef COMPILE_PCRE8
 1566 static void do_utfreadchar(compiler_common *common)
 1567 {
 1568 /* Fast decoding a UTF-8 character. TMP1 contains the first byte
 1569 of the character (>= 0xc0). Return char value in TMP1, length - 1 in TMP2. */
 1570 DEFINE_COMPILER;
 1571 struct sljit_jump *jump;
 1572 
 1573 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);
 1574 /* Searching for the first zero. */
 1575 OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
 1576 jump = JUMP(SLJIT_C_NOT_ZERO);
 1577 /* Two byte sequence. */
 1578 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
 1579 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 1580 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);
 1581 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
 1582 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 1583 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
 1584 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
 1585 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 1586 JUMPHERE(jump);
 1587 
 1588 OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);
 1589 jump = JUMP(SLJIT_C_NOT_ZERO);
 1590 /* Three byte sequence. */
 1591 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
 1592 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);
 1593 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);
 1594 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 1595 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
 1596 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
 1597 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
 1598 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
 1599 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 1600 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
 1601 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
 1602 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 1603 JUMPHERE(jump);
 1604 
 1605 /* Four byte sequence. */
 1606 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
 1607 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);
 1608 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);
 1609 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 1610 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);
 1611 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
 1612 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
 1613 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 1614 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
 1615 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
 1616 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));
 1617 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
 1618 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 1619 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
 1620 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
 1621 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 1622 }
 1623 
 1624 static void do_utfreadtype8(compiler_common *common)
 1625 {
 1626 /* Fast decoding a UTF-8 character type. TMP2 contains the first byte
 1627 of the character (>= 0xc0). Return value in TMP1. */
 1628 DEFINE_COMPILER;
 1629 struct sljit_jump *jump;
 1630 struct sljit_jump *compare;
 1631 
 1632 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);
 1633 
 1634 OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);
 1635 jump = JUMP(SLJIT_C_NOT_ZERO);
 1636 /* Two byte sequence. */
 1637 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
 1638 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 1639 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
 1640 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
 1641 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
 1642 OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
 1643 compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
 1644 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
 1645 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 1646 
 1647 JUMPHERE(compare);
 1648 OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
 1649 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 1650 JUMPHERE(jump);
 1651 
 1652 /* We only have types for characters less than 256. */
 1653 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0);
 1654 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
 1655 OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
 1656 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 1657 }
 1658 
 1659 #else /* COMPILE_PCRE8 */
 1660 
 1661 #ifdef COMPILE_PCRE16
 1662 static void do_utfreadchar(compiler_common *common)
 1663 {
 1664 /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char
 1665 of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */
 1666 DEFINE_COMPILER;
 1667 struct sljit_jump *jump;
 1668 
 1669 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);
 1670 jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);
 1671 /* Do nothing, only return. */
 1672 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 1673 
 1674 JUMPHERE(jump);
 1675 /* Combine two 16 bit characters. */
 1676 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
 1677 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 1678 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
 1679 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);
 1680 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff);
 1681 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
 1682 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
 1683 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
 1684 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 1685 }
 1686 #endif /* COMPILE_PCRE16 */
 1687 
 1688 #endif /* COMPILE_PCRE8 */
 1689 
 1690 #endif /* SUPPORT_UTF */
 1691 
 1692 #ifdef SUPPORT_UCP
 1693 
 1694 /* UCD_BLOCK_SIZE must be 128 (see the assert below). */
 1695 #define UCD_BLOCK_MASK 127
 1696 #define UCD_BLOCK_SHIFT 7
 1697 
 1698 static void do_getucd(compiler_common *common)
 1699 {
 1700 /* Search the UCD record for the character comes in TMP1.
 1701 Returns chartype in TMP1 and UCD offset in TMP2. */
 1702 DEFINE_COMPILER;
 1703 
 1704 SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);
 1705 
 1706 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);
 1707 OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
 1708 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(ucd_stage1));
 1709 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
 1710 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
 1711 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
 1712 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));
 1713 OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
 1714 OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));
 1715 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
 1716 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 1717 }
 1718 #endif
 1719 
 1720 static SLJIT_INLINE struct sljit_label *mainloop_entry(compiler_common *common, BOOL hascrorlf, BOOL firstline)
 1721 {
 1722 DEFINE_COMPILER;
 1723 struct sljit_label *mainloop;
 1724 struct sljit_label *newlinelabel = NULL;
 1725 struct sljit_jump *start;
 1726 struct sljit_jump *end = NULL;
 1727 struct sljit_jump *nl = NULL;
 1728 #ifdef SUPPORT_UTF
 1729 struct sljit_jump *singlechar;
 1730 #endif
 1731 jump_list *newline = NULL;
 1732 BOOL newlinecheck = FALSE;
 1733 BOOL readuchar = FALSE;
 1734 
 1735 if (!(hascrorlf || firstline) && (common->nltype == NLTYPE_ANY ||
 1736     common->nltype == NLTYPE_ANYCRLF || common->newline > 255))
 1737   newlinecheck = TRUE;
 1738 
 1739 if (firstline)
 1740   {
 1741   /* Search for the end of the first line. */
 1742   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);
 1743   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_END, 0);
 1744 
 1745   if (common->nltype == NLTYPE_FIXED && common->newline > 255)
 1746     {
 1747     mainloop = LABEL();
 1748     OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 1749     end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 1750     OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
 1751     OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
 1752     CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);
 1753     CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);
 1754     OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 1755     }
 1756   else
 1757     {
 1758     end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 1759     mainloop = LABEL();
 1760     /* Continual stores does not cause data dependency. */
 1761     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);
 1762     read_char(common);
 1763     check_newlinechar(common, common->nltype, &newline, TRUE);
 1764     CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
 1765     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);
 1766     set_jumps(newline, LABEL());
 1767     }
 1768 
 1769   JUMPHERE(end);
 1770   OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
 1771   }
 1772 
 1773 start = JUMP(SLJIT_JUMP);
 1774 
 1775 if (newlinecheck)
 1776   {
 1777   newlinelabel = LABEL();
 1778   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 1779   end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 1780   OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
 1781   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);
 1782   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);
 1783 #ifdef COMPILE_PCRE16
 1784   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
 1785 #endif
 1786   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
 1787   nl = JUMP(SLJIT_JUMP);
 1788   }
 1789 
 1790 mainloop = LABEL();
 1791 
 1792 /* Increasing the STR_PTR here requires one less jump in the most common case. */
 1793 #ifdef SUPPORT_UTF
 1794 if (UTF_ENABLED(common->utf)) readuchar = TRUE;
 1795 #endif
 1796 if (newlinecheck) readuchar = TRUE;
 1797 
 1798 if (readuchar)
 1799   OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
 1800 
 1801 if (newlinecheck)
 1802   CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);
 1803 
 1804 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 1805 #if defined SUPPORT_UTF && defined COMPILE_PCRE8
 1806 if (UTF_ENABLED(common->utf))
 1807   {
 1808   singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
 1809   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);
 1810   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
 1811   JUMPHERE(singlechar);
 1812   }
 1813 #endif
 1814 #if defined SUPPORT_UTF && defined COMPILE_PCRE16
 1815 if (UTF_ENABLED(common->utf))
 1816   {
 1817   singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
 1818   OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
 1819   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
 1820   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);
 1821   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
 1822   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
 1823   JUMPHERE(singlechar);
 1824   }
 1825 #endif
 1826 JUMPHERE(start);
 1827 
 1828 if (newlinecheck)
 1829   {
 1830   JUMPHERE(end);
 1831   JUMPHERE(nl);
 1832   }
 1833 
 1834 return mainloop;
 1835 }
 1836 
 1837 static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
 1838 {
 1839 DEFINE_COMPILER;
 1840 struct sljit_label *start;
 1841 struct sljit_jump *leave;
 1842 struct sljit_jump *found;
 1843 pcre_uchar oc, bit;
 1844 
 1845 if (firstline)
 1846   {
 1847   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);
 1848   OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);
 1849   }
 1850 
 1851 start = LABEL();
 1852 leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 1853 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
 1854 
 1855 oc = first_char;
 1856 if (caseless)
 1857   {
 1858   oc = TABLE_GET(first_char, common->fcc, first_char);
 1859 #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
 1860   if (first_char > 127 && UTF_ENABLED(common->utf))
 1861     oc = UCD_OTHERCASE(first_char);
 1862 #endif
 1863   }
 1864 if (first_char == oc)
 1865   found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, first_char);
 1866 else
 1867   {
 1868   bit = first_char ^ oc;
 1869   if (ispowerof2(bit))
 1870     {
 1871     OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
 1872     found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
 1873     }
 1874   else
 1875     {
 1876     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char);
 1877     COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);
 1878     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);
 1879     COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
 1880     found = JUMP(SLJIT_C_NOT_ZERO);
 1881     }
 1882   }
 1883 
 1884 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 1885 #if defined SUPPORT_UTF && defined COMPILE_PCRE8
 1886 if (UTF_ENABLED(common->utf))
 1887   {
 1888   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
 1889   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);
 1890   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
 1891   }
 1892 #endif
 1893 #if defined SUPPORT_UTF && defined COMPILE_PCRE16
 1894 if (UTF_ENABLED(common->utf))
 1895   {
 1896   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
 1897   OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
 1898   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
 1899   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);
 1900   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
 1901   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
 1902   }
 1903 #endif
 1904 JUMPTO(SLJIT_JUMP, start);
 1905 JUMPHERE(found);
 1906 JUMPHERE(leave);
 1907 
 1908 if (firstline)
 1909   OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
 1910 }
 1911 
 1912 static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline)
 1913 {
 1914 DEFINE_COMPILER;
 1915 struct sljit_label *loop;
 1916 struct sljit_jump *lastchar;
 1917 struct sljit_jump *firstchar;
 1918 struct sljit_jump *leave;
 1919 struct sljit_jump *foundcr = NULL;
 1920 struct sljit_jump *notfoundnl;
 1921 jump_list *newline = NULL;
 1922 
 1923 if (firstline)
 1924   {
 1925   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);
 1926   OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);
 1927   }
 1928 
 1929 if (common->nltype == NLTYPE_FIXED && common->newline > 255)
 1930   {
 1931   lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 1932   OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
 1933   OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
 1934   OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
 1935   firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);
 1936 
 1937   OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
 1938   OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, TMP1, 0);
 1939   COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);
 1940 #ifdef COMPILE_PCRE16
 1941   OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
 1942 #endif
 1943   OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
 1944 
 1945   loop = LABEL();
 1946   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 1947   leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 1948   OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
 1949   OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
 1950   CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);
 1951   CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);
 1952 
 1953   JUMPHERE(leave);
 1954   JUMPHERE(firstchar);
 1955   JUMPHERE(lastchar);
 1956 
 1957   if (firstline)
 1958     OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
 1959   return;
 1960   }
 1961 
 1962 OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
 1963 OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
 1964 firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);
 1965 skip_char_back(common);
 1966 
 1967 loop = LABEL();
 1968 read_char(common);
 1969 lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 1970 if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
 1971   foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
 1972 check_newlinechar(common, common->nltype, &newline, FALSE);
 1973 set_jumps(newline, loop);
 1974 
 1975 if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
 1976   {
 1977   leave = JUMP(SLJIT_JUMP);
 1978   JUMPHERE(foundcr);
 1979   notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 1980   OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
 1981   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);
 1982   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);
 1983 #ifdef COMPILE_PCRE16
 1984   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
 1985 #endif
 1986   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
 1987   JUMPHERE(notfoundnl);
 1988   JUMPHERE(leave);
 1989   }
 1990 JUMPHERE(lastchar);
 1991 JUMPHERE(firstchar);
 1992 
 1993 if (firstline)
 1994   OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
 1995 }
 1996 
 1997 static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)
 1998 {
 1999 DEFINE_COMPILER;
 2000 struct sljit_label *start;
 2001 struct sljit_jump *leave;
 2002 struct sljit_jump *found;
 2003 #ifndef COMPILE_PCRE8
 2004 struct sljit_jump *jump;
 2005 #endif
 2006 
 2007 if (firstline)
 2008   {
 2009   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);
 2010   OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);
 2011   }
 2012 
 2013 start = LABEL();
 2014 leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 2015 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
 2016 #ifdef SUPPORT_UTF
 2017 if (UTF_ENABLED(common->utf))
 2018   OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
 2019 #endif
 2020 #ifndef COMPILE_PCRE8
 2021 jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
 2022 OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
 2023 JUMPHERE(jump);
 2024 #endif
 2025 OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
 2026 OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
 2027 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
 2028 OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
 2029 OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
 2030 found = JUMP(SLJIT_C_NOT_ZERO);
 2031 
 2032 #ifdef SUPPORT_UTF
 2033 if (UTF_ENABLED(common->utf))
 2034   OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
 2035 #endif
 2036 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 2037 #if defined SUPPORT_UTF && defined COMPILE_PCRE8
 2038 if (UTF_ENABLED(common->utf))
 2039   {
 2040   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
 2041   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);
 2042   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
 2043   }
 2044 #endif
 2045 #if defined SUPPORT_UTF && defined COMPILE_PCRE16
 2046 if (UTF_ENABLED(common->utf))
 2047   {
 2048   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
 2049   OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
 2050   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
 2051   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);
 2052   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
 2053   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
 2054   }
 2055 #endif
 2056 JUMPTO(SLJIT_JUMP, start);
 2057 JUMPHERE(found);
 2058 JUMPHERE(leave);
 2059 
 2060 if (firstline)
 2061   OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
 2062 }
 2063 
 2064 static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar req_char, BOOL caseless, BOOL has_firstchar)
 2065 {
 2066 DEFINE_COMPILER;
 2067 struct sljit_label *loop;
 2068 struct sljit_jump *toolong;
 2069 struct sljit_jump *alreadyfound;
 2070 struct sljit_jump *found;
 2071 struct sljit_jump *foundoc = NULL;
 2072 struct sljit_jump *notfound;
 2073 pcre_uchar oc, bit;
 2074 
 2075 OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_CHAR_PTR);
 2076 OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, REQ_BYTE_MAX);
 2077 toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);
 2078 alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);
 2079 
 2080 if (has_firstchar)
 2081   OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 2082 else
 2083   OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);
 2084 
 2085 loop = LABEL();
 2086 notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);
 2087 
 2088 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(TMP1), 0);
 2089 oc = req_char;
 2090 if (caseless)
 2091   {
 2092   oc = TABLE_GET(req_char, common->fcc, req_char);
 2093 #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
 2094   if (req_char > 127 && UTF_ENABLED(common->utf))
 2095     oc = UCD_OTHERCASE(req_char);
 2096 #endif
 2097   }
 2098 if (req_char == oc)
 2099   found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
 2100 else
 2101   {
 2102   bit = req_char ^ oc;
 2103   if (ispowerof2(bit))
 2104     {
 2105     OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
 2106     found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
 2107     }
 2108   else
 2109     {
 2110     found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
 2111     foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);
 2112     }
 2113   }
 2114 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
 2115 JUMPTO(SLJIT_JUMP, loop);
 2116 
 2117 JUMPHERE(found);
 2118 if (foundoc)
 2119   JUMPHERE(foundoc);
 2120 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_CHAR_PTR, TMP1, 0);
 2121 JUMPHERE(alreadyfound);
 2122 JUMPHERE(toolong);
 2123 return notfound;
 2124 }
 2125 
 2126 static void do_revertframes(compiler_common *common)
 2127 {
 2128 DEFINE_COMPILER;
 2129 struct sljit_jump *jump;
 2130 struct sljit_label *mainloop;
 2131 
 2132 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);
 2133 OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);
 2134 
 2135 /* Drop frames until we reach STACK_TOP. */
 2136 mainloop = LABEL();
 2137 OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
 2138 jump = CMP(SLJIT_C_SIG_LESS_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);
 2139 OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_LOCALS_REG, 0);
 2140 OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));
 2141 OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w));
 2142 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_w));
 2143 JUMPTO(SLJIT_JUMP, mainloop);
 2144 
 2145 JUMPHERE(jump);
 2146 jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);
 2147 /* End of dropping frames. */
 2148 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 2149 
 2150 JUMPHERE(jump);
 2151 jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);
 2152 /* Set string begin. */
 2153 OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));
 2154 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));
 2155 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), TMP2, 0);
 2156 JUMPTO(SLJIT_JUMP, mainloop);
 2157 
 2158 JUMPHERE(jump);
 2159 /* Unknown command. */
 2160 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));
 2161 JUMPTO(SLJIT_JUMP, mainloop);
 2162 }
 2163 
 2164 static void check_wordboundary(compiler_common *common)
 2165 {
 2166 DEFINE_COMPILER;
 2167 struct sljit_jump *beginend;
 2168 #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
 2169 struct sljit_jump *jump;
 2170 #endif
 2171 
 2172 SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
 2173 
 2174 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, 1, 5, 5, common->localsize);
 2175 /* Get type of the previous char, and put it to LOCALS1. */
 2176 OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
 2177 OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
 2178 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);
 2179 beginend = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
 2180 skip_char_back(common);
 2181 read_char(common);
 2182 
 2183 /* Testing char type. */
 2184 #ifdef SUPPORT_UCP
 2185 if (common->use_ucp)
 2186   {
 2187   OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
 2188   jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
 2189   add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
 2190   OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
 2191   OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
 2192   COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);
 2193   OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);
 2194   OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
 2195   COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);
 2196   JUMPHERE(jump);
 2197   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
 2198   }
 2199 else
 2200 #endif
 2201   {
 2202 #ifndef COMPILE_PCRE8
 2203   jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
 2204 #elif defined SUPPORT_UTF
 2205   /* Here LOCALS1 has already been zeroed. */
 2206   jump = NULL;
 2207   if (UTF_ENABLED(common->utf))
 2208     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
 2209 #endif /* COMPILE_PCRE8 */
 2210   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);
 2211   OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);
 2212   OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
 2213   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
 2214 #ifndef COMPILE_PCRE8
 2215   JUMPHERE(jump);
 2216 #elif defined SUPPORT_UTF
 2217   if (jump != NULL)
 2218     JUMPHERE(jump);
 2219 #endif /* COMPILE_PCRE8 */
 2220   }
 2221 JUMPHERE(beginend);
 2222 
 2223 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
 2224 beginend = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 2225 peek_char(common);
 2226 
 2227 /* Testing char type. This is a code duplication. */
 2228 #ifdef SUPPORT_UCP
 2229 if (common->use_ucp)
 2230   {
 2231   OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
 2232   jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
 2233   add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
 2234   OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
 2235   OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
 2236   COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);
 2237   OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);
 2238   OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
 2239   COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);
 2240   JUMPHERE(jump);
 2241   }
 2242 else
 2243 #endif
 2244   {
 2245 #ifndef COMPILE_PCRE8
 2246   /* TMP2 may be destroyed by peek_char. */
 2247   OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
 2248   jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
 2249 #elif defined SUPPORT_UTF
 2250   OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
 2251   jump = NULL;
 2252   if (UTF_ENABLED(common->utf))
 2253     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
 2254 #endif
 2255   OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);
 2256   OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);
 2257   OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
 2258 #ifndef COMPILE_PCRE8
 2259   JUMPHERE(jump);
 2260 #elif defined SUPPORT_UTF
 2261   if (jump != NULL)
 2262     JUMPHERE(jump);
 2263 #endif /* COMPILE_PCRE8 */
 2264   }
 2265 JUMPHERE(beginend);
 2266 
 2267 OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
 2268 sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
 2269 }
 2270 
 2271 static void check_anynewline(compiler_common *common)
 2272 {
 2273 /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
 2274 DEFINE_COMPILER;
 2275 
 2276 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);
 2277 
 2278 OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
 2279 OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
 2280 COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);
 2281 OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
 2282 #if defined SUPPORT_UTF || defined COMPILE_PCRE16
 2283 #ifdef COMPILE_PCRE8
 2284 if (UTF_ENABLED(common->utf))
 2285   {
 2286 #endif
 2287   COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);
 2288   OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
 2289   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
 2290 #ifdef COMPILE_PCRE8
 2291   }
 2292 #endif
 2293 #endif /* SUPPORT_UTF || COMPILE_PCRE16 */
 2294 COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
 2295 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 2296 }
 2297 
 2298 static void check_hspace(compiler_common *common)
 2299 {
 2300 /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
 2301 DEFINE_COMPILER;
 2302 
 2303 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);
 2304 
 2305 OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);
 2306 COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);
 2307 OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
 2308 COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);
 2309 OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);
 2310 #if defined SUPPORT_UTF || defined COMPILE_PCRE16
 2311 #ifdef COMPILE_PCRE8
 2312 if (UTF_ENABLED(common->utf))
 2313   {
 2314 #endif
 2315   COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);
 2316   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);
 2317   COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);
 2318   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);
 2319   COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);
 2320   OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
 2321   OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);
 2322   COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);
 2323   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);
 2324   COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);
 2325   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);
 2326   COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);
 2327   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);
 2328 #ifdef COMPILE_PCRE8
 2329   }
 2330 #endif
 2331 #endif /* SUPPORT_UTF || COMPILE_PCRE16 */
 2332 COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
 2333 
 2334 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 2335 }
 2336 
 2337 static void check_vspace(compiler_common *common)
 2338 {
 2339 /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
 2340 DEFINE_COMPILER;
 2341 
 2342 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);
 2343 
 2344 OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
 2345 OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
 2346 COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);
 2347 OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
 2348 #if defined SUPPORT_UTF || defined COMPILE_PCRE16
 2349 #ifdef COMPILE_PCRE8
 2350 if (UTF_ENABLED(common->utf))
 2351   {
 2352 #endif
 2353   COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
 2354   OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
 2355   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
 2356 #ifdef COMPILE_PCRE8
 2357   }
 2358 #endif
 2359 #endif /* SUPPORT_UTF || COMPILE_PCRE16 */
 2360 COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
 2361 
 2362 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 2363 }
 2364 
 2365 #define CHAR1 STR_END
 2366 #define CHAR2 STACK_TOP
 2367 
 2368 static void do_casefulcmp(compiler_common *common)
 2369 {
 2370 DEFINE_COMPILER;
 2371 struct sljit_jump *jump;
 2372 struct sljit_label *label;
 2373 
 2374 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);
 2375 OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
 2376 OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);
 2377 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);
 2378 OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
 2379 OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 2380 
 2381 label = LABEL();
 2382 OP1(MOVU_UCHAR, CHAR1, 0, SLJIT_MEM1(TMP1), IN_UCHARS(1));
 2383 OP1(MOVU_UCHAR, CHAR2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
 2384 jump = CMP(SLJIT_C_NOT_EQUAL, CHAR1, 0, CHAR2, 0);
 2385 OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
 2386 JUMPTO(SLJIT_C_NOT_ZERO, label);
 2387 
 2388 JUMPHERE(jump);
 2389 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 2390 OP1(SLJIT_MOV, CHAR1, 0, TMP3, 0);
 2391 OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
 2392 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 2393 }
 2394 
 2395 #define LCC_TABLE STACK_LIMIT
 2396 
 2397 static void do_caselesscmp(compiler_common *common)
 2398 {
 2399 DEFINE_COMPILER;
 2400 struct sljit_jump *jump;
 2401 struct sljit_label *label;
 2402 
 2403 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);
 2404 OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
 2405 
 2406 OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);
 2407 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR1, 0);
 2408 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, CHAR2, 0);
 2409 OP1(SLJIT_MOV, LCC_TABLE, 0, SLJIT_IMM, common->lcc);
 2410 OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
 2411 OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 2412 
 2413 label = LABEL();
 2414 OP1(MOVU_UCHAR, CHAR1, 0, SLJIT_MEM1(TMP1), IN_UCHARS(1));
 2415 OP1(MOVU_UCHAR, CHAR2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
 2416 #ifndef COMPILE_PCRE8
 2417 jump = CMP(SLJIT_C_GREATER, CHAR1, 0, SLJIT_IMM, 255);
 2418 #endif
 2419 OP1(SLJIT_MOV_UB, CHAR1, 0, SLJIT_MEM2(LCC_TABLE, CHAR1), 0);
 2420 #ifndef COMPILE_PCRE8
 2421 JUMPHERE(jump);
 2422 jump = CMP(SLJIT_C_GREATER, CHAR2, 0, SLJIT_IMM, 255);
 2423 #endif
 2424 OP1(SLJIT_MOV_UB, CHAR2, 0, SLJIT_MEM2(LCC_TABLE, CHAR2), 0);
 2425 #ifndef COMPILE_PCRE8
 2426 JUMPHERE(jump);
 2427 #endif
 2428 jump = CMP(SLJIT_C_NOT_EQUAL, CHAR1, 0, CHAR2, 0);
 2429 OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
 2430 JUMPTO(SLJIT_C_NOT_ZERO, label);
 2431 
 2432 JUMPHERE(jump);
 2433 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 2434 OP1(SLJIT_MOV, LCC_TABLE, 0, TMP3, 0);
 2435 OP1(SLJIT_MOV, CHAR1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
 2436 OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
 2437 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 2438 }
 2439 
 2440 #undef LCC_TABLE
 2441 #undef CHAR1
 2442 #undef CHAR2
 2443 
 2444 #if defined SUPPORT_UTF && defined SUPPORT_UCP
 2445 
 2446 static const pcre_uchar *SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)
 2447 {
 2448 /* This function would be ineffective to do in JIT level. */
 2449 int c1, c2;
 2450 const pcre_uchar *src2 = args->ptr;
 2451 const pcre_uchar *end2 = args->end;
 2452 
 2453 while (src1 < end1)
 2454   {
 2455   if (src2 >= end2)
 2456     return 0;
 2457   GETCHARINC(c1, src1);
 2458   GETCHARINC(c2, src2);
 2459   if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return 0;
 2460   }
 2461 return src2;
 2462 }
 2463 
 2464 #endif /* SUPPORT_UTF && SUPPORT_UCP */
 2465 
 2466 static pcre_uchar *byte_sequence_compare(compiler_common *common, BOOL caseless, pcre_uchar *cc,
 2467     compare_context* context, jump_list **fallbacks)
 2468 {
 2469 DEFINE_COMPILER;
 2470 unsigned int othercasebit = 0;
 2471 pcre_uchar *othercasechar = NULL;
 2472 #ifdef SUPPORT_UTF
 2473 int utflength;
 2474 #endif
 2475 
 2476 if (caseless && char_has_othercase(common, cc))
 2477   {
 2478   othercasebit = char_get_othercase_bit(common, cc);
 2479   SLJIT_ASSERT(othercasebit);
 2480   /* Extracting bit difference info. */
 2481 #ifdef COMPILE_PCRE8
 2482   othercasechar = cc + (othercasebit >> 8);
 2483   othercasebit &= 0xff;
 2484 #else
 2485 #ifdef COMPILE_PCRE16
 2486   othercasechar = cc + (othercasebit >> 9);
 2487   if ((othercasebit & 0x100) != 0)
 2488     othercasebit = (othercasebit & 0xff) << 8;
 2489   else
 2490     othercasebit &= 0xff;
 2491 #endif
 2492 #endif
 2493   }
 2494 
 2495 if (context->sourcereg == -1)
 2496   {
 2497 #ifdef COMPILE_PCRE8
 2498 #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
 2499   if (context->length >= 4)
 2500     OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
 2501   else if (context->length >= 2)
 2502     OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
 2503   else
 2504 #endif
 2505     OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
 2506 #else
 2507 #ifdef COMPILE_PCRE16
 2508 #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
 2509   if (context->length >= 4)
 2510     OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
 2511   else
 2512 #endif
 2513     OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
 2514 #endif
 2515 #endif /* COMPILE_PCRE8 */
 2516   context->sourcereg = TMP2;
 2517   }
 2518 
 2519 #ifdef SUPPORT_UTF
 2520 utflength = 1;
 2521 if (UTF_ENABLED(common->utf) && HAS_EXTRALEN(*cc))
 2522   utflength += GET_EXTRALEN(*cc);
 2523 
 2524 do
 2525   {
 2526 #endif
 2527 
 2528   context->length -= IN_UCHARS(1);
 2529 #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
 2530 
 2531   /* Unaligned read is supported. */
 2532   if (othercasebit != 0 && othercasechar == cc)
 2533     {
 2534     context->c.asuchars[context->ucharptr] = *cc | othercasebit;
 2535     context->oc.asuchars[context->ucharptr] = othercasebit;
 2536     }
 2537   else
 2538     {
 2539     context->c.asuchars[context->ucharptr] = *cc;
 2540     context->oc.asuchars[context->ucharptr] = 0;
 2541     }
 2542   context->ucharptr++;
 2543 
 2544 #ifdef COMPILE_PCRE8
 2545   if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))
 2546 #else
 2547   if (context->ucharptr >= 2 || context->length == 0)
 2548 #endif
 2549     {
 2550     if (context->length >= 4)
 2551       OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
 2552 #ifdef COMPILE_PCRE8
 2553     else if (context->length >= 2)
 2554       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
 2555     else if (context->length >= 1)
 2556       OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
 2557 #else
 2558     else if (context->length >= 2)
 2559       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
 2560 #endif
 2561     context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
 2562 
 2563     switch(context->ucharptr)
 2564       {
 2565       case 4 / sizeof(pcre_uchar):
 2566       if (context->oc.asint != 0)
 2567         OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asint);
 2568       add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asint | context->oc.asint));
 2569       break;
 2570 
 2571       case 2 / sizeof(pcre_uchar):
 2572       if (context->oc.asushort != 0)
 2573         OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);
 2574       add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asushort | context->oc.asushort));
 2575       break;
 2576 
 2577 #ifdef COMPILE_PCRE8
 2578       case 1:
 2579       if (context->oc.asbyte != 0)
 2580         OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asbyte);
 2581       add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asbyte | context->oc.asbyte));
 2582       break;
 2583 #endif
 2584 
 2585       default:
 2586       SLJIT_ASSERT_STOP();
 2587       break;
 2588       }
 2589     context->ucharptr = 0;
 2590     }
 2591 
 2592 #else
 2593 
 2594   /* Unaligned read is unsupported. */
 2595 #ifdef COMPILE_PCRE8
 2596   if (context->length > 0)
 2597     OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
 2598 #else
 2599   if (context->length > 0)
 2600     OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
 2601 #endif
 2602   context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
 2603 
 2604   if (othercasebit != 0 && othercasechar == cc)
 2605     {
 2606     OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, othercasebit);
 2607     add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc | othercasebit));
 2608     }
 2609   else
 2610     add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc));
 2611 
 2612 #endif
 2613 
 2614   cc++;
 2615 #ifdef SUPPORT_UTF
 2616   utflength--;
 2617   }
 2618 while (utflength > 0);
 2619 #endif
 2620 
 2621 return cc;
 2622 }
 2623 
 2624 #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
 2625 
 2626 #define SET_TYPE_OFFSET(value) \
 2627   if ((value) != typeoffset) \
 2628     { \
 2629     if ((value) > typeoffset) \
 2630       OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \
 2631     else \
 2632       OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \
 2633     } \
 2634   typeoffset = (value);
 2635 
 2636 #define SET_CHAR_OFFSET(value) \
 2637   if ((value) != charoffset) \
 2638     { \
 2639     if ((value) > charoffset) \
 2640       OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (value) - charoffset); \
 2641     else \
 2642       OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, charoffset - (value)); \
 2643     } \
 2644   charoffset = (value);
 2645 
 2646 static void compile_xclass_hotpath(compiler_common *common, pcre_uchar *cc, jump_list **fallbacks)
 2647 {
 2648 DEFINE_COMPILER;
 2649 jump_list *found = NULL;
 2650 jump_list **list = (*cc & XCL_NOT) == 0 ? &found : fallbacks;
 2651 unsigned int c;
 2652 int compares;
 2653 struct sljit_jump *jump = NULL;
 2654 pcre_uchar *ccbegin;
 2655 #ifdef SUPPORT_UCP
 2656 BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
 2657 BOOL charsaved = FALSE;
 2658 int typereg = TMP1, scriptreg = TMP1;
 2659 unsigned int typeoffset;
 2660 #endif
 2661 int invertcmp, numberofcmps;
 2662 unsigned int charoffset;
 2663 
 2664 /* Although SUPPORT_UTF must be defined, we are not necessary in utf mode. */
 2665 check_input_end(common, fallbacks);
 2666 read_char(common);
 2667 
 2668 if ((*cc++ & XCL_MAP) != 0)
 2669   {
 2670   OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
 2671 #ifndef COMPILE_PCRE8
 2672   jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
 2673 #elif defined SUPPORT_UTF
 2674   if (UTF_ENABLED(common->utf))
 2675     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
 2676 #endif
 2677 
 2678   OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
 2679   OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
 2680   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);
 2681   OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
 2682   OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
 2683   add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
 2684 
 2685 #ifndef COMPILE_PCRE8
 2686   JUMPHERE(jump);
 2687 #elif defined SUPPORT_UTF
 2688   if (UTF_ENABLED(common->utf))
 2689     JUMPHERE(jump);
 2690 #endif
 2691   OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
 2692 #ifdef SUPPORT_UCP
 2693   charsaved = TRUE;
 2694 #endif
 2695   cc += 32 / sizeof(pcre_uchar);
 2696   }
 2697 
 2698 /* Scanning the necessary info. */
 2699 ccbegin = cc;
 2700 compares = 0;
 2701 while (*cc != XCL_END)
 2702   {
 2703   compares++;
 2704   if (*cc == XCL_SINGLE)
 2705     {
 2706     cc += 2;
 2707 #ifdef SUPPORT_UTF
 2708     if (UTF_ENABLED(common->utf) && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
 2709 #endif
 2710 #ifdef SUPPORT_UCP
 2711     needschar = TRUE;
 2712 #endif
 2713     }
 2714   else if (*cc == XCL_RANGE)
 2715     {
 2716     cc += 2;
 2717 #ifdef SUPPORT_UTF
 2718     if (UTF_ENABLED(common->utf) && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
 2719 #endif
 2720     cc++;
 2721 #ifdef SUPPORT_UTF
 2722     if (UTF_ENABLED(common->utf) && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
 2723 #endif
 2724 #ifdef SUPPORT_UCP
 2725     needschar = TRUE;
 2726 #endif
 2727     }
 2728 #ifdef SUPPORT_UCP
 2729   else
 2730     {
 2731     SLJIT_ASSERT(*cc == XCL_PROP || *cc == XCL_NOTPROP);
 2732     cc++;
 2733     switch(*cc)
 2734       {
 2735       case PT_ANY:
 2736       break;
 2737 
 2738       case PT_LAMP:
 2739       case PT_GC:
 2740       case PT_PC:
 2741       case PT_ALNUM:
 2742       needstype = TRUE;
 2743       break;
 2744 
 2745       case PT_SC:
 2746       needsscript = TRUE;
 2747       break;
 2748 
 2749       case PT_SPACE:
 2750       case PT_PXSPACE:
 2751       case PT_WORD:
 2752       needstype = TRUE;
 2753       needschar = TRUE;
 2754       break;
 2755 
 2756       default:
 2757       SLJIT_ASSERT_STOP();
 2758       break;
 2759       }
 2760     cc += 2;
 2761     }
 2762 #endif
 2763   }
 2764 
 2765 #ifdef SUPPORT_UCP
 2766 /* Simple register allocation. TMP1 is preferred if possible. */
 2767 if (needstype || needsscript)
 2768   {
 2769   if (needschar && !charsaved)
 2770     OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
 2771   add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
 2772   if (needschar)
 2773     {
 2774     if (needstype)
 2775       {
 2776       OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
 2777       typereg = RETURN_ADDR;
 2778       }
 2779 
 2780     if (needsscript)
 2781       scriptreg = TMP3;
 2782     OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
 2783     }
 2784   else if (needstype && needsscript)
 2785     scriptreg = TMP3;
 2786   /* In all other cases only one of them was specified, and that can goes to TMP1. */
 2787 
 2788   if (needsscript)
 2789     {
 2790     if (scriptreg == TMP1)
 2791       {
 2792       OP1(SLJIT_MOV, scriptreg, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));
 2793       OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
 2794       }
 2795     else
 2796       {
 2797       OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
 2798       OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));
 2799       OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
 2800       }
 2801     }
 2802   }
 2803 #endif
 2804 
 2805 /* Generating code. */
 2806 cc = ccbegin;
 2807 charoffset = 0;
 2808 numberofcmps = 0;
 2809 #ifdef SUPPORT_UCP
 2810 typeoffset = 0;
 2811 #endif
 2812 
 2813 while (*cc != XCL_END)
 2814   {
 2815   compares--;
 2816   invertcmp = (compares == 0 && list != fallbacks);
 2817   jump = NULL;
 2818 
 2819   if (*cc == XCL_SINGLE)
 2820     {
 2821     cc ++;
 2822 #ifdef SUPPORT_UTF
 2823     if (UTF_ENABLED(common->utf))
 2824       {
 2825       GETCHARINC(c, cc);
 2826       }
 2827     else
 2828 #endif
 2829       c = *cc++;
 2830 
 2831     if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
 2832       {
 2833       OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
 2834       COND_VALUE(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);
 2835       numberofcmps++;
 2836       }
 2837     else if (numberofcmps > 0)
 2838       {
 2839       OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
 2840       COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
 2841       jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
 2842       numberofcmps = 0;
 2843       }
 2844     else
 2845       {
 2846       jump = CMP(SLJIT_C_EQUAL ^ invertcmp, TMP1, 0, SLJIT_IMM, c - charoffset);
 2847       numberofcmps = 0;
 2848       }
 2849     }
 2850   else if (*cc == XCL_RANGE)
 2851     {
 2852     cc ++;
 2853 #ifdef SUPPORT_UTF
 2854     if (UTF_ENABLED(common->utf))
 2855       {
 2856       GETCHARINC(c, cc);
 2857       }
 2858     else
 2859 #endif
 2860       c = *cc++;
 2861     SET_CHAR_OFFSET(c);
 2862 #ifdef SUPPORT_UTF
 2863     if (UTF_ENABLED(common->utf))
 2864       {
 2865       GETCHARINC(c, cc);
 2866       }
 2867     else
 2868 #endif
 2869       c = *cc++;
 2870     if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
 2871       {
 2872       OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
 2873       COND_VALUE(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);
 2874       numberofcmps++;
 2875       }
 2876     else if (numberofcmps > 0)
 2877       {
 2878       OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
 2879       COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);
 2880       jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
 2881       numberofcmps = 0;
 2882       }
 2883     else
 2884       {
 2885       jump = CMP(SLJIT_C_LESS_EQUAL ^ invertcmp, TMP1, 0, SLJIT_IMM, c - charoffset);
 2886       numberofcmps = 0;
 2887       }
 2888     }
 2889 #ifdef SUPPORT_UCP
 2890   else
 2891     {
 2892     if (*cc == XCL_NOTPROP)
 2893       invertcmp ^= 0x1;
 2894     cc++;
 2895     switch(*cc)
 2896       {
 2897       case PT_ANY:
 2898       if (list != fallbacks)
 2899         {
 2900         if ((cc[-1] == XCL_NOTPROP && compares > 0) || (cc[-1] == XCL_PROP && compares == 0))
 2901           continue;
 2902         }
 2903       else if (cc[-1] == XCL_NOTPROP)
 2904         continue;
 2905       jump = JUMP(SLJIT_JUMP);
 2906       break;
 2907 
 2908       case PT_LAMP:
 2909       OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - typeoffset);
 2910       COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);
 2911       OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ll - typeoffset);
 2912       COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);
 2913       OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lt - typeoffset);
 2914       COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
 2915       jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
 2916       break;
 2917 
 2918       case PT_GC:
 2919       c = PRIV(ucp_typerange)[(int)cc[1] * 2];
 2920       SET_TYPE_OFFSET(c);
 2921       jump = CMP(SLJIT_C_LESS_EQUAL ^ invertcmp, typereg, 0, SLJIT_IMM, PRIV(ucp_typerange)[(int)cc[1] * 2 + 1] - c);
 2922       break;
 2923 
 2924       case PT_PC:
 2925       jump = CMP(SLJIT_C_EQUAL ^ invertcmp, typereg, 0, SLJIT_IMM, (int)cc[1] - typeoffset);
 2926       break;
 2927 
 2928       case PT_SC:
 2929       jump = CMP(SLJIT_C_EQUAL ^ invertcmp, scriptreg, 0, SLJIT_IMM, (int)cc[1]);
 2930       break;
 2931 
 2932       case PT_SPACE:
 2933       case PT_PXSPACE:
 2934       if (*cc == PT_SPACE)
 2935         {
 2936         OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
 2937         jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 11 - charoffset);
 2938         }
 2939       SET_CHAR_OFFSET(9);
 2940       OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 13 - 9);
 2941       COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);
 2942       if (*cc == PT_SPACE)
 2943         JUMPHERE(jump);
 2944 
 2945       SET_TYPE_OFFSET(ucp_Zl);
 2946       OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);
 2947       COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);
 2948       jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
 2949       break;
 2950 
 2951       case PT_WORD:
 2952       OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE - charoffset);
 2953       COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);
 2954       /* ... fall through */
 2955 
 2956       case PT_ALNUM:
 2957       SET_TYPE_OFFSET(ucp_Ll);
 2958       OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
 2959       COND_VALUE((*cc == PT_ALNUM) ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);
 2960       SET_TYPE_OFFSET(ucp_Nd);
 2961       OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_No - ucp_Nd);
 2962       COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);
 2963       jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
 2964       break;
 2965       }
 2966     cc += 2;
 2967     }
 2968 #endif
 2969 
 2970   if (jump != NULL)
 2971     add_jump(compiler, compares > 0 ? list : fallbacks, jump);
 2972   }
 2973 
 2974 if (found != NULL)
 2975   set_jumps(found, LABEL());
 2976 }
 2977 
 2978 #undef SET_TYPE_OFFSET
 2979 #undef SET_CHAR_OFFSET
 2980 
 2981 #endif
 2982 
 2983 static pcre_uchar *compile_char1_hotpath(compiler_common *common, pcre_uchar type, pcre_uchar *cc, jump_list **fallbacks)
 2984 {
 2985 DEFINE_COMPILER;
 2986 int length;
 2987 unsigned int c, oc, bit;
 2988 compare_context context;
 2989 struct sljit_jump *jump[4];
 2990 #ifdef SUPPORT_UTF
 2991 struct sljit_label *label;
 2992 #ifdef SUPPORT_UCP
 2993 pcre_uchar propdata[5];
 2994 #endif
 2995 #endif
 2996 
 2997 switch(type)
 2998   {
 2999   case OP_SOD:
 3000   OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
 3001   OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
 3002   add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, TMP1, 0));
 3003   return cc;
 3004 
 3005   case OP_SOM:
 3006   OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
 3007   OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
 3008   add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, TMP1, 0));
 3009   return cc;
 3010 
 3011   case OP_NOT_WORD_BOUNDARY:
 3012   case OP_WORD_BOUNDARY:
 3013   add_jump(compiler, &common->wordboundary, JUMP(SLJIT_FAST_CALL));
 3014   add_jump(compiler, fallbacks, JUMP(type == OP_NOT_WORD_BOUNDARY ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
 3015   return cc;
 3016 
 3017   case OP_NOT_DIGIT:
 3018   case OP_DIGIT:
 3019   check_input_end(common, fallbacks);
 3020   read_char8_type(common);
 3021   OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);
 3022   add_jump(compiler, fallbacks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
 3023   return cc;
 3024 
 3025   case OP_NOT_WHITESPACE:
 3026   case OP_WHITESPACE:
 3027   check_input_end(common, fallbacks);
 3028   read_char8_type(common);
 3029   OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_space);
 3030   add_jump(compiler, fallbacks, JUMP(type == OP_WHITESPACE ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
 3031   return cc;
 3032 
 3033   case OP_NOT_WORDCHAR:
 3034   case OP_WORDCHAR:
 3035   check_input_end(common, fallbacks);
 3036   read_char8_type(common);
 3037   OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_word);
 3038   add_jump(compiler, fallbacks, JUMP(type == OP_WORDCHAR ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
 3039   return cc;
 3040 
 3041   case OP_ANY:
 3042   check_input_end(common, fallbacks);
 3043   read_char(common);
 3044   if (common->nltype == NLTYPE_FIXED && common->newline > 255)
 3045     {
 3046     jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
 3047     jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 3048     OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
 3049     add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));
 3050     JUMPHERE(jump[1]);
 3051     JUMPHERE(jump[0]);
 3052     }
 3053   else
 3054     check_newlinechar(common, common->nltype, fallbacks, TRUE);
 3055   return cc;
 3056 
 3057   case OP_ALLANY:
 3058   check_input_end(common, fallbacks);
 3059 #ifdef SUPPORT_UTF
 3060   if (UTF_ENABLED(common->utf))
 3061     {
 3062     OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
 3063     OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 3064 #ifdef COMPILE_PCRE8
 3065     jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
 3066     OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);
 3067     OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
 3068 #else /* COMPILE_PCRE8 */
 3069 #ifdef COMPILE_PCRE16
 3070     jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
 3071     OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
 3072     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
 3073     COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);
 3074     OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
 3075     OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
 3076 #endif /* COMPILE_PCRE16 */
 3077 #endif /* COMPILE_PCRE8 */
 3078     JUMPHERE(jump[0]);
 3079     return cc;
 3080     }
 3081 #endif
 3082   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 3083   return cc;
 3084 
 3085   case OP_ANYBYTE:
 3086   check_input_end(common, fallbacks);
 3087   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 3088   return cc;
 3089 
 3090 #ifdef SUPPORT_UTF
 3091 #ifdef SUPPORT_UCP
 3092   case OP_NOTPROP:
 3093   case OP_PROP:
 3094   propdata[0] = 0;
 3095   propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;
 3096   propdata[2] = cc[0];
 3097   propdata[3] = cc[1];
 3098   propdata[4] = XCL_END;
 3099   compile_xclass_hotpath(common, propdata, fallbacks);
 3100   return cc + 2;
 3101 #endif
 3102 #endif
 3103 
 3104   case OP_ANYNL:
 3105   check_input_end(common, fallbacks);
 3106   read_char(common);
 3107   jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
 3108   jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 3109   OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
 3110   jump[2] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);
 3111   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 3112   jump[3] = JUMP(SLJIT_JUMP);
 3113   JUMPHERE(jump[0]);
 3114   check_newlinechar(common, common->bsr_nltype, fallbacks, FALSE);
 3115   JUMPHERE(jump[1]);
 3116   JUMPHERE(jump[2]);
 3117   JUMPHERE(jump[3]);
 3118   return cc;
 3119 
 3120   case OP_NOT_HSPACE:
 3121   case OP_HSPACE:
 3122   check_input_end(common, fallbacks);
 3123   read_char(common);
 3124   add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));
 3125   add_jump(compiler, fallbacks, JUMP(type == OP_NOT_HSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
 3126   return cc;
 3127 
 3128   case OP_NOT_VSPACE:
 3129   case OP_VSPACE:
 3130   check_input_end(common, fallbacks);
 3131   read_char(common);
 3132   add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));
 3133   add_jump(compiler, fallbacks, JUMP(type == OP_NOT_VSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
 3134   return cc;
 3135 
 3136 #ifdef SUPPORT_UCP
 3137   case OP_EXTUNI:
 3138   check_input_end(common, fallbacks);
 3139   read_char(common);
 3140   add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
 3141   OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Mc);
 3142   add_jump(compiler, fallbacks, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, ucp_Mn - ucp_Mc));
 3143 
 3144   label = LABEL();
 3145   jump[0] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 3146   OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
 3147   read_char(common);
 3148   add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
 3149   OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Mc);
 3150   CMPTO(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, ucp_Mn - ucp_Mc, label);
 3151 
 3152   OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
 3153   JUMPHERE(jump[0]);
 3154   return cc;
 3155 #endif
 3156 
 3157   case OP_EODN:
 3158   jump[0] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 3159   if (common->nltype == NLTYPE_FIXED && common->newline > 255)
 3160     {
 3161     OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
 3162     OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
 3163     add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_END, 0));
 3164     OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
 3165     add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff));
 3166     add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff));
 3167     }
 3168   else if (common->nltype == NLTYPE_FIXED)
 3169     {
 3170     OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 3171     OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
 3172     add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_END, 0));
 3173     add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
 3174     }
 3175   else
 3176     {
 3177     OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
 3178     jump[1] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
 3179     OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
 3180     OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP2, 0, STR_END, 0);
 3181     jump[2] = JUMP(SLJIT_C_GREATER);
 3182     add_jump(compiler, fallbacks, JUMP(SLJIT_C_LESS));
 3183     /* Equal. */
 3184     OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
 3185     jump[3] = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);
 3186     add_jump(compiler, fallbacks, JUMP(SLJIT_JUMP));
 3187 
 3188     JUMPHERE(jump[1]);
 3189     if (common->nltype == NLTYPE_ANYCRLF)
 3190       {
 3191       OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 3192       add_jump(compiler, fallbacks, CMP(SLJIT_C_LESS, TMP2, 0, STR_END, 0));
 3193       add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
 3194       }
 3195     else
 3196       {
 3197       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);
 3198       read_char(common);
 3199       add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, STR_END, 0));
 3200       add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
 3201       add_jump(compiler, fallbacks, JUMP(SLJIT_C_ZERO));
 3202       OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
 3203       }
 3204     JUMPHERE(jump[2]);
 3205     JUMPHERE(jump[3]);
 3206     }
 3207   JUMPHERE(jump[0]);
 3208   return cc;
 3209 
 3210   case OP_EOD:
 3211   add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, STR_END, 0));
 3212   return cc;
 3213 
 3214   case OP_CIRC:
 3215   OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0);
 3216   OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, begin));
 3217   add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER, STR_PTR, 0, TMP1, 0));
 3218   OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, notbol));
 3219   add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
 3220   return cc;
 3221 
 3222   case OP_CIRCM:
 3223   OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0);
 3224   OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, begin));
 3225   jump[1] = CMP(SLJIT_C_GREATER, STR_PTR, 0, TMP1, 0);
 3226   OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, notbol));
 3227   add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
 3228   jump[0] = JUMP(SLJIT_JUMP);
 3229   JUMPHERE(jump[1]);
 3230 
 3231   add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, STR_PTR, 0, STR_END, 0));
 3232   if (common->nltype == NLTYPE_FIXED && common->newline > 255)
 3233     {
 3234     OP2(SLJIT_SUB, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
 3235     add_jump(compiler, fallbacks, CMP(SLJIT_C_LESS, TMP2, 0, TMP1, 0));
 3236     OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
 3237     OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
 3238     add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff));
 3239     add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff));
 3240     }
 3241   else
 3242     {
 3243     skip_char_back(common);
 3244     read_char(common);
 3245     check_newlinechar(common, common->nltype, fallbacks, FALSE);
 3246     }
 3247   JUMPHERE(jump[0]);
 3248   return cc;
 3249 
 3250   case OP_DOLL:
 3251   OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0);
 3252   OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, noteol));
 3253   add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
 3254 
 3255   if (!common->endonly)
 3256     compile_char1_hotpath(common, OP_EODN, cc, fallbacks);
 3257   else
 3258     add_jump(compiler, fallbacks, CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0));
 3259   return cc;
 3260 
 3261   case OP_DOLLM:
 3262   jump[1] = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
 3263   OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0);
 3264   OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, noteol));
 3265   add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
 3266   jump[0] = JUMP(SLJIT_JUMP);
 3267   JUMPHERE(jump[1]);
 3268 
 3269   if (common->nltype == NLTYPE_FIXED && common->newline > 255)
 3270     {
 3271     OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
 3272     add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER, TMP2, 0, STR_END, 0));
 3273     OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
 3274     OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
 3275     add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff));
 3276     add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff));
 3277     }
 3278   else
 3279     {
 3280     peek_char(common);
 3281     check_newlinechar(common, common->nltype, fallbacks, FALSE);
 3282     }
 3283   JUMPHERE(jump[0]);
 3284   return cc;
 3285 
 3286   case OP_CHAR:
 3287   case OP_CHARI:
 3288   length = 1;
 3289 #ifdef SUPPORT_UTF
 3290   if (UTF_ENABLED(common->utf) && HAS_EXTRALEN(*cc)) length += GET_EXTRALEN(*cc);
 3291 #endif
 3292   if (type == OP_CHAR || !char_has_othercase(common, cc) || char_get_othercase_bit(common, cc) != 0)
 3293     {
 3294     OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(length));
 3295     add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER, STR_PTR, 0, STR_END, 0));
 3296 
 3297     context.length = IN_UCHARS(length);
 3298     context.sourcereg = -1;
 3299 #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
 3300     context.ucharptr = 0;
 3301 #endif
 3302     return byte_sequence_compare(common, type == OP_CHARI, cc, &context, fallbacks);
 3303     }
 3304   check_input_end(common, fallbacks);
 3305   read_char(common);
 3306 #ifdef SUPPORT_UTF
 3307   if (UTF_ENABLED(common->utf))
 3308     {
 3309     GETCHAR(c, cc);
 3310     }
 3311   else
 3312 #endif
 3313     c = *cc;
 3314   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c);
 3315   COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);
 3316   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, char_othercase(common, c));
 3317   COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
 3318   add_jump(compiler, fallbacks, JUMP(SLJIT_C_ZERO));
 3319   return cc + length;
 3320 
 3321   case OP_NOT:
 3322   case OP_NOTI:
 3323   check_input_end(common, fallbacks);
 3324   length = 1;
 3325 #ifdef SUPPORT_UTF
 3326   if (UTF_ENABLED(common->utf))
 3327     {
 3328 #ifdef COMPILE_PCRE8
 3329     c = *cc;
 3330     if (c < 128)
 3331       {
 3332       OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
 3333       if (type == OP_NOT || !char_has_othercase(common, cc))
 3334         add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));
 3335       else
 3336         {
 3337         /* Since UTF8 code page is fixed, we know that c is in [a-z] or [A-Z] range. */
 3338         OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x20);
 3339         add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, c | 0x20));
 3340         }
 3341       /* Skip the variable-length character. */
 3342       OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 3343       jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
 3344       OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);
 3345       OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
 3346       JUMPHERE(jump[0]);
 3347       return cc + 1;
 3348       }
 3349     else
 3350 #endif /* COMPILE_PCRE8 */
 3351       {
 3352       GETCHARLEN(c, cc, length);
 3353       read_char(common);
 3354       }
 3355     }
 3356   else
 3357 #endif /* SUPPORT_UTF */
 3358     {
 3359     read_char(common);
 3360     c = *cc;
 3361     }
 3362 
 3363   if (type == OP_NOT || !char_has_othercase(common, cc))
 3364     add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));
 3365   else
 3366     {
 3367     oc = char_othercase(common, c);
 3368     bit = c ^ oc;
 3369     if (ispowerof2(bit))
 3370       {
 3371       OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
 3372       add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));
 3373       }
 3374     else
 3375       {
 3376       add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));
 3377       add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, oc));
 3378       }
 3379     }
 3380   return cc + 1;
 3381 
 3382   case OP_CLASS:
 3383   case OP_NCLASS:
 3384   check_input_end(common, fallbacks);
 3385   read_char(common);
 3386 #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
 3387   jump[0] = NULL;
 3388 #ifdef COMPILE_PCRE8
 3389   /* This check only affects 8 bit mode. In other modes, we
 3390   always need to compare the value with 255. */
 3391   if (UTF_ENABLED(common->utf))
 3392 #endif /* COMPILE_PCRE8 */
 3393     {
 3394     jump[0] = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
 3395     if (type == OP_CLASS)
 3396       {
 3397       add_jump(compiler, fallbacks, jump[0]);
 3398       jump[0] = NULL;
 3399       }
 3400     }
 3401 #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
 3402   OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
 3403   OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
 3404   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);
 3405   OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
 3406   OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
 3407   add_jump(compiler, fallbacks, JUMP(SLJIT_C_ZERO));
 3408 #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
 3409   if (jump[0] != NULL)
 3410     JUMPHERE(jump[0]);
 3411 #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
 3412   return cc + 32 / sizeof(pcre_uchar);
 3413 
 3414 #if defined SUPPORT_UTF || defined COMPILE_PCRE16
 3415   case OP_XCLASS:
 3416   compile_xclass_hotpath(common, cc + LINK_SIZE, fallbacks);
 3417   return cc + GET(cc, 0) - 1;
 3418 #endif
 3419 
 3420   case OP_REVERSE:
 3421   length = GET(cc, 0);
 3422   SLJIT_ASSERT(length > 0);
 3423   OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
 3424 #ifdef SUPPORT_UTF
 3425   if (UTF_ENABLED(common->utf))
 3426     {
 3427     OP1(SLJIT_MOV, TMP3, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
 3428     OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, length);
 3429     label = LABEL();
 3430     add_jump(compiler, fallbacks, CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP3, 0));
 3431     skip_char_back(common);
 3432     OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
 3433     JUMPTO(SLJIT_C_NOT_ZERO, label);
 3434     return cc + LINK_SIZE;
 3435     }
 3436 #endif
 3437   OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
 3438   OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(length));
 3439   add_jump(compiler, fallbacks, CMP(SLJIT_C_LESS, STR_PTR, 0, TMP1, 0));
 3440   return cc + LINK_SIZE;
 3441   }
 3442 SLJIT_ASSERT_STOP();
 3443 return cc;
 3444 }
 3445 
 3446 static SLJIT_INLINE pcre_uchar *compile_charn_hotpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, jump_list **fallbacks)
 3447 {
 3448 /* This function consumes at least one input character. */
 3449 /* To decrease the number of length checks, we try to concatenate the fixed length character sequences. */
 3450 DEFINE_COMPILER;
 3451 pcre_uchar *ccbegin = cc;
 3452 compare_context context;
 3453 int size;
 3454 
 3455 context.length = 0;
 3456 do
 3457   {
 3458   if (cc >= ccend)
 3459     break;
 3460 
 3461   if (*cc == OP_CHAR)
 3462     {
 3463     size = 1;
 3464 #ifdef SUPPORT_UTF
 3465     if (UTF_ENABLED(common->utf) && HAS_EXTRALEN(cc[1]))
 3466       size += GET_EXTRALEN(cc[1]);
 3467 #endif
 3468     }
 3469   else if (*cc == OP_CHARI)
 3470     {
 3471     size = 1;
 3472 #ifdef SUPPORT_UTF
 3473     if (UTF_ENABLED(common->utf))
 3474       {
 3475       if (char_has_othercase(common, cc + 1) && char_get_othercase_bit(common, cc + 1) == 0)
 3476         size = 0;
 3477       else if (HAS_EXTRALEN(cc[1]))
 3478         size += GET_EXTRALEN(cc[1]);
 3479       }
 3480     else
 3481 #endif
 3482     if (char_has_othercase(common, cc + 1) && char_get_othercase_bit(common, cc + 1) == 0)
 3483       size = 0;
 3484     }
 3485   else
 3486     size = 0;
 3487 
 3488   cc += 1 + size;
 3489   context.length += IN_UCHARS(size);
 3490   }
 3491 while (size > 0 && context.length <= 128);
 3492 
 3493 cc = ccbegin;
 3494 if (context.length > 0)
 3495   {
 3496   /* We have a fixed-length byte sequence. */
 3497   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, context.length);
 3498   add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER, STR_PTR, 0, STR_END, 0));
 3499 
 3500   context.sourcereg = -1;
 3501 #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
 3502   context.ucharptr = 0;
 3503 #endif
 3504   do cc = byte_sequence_compare(common, *cc == OP_CHARI, cc + 1, &context, fallbacks); while (context.length > 0);
 3505   return cc;
 3506   }
 3507 
 3508 /* A non-fixed length character will be checked if length == 0. */
 3509 return compile_char1_hotpath(common, *cc, cc + 1, fallbacks);
 3510 }
 3511 
 3512 static struct sljit_jump *compile_ref_checks(compiler_common *common, pcre_uchar *cc, jump_list **fallbacks)
 3513 {
 3514 DEFINE_COMPILER;
 3515 int offset = GET2(cc, 1) << 1;
 3516 
 3517 OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
 3518 if (!common->jscript_compat)
 3519   {
 3520   if (fallbacks == NULL)
 3521     {
 3522     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
 3523     COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);
 3524     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
 3525     COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
 3526     return JUMP(SLJIT_C_NOT_ZERO);
 3527     }
 3528   add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
 3529   }
 3530 return CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
 3531 }
 3532 
 3533 /* Forward definitions. */
 3534 static void compile_hotpath(compiler_common *, pcre_uchar *, pcre_uchar *, fallback_common *);
 3535 static void compile_fallbackpath(compiler_common *, struct fallback_common *);
 3536 
 3537 #define PUSH_FALLBACK(size, ccstart, error) \
 3538   do \
 3539     { \
 3540     fallback = sljit_alloc_memory(compiler, (size)); \
 3541     if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) \
 3542       return error; \
 3543     memset(fallback, 0, size); \
 3544     fallback->prev = parent->top; \
 3545     fallback->cc = (ccstart); \
 3546     parent->top = fallback; \
 3547     } \
 3548   while (0)
 3549 
 3550 #define PUSH_FALLBACK_NOVALUE(size, ccstart) \
 3551   do \
 3552     { \
 3553     fallback = sljit_alloc_memory(compiler, (size)); \
 3554     if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) \
 3555       return; \
 3556     memset(fallback, 0, size); \
 3557     fallback->prev = parent->top; \
 3558     fallback->cc = (ccstart); \
 3559     parent->top = fallback; \
 3560     } \
 3561   while (0)
 3562 
 3563 #define FALLBACK_AS(type) ((type*)fallback)
 3564 
 3565 static pcre_uchar *compile_ref_hotpath(compiler_common *common, pcre_uchar *cc, jump_list **fallbacks, BOOL withchecks, BOOL emptyfail)
 3566 {
 3567 DEFINE_COMPILER;
 3568 int offset = GET2(cc, 1) << 1;
 3569 struct sljit_jump *jump = NULL;
 3570 
 3571 OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
 3572 if (withchecks && !common->jscript_compat)
 3573   add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
 3574 
 3575 #if defined SUPPORT_UTF && defined SUPPORT_UCP
 3576 if (UTF_ENABLED(common->utf) && *cc == OP_REFI)
 3577   {
 3578   SLJIT_ASSERT(TMP1 == SLJIT_TEMPORARY_REG1 && STACK_TOP == SLJIT_TEMPORARY_REG2 && TMP2 == SLJIT_TEMPORARY_REG3);
 3579   OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
 3580   if (withchecks)
 3581     jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
 3582 
 3583   /* Needed to save important temporary registers. */
 3584   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
 3585   OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);
 3586   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, ptr), STR_PTR, 0);
 3587   sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_utf_caselesscmp));
 3588   OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
 3589   add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0));
 3590   OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_RETURN_REG, 0);
 3591   }
 3592 else
 3593 #endif /* SUPPORT_UTF && SUPPORT_UCP */
 3594   {
 3595   OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
 3596   if (withchecks)
 3597     jump = JUMP(SLJIT_C_ZERO);
 3598   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
 3599 
 3600   add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER, STR_PTR, 0, STR_END, 0));
 3601   add_jump(compiler, *cc == OP_REF ? &common->casefulcmp : &common->caselesscmp, JUMP(SLJIT_FAST_CALL));
 3602   add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
 3603   }
 3604 
 3605 if (jump != NULL)
 3606   {
 3607   if (emptyfail)
 3608     add_jump(compiler, fallbacks, jump);
 3609   else
 3610     JUMPHERE(jump);
 3611   }
 3612 return cc + 1 + IMM2_SIZE;
 3613 }
 3614 
 3615 static SLJIT_INLINE pcre_uchar *compile_ref_iterator_hotpath(compiler_common *common, pcre_uchar *cc, fallback_common *parent)
 3616 {
 3617 DEFINE_COMPILER;
 3618 fallback_common *fallback;
 3619 pcre_uchar type;
 3620 struct sljit_label *label;
 3621 struct sljit_jump *zerolength;
 3622 struct sljit_jump *jump = NULL;
 3623 pcre_uchar *ccbegin = cc;
 3624 int min = 0, max = 0;
 3625 BOOL minimize;
 3626 
 3627 PUSH_FALLBACK(sizeof(iterator_fallback), cc, NULL);
 3628 
 3629 type = cc[1 + IMM2_SIZE];
 3630 minimize = (type & 0x1) != 0;
 3631 switch(type)
 3632   {
 3633   case OP_CRSTAR:
 3634   case OP_CRMINSTAR:
 3635   min = 0;
 3636   max = 0;
 3637   cc += 1 + IMM2_SIZE + 1;
 3638   break;
 3639   case OP_CRPLUS:
 3640   case OP_CRMINPLUS:
 3641   min = 1;
 3642   max = 0;
 3643   cc += 1 + IMM2_SIZE + 1;
 3644   break;
 3645   case OP_CRQUERY:
 3646   case OP_CRMINQUERY:
 3647   min = 0;
 3648   max = 1;
 3649   cc += 1 + IMM2_SIZE + 1;
 3650   break;
 3651   case OP_CRRANGE:
 3652   case OP_CRMINRANGE:
 3653   min = GET2(cc, 1 + IMM2_SIZE + 1);
 3654   max = GET2(cc, 1 + IMM2_SIZE + 1 + IMM2_SIZE);
 3655   cc += 1 + IMM2_SIZE + 1 + 2 * IMM2_SIZE;
 3656   break;
 3657   default:
 3658   SLJIT_ASSERT_STOP();
 3659   break;
 3660   }
 3661 
 3662 if (!minimize)
 3663   {
 3664   if (min == 0)
 3665     {
 3666     allocate_stack(common, 2);
 3667     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
 3668     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
 3669     /* Temporary release of STR_PTR. */
 3670     OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));
 3671     zerolength = compile_ref_checks(common, ccbegin, NULL);
 3672     /* Restore if not zero length. */
 3673     OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));
 3674     }
 3675   else
 3676     {
 3677     allocate_stack(common, 1);
 3678     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
 3679     zerolength = compile_ref_checks(common, ccbegin, &fallback->topfallbacks);
 3680     }
 3681 
 3682   if (min > 1 || max > 1)
 3683     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
 3684 
 3685   label = LABEL();
 3686   compile_ref_hotpath(common, ccbegin, &fallback->topfallbacks, FALSE, FALSE);
 3687 
 3688   if (min > 1 || max > 1)
 3689     {
 3690     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
 3691     OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
 3692     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);
 3693     if (min > 1)
 3694       CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, label);
 3695     if (max > 1)
 3696       {
 3697       jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, max);
 3698       allocate_stack(common, 1);
 3699       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
 3700       JUMPTO(SLJIT_JUMP, label);
 3701       JUMPHERE(jump);
 3702       }
 3703     }
 3704 
 3705   if (max == 0)
 3706     {
 3707     /* Includes min > 1 case as well. */
 3708     allocate_stack(common, 1);
 3709     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
 3710     JUMPTO(SLJIT_JUMP, label);
 3711     }
 3712 
 3713   JUMPHERE(zerolength);
 3714   FALLBACK_AS(iterator_fallback)->hotpath = LABEL();
 3715 
 3716   decrease_call_count(common);
 3717   return cc;
 3718   }
 3719 
 3720 allocate_stack(common, 2);
 3721 OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
 3722 if (type != OP_CRMINSTAR)
 3723   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
 3724 
 3725 if (min == 0)
 3726   {
 3727   zerolength = compile_ref_checks(common, ccbegin, NULL);
 3728   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
 3729   jump = JUMP(SLJIT_JUMP);
 3730   }
 3731 else
 3732   zerolength = compile_ref_checks(common, ccbegin, &fallback->topfallbacks);
 3733 
 3734 FALLBACK_AS(iterator_fallback)->hotpath = LABEL();
 3735 if (max > 0)
 3736   add_jump(compiler, &fallback->topfallbacks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, max));
 3737 
 3738 compile_ref_hotpath(common, ccbegin, &fallback->topfallbacks, TRUE, TRUE);
 3739 OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
 3740 
 3741 if (min > 1)
 3742   {
 3743   OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
 3744   OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
 3745   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
 3746   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, FALLBACK_AS(iterator_fallback)->hotpath);
 3747   }
 3748 else if (max > 0)
 3749   OP2(SLJIT_ADD, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 1);
 3750 
 3751 if (jump != NULL)
 3752   JUMPHERE(jump);
 3753 JUMPHERE(zerolength);
 3754 
 3755 decrease_call_count(common);
 3756 return cc;
 3757 }
 3758 
 3759 static SLJIT_INLINE pcre_uchar *compile_recurse_hotpath(compiler_common *common, pcre_uchar *cc, fallback_common *parent)
 3760 {
 3761 DEFINE_COMPILER;
 3762 fallback_common *fallback;
 3763 recurse_entry *entry = common->entries;
 3764 recurse_entry *prev = NULL;
 3765 int start = GET(cc, 1);
 3766 
 3767 PUSH_FALLBACK(sizeof(recurse_fallback), cc, NULL);
 3768 while (entry != NULL)
 3769   {
 3770   if (entry->start == start)
 3771     break;
 3772   prev = entry;
 3773   entry = entry->next;
 3774   }
 3775 
 3776 if (entry == NULL)
 3777   {
 3778   entry = sljit_alloc_memory(compiler, sizeof(recurse_entry));
 3779   if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
 3780     return NULL;
 3781   entry->next = NULL;
 3782   entry->entry = NULL;
 3783   entry->calls = NULL;
 3784   entry->start = start;
 3785 
 3786   if (prev != NULL)
 3787     prev->next = entry;
 3788   else
 3789     common->entries = entry;
 3790   }
 3791 
 3792 OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
 3793 allocate_stack(common, 1);
 3794 OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
 3795 
 3796 if (entry->entry == NULL)
 3797   add_jump(compiler, &entry->calls, JUMP(SLJIT_FAST_CALL));
 3798 else
 3799   JUMPTO(SLJIT_FAST_CALL, entry->entry);
 3800 /* Leave if the match is failed. */
 3801 add_jump(compiler, &fallback->topfallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0));
 3802 return cc + 1 + LINK_SIZE;
 3803 }
 3804 
 3805 static pcre_uchar *compile_assert_hotpath(compiler_common *common, pcre_uchar *cc, assert_fallback *fallback, BOOL conditional)
 3806 {
 3807 DEFINE_COMPILER;
 3808 int framesize;
 3809 int localptr;
 3810 fallback_common altfallback;
 3811 pcre_uchar *ccbegin;
 3812 pcre_uchar opcode;
 3813 pcre_uchar bra = OP_BRA;
 3814 jump_list *tmp = NULL;
 3815 jump_list **target = (conditional) ? &fallback->condfailed : &fallback->common.topfallbacks;
 3816 jump_list **found;
 3817 /* Saving previous accept variables. */
 3818 struct sljit_label *save_acceptlabel = common->acceptlabel;
 3819 struct sljit_jump *jump;
 3820 struct sljit_jump *brajump = NULL;
 3821 jump_list *save_accept = common->accept;
 3822 
 3823 if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
 3824   {
 3825   SLJIT_ASSERT(!conditional);
 3826   bra = *cc;
 3827   cc++;
 3828   }
 3829 localptr = PRIV_DATA(cc);
 3830 SLJIT_ASSERT(localptr != 0);
 3831 framesize = get_framesize(common, cc, FALSE);
 3832 fallback->framesize = framesize;
 3833 fallback->localptr = localptr;
 3834 opcode = *cc;
 3835 SLJIT_ASSERT(opcode >= OP_ASSERT && opcode <= OP_ASSERTBACK_NOT);
 3836 found = (opcode == OP_ASSERT || opcode == OP_ASSERTBACK) ? &tmp : target;
 3837 ccbegin = cc;
 3838 cc += GET(cc, 1);
 3839 
 3840 if (bra == OP_BRAMINZERO)
 3841   {
 3842   /* This is a braminzero fallback path. */
 3843   OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
 3844   free_stack(common, 1);
 3845   brajump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);
 3846   }
 3847 
 3848 if (framesize < 0)
 3849   {
 3850   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STACK_TOP, 0);
 3851   allocate_stack(common, 1);
 3852   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
 3853   }
 3854 else
 3855   {
 3856   allocate_stack(common, framesize + 2);
 3857   OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
 3858   OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(framesize + 1));
 3859   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP2, 0);
 3860   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
 3861   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
 3862   init_frame(common, ccbegin, framesize + 1, 2, FALSE);
 3863   }
 3864 
 3865 memset(&altfallback, 0, sizeof(fallback_common));
 3866 while (1)
 3867   {
 3868   common->acceptlabel = NULL;
 3869   common->accept = NULL;
 3870   altfallback.top = NULL;
 3871   altfallback.topfallbacks = NULL;
 3872 
 3873   if (*ccbegin == OP_ALT)
 3874     OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
 3875 
 3876   altfallback.cc = ccbegin;
 3877   compile_hotpath(common, ccbegin + 1 + LINK_SIZE, cc, &altfallback);
 3878   if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
 3879     {
 3880     common->acceptlabel = save_acceptlabel;
 3881     common->accept = save_accept;
 3882     return NULL;
 3883     }
 3884   common->acceptlabel = LABEL();
 3885   if (common->accept != NULL)
 3886     set_jumps(common->accept, common->acceptlabel);
 3887 
 3888   /* Reset stack. */
 3889   if (framesize < 0)
 3890     OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
 3891   else {
 3892     if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
 3893       {
 3894       /* We don't need to keep the STR_PTR, only the previous localptr. */
 3895       OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_w));
 3896       }
 3897     else
 3898       {
 3899       OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
 3900       add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
 3901       }
 3902   }
 3903 
 3904   if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
 3905     {
 3906     /* We know that STR_PTR was stored on the top of the stack. */
 3907     if (conditional)
 3908       OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
 3909     else if (bra == OP_BRAZERO)
 3910       {
 3911       if (framesize < 0)
 3912         OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
 3913       else
 3914         {
 3915         OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_w));
 3916         OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_w));
 3917         OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP1, 0);
 3918         }
 3919       OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));
 3920       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
 3921       }
 3922     else if (framesize >= 0)
 3923       {
 3924       /* For OP_BRA and OP_BRAMINZERO. */
 3925       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_w));
 3926       }
 3927     }
 3928   add_jump(compiler, found, JUMP(SLJIT_JUMP));
 3929 
 3930   compile_fallbackpath(common, altfallback.top);
 3931   if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
 3932     {
 3933     common->acceptlabel = save_acceptlabel;
 3934     common->accept = save_accept;
 3935     return NULL;
 3936     }
 3937   set_jumps(altfallback.topfallbacks, LABEL());
 3938 
 3939   if (*cc != OP_ALT)
 3940     break;
 3941 
 3942   ccbegin = cc;
 3943   cc += GET(cc, 1);
 3944   }
 3945 /* None of them matched. */
 3946 
 3947 if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)
 3948   {
 3949   /* Assert is failed. */
 3950   if (conditional || bra == OP_BRAZERO)
 3951     OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
 3952 
 3953   if (framesize < 0)
 3954     {
 3955     /* The topmost item should be 0. */
 3956     if (bra == OP_BRAZERO)
 3957       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
 3958     else
 3959       free_stack(common, 1);
 3960     }
 3961   else
 3962     {
 3963     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
 3964     /* The topmost item should be 0. */
 3965     if (bra == OP_BRAZERO)
 3966       {
 3967       free_stack(common, framesize + 1);
 3968       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
 3969       }
 3970     else
 3971       free_stack(common, framesize + 2);
 3972     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP1, 0);
 3973     }
 3974   jump = JUMP(SLJIT_JUMP);
 3975   if (bra != OP_BRAZERO)
 3976     add_jump(compiler, target, jump);
 3977 
 3978   /* Assert is successful. */
 3979   set_jumps(tmp, LABEL());
 3980   if (framesize < 0)
 3981     {
 3982     /* We know that STR_PTR was stored on the top of the stack. */
 3983     OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
 3984     /* Keep the STR_PTR on the top of the stack. */
 3985     if (bra == OP_BRAZERO)
 3986       OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));
 3987     else if (bra == OP_BRAMINZERO)
 3988       {
 3989       OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));
 3990       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
 3991       }
 3992     }
 3993   else
 3994     {
 3995     if (bra == OP_BRA)
 3996       {
 3997       /* We don't need to keep the STR_PTR, only the previous localptr. */
 3998       OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_w));
 3999       OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
 4000       }
 4001     else
 4002       {
 4003       /* We don't need to keep the STR_PTR, only the previous localptr. */
 4004       OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_w));
 4005       OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
 4006       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);
 4007       }
 4008     }
 4009 
 4010   if (bra == OP_BRAZERO)
 4011     {
 4012     fallback->hotpath = LABEL();
 4013     sljit_set_label(jump, fallback->hotpath);
 4014     }
 4015   else if (bra == OP_BRAMINZERO)
 4016     {
 4017     JUMPTO(SLJIT_JUMP, fallback->hotpath);
 4018     JUMPHERE(brajump);
 4019     if (framesize >= 0)
 4020       {
 4021       OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
 4022       add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
 4023       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_w));
 4024       }
 4025     set_jumps(fallback->common.topfallbacks, LABEL());
 4026     }
 4027   }
 4028 else
 4029   {
 4030   /* AssertNot is successful. */
 4031   if (framesize < 0)
 4032     {
 4033     OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
 4034     if (bra != OP_BRA)
 4035       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
 4036     else
 4037       free_stack(common, 1);
 4038     }
 4039   else
 4040     {
 4041     OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
 4042     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
 4043     /* The topmost item should be 0. */
 4044     if (bra != OP_BRA)
 4045       {
 4046       free_stack(common, framesize + 1);
 4047       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
 4048       }
 4049     else
 4050       free_stack(common, framesize + 2);
 4051     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP1, 0);
 4052     }
 4053 
 4054   if (bra == OP_BRAZERO)
 4055     fallback->hotpath = LABEL();
 4056   else if (bra == OP_BRAMINZERO)
 4057     {
 4058     JUMPTO(SLJIT_JUMP, fallback->hotpath);
 4059     JUMPHERE(brajump);
 4060     }
 4061 
 4062   if (bra != OP_BRA)
 4063     {
 4064     SLJIT_ASSERT(found == &fallback->common.topfallbacks);
 4065     set_jumps(fallback->common.topfallbacks, LABEL());
 4066     fallback->common.topfallbacks = NULL;
 4067     }
 4068   }
 4069 
 4070 common->acceptlabel = save_acceptlabel;
 4071 common->accept = save_accept;
 4072 return cc + 1 + LINK_SIZE;
 4073 }
 4074 
 4075 static sljit_w SLJIT_CALL do_searchovector(sljit_w refno, sljit_w* locals, pcre_uchar *name_table)
 4076 {
 4077 int condition = FALSE;
 4078 pcre_uchar *slotA = name_table;
 4079 pcre_uchar *slotB;
 4080 sljit_w name_count = locals[LOCALS0 / sizeof(sljit_w)];
 4081 sljit_w name_entry_size = locals[LOCALS1 / sizeof(sljit_w)];
 4082 sljit_w no_capture;
 4083 int i;
 4084 
 4085 locals += OVECTOR_START / sizeof(sljit_w);
 4086 no_capture = locals[1];
 4087 
 4088 for (i = 0; i < name_count; i++)
 4089   {
 4090   if (GET2(slotA, 0) == refno) break;
 4091   slotA += name_entry_size;
 4092   }
 4093 
 4094 if (i < name_count)
 4095   {
 4096   /* Found a name for the number - there can be only one; duplicate names
 4097   for different numbers are allowed, but not vice versa. First scan down
 4098   for duplicates. */
 4099 
 4100   slotB = slotA;
 4101   while (slotB > name_table)
 4102     {
 4103     slotB -= name_entry_size;
 4104     if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
 4105       {
 4106       condition = locals[GET2(slotB, 0) << 1] != no_capture;
 4107       if (condition) break;
 4108       }
 4109     else break;
 4110     }
 4111 
 4112   /* Scan up for duplicates */
 4113   if (!condition)
 4114     {
 4115     slotB = slotA;
 4116     for (i++; i < name_count; i++)
 4117       {
 4118       slotB += name_entry_size;
 4119       if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
 4120         {
 4121         condition = locals[GET2(slotB, 0) << 1] != no_capture;
 4122         if (condition) break;
 4123         }
 4124       else break;
 4125       }
 4126     }
 4127   }
 4128 return condition;
 4129 }
 4130 
 4131 static sljit_w SLJIT_CALL do_searchgroups(sljit_w recno, sljit_w* locals, pcre_uchar *name_table)
 4132 {
 4133 int condition = FALSE;
 4134 pcre_uchar *slotA = name_table;
 4135 pcre_uchar *slotB;
 4136 sljit_w name_count = locals[LOCALS0 / sizeof(sljit_w)];
 4137 sljit_w name_entry_size = locals[LOCALS1 / sizeof(sljit_w)];
 4138 sljit_w group_num = locals[POSSESSIVE0 / sizeof(sljit_w)];
 4139 int i;
 4140 
 4141 for (i = 0; i < name_count; i++)
 4142   {
 4143   if (GET2(slotA, 0) == recno) break;
 4144   slotA += name_entry_size;
 4145   }
 4146 
 4147 if (i < name_count)
 4148   {
 4149   /* Found a name for the number - there can be only one; duplicate
 4150   names for different numbers are allowed, but not vice versa. First
 4151   scan down for duplicates. */
 4152 
 4153   slotB = slotA;
 4154   while (slotB > name_table)
 4155     {
 4156     slotB -= name_entry_size;
 4157     if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
 4158       {
 4159       condition = GET2(slotB, 0) == group_num;
 4160       if (condition) break;
 4161       }
 4162     else break;
 4163     }
 4164 
 4165   /* Scan up for duplicates */
 4166   if (!condition)
 4167     {
 4168     slotB = slotA;
 4169     for (i++; i < name_count; i++)
 4170       {
 4171       slotB += name_entry_size;
 4172       if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
 4173         {
 4174         condition = GET2(slotB, 0) == group_num;
 4175         if (condition) break;
 4176         }
 4177       else break;
 4178       }
 4179     }
 4180   }
 4181 return condition;
 4182 }
 4183 
 4184 /*
 4185   Handling bracketed expressions is probably the most complex part.
 4186 
 4187   Stack layout naming characters:
 4188     S - Push the current STR_PTR
 4189     0 - Push a 0 (NULL)
 4190     A - Push the current STR_PTR. Needed for restoring the STR_PTR
 4191         before the next alternative. Not pushed if there are no alternatives.
 4192     M - Any values pushed by the current alternative. Can be empty, or anything.
 4193     C - Push the previous OVECTOR(i), OVECTOR(i+1) and OVECTOR_PRIV(i) to the stack.
 4194     L - Push the previous local (pointed by localptr) to the stack
 4195    () - opional values stored on the stack
 4196   ()* - optonal, can be stored multiple times
 4197 
 4198   The following list shows the regular expression templates, their PCRE byte codes
 4199   and stack layout supported by pcre-sljit.
 4200 
 4201   (?:)                     OP_BRA     | OP_KET                A M
 4202   ()                       OP_CBRA    | OP_KET                C M
 4203   (?:)+                    OP_BRA     | OP_KETRMAX        0   A M S   ( A M S )*
 4204                            OP_SBRA    | OP_KETRMAX        0   L M S   ( L M S )*
 4205   (?:)+?                   OP_BRA     | OP_KETRMIN        0   A M S   ( A M S )*
 4206                            OP_SBRA    | OP_KETRMIN        0   L M S   ( L M S )*
 4207   ()+                      OP_CBRA    | OP_KETRMAX        0   C M S   ( C M S )*
 4208                            OP_SCBRA   | OP_KETRMAX        0   C M S   ( C M S )*
 4209   ()+?                     OP_CBRA    | OP_KETRMIN        0   C M S   ( C M S )*
 4210                            OP_SCBRA   | OP_KETRMIN        0   C M S   ( C M S )*
 4211   (?:)?    OP_BRAZERO    | OP_BRA     | OP_KET            S ( A M 0 )
 4212   (?:)??   OP_BRAMINZERO | OP_BRA     | OP_KET            S ( A M 0 )
 4213   ()?      OP_BRAZERO    | OP_CBRA    | OP_KET            S ( C M 0 )
 4214   ()??     OP_BRAMINZERO | OP_CBRA    | OP_KET            S ( C M 0 )
 4215   (?:)*    OP_BRAZERO    | OP_BRA     | OP_KETRMAX      S 0 ( A M S )*
 4216            OP_BRAZERO    | OP_SBRA    | OP_KETRMAX      S 0 ( L M S )*
 4217   (?:)*?   OP_BRAMINZERO | OP_BRA     | OP_KETRMIN      S 0 ( A M S )*
 4218            OP_BRAMINZERO | OP_SBRA    | OP_KETRMIN      S 0 ( L M S )*
 4219   ()*      OP_BRAZERO    | OP_CBRA    | OP_KETRMAX      S 0 ( C M S )*
 4220            OP_BRAZERO    | OP_SCBRA   | OP_KETRMAX      S 0 ( C M S )*
 4221   ()*?     OP_BRAMINZERO | OP_CBRA    | OP_KETRMIN      S 0 ( C M S )*
 4222            OP_BRAMINZERO | OP_SCBRA   | OP_KETRMIN      S 0 ( C M S )*
 4223 
 4224 
 4225   Stack layout naming characters:
 4226     A - Push the alternative index (starting from 0) on the stack.
 4227         Not pushed if there is no alternatives.
 4228     M - Any values pushed by the current alternative. Can be empty, or anything.
 4229 
 4230   The next list shows the possible content of a bracket:
 4231   (|)     OP_*BRA    | OP_ALT ...         M A
 4232   (?()|)  OP_*COND   | OP_ALT             M A
 4233   (?>|)   OP_ONCE    | OP_ALT ...         [stack trace] M A
 4234   (?>|)   OP_ONCE_NC | OP_ALT ...         [stack trace] M A
 4235                                           Or nothing, if trace is unnecessary
 4236 */
 4237 
 4238 static pcre_uchar *compile_bracket_hotpath(compiler_common *common, pcre_uchar *cc, fallback_common *parent)
 4239 {
 4240 DEFINE_COMPILER;
 4241 fallback_common *fallback;
 4242 pcre_uchar opcode;
 4243 int localptr = 0;
 4244 int offset = 0;
 4245 int stacksize;
 4246 pcre_uchar *ccbegin;
 4247 pcre_uchar *hotpath;
 4248 pcre_uchar bra = OP_BRA;
 4249 pcre_uchar ket;
 4250 assert_fallback *assert;
 4251 BOOL has_alternatives;
 4252 struct sljit_jump *jump;
 4253 struct sljit_jump *skip;
 4254 struct sljit_label *rmaxlabel = NULL;
 4255 struct sljit_jump *braminzerojump = NULL;
 4256 
 4257 PUSH_FALLBACK(sizeof(bracket_fallback), cc, NULL);
 4258 
 4259 if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
 4260   {
 4261   bra = *cc;
 4262   cc++;
 4263   opcode = *cc;
 4264   }
 4265 
 4266 opcode = *cc;
 4267 ccbegin = cc;
 4268 hotpath = ccbegin + 1 + LINK_SIZE;
 4269 
 4270 if ((opcode == OP_COND || opcode == OP_SCOND) && cc[1 + LINK_SIZE] == OP_DEF)
 4271   {
 4272   /* Drop this bracket_fallback. */
 4273   parent->top = fallback->prev;
 4274   return bracketend(cc);
 4275   }
 4276 
 4277 ket = *(bracketend(cc) - 1 - LINK_SIZE);
 4278 SLJIT_ASSERT(ket == OP_KET || ket == OP_KETRMAX || ket == OP_KETRMIN);
 4279 SLJIT_ASSERT(!((bra == OP_BRAZERO && ket == OP_KETRMIN) || (bra == OP_BRAMINZERO && ket == OP_KETRMAX)));
 4280 cc += GET(cc, 1);
 4281 
 4282 has_alternatives = *cc == OP_ALT;
 4283 if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))
 4284   {
 4285   has_alternatives = (*hotpath == OP_RREF) ? FALSE : TRUE;
 4286   if (*hotpath == OP_NRREF)
 4287     {
 4288     stacksize = GET2(hotpath, 1);
 4289     if (common->currententry == NULL || stacksize == RREF_ANY)
 4290       has_alternatives = FALSE;
 4291     else if (common->currententry->start == 0)
 4292       has_alternatives = stacksize != 0;
 4293     else
 4294       has_alternatives = stacksize != GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
 4295     }
 4296   }
 4297 
 4298 if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))
 4299   opcode = OP_SCOND;
 4300 if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))
 4301   opcode = OP_ONCE;
 4302 
 4303 if (opcode == OP_CBRA || opcode == OP_SCBRA)
 4304   {
 4305   /* Capturing brackets has a pre-allocated space. */
 4306   offset = GET2(ccbegin, 1 + LINK_SIZE);
 4307   localptr = OVECTOR_PRIV(offset);
 4308   offset <<= 1;
 4309   FALLBACK_AS(bracket_fallback)->localptr = localptr;
 4310   hotpath += IMM2_SIZE;
 4311   }
 4312 else if (opcode == OP_ONCE || opcode == OP_SBRA || opcode == OP_SCOND)
 4313   {
 4314   /* Other brackets simply allocate the next entry. */
 4315   localptr = PRIV_DATA(ccbegin);
 4316   SLJIT_ASSERT(localptr != 0);
 4317   FALLBACK_AS(bracket_fallback)->localptr = localptr;
 4318   if (opcode == OP_ONCE)
 4319     FALLBACK_AS(bracket_fallback)->u.framesize = get_framesize(common, ccbegin, FALSE);
 4320   }
 4321 
 4322 /* Instructions before the first alternative. */
 4323 stacksize = 0;
 4324 if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
 4325   stacksize++;
 4326 if (bra == OP_BRAZERO)
 4327   stacksize++;
 4328 
 4329 if (stacksize > 0)
 4330   allocate_stack(common, stacksize);
 4331 
 4332 stacksize = 0;
 4333 if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
 4334   {
 4335   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
 4336   stacksize++;
 4337   }
 4338 
 4339 if (bra == OP_BRAZERO)
 4340   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
 4341 
 4342 if (bra == OP_BRAMINZERO)
 4343   {
 4344   /* This is a fallback path! (Since the hot-path of OP_BRAMINZERO matches to the empty string) */
 4345   OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
 4346   if (ket != OP_KETRMIN)
 4347     {
 4348     free_stack(common, 1);
 4349     braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);
 4350     }
 4351   else
 4352     {
 4353     if (opcode == OP_ONCE || opcode >= OP_SBRA)
 4354       {
 4355       jump = CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);
 4356       OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
 4357       /* Nothing stored during the first run. */
 4358       skip = JUMP(SLJIT_JUMP);
 4359       JUMPHERE(jump);
 4360       /* Checking zero-length iteration. */
 4361       if (opcode != OP_ONCE || FALLBACK_AS(bracket_fallback)->u.framesize < 0)
 4362         {
 4363         /* When we come from outside, localptr contains the previous STR_PTR. */
 4364         braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
 4365         }
 4366       else
 4367         {
 4368         /* Except when the whole stack frame must be saved. */
 4369         OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
 4370         braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (FALLBACK_AS(bracket_fallback)->u.framesize + 1) * sizeof(sljit_w));
 4371         }
 4372       JUMPHERE(skip);
 4373       }
 4374     else
 4375       {
 4376       jump = CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);
 4377       OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
 4378       JUMPHERE(jump);
 4379       }
 4380     }
 4381   }
 4382 
 4383 if (ket == OP_KETRMIN)
 4384   FALLBACK_AS(bracket_fallback)->recursivehotpath = LABEL();
 4385 
 4386 if (ket == OP_KETRMAX)
 4387   {
 4388   rmaxlabel = LABEL();
 4389   if (has_alternatives && opcode != OP_ONCE && opcode < OP_SBRA)
 4390     FALLBACK_AS(bracket_fallback)->althotpath = rmaxlabel;
 4391   }
 4392 
 4393 /* Handling capturing brackets and alternatives. */
 4394 if (opcode == OP_ONCE)
 4395   {
 4396   if (FALLBACK_AS(bracket_fallback)->u.framesize < 0)
 4397     {
 4398     /* Neither capturing brackets nor recursions are not found in the block. */
 4399     if (ket == OP_KETRMIN)
 4400       {
 4401       OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
 4402       allocate_stack(common, 2);
 4403       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
 4404       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
 4405       OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));
 4406       }
 4407     else if (ket == OP_KETRMAX || has_alternatives)
 4408       {
 4409       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STACK_TOP, 0);
 4410       allocate_stack(common, 1);
 4411       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
 4412       }
 4413     else
 4414       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STACK_TOP, 0);
 4415     }
 4416   else
 4417     {
 4418     if (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives)
 4419       {
 4420       allocate_stack(common, FALLBACK_AS(bracket_fallback)->u.framesize + 2);
 4421       OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
 4422       OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(FALLBACK_AS(bracket_fallback)->u.framesize + 1));
 4423       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
 4424       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP2, 0);
 4425       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
 4426       init_frame(common, ccbegin, FALLBACK_AS(bracket_fallback)->u.framesize + 1, 2, FALSE);
 4427       }
 4428     else
 4429       {
 4430       allocate_stack(common, FALLBACK_AS(bracket_fallback)->u.framesize + 1);
 4431       OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
 4432       OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(FALLBACK_AS(bracket_fallback)->u.framesize));
 4433       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP2, 0);
 4434       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
 4435       init_frame(common, ccbegin, FALLBACK_AS(bracket_fallback)->u.framesize, 1, FALSE);
 4436       }
 4437     }
 4438   }
 4439 else if (opcode == OP_CBRA || opcode == OP_SCBRA)
 4440   {
 4441   /* Saving the previous values. */
 4442   allocate_stack(common, 3);
 4443   OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
 4444   OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
 4445   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
 4446   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
 4447   OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
 4448   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STR_PTR, 0);
 4449   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
 4450   }
 4451 else if (opcode == OP_SBRA || opcode == OP_SCOND)
 4452   {
 4453   /* Saving the previous value. */
 4454   OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
 4455   allocate_stack(common, 1);
 4456   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STR_PTR, 0);
 4457   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
 4458   }
 4459 else if (has_alternatives)
 4460   {
 4461   /* Pushing the starting string pointer. */
 4462   allocate_stack(common, 1);
 4463   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
 4464   }
 4465 
 4466 /* Generating code for the first alternative. */
 4467 if (opcode == OP_COND || opcode == OP_SCOND)
 4468   {
 4469   if (*hotpath == OP_CREF)
 4470     {
 4471     SLJIT_ASSERT(has_alternatives);
 4472     add_jump(compiler, &(FALLBACK_AS(bracket_fallback)->u.condfailed),
 4473       CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(hotpath, 1) << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
 4474     hotpath += 1 + IMM2_SIZE;
 4475     }
 4476   else if (*hotpath == OP_NCREF)
 4477     {
 4478     SLJIT_ASSERT(has_alternatives);
 4479     stacksize = GET2(hotpath, 1);
 4480     jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(stacksize << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
 4481 
 4482     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);
 4483     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);
 4484     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);
 4485     OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, stacksize);
 4486     OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_LOCALS_REG, 0);
 4487     OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, common->name_table);
 4488     sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchovector));
 4489     OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
 4490     add_jump(compiler, &(FALLBACK_AS(bracket_fallback)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0));
 4491 
 4492     JUMPHERE(jump);
 4493     hotpath += 1 + IMM2_SIZE;
 4494     }
 4495   else if (*hotpath == OP_RREF || *hotpath == OP_NRREF)
 4496     {
 4497     /* Never has other case. */
 4498     FALLBACK_AS(bracket_fallback)->u.condfailed = NULL;
 4499 
 4500     stacksize = GET2(hotpath, 1);
 4501     if (common->currententry == NULL)
 4502       stacksize = 0;
 4503     else if (stacksize == RREF_ANY)
 4504       stacksize = 1;
 4505     else if (common->currententry->start == 0)
 4506       stacksize = stacksize == 0;
 4507     else
 4508       stacksize = stacksize == GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
 4509 
 4510     if (*hotpath == OP_RREF || stacksize || common->currententry == NULL)
 4511       {
 4512       SLJIT_ASSERT(!has_alternatives);
 4513       if (stacksize != 0)
 4514         hotpath += 1 + IMM2_SIZE;
 4515       else
 4516         {
 4517         if (*cc == OP_ALT)
 4518           {
 4519           hotpath = cc + 1 + LINK_SIZE;
 4520           cc += GET(cc, 1);
 4521           }
 4522         else
 4523           hotpath = cc;
 4524         }
 4525       }
 4526     else
 4527       {
 4528       SLJIT_ASSERT(has_alternatives);
 4529 
 4530       stacksize = GET2(hotpath, 1);
 4531       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);
 4532       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);
 4533       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);
 4534       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, GET2(common->start, common->currententry->start + 1 + LINK_SIZE));
 4535       OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, stacksize);
 4536       OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_LOCALS_REG, 0);
 4537       OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, common->name_table);
 4538       sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchgroups));
 4539       OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
 4540       add_jump(compiler, &(FALLBACK_AS(bracket_fallback)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0));
 4541       hotpath += 1 + IMM2_SIZE;
 4542       }
 4543     }
 4544   else
 4545     {
 4546     SLJIT_ASSERT(has_alternatives && *hotpath >= OP_ASSERT && *hotpath <= OP_ASSERTBACK_NOT);
 4547     /* Similar code as PUSH_FALLBACK macro. */
 4548     assert = sljit_alloc_memory(compiler, sizeof(assert_fallback));
 4549     if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
 4550       return NULL;
 4551     memset(assert, 0, sizeof(assert_fallback));
 4552     assert->common.cc = hotpath;
 4553     FALLBACK_AS(bracket_fallback)->u.assert = assert;
 4554     hotpath = compile_assert_hotpath(common, hotpath, assert, TRUE);
 4555     }
 4556   }
 4557 
 4558 compile_hotpath(common, hotpath, cc, fallback);
 4559 if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
 4560   return NULL;
 4561 
 4562 if (opcode == OP_ONCE)
 4563   {
 4564   if (FALLBACK_AS(bracket_fallback)->u.framesize < 0)
 4565     {
 4566     OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
 4567     /* TMP2 which is set here used by OP_KETRMAX below. */
 4568     if (ket == OP_KETRMAX)
 4569       OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);
 4570     else if (ket == OP_KETRMIN)
 4571       {
 4572       /* Move the STR_PTR to the localptr. */
 4573       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_MEM1(STACK_TOP), 0);
 4574       }
 4575     }
 4576   else
 4577     {
 4578     stacksize = (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives) ? 2 : 1;
 4579     OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_IMM, (FALLBACK_AS(bracket_fallback)->u.framesize + stacksize) * sizeof(sljit_w));
 4580     if (ket == OP_KETRMAX)
 4581       {
 4582       /* TMP2 which is set here used by OP_KETRMAX below. */
 4583       OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
 4584       }
 4585     }
 4586   }
 4587 
 4588 stacksize = 0;
 4589 if (ket != OP_KET || bra != OP_BRA)
 4590   stacksize++;
 4591 if (has_alternatives && opcode != OP_ONCE)
 4592   stacksize++;
 4593 
 4594 if (stacksize > 0)
 4595   allocate_stack(common, stacksize);
 4596 
 4597 stacksize = 0;
 4598 if (ket != OP_KET)
 4599   {
 4600   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
 4601   stacksize++;
 4602   }
 4603 else if (bra != OP_BRA)
 4604   {
 4605   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
 4606   stacksize++;
 4607   }
 4608 
 4609 if (has_alternatives)
 4610   {
 4611   if (opcode != OP_ONCE)
 4612     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
 4613   if (ket != OP_KETRMAX)
 4614     FALLBACK_AS(bracket_fallback)->althotpath = LABEL();
 4615   }
 4616 
 4617 /* Must be after the hotpath label. */
 4618 if (offset != 0)
 4619   {
 4620   OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
 4621   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
 4622   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 0), TMP1, 0);
 4623   }
 4624 
 4625 if (ket == OP_KETRMAX)
 4626   {
 4627   if (opcode == OP_ONCE || opcode >= OP_SBRA)
 4628     {
 4629     if (has_alternatives)
 4630       FALLBACK_AS(bracket_fallback)->althotpath = LABEL();
 4631     /* Checking zero-length iteration. */
 4632     if (opcode != OP_ONCE)
 4633       CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STR_PTR, 0, rmaxlabel);
 4634     else
 4635       /* TMP2 must contain the starting STR_PTR. */
 4636       CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, rmaxlabel);
 4637     }
 4638   else
 4639     JUMPTO(SLJIT_JUMP, rmaxlabel);
 4640   FALLBACK_AS(bracket_fallback)->recursivehotpath = LABEL();
 4641   }
 4642 
 4643 if (bra == OP_BRAZERO)
 4644   FALLBACK_AS(bracket_fallback)->zerohotpath = LABEL();
 4645 
 4646 if (bra == OP_BRAMINZERO)
 4647   {
 4648   /* This is a fallback path! (From the viewpoint of OP_BRAMINZERO) */
 4649   JUMPTO(SLJIT_JUMP, ((braminzero_fallback*)parent)->hotpath);
 4650   if (braminzerojump != NULL)
 4651     {
 4652     JUMPHERE(braminzerojump);
 4653     /* We need to release the end pointer to perform the
 4654     fallback for the zero-length iteration. When
 4655     framesize is < 0, OP_ONCE will do the release itself. */
 4656     if (opcode == OP_ONCE && FALLBACK_AS(bracket_fallback)->u.framesize >= 0)
 4657       {
 4658       OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
 4659       add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
 4660       }
 4661     else if (ket == OP_KETRMIN && opcode != OP_ONCE)
 4662       free_stack(common, 1);
 4663     }
 4664   /* Continue to the normal fallback. */
 4665   }
 4666 
 4667 if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)
 4668   decrease_call_count(common);
 4669 
 4670 /* Skip the other alternatives. */
 4671 while (*cc == OP_ALT)
 4672   cc += GET(cc, 1);
 4673 cc += 1 + LINK_SIZE;
 4674 return cc;
 4675 }
 4676 
 4677 static pcre_uchar *compile_bracketpos_hotpath(compiler_common *common, pcre_uchar *cc, fallback_common *parent)
 4678 {
 4679 DEFINE_COMPILER;
 4680 fallback_common *fallback;
 4681 pcre_uchar opcode;
 4682 int localptr;
 4683 int cbraprivptr = 0;
 4684 int framesize;
 4685 int stacksize;
 4686 int offset = 0;
 4687 BOOL zero = FALSE;
 4688 pcre_uchar *ccbegin = NULL;
 4689 int stack;
 4690 struct sljit_label *loop = NULL;
 4691 struct jump_list *emptymatch = NULL;
 4692 
 4693 PUSH_FALLBACK(sizeof(bracketpos_fallback), cc, NULL);
 4694 if (*cc == OP_BRAPOSZERO)
 4695   {
 4696   zero = TRUE;
 4697   cc++;
 4698   }
 4699 
 4700 opcode = *cc;
 4701 localptr = PRIV_DATA(cc);
 4702 SLJIT_ASSERT(localptr != 0);
 4703 FALLBACK_AS(bracketpos_fallback)->localptr = localptr;
 4704 switch(opcode)
 4705   {
 4706   case OP_BRAPOS:
 4707   case OP_SBRAPOS:
 4708   ccbegin = cc + 1 + LINK_SIZE;
 4709   break;
 4710 
 4711   case OP_CBRAPOS:
 4712   case OP_SCBRAPOS:
 4713   offset = GET2(cc, 1 + LINK_SIZE);
 4714   cbraprivptr = OVECTOR_PRIV(offset);
 4715   offset <<= 1;
 4716   ccbegin = cc + 1 + LINK_SIZE + IMM2_SIZE;
 4717   break;
 4718 
 4719   default:
 4720   SLJIT_ASSERT_STOP();
 4721   break;
 4722   }
 4723 
 4724 framesize = get_framesize(common, cc, FALSE);
 4725 FALLBACK_AS(bracketpos_fallback)->framesize = framesize;
 4726 if (framesize < 0)
 4727   {
 4728   stacksize = (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS) ? 2 : 1;
 4729   if (!zero)
 4730     stacksize++;
 4731   FALLBACK_AS(bracketpos_fallback)->stacksize = stacksize;
 4732   allocate_stack(common, stacksize);
 4733   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STACK_TOP, 0);
 4734 
 4735   if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)
 4736     {
 4737     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
 4738     OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
 4739     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
 4740     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
 4741     }
 4742   else
 4743     OP1(<