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

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

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

revision 715 by zherczeg, Sat Oct 1 06:42:38 2011 UTC revision 1249 by zherczeg, Mon Feb 18 09:55:43 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2008 University of Cambridge             Copyright (c) 1997-2012 University of Cambridge
10    
11    The machine code generator part (this module) was written by Zoltan Herczeg    The machine code generator part (this module) was written by Zoltan Herczeg
12                        Copyright (c) 2010-2011                        Copyright (c) 2010-2012
13    
14  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
15  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 46  POSSIBILITY OF SUCH DAMAGE. Line 46  POSSIBILITY OF SUCH DAMAGE.
46    
47  #include "pcre_internal.h"  #include "pcre_internal.h"
48    
49  #ifdef SUPPORT_JIT  #if defined SUPPORT_JIT
50    
51  /* All-in-one: Since we use the JIT compiler only from here,  /* All-in-one: Since we use the JIT compiler only from here,
52  we just include it. This way we don't need to touch the build  we just include it. This way we don't need to touch the build
53  system files. */  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  #define SLJIT_CONFIG_AUTO 1
58    #define SLJIT_CONFIG_STATIC 1
59  #define SLJIT_VERBOSE 0  #define SLJIT_VERBOSE 0
60  #define SLJIT_DEBUG 0  #define SLJIT_DEBUG 0
61    
62  #include "sljit/sljitLir.c"  #include "sljit/sljitLir.c"
63    
64  #if defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED  #if defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED
65  #error "Unsupported architecture"  #error Unsupported architecture
66  #endif  #endif
67    
68  /* Allocate memory on the stack. Fast, but limited size. */  /* Defines for debugging purposes. */
 #define LOCAL_SPACE_SIZE 32768  
69    
70    /* 1 - Use unoptimized capturing brackets.
71       2 - Enable capture_last_ptr (includes option 1). */
72    /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */
73    
74    /* Allocate memory for the regex stack on the real machine stack.
75    Fast, but limited size. */
76    #define MACHINE_STACK_SIZE 32768
77    
78    /* Growth rate for stack allocated by the OS. Should be the multiply
79    of page size. */
80  #define STACK_GROWTH_RATE 8192  #define STACK_GROWTH_RATE 8192
81    
82  /* Enable to check that the allocation could destroy temporaries. */  /* Enable to check that the allocation could destroy temporaries. */
# Line 79  The code generator follows the recursive Line 91  The code generator follows the recursive
91  expressions. The basic blocks of regular expressions are condition checkers  expressions. The basic blocks of regular expressions are condition checkers
92  whose execute different commands depending on the result of the condition check.  whose execute different commands depending on the result of the condition check.
93  The relationship between the operators can be horizontal (concatenation) and  The relationship between the operators can be horizontal (concatenation) and
94  vertical (sub-expression) (See struct fallback_common for more details).  vertical (sub-expression) (See struct backtrack_common for more details).
95    
96    'ab' - 'a' and 'b' regexps are concatenated    'ab' - 'a' and 'b' regexps are concatenated
97    'a+' - 'a' is the sub-expression of the '+' operator    'a+' - 'a' is the sub-expression of the '+' operator
98    
99  The condition checkers are boolean (true/false) checkers. Machine code is generated  The condition checkers are boolean (true/false) checkers. Machine code is generated
100  for the checker itself and for the actions depending on the result of the checker.  for the checker itself and for the actions depending on the result of the checker.
101  The 'true' case is called as the hot path (expected path), and the other is called as  The 'true' case is called as the matching path (expected path), and the other is called as
102  the 'fallback' path. Branch instructions are expesive for all CPUs, so we avoid taken  the 'backtrack' path. Branch instructions are expesive for all CPUs, so we avoid taken
103  branches on the hot path.  branches on the matching path.
104    
105   Greedy star operator (*) :   Greedy star operator (*) :
106     Hot path: match happens.     Matching path: match happens.
107     Fallback path: match failed.     Backtrack path: match failed.
108   Non-greedy star operator (*?) :   Non-greedy star operator (*?) :
109     Hot path: no need to perform a match.     Matching path: no need to perform a match.
110     Fallback path: match is required.     Backtrack path: match is required.
111    
112  The following example shows how the code generated for a capturing bracket  The following example shows how the code generated for a capturing bracket
113  with two alternatives. Let A, B, C, D are arbirary regular expressions, and  with two alternatives. Let A, B, C, D are arbirary regular expressions, and
# Line 105  we have the following regular expression Line 117  we have the following regular expression
117    
118  The generated code will be the following:  The generated code will be the following:
119    
120   A hot path   A matching path
121   '(' hot path (pushing arguments to the stack)   '(' matching path (pushing arguments to the stack)
122   B hot path   B matching path
123   ')' hot path (pushing arguments to the stack)   ')' matching path (pushing arguments to the stack)
124   D hot path   D matching path
125   return with successful match   return with successful match
126    
127   D fallback path   D backtrack path
128   ')' fallback path (If we arrived from "C" jump to the fallback of "C")   ')' backtrack path (If we arrived from "C" jump to the backtrack of "C")
129   B fallback path   B backtrack path
130   C expected path   C expected path
131   jump to D hot path   jump to D matching path
132   C fallback path   C backtrack path
133   A fallback path   A backtrack path
134    
135   Notice, that the order of fallback code paths are the opposite of the fast   Notice, that the order of backtrack code paths are the opposite of the fast
136   code paths. In this way the topmost value on the stack is always belong   code paths. In this way the topmost value on the stack is always belong
137   to the current fallback code path. The fallback code path must check   to the current backtrack code path. The backtrack path must check
138   whether there is a next alternative. If so, it needs to jump back to   whether there is a next alternative. If so, it needs to jump back to
139   the hot path eventually. Otherwise it needs to clear out its own stack   the matching path eventually. Otherwise it needs to clear out its own stack
140   frame and continue the execution on the fallback code paths.   frame and continue the execution on the backtrack code paths.
141  */  */
142    
143  /*  /*
144  Saved stack frames:  Saved stack frames:
145    
146  Atomic blocks and asserts require reloading the values of local variables  Atomic blocks and asserts require reloading the values of private data
147  when the fallback mechanism performed. Because of OP_RECURSE, the locals  when the backtrack mechanism performed. Because of OP_RECURSE, the data
148  are not necessarly known in compile time, thus we need a dynamic restore  are not necessarly known in compile time, thus we need a dynamic restore
149  mechanism.  mechanism.
150    
151  The stack frames are stored in a chain list, and have the following format:  The stack frames are stored in a chain list, and have the following format:
152  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]
153    
154  Thus we can restore the locals to a particular point in the stack.  Thus we can restore the private data to a particular point in the stack.
155  */  */
156    
157  typedef struct jit_arguments {  typedef struct jit_arguments {
158    /* Pointers first. */    /* Pointers first. */
159    struct sljit_stack *stack;    struct sljit_stack *stack;
160    PCRE_SPTR str;    const pcre_uchar *str;
161    PCRE_SPTR begin;    const pcre_uchar *begin;
162    PCRE_SPTR end;    const pcre_uchar *end;
163    int *offsets;    int *offsets;
164    uschar *ptr;    pcre_uchar *uchar_ptr;
165      pcre_uchar *mark_ptr;
166      void *callout_data;
167    /* Everything else after. */    /* Everything else after. */
168    int offsetcount;    int offset_count;
169    int calllimit;    int call_limit;
170    uschar notbol;    pcre_uint8 notbol;
171    uschar noteol;    pcre_uint8 noteol;
172    uschar notempty;    pcre_uint8 notempty;
173    uschar notempty_atstart;    pcre_uint8 notempty_atstart;
174  } jit_arguments;  } jit_arguments;
175    
176  typedef struct executable_function {  typedef struct executable_functions {
177    void *executable_func;    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
178    pcre_jit_callback callback;    PUBL(jit_callback) callback;
179    void *userdata;    void *userdata;
180  } executable_function;    pcre_uint32 top_bracket;
181      sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
182    } executable_functions;
183    
184  typedef struct jump_list {  typedef struct jump_list {
185    struct sljit_jump *jump;    struct sljit_jump *jump;
186    struct jump_list *next;    struct jump_list *next;
187  } jump_list;  } jump_list;
188    
 enum stub_types { stack_alloc };  
   
189  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
190    struct sljit_jump *start;    struct sljit_jump *start;
191    struct sljit_label *leave;    struct sljit_label *quit;
192    struct stub_list *next;    struct stub_list *next;
193  } stub_list;  } stub_list;
194    
195    enum frame_types { no_frame = -1, no_stack = -2 };
196    
197  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
198    
199  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
200  code generator. It is allocated by compile_hotpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
201  the aguments for compile_fallbackpath. Must be the first member  the aguments for compile_backtrackingpath. Must be the first member
202  of its descendants. */  of its descendants. */
203  typedef struct fallback_common {  typedef struct backtrack_common {
204    /* Concatenation stack. */    /* Concatenation stack. */
205    struct fallback_common *prev;    struct backtrack_common *prev;
206    jump_list *nextfallbacks;    jump_list *nextbacktracks;
207    /* Internal stack (for component operators). */    /* Internal stack (for component operators). */
208    struct fallback_common *top;    struct backtrack_common *top;
209    jump_list *topfallbacks;    jump_list *topbacktracks;
210    /* Opcode pointer. */    /* Opcode pointer. */
211    uschar *cc;    pcre_uchar *cc;
212  } fallback_common;  } backtrack_common;
213    
214  typedef struct assert_fallback {  typedef struct assert_backtrack {
215    fallback_common common;    backtrack_common common;
216    jump_list *condfailed;    jump_list *condfailed;
217    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 (-1) if a frame is not needed. */
218    int framesize;    int framesize;
219    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
220    int localptr;    int private_data_ptr;
221    /* For iterators. */    /* For iterators. */
222    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
223  } assert_fallback;  } assert_backtrack;
224    
225  typedef struct bracket_fallback {  typedef struct bracket_backtrack {
226    fallback_common common;    backtrack_common common;
227    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
228    struct sljit_label *althotpath;    struct sljit_label *alternative_matchingpath;
229    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
230    struct sljit_label *recursivehotpath;    struct sljit_label *recursive_matchingpath;
231    /* For greedy ? operator. */    /* For greedy ? operator. */
232    struct sljit_label *zerohotpath;    struct sljit_label *zero_matchingpath;
233    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
234    union {    union {
235      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
236      jump_list *condfailed;      jump_list *condfailed;
237      assert_fallback *assert;      assert_backtrack *assert;
238      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. -1 if not needed. */
239      int framesize;      int framesize;
240    } u;    } u;
241    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
242    int localptr;    int private_data_ptr;
243  } bracket_fallback;  } bracket_backtrack;
244    
245  typedef struct bracketpos_fallback {  typedef struct bracketpos_backtrack {
246    fallback_common common;    backtrack_common common;
247    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
248    int localptr;    int private_data_ptr;
249    /* Reverting stack is needed. */    /* Reverting stack is needed. */
250    int framesize;    int framesize;
251    /* Allocated stack size. */    /* Allocated stack size. */
252    int stacksize;    int stacksize;
253  } bracketpos_fallback;  } bracketpos_backtrack;
254    
255  typedef struct braminzero_fallback {  typedef struct braminzero_backtrack {
256    fallback_common common;    backtrack_common common;
257    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
258  } braminzero_fallback;  } braminzero_backtrack;
259    
260  typedef struct iterator_fallback {  typedef struct iterator_backtrack {
261    fallback_common common;    backtrack_common common;
262    /* Next iteration. */    /* Next iteration. */
263    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
264  } iterator_fallback;  } iterator_backtrack;
265    
266  typedef struct recurse_entry {  typedef struct recurse_entry {
267    struct recurse_entry *next;    struct recurse_entry *next;
# Line 259  typedef struct recurse_entry { Line 273  typedef struct recurse_entry {
273    int start;    int start;
274  } recurse_entry;  } recurse_entry;
275    
276  typedef struct recurse_fallback {  typedef struct recurse_backtrack {
277    fallback_common common;    backtrack_common common;
278  } recurse_fallback;    BOOL inlined_pattern;
279    } recurse_backtrack;
280    
281    #define MAX_RANGE_SIZE 6
282    
283  typedef struct compiler_common {  typedef struct compiler_common {
284    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
285    uschar *start;    pcre_uchar *start;
286    int localsize;  
287    int *localptrs;    /* Maps private data offset to each opcode. */
288    const uschar *fcc;    int *private_data_ptrs;
289    sljit_w lcc;    /* Tells whether the capturing bracket is optimized. */
290      pcre_uint8 *optimized_cbracket;
291      /* Starting offset of private data for capturing brackets. */
292    int cbraptr;    int cbraptr;
293      /* OVector starting point. Must be divisible by 2. */
294      int ovector_start;
295      /* Last known position of the requested byte. */
296      int req_char_ptr;
297      /* Head of the last recursion. */
298      int recursive_head_ptr;
299      /* First inspected character for partial matching. */
300      int start_used_ptr;
301      /* Starting pointer for partial soft matches. */
302      int hit_start;
303      /* End pointer of the first line. */
304      int first_line_end;
305      /* Points to the marked string. */
306      int mark_ptr;
307      /* Points to the last matched capture block index. */
308      int capture_last_ptr;
309    
310      /* Flipped and lower case tables. */
311      const pcre_uint8 *fcc;
312      sljit_sw lcc;
313      /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
314      int mode;
315      /* Newline control. */
316    int nltype;    int nltype;
317    int newline;    int newline;
318    int bsr_nltype;    int bsr_nltype;
319      /* Dollar endonly. */
320    int endonly;    int endonly;
321    sljit_w ctypes;    BOOL has_set_som;
322    struct sljit_label *acceptlabel;    /* Tables. */
323      sljit_sw ctypes;
324      int digits[2 + MAX_RANGE_SIZE];
325      /* Named capturing brackets. */
326      sljit_uw name_table;
327      sljit_sw name_count;
328      sljit_sw name_entry_size;
329    
330      /* Labels and jump lists. */
331      struct sljit_label *partialmatchlabel;
332      struct sljit_label *quit_label;
333      struct sljit_label *forced_quit_label;
334      struct sljit_label *accept_label;
335    stub_list *stubs;    stub_list *stubs;
336    recurse_entry *entries;    recurse_entry *entries;
337    recurse_entry *currententry;    recurse_entry *currententry;
338      jump_list *partialmatch;
339      jump_list *quit;
340      jump_list *forced_quit;
341    jump_list *accept;    jump_list *accept;
342    jump_list *calllimit;    jump_list *calllimit;
343    jump_list *stackalloc;    jump_list *stackalloc;
# Line 291  typedef struct compiler_common { Line 349  typedef struct compiler_common {
349    jump_list *casefulcmp;    jump_list *casefulcmp;
350    jump_list *caselesscmp;    jump_list *caselesscmp;
351    BOOL jscript_compat;    BOOL jscript_compat;
352  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
353    BOOL utf8;    BOOL utf;
354  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
355    BOOL useucp;    BOOL use_ucp;
356  #endif  #endif
357    jump_list *utf8readchar;  #ifndef COMPILE_PCRE32
358    jump_list *utf8readtype8;    jump_list *utfreadchar;
359  #endif  #endif
360    #ifdef COMPILE_PCRE8
361      jump_list *utfreadtype8;
362    #endif
363    #endif /* SUPPORT_UTF */
364  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
365    jump_list *getucd;    jump_list *getucd;
366  #endif  #endif
# Line 310  typedef struct compare_context { Line 372  typedef struct compare_context {
372    int length;    int length;
373    int sourcereg;    int sourcereg;
374  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
375    int byteptr;    int ucharptr;
376    union {    union {
377      int asint;      sljit_si asint;
378      short asshort;      sljit_uh asushort;
379    #if defined COMPILE_PCRE8
380      sljit_ub asbyte;      sljit_ub asbyte;
381      sljit_ub asbytes[4];      sljit_ub asuchars[4];
382    #elif defined COMPILE_PCRE16
383        sljit_uh asuchars[2];
384    #elif defined COMPILE_PCRE32
385        sljit_ui asuchars[1];
386    #endif
387    } c;    } c;
388    union {    union {
389      int asint;      sljit_si asint;
390      short asshort;      sljit_uh asushort;
391    #if defined COMPILE_PCRE8
392      sljit_ub asbyte;      sljit_ub asbyte;
393      sljit_ub asbytes[4];      sljit_ub asuchars[4];
394    #elif defined COMPILE_PCRE16
395        sljit_uh asuchars[2];
396    #elif defined COMPILE_PCRE32
397        sljit_ui asuchars[1];
398    #endif
399    } oc;    } oc;
400  #endif  #endif
401  } compare_context;  } compare_context;
402    
403  enum {  /* Undefine sljit macros. */
404    frame_end = 0,  #undef CMP
   frame_setstrbegin = -1  
 };  
405    
406  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
407  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
408    
409  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
410  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
411  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
412  #define STR_PTR       SLJIT_GENERAL_REG1  #define STR_PTR       SLJIT_SAVED_REG1
413  #define STR_END       SLJIT_GENERAL_REG2  #define STR_END       SLJIT_SAVED_REG2
414  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
415  #define STACK_LIMIT   SLJIT_GENERAL_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
416  #define ARGUMENTS     SLJIT_GENERAL_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
417  #define CALL_COUNT    SLJIT_GENERAL_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
418  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
419    
420  /* Locals layout. */  /* Local space layout. */
421  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
422  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
423  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
424  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
425  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
426  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
 /* Head of the saved local variables */  
 #define LOCALS_HEAD      (4 * sizeof(sljit_w))  
 /* Head of the last recursion. */  
 #define RECURSIVE_HEAD   (5 * sizeof(sljit_w))  
427  /* Max limit of recursions. */  /* Max limit of recursions. */
428  #define CALL_LIMIT       (7 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
 /* Last known position of the requested byte. */  
 #define REQ_BYTE_PTR     (8 * sizeof(sljit_w))  
 /* End pointer of the first line. */  
 #define FIRSTLINE_END    (9 * sizeof(sljit_w))  
429  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
430  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
431  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
432  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
433  #define OVECTOR_START    (10 * sizeof(sljit_w))  #define OVECTOR_START    (common->ovector_start)
434  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
435  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_sw))
436  #define PRIV(cc)         (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
437    
438    #if defined COMPILE_PCRE8
439    #define MOV_UCHAR  SLJIT_MOV_UB
440    #define MOVU_UCHAR SLJIT_MOVU_UB
441    #elif defined COMPILE_PCRE16
442    #define MOV_UCHAR  SLJIT_MOV_UH
443    #define MOVU_UCHAR SLJIT_MOVU_UH
444    #elif defined COMPILE_PCRE32
445    #define MOV_UCHAR  SLJIT_MOV_UI
446    #define MOVU_UCHAR SLJIT_MOVU_UI
447    #else
448    #error Unsupported compiling mode
449    #endif
450    
451  /* Shortcuts. */  /* Shortcuts. */
452  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 386  the start pointers when the end of the c Line 463  the start pointers when the end of the c
463    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
464  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
465    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
466    #define SET_LABEL(jump, label) \
467      sljit_set_label((jump), (label))
468  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
469    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
470  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
471    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))
472  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
473    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
474    #define GET_LOCAL_BASE(dst, dstw, offset) \
475      sljit_get_local_base(compiler, (dst), (dstw), (offset))
476    
477  static uschar* bracketend(uschar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
478  {  {
479  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
480  do cc += GET(cc, 1); while (*cc == OP_ALT);  do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 404  return cc; Line 485  return cc;
485    
486  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
487   next_opcode   next_opcode
488   get_localspace   get_private_data_length
489   set_localptrs   set_private_data_ptrs
490   get_framesize   get_framesize
491   init_frame   init_frame
492   get_localsize   get_private_data_length_for_copy
493   copy_locals   copy_private_data
494   compile_hotpath   compile_matchingpath
495   compile_fallbackpath   compile_backtrackingpath
496  */  */
497    
498  static uschar *next_opcode(compiler_common *common, uschar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
499  {  {
500  SLJIT_UNUSED_ARG(common);  SLJIT_UNUSED_ARG(common);
501  switch(*cc)  switch(*cc)
# Line 432  switch(*cc) Line 513  switch(*cc)
513    case OP_WORDCHAR:    case OP_WORDCHAR:
514    case OP_ANY:    case OP_ANY:
515    case OP_ALLANY:    case OP_ALLANY:
516      case OP_NOTPROP:
517      case OP_PROP:
518    case OP_ANYNL:    case OP_ANYNL:
519    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
520    case OP_HSPACE:    case OP_HSPACE:
# Line 444  switch(*cc) Line 527  switch(*cc)
527    case OP_CIRCM:    case OP_CIRCM:
528    case OP_DOLL:    case OP_DOLL:
529    case OP_DOLLM:    case OP_DOLLM:
   case OP_TYPESTAR:  
   case OP_TYPEMINSTAR:  
   case OP_TYPEPLUS:  
   case OP_TYPEMINPLUS:  
   case OP_TYPEQUERY:  
   case OP_TYPEMINQUERY:  
   case OP_TYPEPOSSTAR:  
   case OP_TYPEPOSPLUS:  
   case OP_TYPEPOSQUERY:  
530    case OP_CRSTAR:    case OP_CRSTAR:
531    case OP_CRMINSTAR:    case OP_CRMINSTAR:
532    case OP_CRPLUS:    case OP_CRPLUS:
533    case OP_CRMINPLUS:    case OP_CRMINPLUS:
534    case OP_CRQUERY:    case OP_CRQUERY:
535    case OP_CRMINQUERY:    case OP_CRMINQUERY:
536      case OP_CRRANGE:
537      case OP_CRMINRANGE:
538      case OP_CLASS:
539      case OP_NCLASS:
540      case OP_REF:
541      case OP_REFI:
542      case OP_RECURSE:
543      case OP_CALLOUT:
544      case OP_ALT:
545      case OP_KET:
546      case OP_KETRMAX:
547      case OP_KETRMIN:
548      case OP_KETRPOS:
549      case OP_REVERSE:
550      case OP_ASSERT:
551      case OP_ASSERT_NOT:
552      case OP_ASSERTBACK:
553      case OP_ASSERTBACK_NOT:
554      case OP_ONCE:
555      case OP_ONCE_NC:
556      case OP_BRA:
557      case OP_BRAPOS:
558      case OP_CBRA:
559      case OP_CBRAPOS:
560      case OP_COND:
561      case OP_SBRA:
562      case OP_SBRAPOS:
563      case OP_SCBRA:
564      case OP_SCBRAPOS:
565      case OP_SCOND:
566      case OP_CREF:
567      case OP_NCREF:
568      case OP_RREF:
569      case OP_NRREF:
570    case OP_DEF:    case OP_DEF:
571    case OP_BRAZERO:    case OP_BRAZERO:
572    case OP_BRAMINZERO:    case OP_BRAMINZERO:
573    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
574      case OP_COMMIT:
575    case OP_FAIL:    case OP_FAIL:
576    case OP_ACCEPT:    case OP_ACCEPT:
577    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
578      case OP_CLOSE:
579    case OP_SKIPZERO:    case OP_SKIPZERO:
580    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
581    
582    case OP_CHAR:    case OP_CHAR:
583    case OP_CHARI:    case OP_CHARI:
584    case OP_NOT:    case OP_NOT:
585    case OP_NOTI:    case OP_NOTI:
   
586    case OP_STAR:    case OP_STAR:
587    case OP_MINSTAR:    case OP_MINSTAR:
588    case OP_PLUS:    case OP_PLUS:
589    case OP_MINPLUS:    case OP_MINPLUS:
590    case OP_QUERY:    case OP_QUERY:
591    case OP_MINQUERY:    case OP_MINQUERY:
592      case OP_UPTO:
593      case OP_MINUPTO:
594      case OP_EXACT:
595    case OP_POSSTAR:    case OP_POSSTAR:
596    case OP_POSPLUS:    case OP_POSPLUS:
597    case OP_POSQUERY:    case OP_POSQUERY:
598      case OP_POSUPTO:
599    case OP_STARI:    case OP_STARI:
600    case OP_MINSTARI:    case OP_MINSTARI:
601    case OP_PLUSI:    case OP_PLUSI:
602    case OP_MINPLUSI:    case OP_MINPLUSI:
603    case OP_QUERYI:    case OP_QUERYI:
604    case OP_MINQUERYI:    case OP_MINQUERYI:
605      case OP_UPTOI:
606      case OP_MINUPTOI:
607      case OP_EXACTI:
608    case OP_POSSTARI:    case OP_POSSTARI:
609    case OP_POSPLUSI:    case OP_POSPLUSI:
610    case OP_POSQUERYI:    case OP_POSQUERYI:
611      case OP_POSUPTOI:
612    case OP_NOTSTAR:    case OP_NOTSTAR:
613    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
614    case OP_NOTPLUS:    case OP_NOTPLUS:
615    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
616    case OP_NOTQUERY:    case OP_NOTQUERY:
617    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
618      case OP_NOTUPTO:
619      case OP_NOTMINUPTO:
620      case OP_NOTEXACT:
621    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
622    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
623    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
624      case OP_NOTPOSUPTO:
625    case OP_NOTSTARI:    case OP_NOTSTARI:
626    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
627    case OP_NOTPLUSI:    case OP_NOTPLUSI:
628    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
629    case OP_NOTQUERYI:    case OP_NOTQUERYI:
630    case OP_NOTMINQUERYI:    case OP_NOTMINQUERYI:
   case OP_NOTPOSSTARI:  
   case OP_NOTPOSPLUSI:  
   case OP_NOTPOSQUERYI:  
   cc += 2;  
 #ifdef SUPPORT_UTF8  
   if (common->utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];  
 #endif  
   return cc;  
   
   case OP_UPTO:  
   case OP_MINUPTO:  
   case OP_EXACT:  
   case OP_POSUPTO:  
   case OP_UPTOI:  
   case OP_MINUPTOI:  
   case OP_EXACTI:  
   case OP_POSUPTOI:  
   case OP_NOTUPTO:  
   case OP_NOTMINUPTO:  
   case OP_NOTEXACT:  
   case OP_NOTPOSUPTO:  
631    case OP_NOTUPTOI:    case OP_NOTUPTOI:
632    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
633    case OP_NOTEXACTI:    case OP_NOTEXACTI:
634      case OP_NOTPOSSTARI:
635      case OP_NOTPOSPLUSI:
636      case OP_NOTPOSQUERYI:
637    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
638    cc += 4;    cc += PRIV(OP_lengths)[*cc];
639  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
640    if (common->utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
641  #endif  #endif
642    return cc;    return cc;
643    
644    case OP_NOTPROP:    /* Special cases. */
645    case OP_PROP:    case OP_TYPESTAR:
646      case OP_TYPEMINSTAR:
647      case OP_TYPEPLUS:
648      case OP_TYPEMINPLUS:
649      case OP_TYPEQUERY:
650      case OP_TYPEMINQUERY:
651    case OP_TYPEUPTO:    case OP_TYPEUPTO:
652    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
653    case OP_TYPEEXACT:    case OP_TYPEEXACT:
654      case OP_TYPEPOSSTAR:
655      case OP_TYPEPOSPLUS:
656      case OP_TYPEPOSQUERY:
657    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
658    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_CLOSE:  
   cc += 3;  
   return cc;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   return cc + 5;  
659    
660    case OP_CLASS:    case OP_ANYBYTE:
661    case OP_NCLASS:  #ifdef SUPPORT_UTF
662    return cc + 33;    if (common->utf) return NULL;
663    #endif
664      return cc + 1;
665    
666  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
667    case OP_XCLASS:    case OP_XCLASS:
668    return cc + GET(cc, 1);    return cc + GET(cc, 1);
669  #endif  #endif
670    
671    case OP_RECURSE:    case OP_MARK:
672    case OP_ASSERT:    return cc + 1 + 2 + cc[1];
   case OP_ASSERT_NOT:  
   case OP_ASSERTBACK:  
   case OP_ASSERTBACK_NOT:  
   case OP_REVERSE:  
   case OP_ONCE:  
   case OP_BRA:  
   case OP_BRAPOS:  
   case OP_COND:  
   case OP_SBRA:  
   case OP_SBRAPOS:  
   case OP_SCOND:  
   case OP_ALT:  
   case OP_KET:  
   case OP_KETRMAX:  
   case OP_KETRMIN:  
   case OP_KETRPOS:  
   return cc + 1 + LINK_SIZE;  
   
   case OP_CBRA:  
   case OP_CBRAPOS:  
   case OP_SCBRA:  
   case OP_SCBRAPOS:  
   return cc + 1 + LINK_SIZE + 2;  
673    
674    default:    default:
675    return NULL;    return NULL;
676    }    }
677  }  }
678    
679  static int get_localspace(compiler_common *common, uschar *cc, uschar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
680        case OP_MINSTAR: \
681        case OP_MINPLUS: \
682        case OP_QUERY: \
683        case OP_MINQUERY: \
684        case OP_MINSTARI: \
685        case OP_MINPLUSI: \
686        case OP_QUERYI: \
687        case OP_MINQUERYI: \
688        case OP_NOTMINSTAR: \
689        case OP_NOTMINPLUS: \
690        case OP_NOTQUERY: \
691        case OP_NOTMINQUERY: \
692        case OP_NOTMINSTARI: \
693        case OP_NOTMINPLUSI: \
694        case OP_NOTQUERYI: \
695        case OP_NOTMINQUERYI:
696    
697    #define CASE_ITERATOR_PRIVATE_DATA_2A \
698        case OP_STAR: \
699        case OP_PLUS: \
700        case OP_STARI: \
701        case OP_PLUSI: \
702        case OP_NOTSTAR: \
703        case OP_NOTPLUS: \
704        case OP_NOTSTARI: \
705        case OP_NOTPLUSI:
706    
707    #define CASE_ITERATOR_PRIVATE_DATA_2B \
708        case OP_UPTO: \
709        case OP_MINUPTO: \
710        case OP_UPTOI: \
711        case OP_MINUPTOI: \
712        case OP_NOTUPTO: \
713        case OP_NOTMINUPTO: \
714        case OP_NOTUPTOI: \
715        case OP_NOTMINUPTOI:
716    
717    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
718        case OP_TYPEMINSTAR: \
719        case OP_TYPEMINPLUS: \
720        case OP_TYPEQUERY: \
721        case OP_TYPEMINQUERY:
722    
723    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
724        case OP_TYPESTAR: \
725        case OP_TYPEPLUS:
726    
727    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
728        case OP_TYPEUPTO: \
729        case OP_TYPEMINUPTO:
730    
731    static int get_class_iterator_size(pcre_uchar *cc)
732  {  {
733  int localspace = 0;  switch(*cc)
734  uschar *alternative;    {
735      case OP_CRSTAR:
736      case OP_CRPLUS:
737      return 2;
738    
739      case OP_CRMINSTAR:
740      case OP_CRMINPLUS:
741      case OP_CRQUERY:
742      case OP_CRMINQUERY:
743      return 1;
744    
745      case OP_CRRANGE:
746      case OP_CRMINRANGE:
747      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
748        return 0;
749      return 2;
750    
751      default:
752      return 0;
753      }
754    }
755    
756    static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
757    {
758    int private_data_length = 0;
759    pcre_uchar *alternative;
760    pcre_uchar *name;
761    pcre_uchar *end = NULL;
762    int space, size, i;
763    pcre_uint32 bracketlen;
764    
765  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
766  while (cc < ccend)  while (cc < ccend)
767    {    {
768      space = 0;
769      size = 0;
770      bracketlen = 0;
771    switch(*cc)    switch(*cc)
772      {      {
773        case OP_SET_SOM:
774        common->has_set_som = TRUE;
775        cc += 1;
776        break;
777    
778        case OP_REF:
779        case OP_REFI:
780        common->optimized_cbracket[GET2(cc, 1)] = 0;
781        cc += 1 + IMM2_SIZE;
782        break;
783    
784      case OP_ASSERT:      case OP_ASSERT:
785      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
786      case OP_ASSERTBACK:      case OP_ASSERTBACK:
787      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
788      case OP_ONCE:      case OP_ONCE:
789        case OP_ONCE_NC:
790      case OP_BRAPOS:      case OP_BRAPOS:
791      case OP_SBRA:      case OP_SBRA:
792      case OP_SBRAPOS:      case OP_SBRAPOS:
793      case OP_SCOND:      private_data_length += sizeof(sljit_sw);
794      localspace += sizeof(sljit_w);      bracketlen = 1 + LINK_SIZE;
     cc += 1 + LINK_SIZE;  
795      break;      break;
796    
797      case OP_CBRAPOS:      case OP_CBRAPOS:
798      case OP_SCBRAPOS:      case OP_SCBRAPOS:
799      localspace += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
800      cc += 1 + LINK_SIZE + 2;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
801        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
802      break;      break;
803    
804      case OP_COND:      case OP_COND:
805      /* Might be a hidden SCOND. */      case OP_SCOND:
806      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
807      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
808        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
809          return -1;
810    
811        if (*cc == OP_COND)
812          {
813          /* Might be a hidden SCOND. */
814          alternative = cc + GET(cc, 1);
815          if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
816            private_data_length += sizeof(sljit_sw);
817          }
818        else
819          private_data_length += sizeof(sljit_sw);
820        bracketlen = 1 + LINK_SIZE;
821        break;
822    
823        case OP_CREF:
824        i = GET2(cc, 1);
825        common->optimized_cbracket[i] = 0;
826        cc += 1 + IMM2_SIZE;
827        break;
828    
829        case OP_NCREF:
830        bracketlen = GET2(cc, 1);
831        name = (pcre_uchar *)common->name_table;
832        alternative = name;
833        for (i = 0; i < common->name_count; i++)
834          {
835          if (GET2(name, 0) == bracketlen) break;
836          name += common->name_entry_size;
837          }
838        SLJIT_ASSERT(i != common->name_count);
839    
840        for (i = 0; i < common->name_count; i++)
841          {
842          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
843            common->optimized_cbracket[GET2(alternative, 0)] = 0;
844          alternative += common->name_entry_size;
845          }
846        bracketlen = 0;
847        cc += 1 + IMM2_SIZE;
848        break;
849    
850        case OP_BRA:
851        bracketlen = 1 + LINK_SIZE;
852        break;
853    
854        case OP_CBRA:
855        case OP_SCBRA:
856        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
857        break;
858    
859        CASE_ITERATOR_PRIVATE_DATA_1
860        space = 1;
861        size = -2;
862        break;
863    
864        CASE_ITERATOR_PRIVATE_DATA_2A
865        space = 2;
866        size = -2;
867        break;
868    
869        CASE_ITERATOR_PRIVATE_DATA_2B
870        space = 2;
871        size = -(2 + IMM2_SIZE);
872        break;
873    
874        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
875        space = 1;
876        size = 1;
877        break;
878    
879        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
880        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
881          space = 2;
882        size = 1;
883        break;
884    
885        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
886        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
887          space = 2;
888        size = 1 + IMM2_SIZE;
889        break;
890    
891        case OP_CLASS:
892        case OP_NCLASS:
893        size += 1 + 32 / sizeof(pcre_uchar);
894        space = get_class_iterator_size(cc + size);
895        break;
896    
897    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
898        case OP_XCLASS:
899        size = GET(cc, 1);
900        space = get_class_iterator_size(cc + size);
901        break;
902    #endif
903    
904        case OP_RECURSE:
905        /* Set its value only once. */
906        if (common->recursive_head_ptr == 0)
907          {
908          common->recursive_head_ptr = common->ovector_start;
909          common->ovector_start += sizeof(sljit_sw);
910          }
911      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
912      break;      break;
913    
914        case OP_CALLOUT:
915        if (common->capture_last_ptr == 0)
916          {
917          common->capture_last_ptr = common->ovector_start;
918          common->ovector_start += sizeof(sljit_sw);
919          }
920        cc += 2 + 2 * LINK_SIZE;
921        break;
922    
923        case OP_MARK:
924        if (common->mark_ptr == 0)
925          {
926          common->mark_ptr = common->ovector_start;
927          common->ovector_start += sizeof(sljit_sw);
928          }
929        cc += 1 + 2 + cc[1];
930        break;
931    
932      default:      default:
933      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
934      if (cc == NULL)      if (cc == NULL)
935        return -1;        return -1;
936      break;      break;
937      }      }
938    
939      if (space > 0 && cc >= end)
940        private_data_length += sizeof(sljit_sw) * space;
941    
942      if (size != 0)
943        {
944        if (size < 0)
945          {
946          cc += -size;
947    #ifdef SUPPORT_UTF
948          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
949    #endif
950          }
951        else
952          cc += size;
953        }
954    
955      if (bracketlen != 0)
956        {
957        if (cc >= end)
958          {
959          end = bracketend(cc);
960          if (end[-1 - LINK_SIZE] == OP_KET)
961            end = NULL;
962          }
963        cc += bracketlen;
964        }
965    }    }
966  return localspace;  return private_data_length;
967  }  }
968    
969  static void set_localptrs(compiler_common *common, int localptr, uschar *ccend)  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)
970  {  {
971  uschar *cc = common->start;  pcre_uchar *cc = common->start;
972  uschar *alternative;  pcre_uchar *alternative;
973    pcre_uchar *end = NULL;
974    int space, size, bracketlen;
975    
976  while (cc < ccend)  while (cc < ccend)
977    {    {
978      space = 0;
979      size = 0;
980      bracketlen = 0;
981    switch(*cc)    switch(*cc)
982      {      {
983      case OP_ASSERT:      case OP_ASSERT:
# Line 654  while (cc < ccend) Line 985  while (cc < ccend)
985      case OP_ASSERTBACK:      case OP_ASSERTBACK:
986      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
987      case OP_ONCE:      case OP_ONCE:
988        case OP_ONCE_NC:
989      case OP_BRAPOS:      case OP_BRAPOS:
990      case OP_SBRA:      case OP_SBRA:
991      case OP_SBRAPOS:      case OP_SBRAPOS:
992      case OP_SCOND:      case OP_SCOND:
993      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
994      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
995      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
996      break;      break;
997    
998      case OP_CBRAPOS:      case OP_CBRAPOS:
999      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1000      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1001      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1002      cc += 1 + LINK_SIZE + 2;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1003      break;      break;
1004    
1005      case OP_COND:      case OP_COND:
# Line 675  while (cc < ccend) Line 1007  while (cc < ccend)
1007      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1008      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1009        {        {
1010        common->localptrs[cc - common->start] = localptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1011        localptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1012        }        }
1013      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1014        break;
1015    
1016        case OP_BRA:
1017        bracketlen = 1 + LINK_SIZE;
1018      break;      break;
1019    
1020        case OP_CBRA:
1021        case OP_SCBRA:
1022        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1023        break;
1024    
1025        CASE_ITERATOR_PRIVATE_DATA_1
1026        space = 1;
1027        size = -2;
1028        break;
1029    
1030        CASE_ITERATOR_PRIVATE_DATA_2A
1031        space = 2;
1032        size = -2;
1033        break;
1034    
1035        CASE_ITERATOR_PRIVATE_DATA_2B
1036        space = 2;
1037        size = -(2 + IMM2_SIZE);
1038        break;
1039    
1040        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1041        space = 1;
1042        size = 1;
1043        break;
1044    
1045        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1046        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1047          space = 2;
1048        size = 1;
1049        break;
1050    
1051        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1052        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1053          space = 2;
1054        size = 1 + IMM2_SIZE;
1055        break;
1056    
1057        case OP_CLASS:
1058        case OP_NCLASS:
1059        size += 1 + 32 / sizeof(pcre_uchar);
1060        space = get_class_iterator_size(cc + size);
1061        break;
1062    
1063    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1064        case OP_XCLASS:
1065        size = GET(cc, 1);
1066        space = get_class_iterator_size(cc + size);
1067        break;
1068    #endif
1069    
1070      default:      default:
1071      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1072      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1073      break;      break;
1074      }      }
1075    
1076      if (space > 0 && cc >= end)
1077        {
1078        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1079        private_data_ptr += sizeof(sljit_sw) * space;
1080        }
1081    
1082      if (size != 0)
1083        {
1084        if (size < 0)
1085          {
1086          cc += -size;
1087    #ifdef SUPPORT_UTF
1088          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1089    #endif
1090          }
1091        else
1092          cc += size;
1093        }
1094    
1095      if (bracketlen > 0)
1096        {
1097        if (cc >= end)
1098          {
1099          end = bracketend(cc);
1100          if (end[-1 - LINK_SIZE] == OP_KET)
1101            end = NULL;
1102          }
1103        cc += bracketlen;
1104        }
1105    }    }
1106  }  }
1107    
1108  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1109  static int get_framesize(compiler_common *common, uschar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)
1110  {  {
1111  uschar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
 uschar *end;  
1112  int length = 0;  int length = 0;
1113  BOOL possessive = FALSE;  int possessive = 0;
1114  BOOL needs_frame = FALSE;  BOOL stack_restore = FALSE;
1115  BOOL setsom_found = FALSE;  BOOL setsom_found = recursive;
1116    BOOL setmark_found = recursive;
1117    /* The last capture is a local variable even for recursions. */
1118    BOOL capture_last_found = FALSE;
1119    
1120  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1121    {    {
1122    length = 3;    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1123    possessive = TRUE;    /* This is correct regardless of common->capture_last_ptr. */
1124      capture_last_found = TRUE;
1125    }    }
1126    
1127  cc = next_opcode(common, cc);  cc = next_opcode(common, cc);
# Line 711  while (cc < ccend) Line 1130  while (cc < ccend)
1130    switch(*cc)    switch(*cc)
1131      {      {
1132      case OP_SET_SOM:      case OP_SET_SOM:
1133      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1134        stack_restore = TRUE;
1135      if (!setsom_found)      if (!setsom_found)
1136        {        {
1137        length += 2;        length += 2;
1138        setsom_found = TRUE;        setsom_found = TRUE;
1139        }        }
1140      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      cc += 1;
1141      break;      break;
1142    
1143      case OP_ASSERT:      case OP_MARK:
1144      case OP_ASSERT_NOT:      SLJIT_ASSERT(common->mark_ptr != 0);
1145      case OP_ASSERTBACK:      stack_restore = TRUE;
1146      case OP_ASSERTBACK_NOT:      if (!setmark_found)
     case OP_ONCE:  
     if (needs_frame || length > 0)  
1147        {        {
1148        cc = bracketend(cc);        length += 2;
1149        break;        setmark_found = TRUE;
1150        }        }
1151      /* Check whether a frame must be created. */      cc += 1 + 2 + cc[1];
1152      end = bracketend(cc);      break;
1153      while (cc < end)  
1154        {      case OP_RECURSE:
1155        if (*cc == OP_SET_SOM || *cc == OP_CBRA || *cc == OP_CBRAPOS      stack_restore = TRUE;
1156            || *cc == OP_SCBRA || *cc == OP_SCBRAPOS || *cc == OP_RECURSE)      if (common->has_set_som && !setsom_found)
1157          needs_frame = TRUE;        {
1158        cc = next_opcode(common, cc);        length += 2;
1159        SLJIT_ASSERT(cc != NULL);        setsom_found = TRUE;
1160        }        }
1161        if (common->mark_ptr != 0 && !setmark_found)
1162          {
1163          length += 2;
1164          setmark_found = TRUE;
1165          }
1166        if (common->capture_last_ptr != 0 && !capture_last_found)
1167          {
1168          length += 2;
1169          capture_last_found = TRUE;
1170          }
1171        cc += 1 + LINK_SIZE;
1172      break;      break;
1173    
1174      case OP_CBRA:      case OP_CBRA:
1175      case OP_CBRAPOS:      case OP_CBRAPOS:
1176      case OP_SCBRA:      case OP_SCBRA:
1177      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1178        stack_restore = TRUE;
1179        if (common->capture_last_ptr != 0 && !capture_last_found)
1180          {
1181          length += 2;
1182          capture_last_found = TRUE;
1183          }
1184      length += 3;      length += 3;
1185      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1186      break;      break;
1187    
1188      default:      default:
1189        stack_restore = TRUE;
1190        /* Fall through. */
1191    
1192        case OP_NOT_WORD_BOUNDARY:
1193        case OP_WORD_BOUNDARY:
1194        case OP_NOT_DIGIT:
1195        case OP_DIGIT:
1196        case OP_NOT_WHITESPACE:
1197        case OP_WHITESPACE:
1198        case OP_NOT_WORDCHAR:
1199        case OP_WORDCHAR:
1200        case OP_ANY:
1201        case OP_ALLANY:
1202        case OP_ANYBYTE:
1203        case OP_NOTPROP:
1204        case OP_PROP:
1205        case OP_ANYNL:
1206        case OP_NOT_HSPACE:
1207        case OP_HSPACE:
1208        case OP_NOT_VSPACE:
1209        case OP_VSPACE:
1210        case OP_EXTUNI:
1211        case OP_EODN:
1212        case OP_EOD:
1213        case OP_CIRC:
1214        case OP_CIRCM:
1215        case OP_DOLL:
1216        case OP_DOLLM:
1217        case OP_CHAR:
1218        case OP_CHARI:
1219        case OP_NOT:
1220        case OP_NOTI:
1221    
1222        case OP_EXACT:
1223        case OP_POSSTAR:
1224        case OP_POSPLUS:
1225        case OP_POSQUERY:
1226        case OP_POSUPTO:
1227    
1228        case OP_EXACTI:
1229        case OP_POSSTARI:
1230        case OP_POSPLUSI:
1231        case OP_POSQUERYI:
1232        case OP_POSUPTOI:
1233    
1234        case OP_NOTEXACT:
1235        case OP_NOTPOSSTAR:
1236        case OP_NOTPOSPLUS:
1237        case OP_NOTPOSQUERY:
1238        case OP_NOTPOSUPTO:
1239    
1240        case OP_NOTEXACTI:
1241        case OP_NOTPOSSTARI:
1242        case OP_NOTPOSPLUSI:
1243        case OP_NOTPOSQUERYI:
1244        case OP_NOTPOSUPTOI:
1245    
1246        case OP_TYPEEXACT:
1247        case OP_TYPEPOSSTAR:
1248        case OP_TYPEPOSPLUS:
1249        case OP_TYPEPOSQUERY:
1250        case OP_TYPEPOSUPTO:
1251    
1252        case OP_CLASS:
1253        case OP_NCLASS:
1254        case OP_XCLASS:
1255    
1256      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1257      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1258      break;      break;
1259      }      }
1260    
1261  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1262  if (SLJIT_UNLIKELY(possessive) && !needs_frame && length == 3 + 2)  if (SLJIT_UNLIKELY(possessive == length))
1263    return -1;    return stack_restore ? no_frame : no_stack;
1264    
1265  if (length > 0)  if (length > 0)
1266    return length + 2;    return length + 1;
1267  return needs_frame ? 0 : -1;  return stack_restore ? no_frame : no_stack;
1268  }  }
1269    
1270  static void init_frame(compiler_common *common, uschar *cc, int stackpos, int stacktop, BOOL recursive)  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)
1271  {  {
 /* TMP2 must contain STACK_TOP - (-STACK(stackpos)) */  
1272  DEFINE_COMPILER;  DEFINE_COMPILER;
1273  uschar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1274  BOOL setsom_found = FALSE;  BOOL setsom_found = recursive;
1275    BOOL setmark_found = recursive;
1276    /* The last capture is a local variable even for recursions. */
1277    BOOL capture_last_found = FALSE;
1278  int offset;  int offset;
1279    
1280  if (stackpos < stacktop)  /* >= 1 + shortest item size (2) */
1281    {  SLJIT_UNUSED_ARG(stacktop);
1282    SLJIT_ASSERT(stackpos + 1 == stacktop);  SLJIT_ASSERT(stackpos >= stacktop + 2);
   return;  
   }  
1283    
1284  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS_HEAD);  
 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS_HEAD, TMP2, 0);  
 OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacktop), TMP1, 0);  
   
1285  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1286    cc = next_opcode(common, cc);    cc = next_opcode(common, cc);
1287  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
# Line 791  while (cc < ccend) Line 1289  while (cc < ccend)
1289    switch(*cc)    switch(*cc)
1290      {      {
1291      case OP_SET_SOM:      case OP_SET_SOM:
1292      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1293      if (!setsom_found)      if (!setsom_found)
1294        {        {
1295        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1296        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1297        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1298        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1299        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1300        setsom_found = TRUE;        setsom_found = TRUE;
1301        }        }
1302      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      cc += 1;
1303      break;      break;
1304    
1305      case OP_ASSERT:      case OP_MARK:
1306      case OP_ASSERT_NOT:      SLJIT_ASSERT(common->mark_ptr != 0);
1307      case OP_ASSERTBACK:      if (!setmark_found)
1308      case OP_ASSERTBACK_NOT:        {
1309      case OP_ONCE:        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1310      cc = bracketend(cc);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1311          stackpos += (int)sizeof(sljit_sw);
1312          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1313          stackpos += (int)sizeof(sljit_sw);
1314          setmark_found = TRUE;
1315          }
1316        cc += 1 + 2 + cc[1];
1317        break;
1318    
1319        case OP_RECURSE:
1320        if (common->has_set_som && !setsom_found)
1321          {
1322          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1323          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1324          stackpos += (int)sizeof(sljit_sw);
1325          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1326          stackpos += (int)sizeof(sljit_sw);
1327          setsom_found = TRUE;
1328          }
1329        if (common->mark_ptr != 0 && !setmark_found)
1330          {
1331          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1332          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1333          stackpos += (int)sizeof(sljit_sw);
1334          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1335          stackpos += (int)sizeof(sljit_sw);
1336          setmark_found = TRUE;
1337          }
1338        if (common->capture_last_ptr != 0 && !capture_last_found)
1339          {
1340          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1341          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1342          stackpos += (int)sizeof(sljit_sw);
1343          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1344          stackpos += (int)sizeof(sljit_sw);
1345          capture_last_found = TRUE;
1346          }
1347        cc += 1 + LINK_SIZE;
1348      break;      break;
1349    
1350      case OP_CBRA:      case OP_CBRA:
1351      case OP_CBRAPOS:      case OP_CBRAPOS:
1352      case OP_SCBRA:      case OP_SCBRA:
1353      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1354        if (common->capture_last_ptr != 0 && !capture_last_found)
1355          {
1356          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1357          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1358          stackpos += (int)sizeof(sljit_sw);
1359          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1360          stackpos += (int)sizeof(sljit_sw);
1361          capture_last_found = TRUE;
1362          }
1363      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1364      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1365      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1366      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1367      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
1368      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1369      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1370      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1371      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1372    
1373      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1374      break;      break;
1375    
1376      default:      default:
# Line 835  while (cc < ccend) Line 1379  while (cc < ccend)
1379      break;      break;
1380      }      }
1381    
1382  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1383  SLJIT_ASSERT(stackpos == STACK(stacktop + 1));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1384  }  }
1385    
1386  static SLJIT_INLINE int get_localsize(compiler_common *common, uschar *cc, uschar *ccend)  static SLJIT_INLINE int get_private_data_length_for_copy(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
1387  {  {
1388  int localsize = 2;  int private_data_length = 2;
1389  uschar *alternative;  int size;
1390  /* Calculate the sum of the local variables. */  pcre_uchar *alternative;
1391    /* Calculate the sum of the private machine words. */
1392  while (cc < ccend)  while (cc < ccend)
1393    {    {
1394      size = 0;
1395    switch(*cc)    switch(*cc)
1396      {      {
1397      case OP_ASSERT:      case OP_ASSERT:
# Line 853  while (cc < ccend) Line 1399  while (cc < ccend)
1399      case OP_ASSERTBACK:      case OP_ASSERTBACK:
1400      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1401      case OP_ONCE:      case OP_ONCE:
1402        case OP_ONCE_NC:
1403      case OP_BRAPOS:      case OP_BRAPOS:
1404      case OP_SBRA:      case OP_SBRA:
1405      case OP_SBRAPOS:      case OP_SBRAPOS:
1406      case OP_SCOND:      case OP_SCOND:
1407      localsize++;      private_data_length++;
1408      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1409      break;      break;
1410    
1411      case OP_CBRA:      case OP_CBRA:
1412      case OP_SCBRA:      case OP_SCBRA:
1413      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1414      cc += 1 + LINK_SIZE + 2;        private_data_length++;
1415        cc += 1 + LINK_SIZE + IMM2_SIZE;
1416      break;      break;
1417    
1418      case OP_CBRAPOS:      case OP_CBRAPOS:
1419      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1420      localsize += 2;      private_data_length += 2;
1421      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1422      break;      break;
1423    
1424      case OP_COND:      case OP_COND:
1425      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1426      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1427      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1428        localsize++;        private_data_length++;
1429      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1430      break;      break;
1431    
1432        CASE_ITERATOR_PRIVATE_DATA_1
1433        if (PRIVATE_DATA(cc))
1434          private_data_length++;
1435        cc += 2;
1436    #ifdef SUPPORT_UTF
1437        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1438    #endif
1439        break;
1440    
1441        CASE_ITERATOR_PRIVATE_DATA_2A
1442        if (PRIVATE_DATA(cc))
1443          private_data_length += 2;
1444        cc += 2;
1445    #ifdef SUPPORT_UTF
1446        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1447    #endif
1448        break;
1449    
1450        CASE_ITERATOR_PRIVATE_DATA_2B
1451        if (PRIVATE_DATA(cc))
1452          private_data_length += 2;
1453        cc += 2 + IMM2_SIZE;
1454    #ifdef SUPPORT_UTF
1455        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1456    #endif
1457        break;
1458    
1459        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1460        if (PRIVATE_DATA(cc))
1461          private_data_length++;
1462        cc += 1;
1463        break;
1464    
1465        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1466        if (PRIVATE_DATA(cc))
1467          private_data_length += 2;
1468        cc += 1;
1469        break;
1470    
1471        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1472        if (PRIVATE_DATA(cc))
1473          private_data_length += 2;
1474        cc += 1 + IMM2_SIZE;
1475        break;
1476    
1477        case OP_CLASS:
1478        case OP_NCLASS:
1479    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1480        case OP_XCLASS:
1481        size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1482    #else
1483        size = 1 + 32 / (int)sizeof(pcre_uchar);
1484    #endif
1485        if (PRIVATE_DATA(cc))
1486          private_data_length += get_class_iterator_size(cc + size);
1487        cc += size;
1488        break;
1489    
1490      default:      default:
1491      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1492      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 888  while (cc < ccend) Line 1494  while (cc < ccend)
1494      }      }
1495    }    }
1496  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1497  return localsize;  return private_data_length;
1498  }  }
1499    
1500  static void copy_locals(compiler_common *common, uschar *cc, uschar *ccend,  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,
1501    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop)
1502  {  {
1503  DEFINE_COMPILER;  DEFINE_COMPILER;
1504  int srcw[2];  int srcw[2];
1505  int count;  int count, size;
1506  BOOL tmp1next = TRUE;  BOOL tmp1next = TRUE;
1507  BOOL tmp1empty = TRUE;  BOOL tmp1empty = TRUE;
1508  BOOL tmp2empty = TRUE;  BOOL tmp2empty = TRUE;
1509  uschar *alternative;  pcre_uchar *alternative;
1510  enum {  enum {
1511    start,    start,
1512    loop,    loop,
# Line 913  stacktop = STACK(stacktop - 1); Line 1519  stacktop = STACK(stacktop - 1);
1519    
1520  if (!save)  if (!save)
1521    {    {
1522    stackptr += sizeof(sljit_w);    stackptr += sizeof(sljit_sw);
1523    if (stackptr < stacktop)    if (stackptr < stacktop)
1524      {      {
1525      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1526      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1527      tmp1empty = FALSE;      tmp1empty = FALSE;
1528      }      }
1529    if (stackptr < stacktop)    if (stackptr < stacktop)
1530      {      {
1531      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1532      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1533      tmp2empty = FALSE;      tmp2empty = FALSE;
1534      }      }
1535    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
# Line 935  while (status != end) Line 1541  while (status != end)
1541    switch(status)    switch(status)
1542      {      {
1543      case start:      case start:
1544      SLJIT_ASSERT(save);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1545      count = 1;      count = 1;
1546      srcw[0] = RECURSIVE_HEAD;      srcw[0] = common->recursive_head_ptr;
1547      status = loop;      status = loop;
1548      break;      break;
1549    
# Line 955  while (status != end) Line 1561  while (status != end)
1561        case OP_ASSERTBACK:        case OP_ASSERTBACK:
1562        case OP_ASSERTBACK_NOT:        case OP_ASSERTBACK_NOT:
1563        case OP_ONCE:        case OP_ONCE:
1564          case OP_ONCE_NC:
1565        case OP_BRAPOS:        case OP_BRAPOS:
1566        case OP_SBRA:        case OP_SBRA:
1567        case OP_SBRAPOS:        case OP_SBRAPOS:
1568        case OP_SCOND:        case OP_SCOND:
1569        count = 1;        count = 1;
1570        srcw[0] = PRIV(cc);        srcw[0] = PRIVATE_DATA(cc);
1571        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1572        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1573        break;        break;
1574    
1575        case OP_CBRA:        case OP_CBRA:
1576        case OP_SCBRA:        case OP_SCBRA:
1577        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1578        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1579        cc += 1 + LINK_SIZE + 2;          count = 1;
1580            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1581            }
1582          cc += 1 + LINK_SIZE + IMM2_SIZE;
1583        break;        break;
1584    
1585        case OP_CBRAPOS:        case OP_CBRAPOS:
1586        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1587        count = 2;        count = 2;
1588          srcw[0] = PRIVATE_DATA(cc);
1589        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1590        srcw[0] = PRIV(cc);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
1591        SLJIT_ASSERT(srcw[0] != 0);        cc += 1 + LINK_SIZE + IMM2_SIZE;
       cc += 1 + LINK_SIZE + 2;  
1592        break;        break;
1593    
1594        case OP_COND:        case OP_COND:
# Line 987  while (status != end) Line 1597  while (status != end)
1597        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1598          {          {
1599          count = 1;          count = 1;
1600          srcw[0] = PRIV(cc);          srcw[0] = PRIVATE_DATA(cc);
1601          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1602          }          }
1603        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1604        break;        break;
1605    
1606          CASE_ITERATOR_PRIVATE_DATA_1
1607          if (PRIVATE_DATA(cc))
1608            {
1609            count = 1;
1610            srcw[0] = PRIVATE_DATA(cc);
1611            }
1612          cc += 2;
1613    #ifdef SUPPORT_UTF
1614          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1615    #endif
1616          break;
1617    
1618          CASE_ITERATOR_PRIVATE_DATA_2A
1619          if (PRIVATE_DATA(cc))
1620            {
1621            count = 2;
1622            srcw[0] = PRIVATE_DATA(cc);
1623            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1624            }
1625          cc += 2;
1626    #ifdef SUPPORT_UTF
1627          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1628    #endif
1629          break;
1630    
1631          CASE_ITERATOR_PRIVATE_DATA_2B
1632          if (PRIVATE_DATA(cc))
1633            {
1634            count = 2;
1635            srcw[0] = PRIVATE_DATA(cc);
1636            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1637            }
1638          cc += 2 + IMM2_SIZE;
1639    #ifdef SUPPORT_UTF
1640          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1641    #endif
1642          break;
1643    
1644          CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1645          if (PRIVATE_DATA(cc))
1646            {
1647            count = 1;
1648            srcw[0] = PRIVATE_DATA(cc);
1649            }
1650          cc += 1;
1651          break;
1652    
1653          CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1654          if (PRIVATE_DATA(cc))
1655            {
1656            count = 2;
1657            srcw[0] = PRIVATE_DATA(cc);
1658            srcw[1] = srcw[0] + sizeof(sljit_sw);
1659            }
1660          cc += 1;
1661          break;
1662    
1663          CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1664          if (PRIVATE_DATA(cc))
1665            {
1666            count = 2;
1667            srcw[0] = PRIVATE_DATA(cc);
1668            srcw[1] = srcw[0] + sizeof(sljit_sw);
1669            }
1670          cc += 1 + IMM2_SIZE;
1671          break;
1672    
1673          case OP_CLASS:
1674          case OP_NCLASS:
1675    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1676          case OP_XCLASS:
1677          size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1678    #else
1679          size = 1 + 32 / (int)sizeof(pcre_uchar);
1680    #endif
1681          if (PRIVATE_DATA(cc))
1682            switch(get_class_iterator_size(cc + size))
1683              {
1684              case 1:
1685              count = 1;
1686              srcw[0] = PRIVATE_DATA(cc);
1687              break;
1688    
1689              case 2:
1690              count = 2;
1691              srcw[0] = PRIVATE_DATA(cc);
1692              srcw[1] = srcw[0] + sizeof(sljit_sw);
1693              break;
1694    
1695              default:
1696              SLJIT_ASSERT_STOP();
1697              break;
1698              }
1699          cc += size;
1700          break;
1701    
1702        default:        default:
1703        cc = next_opcode(common, cc);        cc = next_opcode(common, cc);
1704        SLJIT_ASSERT(cc != NULL);        SLJIT_ASSERT(cc != NULL);
# Line 1015  while (status != end) Line 1721  while (status != end)
1721          if (!tmp1empty)          if (!tmp1empty)
1722            {            {
1723            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1724            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1725            }            }
1726          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1727          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1026  while (status != end) Line 1732  while (status != end)
1732          if (!tmp2empty)          if (!tmp2empty)
1733            {            {
1734            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1735            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1736            }            }
1737          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1738          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1043  while (status != end) Line 1749  while (status != end)
1749          if (!tmp1empty)          if (!tmp1empty)
1750            {            {
1751            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1752            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1753            }            }
1754          tmp1next = FALSE;          tmp1next = FALSE;
1755          }          }
# Line 1055  while (status != end) Line 1761  while (status != end)
1761          if (!tmp2empty)          if (!tmp2empty)
1762            {            {
1763            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1764            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1765            }            }
1766          tmp1next = TRUE;          tmp1next = TRUE;
1767          }          }
# Line 1070  if (save) Line 1776  if (save)
1776      if (!tmp1empty)      if (!tmp1empty)
1777        {        {
1778        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1779        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1780        }        }
1781      if (!tmp2empty)      if (!tmp2empty)
1782        {        {
1783        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1784        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1785        }        }
1786      }      }
1787    else    else
# Line 1083  if (save) Line 1789  if (save)
1789      if (!tmp2empty)      if (!tmp2empty)
1790        {        {
1791        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1792        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1793        }        }
1794      if (!tmp1empty)      if (!tmp1empty)
1795        {        {
1796        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1797        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1798        }        }
1799      }      }
1800    }    }
1801  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1802  }  }
1803    
1804  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  #undef CASE_ITERATOR_PRIVATE_DATA_1
1805    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1806    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1807    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1808    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1809    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1810    
1811    static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1812  {  {
1813  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1814  }  }
# Line 1105  static SLJIT_INLINE void set_jumps(jump_ Line 1818  static SLJIT_INLINE void set_jumps(jump_
1818  while (list)  while (list)
1819    {    {
1820    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1821    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1822    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1823    list = list->next;    list = list->next;
1824    }    }
1825  }  }
# Line 1122  if (list_item) Line 1835  if (list_item)
1835    }    }
1836  }  }
1837    
1838  static void add_stub(compiler_common *common, enum stub_types type, int data, struct sljit_jump *start)  static void add_stub(compiler_common *common, struct sljit_jump *start)
1839  {  {
1840  DEFINE_COMPILER;  DEFINE_COMPILER;
1841  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1842    
1843  if (list_item)  if (list_item)
1844    {    {
   list_item->type = type;  
   list_item->data = data;  
1845    list_item->start = start;    list_item->start = start;
1846    list_item->leave = LABEL();    list_item->quit = LABEL();
1847    list_item->next = common->stubs;    list_item->next = common->stubs;
1848    common->stubs = list_item;    common->stubs = list_item;
1849    }    }
# Line 1146  stub_list* list_item = common->stubs; Line 1857  stub_list* list_item = common->stubs;
1857  while (list_item)  while (list_item)
1858    {    {
1859    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
1860    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
1861      {    JUMPTO(SLJIT_JUMP, list_item->quit);
     case stack_alloc:  
     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));  
     break;  
     }  
   JUMPTO(SLJIT_JUMP, list_item->leave);  
1862    list_item = list_item->next;    list_item = list_item->next;
1863    }    }
1864  common->stubs = NULL;  common->stubs = NULL;
# Line 1171  static SLJIT_INLINE void allocate_stack( Line 1877  static SLJIT_INLINE void allocate_stack(
1877  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
1878  DEFINE_COMPILER;  DEFINE_COMPILER;
1879    
1880  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
1881  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
1882  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
1883  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1179  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 1885  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
1885  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
1886  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
1887  #endif  #endif
1888  add_stub(common, stack_alloc, 0, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));  add_stub(common, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));
1889  }  }
1890    
1891  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
1892  {  {
1893  DEFINE_COMPILER;  DEFINE_COMPILER;
1894  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
1895  }  }
1896    
1897  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1195  struct sljit_label *loop; Line 1901  struct sljit_label *loop;
1901  int i;  int i;
1902  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
1903  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
1904  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_GENERAL_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, 1);  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
1905  if (length < 8)  if (length < 8)
1906    {    {
1907    for (i = 0; i < length; i++)    for (i = 0; i < length; i++)
1908      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_TEMPORARY_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
1909    }    }
1910  else  else
1911    {    {
1912    OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START - sizeof(sljit_sw));
1913    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length);
1914    loop = LABEL();    loop = LABEL();
1915    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
1916    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
1917    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
1918    }    }
1919  }  }
# Line 1216  static SLJIT_INLINE void copy_ovector(co Line 1922  static SLJIT_INLINE void copy_ovector(co
1922  {  {
1923  DEFINE_COMPILER;  DEFINE_COMPILER;
1924  struct sljit_label *loop;  struct sljit_label *loop;
1925  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
1926    
1927  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
1928  OP1(SLJIT_MOV, SLJIT_GENERAL_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
1929  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);
1930    
1931  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
1932  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  if (common->mark_ptr != 0)
1933  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1934  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offset_count));
1935  OP2(SLJIT_ADD, SLJIT_GENERAL_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START);  if (common->mark_ptr != 0)
1936      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);
1937    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
1938    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
1939    GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
1940  /* Unlikely, but possible */  /* Unlikely, but possible */
1941  earlyexit = CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0);  early_quit = CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
1942  loop = LABEL();  loop = LABEL();
1943  OP2(SLJIT_SUB, SLJIT_GENERAL_REG2, 0, SLJIT_MEM1(SLJIT_GENERAL_REG1), 0, SLJIT_TEMPORARY_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
1944  OP2(SLJIT_ADD, SLJIT_GENERAL_REG1, 0, SLJIT_GENERAL_REG1, 0, SLJIT_IMM, sizeof(sljit_w));  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
1945  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
1946  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_GENERAL_REG2, 0);  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1947  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
1948    #endif
1949    OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
1950    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
1951  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
1952  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
1953    
1954  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
1955  if (topbracket > 1)  if (topbracket > 1)
1956    {    {
1957    OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START + topbracket * 2 * sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
1958    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
1959    
1960    /* OVECTOR(0) is never equal to SLJIT_GENERAL_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
1961    loop = LABEL();    loop = LABEL();
1962    OP1(SLJIT_MOVU, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), -(2 * (sljit_w)sizeof(sljit_w)));    OP1(SLJIT_MOVU, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -(2 * (sljit_sw)sizeof(sljit_sw)));
1963    OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
1964    CMPTO(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG3, 0, SLJIT_GENERAL_REG3, 0, loop);    CMPTO(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG3, 0, loop);
1965    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
1966    }    }
1967  else  else
1968    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
1969  }  }
1970    
1971  static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, uschar* cc)  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
1972    {
1973    DEFINE_COMPILER;
1974    
1975    SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
1976    SLJIT_ASSERT(common->start_used_ptr != 0 && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
1977    
1978    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
1979    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
1980    OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offset_count));
1981    CMPTO(SLJIT_C_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
1982    
1983    /* Store match begin and end. */
1984    OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));
1985    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
1986    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);
1987    OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);
1988    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1989    OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
1990    #endif
1991    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);
1992    
1993    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);
1994    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1995    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
1996    #endif
1997    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0);
1998    
1999    JUMPTO(SLJIT_JUMP, quit);
2000    }
2001    
2002    static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)
2003    {
2004    /* May destroy TMP1. */
2005    DEFINE_COMPILER;
2006    struct sljit_jump *jump;
2007    
2008    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2009      {
2010      /* The value of -1 must be kept for start_used_ptr! */
2011      OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, 1);
2012      /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting
2013      is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */
2014      jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_PTR, 0);
2015      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2016      JUMPHERE(jump);
2017      }
2018    else if (common->mode == JIT_PARTIAL_HARD_COMPILE)
2019      {
2020      jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2021      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2022      JUMPHERE(jump);
2023      }
2024    }
2025    
2026    static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar* cc)
2027  {  {
2028  /* Detects if the character has an othercase. */  /* Detects if the character has an othercase. */
2029  unsigned int c;  unsigned int c;
2030    
2031  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2032  if (common->utf8)  if (common->utf)
2033    {    {
2034    GETCHAR(c, cc);    GETCHAR(c, cc);
2035    if (c > 127)    if (c > 127)
# Line 1272  if (common->utf8) Line 2040  if (common->utf8)
2040      return FALSE;      return FALSE;
2041  #endif  #endif
2042      }      }
2043    #ifndef COMPILE_PCRE8
2044      return common->fcc[c] != c;
2045    #endif
2046    }    }
2047  else  else
2048  #endif  #endif
2049    c = *cc;    c = *cc;
2050  return common->fcc[c] != c;  return MAX_255(c) ? common->fcc[c] != c : FALSE;
2051  }  }
2052    
2053  static SLJIT_INLINE unsigned int char_othercase(compiler_common *common, unsigned int c)  static SLJIT_INLINE unsigned int char_othercase(compiler_common *common, unsigned int c)
2054  {  {
2055  /* Returns with the othercase. */  /* Returns with the othercase. */
2056  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2057  if (common->utf8 && c > 127)  if (common->utf && c > 127)
2058    {    {
2059  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2060    return UCD_OTHERCASE(c);    return UCD_OTHERCASE(c);
# Line 1292  if (common->utf8 && c > 127) Line 2063  if (common->utf8 && c > 127)
2063  #endif  #endif
2064    }    }
2065  #endif  #endif
2066  return common->fcc[c];  return TABLE_GET(c, common->fcc, c);
2067  }  }
2068    
2069  static unsigned int char_get_othercase_bit(compiler_common *common, uschar* cc)  static unsigned int char_get_othercase_bit(compiler_common *common, pcre_uchar* cc)
2070  {  {
2071  /* Detects if the character and its othercase has only 1 bit difference. */  /* Detects if the character and its othercase has only 1 bit difference. */
2072  unsigned int c, oc, bit;  unsigned int c, oc, bit;
2073  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2074  int n;  int n;
2075  #endif  #endif
2076    
2077  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2078  if (common->utf8)  if (common->utf)
2079    {    {
2080    GETCHAR(c, cc);    GETCHAR(c, cc);
2081    if (c <= 127)    if (c <= 127)
# Line 1321  if (common->utf8) Line 2092  if (common->utf8)
2092  else  else
2093    {    {
2094    c = *cc;    c = *cc;
2095    oc = common->fcc[c];    oc = TABLE_GET(c, common->fcc, c);
2096    }    }
2097  #else  #else
2098  c = *cc;  c = *cc;
2099  oc = common->fcc[c];  oc = TABLE_GET(c, common->fcc, c);
2100  #endif  #endif
2101    
2102  SLJIT_ASSERT(c != oc);  SLJIT_ASSERT(c != oc);
# Line 1336  if (c <= 127 && bit == 0x20) Line 2107  if (c <= 127 && bit == 0x20)
2107    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2108    
2109  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2110  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2111    return 0;    return 0;
2112    
2113  #ifdef SUPPORT_UTF8  #if defined COMPILE_PCRE8
2114  if (common->utf8 && c > 127)  
2115    #ifdef SUPPORT_UTF
2116    if (common->utf && c > 127)
2117    {    {
2118    n = _pcre_utf8_table4[*cc & 0x3f];    n = GET_EXTRALEN(*cc);
2119    while ((bit & 0x3f) == 0)    while ((bit & 0x3f) == 0)
2120      {      {
2121      n--;      n--;
# Line 1350  if (common->utf8 && c > 127) Line 2123  if (common->utf8 && c > 127)
2123      }      }
2124    return (n << 8) | bit;    return (n << 8) | bit;
2125    }    }
2126  #endif  #endif /* SUPPORT_UTF */
2127  return (0 << 8) | bit;  return (0 << 8) | bit;
2128    
2129    #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2130    
2131    #ifdef SUPPORT_UTF
2132    if (common->utf && c > 65535)
2133      {
2134      if (bit >= (1 << 10))
2135        bit >>= 10;
2136      else
2137        return (bit < 256) ? ((2 << 8) | bit) : ((3 << 8) | (bit >> 8));
2138      }
2139    #endif /* SUPPORT_UTF */
2140    return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
2141    
2142    #endif /* COMPILE_PCRE[8|16|32] */
2143    }
2144    
2145    static void check_partial(compiler_common *common, BOOL force)
2146    {
2147    /* Checks whether a partial matching is occured. Does not modify registers. */
2148    DEFINE_COMPILER;
2149    struct sljit_jump *jump = NULL;
2150    
2151    SLJIT_ASSERT(!force || common->mode != JIT_COMPILE);
2152    
2153    if (common->mode == JIT_COMPILE)
2154      return;
2155    
2156    if (!force)
2157      jump = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2158    else if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2159      jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2160    
2161    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2162      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
2163    else
2164      {
2165      if (common->partialmatchlabel != NULL)
2166        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2167      else
2168        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2169      }
2170    
2171    if (jump != NULL)
2172      JUMPHERE(jump);
2173    }
2174    
2175    static struct sljit_jump *check_str_end(compiler_common *common)
2176    {
2177    /* Does not affect registers. Usually used in a tight spot. */
2178    DEFINE_COMPILER;
2179    struct sljit_jump *jump;
2180    struct sljit_jump *nohit;
2181    struct sljit_jump *return_value;
2182    
2183    if (common->mode == JIT_COMPILE)
2184      return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2185    
2186    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2187    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2188      {
2189      nohit = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2190      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
2191      JUMPHERE(nohit);
2192      return_value = JUMP(SLJIT_JUMP);
2193      }
2194    else
2195      {
2196      return_value = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2197      if (common->partialmatchlabel != NULL)
2198        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2199      else
2200        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2201      }
2202    JUMPHERE(jump);
2203    return return_value;
2204  }  }
2205    
2206  static SLJIT_INLINE void check_input_end(compiler_common *common, jump_list **fallbacks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
2207  {  {
2208  DEFINE_COMPILER;  DEFINE_COMPILER;
2209  add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));  struct sljit_jump *jump;
2210    
2211    if (common->mode == JIT_COMPILE)
2212      {
2213      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2214      return;
2215      }
2216    
2217    /* Partial matching mode. */
2218    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2219    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2220    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2221      {
2222      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
2223      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2224      }
2225    else
2226      {
2227      if (common->partialmatchlabel != NULL)
2228        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2229      else
2230        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2231      }
2232    JUMPHERE(jump);
2233  }  }
2234    
2235  static void read_char(compiler_common *common)  static void read_char(compiler_common *common)
# Line 1365  static void read_char(compiler_common *c Line 2237  static void read_char(compiler_common *c
2237  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2238  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2239  DEFINE_COMPILER;  DEFINE_COMPILER;
2240  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2241  struct sljit_jump *jump;  struct sljit_jump *jump;
2242  #endif  #endif
2243    
2244  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2245  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2246  if (common->utf8)  if (common->utf)
2247    {    {
2248    /* Should not found a value between 128 and 192 here. */  #if defined COMPILE_PCRE8
2249    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 192);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2250    add_jump(compiler, &common->utf8readchar, JUMP(SLJIT_FAST_CALL));  #elif defined COMPILE_PCRE16
2251      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2252    #endif /* COMPILE_PCRE[8|16] */
2253      add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2254    JUMPHERE(jump);    JUMPHERE(jump);
2255    }    }
2256  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2257  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2258  }  }
2259    
2260  static void peek_char(compiler_common *common)  static void peek_char(compiler_common *common)
# Line 1387  static void peek_char(compiler_common *c Line 2262  static void peek_char(compiler_common *c
2262  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2263  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2264  DEFINE_COMPILER;  DEFINE_COMPILER;
2265  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2266  struct sljit_jump *jump;  struct sljit_jump *jump;
2267  #endif  #endif
2268    
2269  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2270  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2271  if (common->utf8)  if (common->utf)
2272    {    {
2273    /* Should not found a value between 128 and 192 here. */  #if defined COMPILE_PCRE8
2274    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 192);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2275    add_jump(compiler, &common->utf8readchar, JUMP(SLJIT_FAST_CALL));  #elif defined COMPILE_PCRE16
2276      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2277    #endif /* COMPILE_PCRE[8|16] */
2278      add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2279    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2280    JUMPHERE(jump);    JUMPHERE(jump);
2281    }    }
2282  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2283  }  }
2284    
2285  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2286  {  {
2287  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */
2288  DEFINE_COMPILER;  DEFINE_COMPILER;
2289  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2290  struct sljit_jump *jump;  struct sljit_jump *jump;
2291  #endif  #endif
2292    
2293  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2294  if (common->utf8)  if (common->utf)
2295    {    {
2296    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2297    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2298    #if defined COMPILE_PCRE8
2299    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2300    it is a clever early read in most cases. */    it is needed in most cases. */
2301      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2302      jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2303      add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2304      JUMPHERE(jump);
2305    #elif defined COMPILE_PCRE16
2306      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2307      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2308      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2309      JUMPHERE(jump);
2310      /* Skip low surrogate if necessary. */
2311      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2312      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2313      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2314      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2315      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2316    #elif defined COMPILE_PCRE32
2317      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2318      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2319    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
   /* Should not found a value between 128 and 192 here. */  
   jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 192);  
   add_jump(compiler, &common->utf8readtype8, JUMP(SLJIT_FAST_CALL));  
2320    JUMPHERE(jump);    JUMPHERE(jump);
2321    #endif /* COMPILE_PCRE[8|16|32] */
2322    return;    return;
2323    }    }
2324    #endif /* SUPPORT_UTF */
2325    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2326    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2327    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2328    /* The ctypes array contains only 256 values. */
2329    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2330    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2331    #endif
2332    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2333    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2334    JUMPHERE(jump);
2335  #endif  #endif
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);  
2336  }  }
2337    
2338  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
2339  {  {
2340  /* Goes one character back. Only affects STR_PTR. Does not check begin. */  /* Goes one character back. Affects STR_PTR and TMP1. Does not check begin. */
2341  DEFINE_COMPILER;  DEFINE_COMPILER;
2342  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2343    #if defined COMPILE_PCRE8
2344  struct sljit_label *label;  struct sljit_label *label;
2345    
2346  if (common->utf8)  if (common->utf)
2347    {    {
2348    label = LABEL();    label = LABEL();
2349    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
2350    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2351    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);
2352    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2353    return;    return;
2354    }    }
2355  #endif  #elif defined COMPILE_PCRE16
2356  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  if (common->utf)
2357      {
2358      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
2359      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2360      /* Skip low surrogate if necessary. */
2361      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2362      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);
2363      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2364      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2365      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2366      return;
2367      }
2368    #endif /* COMPILE_PCRE[8|16] */
2369    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2370    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2371  }  }
2372    
2373  static void check_newlinechar(compiler_common *common, int nltype, jump_list **fallbacks, BOOL jumpiftrue)  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpiftrue)
2374  {  {
2375  /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */  /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */
2376  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1460  DEFINE_COMPILER; Line 2378  DEFINE_COMPILER;
2378  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2379    {    {
2380    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2381    add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2382    }    }
2383  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2384    {    {
2385    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);
2386    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2387    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);
2388    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
2389    add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2390    }    }
2391  else  else
2392    {    {
2393    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline <= 255);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2394    add_jump(compiler, fallbacks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));    add_jump(compiler, backtracks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
2395    }    }
2396  }  }
2397    
2398  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2399  static void do_utf8readchar(compiler_common *common)  
2400    #if defined COMPILE_PCRE8
2401    static void do_utfreadchar(compiler_common *common)
2402  {  {
2403  /* Fast decoding an utf8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2404  of the character (>= 192). Return char value in TMP1, length - 1 in TMP2. */  of the character (>= 0xc0). Return char value in TMP1, length - 1 in TMP2. */
2405  DEFINE_COMPILER;  DEFINE_COMPILER;
2406  struct sljit_jump *jump;  struct sljit_jump *jump;
2407    
2408  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2409  /* Searching for the first zero. */  /* Searching for the first zero. */
2410  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
2411  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2412  /* 2 byte sequence */  /* Two byte sequence. */
2413  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2414  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2415  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);
2416  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2417  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2418  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2419  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
2420  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2421  JUMPHERE(jump);  JUMPHERE(jump);
2422    
2423  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);
2424  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2425  /* 3 byte sequence */  /* Three byte sequence. */
2426  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2427  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);
2428  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);
2429  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2430  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2431  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2432  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 2);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2433  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 2);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2434  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2435  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2436  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 2);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2437  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2438  JUMPHERE(jump);  JUMPHERE(jump);
2439    
2440  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x08);  /* Four byte sequence. */
2441  jump = JUMP(SLJIT_C_NOT_ZERO);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
 /* 4 byte sequence */  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  
2442  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);
2443  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);
2444  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2445  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);
2446  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2447  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 2);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 3);  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 3);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 3);  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 JUMPHERE(jump);  
   
 /* 5 byte sequence */  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x03);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 24);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 18);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 2);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 3);  
2448  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2449  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2450  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2451  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 4);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));
2452  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 4);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2453  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2454  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2455  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 4);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
2456  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2457  }  }
2458    
2459  static void do_utf8readtype8(compiler_common *common)  static void do_utfreadtype8(compiler_common *common)
2460  {  {
2461  /* Fast decoding an utf8 character type. TMP2 contains the first byte  /* Fast decoding a UTF-8 character type. TMP2 contains the first byte
2462  of the character (>= 192) and TMP1 is destroyed. Return value in TMP1. */  of the character (>= 0xc0). Return value in TMP1. */
2463  DEFINE_COMPILER;  DEFINE_COMPILER;
2464  struct sljit_jump *jump;  struct sljit_jump *jump;
2465  struct sljit_jump *compare;  struct sljit_jump *compare;
2466    
2467  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2468    
2469  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);
2470  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2471  /* 2 byte sequence */  /* Two byte sequence. */
2472  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2473  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2474  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2475  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2476  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
# Line 1590  sljit_emit_fast_return(compiler, RETURN_ Line 2485  sljit_emit_fast_return(compiler, RETURN_
2485  JUMPHERE(jump);  JUMPHERE(jump);
2486    
2487  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2488  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)_pcre_utf8_char_sizes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
 OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  
2489  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2490  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2491  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2492  }  }
2493    
2494  #endif  #elif defined COMPILE_PCRE16
2495    
2496    static void do_utfreadchar(compiler_common *common)
2497    {
2498    /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char
2499    of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */
2500    DEFINE_COMPILER;
2501    struct sljit_jump *jump;
2502    
2503    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2504    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);
2505    /* Do nothing, only return. */
2506    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2507    
2508    JUMPHERE(jump);
2509    /* Combine two 16 bit characters. */
2510    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2511    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2512    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2513    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);
2514    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff);
2515    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2516    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
2517    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2518    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2519    }
2520    
2521    #endif /* COMPILE_PCRE[8|16] */
2522    
2523    #endif /* SUPPORT_UTF */
2524    
2525  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2526    
# Line 1613  DEFINE_COMPILER; Line 2536  DEFINE_COMPILER;
2536    
2537  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);
2538    
2539  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2540  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2541  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_w)_pcre_ucd_stage1);  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(ucd_stage1));
2542  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2543  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2544  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2545  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)_pcre_ucd_stage2);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2546  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2547  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)_pcre_ucd_records + SLJIT_OFFSETOF(ucd_record, chartype));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));
2548  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2549  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2550  }  }
# Line 1635  struct sljit_label *newlinelabel = NULL; Line 2558  struct sljit_label *newlinelabel = NULL;
2558  struct sljit_jump *start;  struct sljit_jump *start;
2559  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2560  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2561    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2562    struct sljit_jump *singlechar;
2563    #endif
2564  jump_list *newline = NULL;  jump_list *newline = NULL;
2565  BOOL newlinecheck = FALSE;  BOOL newlinecheck = FALSE;
2566  BOOL readbyte = FALSE;  BOOL readuchar = FALSE;
2567    
2568  if (!(hascrorlf || firstline) && (common->nltype == NLTYPE_ANY ||  if (!(hascrorlf || firstline) && (common->nltype == NLTYPE_ANY ||
2569      common->nltype == NLTYPE_ANYCRLF || common->newline > 255))      common->nltype == NLTYPE_ANYCRLF || common->newline > 255))
# Line 1646  if (!(hascrorlf || firstline) && (common Line 2572  if (!(hascrorlf || firstline) && (common
2572  if (firstline)  if (firstline)
2573    {    {
2574    /* Search for the end of the first line. */    /* Search for the end of the first line. */
2575    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2576    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
2577    
2578    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2579      {      {
2580      mainloop = LABEL();      mainloop = LABEL();
2581      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2582      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2583      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -1);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
2584      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2585      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);
2586      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);
2587      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0, SLJIT_IMM, 1);      JUMPHERE(end);
2588        OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2589      }      }
2590    else    else
2591      {      {
2592      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2593      mainloop = LABEL();      mainloop = LABEL();
2594      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
2595      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2596      read_char(common);      read_char(common);
2597      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
2598      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2599      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);      JUMPHERE(end);
2600        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2601      set_jumps(newline, LABEL());      set_jumps(newline, LABEL());
2602      }      }
2603    
2604    JUMPHERE(end);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
   OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
2605    }    }
2606    
2607  start = JUMP(SLJIT_JUMP);  start = JUMP(SLJIT_JUMP);
# Line 1682  start = JUMP(SLJIT_JUMP); Line 2609  start = JUMP(SLJIT_JUMP);
2609  if (newlinecheck)  if (newlinecheck)
2610    {    {
2611    newlinelabel = LABEL();    newlinelabel = LABEL();
2612    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2613    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2614    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2615    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);
2616    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2617    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2618      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2619    #endif
2620    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2621    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
2622    }    }
# Line 1694  if (newlinecheck) Line 2624  if (newlinecheck)
2624  mainloop = LABEL();  mainloop = LABEL();
2625    
2626  /* Increasing the STR_PTR here requires one less jump in the most common case. */  /* Increasing the STR_PTR here requires one less jump in the most common case. */
2627  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2628  if (common->utf8) readbyte = TRUE;  if (common->utf) readuchar = TRUE;
2629  #endif  #endif
2630  if (newlinecheck) readbyte = TRUE;  if (newlinecheck) readuchar = TRUE;
2631    
2632  if (readbyte)  if (readuchar)
2633    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2634    
2635  if (newlinecheck)  if (newlinecheck)
2636    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);
2637    
2638  #ifdef SUPPORT_UTF8  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2639  if (common->utf8)  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2640    #if defined COMPILE_PCRE8
2641    if (common->utf)
2642    {    {
2643    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)_pcre_utf8_char_sizes);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2644      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2645    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2646      JUMPHERE(singlechar);
2647    }    }
2648  else  #elif defined COMPILE_PCRE16
2649    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  if (common->utf)
2650  #else    {
2651  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2652  #endif    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2653      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2654      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2655      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2656      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2657      JUMPHERE(singlechar);
2658      }
2659    #endif /* COMPILE_PCRE[8|16] */
2660    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2661  JUMPHERE(start);  JUMPHERE(start);
2662    
2663  if (newlinecheck)  if (newlinecheck)
# Line 1727  if (newlinecheck) Line 2669  if (newlinecheck)
2669  return mainloop;  return mainloop;
2670  }  }
2671    
2672  static SLJIT_INLINE void fast_forward_first_byte(compiler_common *common, pcre_uint16 firstbyte, BOOL firstline)  #define MAX_N_CHARS 3
2673    
2674    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2675    {
2676    DEFINE_COMPILER;
2677    struct sljit_label *start;
2678    struct sljit_jump *quit;
2679    pcre_uint32 chars[MAX_N_CHARS * 2];
2680    pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2681    int location = 0;
2682    pcre_int32 len, c, bit, caseless;
2683    int must_stop;
2684    
2685    /* We do not support alternatives now. */
2686    if (*(common->start + GET(common->start, 1)) == OP_ALT)
2687      return FALSE;
2688    
2689    while (TRUE)
2690      {
2691      caseless = 0;
2692      must_stop = 1;
2693      switch(*cc)
2694        {
2695        case OP_CHAR:
2696        must_stop = 0;
2697        cc++;
2698        break;
2699    
2700        case OP_CHARI:
2701        caseless = 1;
2702        must_stop = 0;
2703        cc++;
2704        break;
2705    
2706        case OP_SOD:
2707        case OP_SOM:
2708        case OP_SET_SOM:
2709        case OP_NOT_WORD_BOUNDARY:
2710        case OP_WORD_BOUNDARY:
2711        case OP_EODN:
2712        case OP_EOD:
2713        case OP_CIRC:
2714        case OP_CIRCM:
2715        case OP_DOLL:
2716        case OP_DOLLM:
2717        /* Zero width assertions. */
2718        cc++;
2719        continue;
2720    
2721        case OP_PLUS:
2722        case OP_MINPLUS:
2723        case OP_POSPLUS:
2724        cc++;
2725        break;
2726    
2727        case OP_EXACT:
2728        cc += 1 + IMM2_SIZE;
2729        break;
2730    
2731        case OP_PLUSI:
2732        case OP_MINPLUSI:
2733        case OP_POSPLUSI:
2734        caseless = 1;
2735        cc++;
2736        break;
2737    
2738        case OP_EXACTI:
2739        caseless = 1;
2740        cc += 1 + IMM2_SIZE;
2741        break;
2742    
2743        default:
2744        must_stop = 2;
2745        break;
2746        }
2747    
2748      if (must_stop == 2)
2749          break;
2750    
2751      len = 1;
2752    #ifdef SUPPORT_UTF
2753      if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
2754    #endif
2755    
2756      if (caseless && char_has_othercase(common, cc))
2757        {
2758        caseless = char_get_othercase_bit(common, cc);
2759        if (caseless == 0)
2760          return FALSE;
2761    #ifdef COMPILE_PCRE8
2762        caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
2763    #else
2764        if ((caseless & 0x100) != 0)
2765          caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
2766        else
2767          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
2768    #endif
2769        }
2770      else
2771        caseless = 0;
2772    
2773      while (len > 0 && location < MAX_N_CHARS * 2)
2774        {
2775        c = *cc;
2776        bit = 0;
2777        if (len == (caseless & 0xff))
2778          {
2779          bit = caseless >> 8;
2780          c |= bit;
2781          }
2782    
2783        chars[location] = c;
2784        chars[location + 1] = bit;
2785    
2786        len--;
2787        location += 2;
2788        cc++;
2789        }
2790    
2791      if (location >= MAX_N_CHARS * 2 || must_stop != 0)
2792        break;
2793      }
2794    
2795    /* At least two characters are required. */
2796    if (location < 2 * 2)
2797        return FALSE;
2798    
2799    if (firstline)
2800      {
2801      SLJIT_ASSERT(common->first_line_end != 0);
2802      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2803      OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2804      }
2805    else
2806      OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2807    
2808    start = LABEL();
2809    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2810    
2811    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2812    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2813    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2814    if (chars[1] != 0)
2815      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
2816    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
2817    if (location > 2 * 2)
2818      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2819    if (chars[3] != 0)
2820      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
2821    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
2822    if (location > 2 * 2)
2823      {
2824      if (chars[5] != 0)
2825        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
2826      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);
2827      }
2828    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2829    
2830    JUMPHERE(quit);
2831    
2832    if (firstline)
2833      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2834    else
2835      OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2836    return TRUE;
2837    }
2838    
2839    #undef MAX_N_CHARS
2840    
2841    static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
2842  {  {
2843  DEFINE_COMPILER;  DEFINE_COMPILER;
2844  struct sljit_label *start;  struct sljit_label *start;
2845  struct sljit_jump *leave;  struct sljit_jump *quit;
2846  struct sljit_jump *found;  struct sljit_jump *found;
2847  pcre_uint16 oc, bit;  pcre_uchar oc, bit;
2848    
2849  if (firstline)  if (firstline)
2850    {    {
2851    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2852    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2853      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
2854    }    }
2855    
2856  start = LABEL();  start = LABEL();
2857  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2858  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2859    
2860  if ((firstbyte & REQ_CASELESS) == 0)  oc = first_char;
2861    found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, firstbyte & 0xff);  if (caseless)
2862      {
2863      oc = TABLE_GET(first_char, common->fcc, first_char);
2864    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
2865      if (first_char > 127 && common->utf)
2866        oc = UCD_OTHERCASE(first_char);
2867    #endif
2868      }
2869    if (first_char == oc)
2870      found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, first_char);
2871  else  else
2872    {    {
2873    firstbyte &= 0xff;    bit = first_char ^ oc;
2874    oc = common->fcc[firstbyte];    if (is_powerof2(bit))
   bit = firstbyte ^ oc;  
   if (ispowerof2(bit))  
2875      {      {
2876      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
2877      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, firstbyte | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
2878      }      }
2879    else    else
2880      {      {
2881      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, firstbyte);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char);
2882      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2883      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);
2884      COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
2885      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
2886      }      }
2887    }    }
2888    
2889  #ifdef SUPPORT_UTF8  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 if (common->utf8)  
   {  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)_pcre_utf8_char_sizes);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 else  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  
 #else  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  
 #endif  
2890  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
2891  JUMPHERE(found);  JUMPHERE(found);
2892  JUMPHERE(leave);  JUMPHERE(quit);
2893    
2894  if (firstline)  if (firstline)
2895    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2896  }  }
2897    
2898  static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline)  static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline)
# Line 1792  DEFINE_COMPILER; Line 2901  DEFINE_COMPILER;
2901  struct sljit_label *loop;  struct sljit_label *loop;
2902  struct sljit_jump *lastchar;  struct sljit_jump *lastchar;
2903  struct sljit_jump *firstchar;  struct sljit_jump *firstchar;
2904  struct sljit_jump *leave;  struct sljit_jump *quit;
2905  struct sljit_jump *foundcr = NULL;  struct sljit_jump *foundcr = NULL;
2906  struct sljit_jump *notfoundnl;  struct sljit_jump *notfoundnl;
2907  jump_list *newline = NULL;  jump_list *newline = NULL;
2908    
2909  if (firstline)  if (firstline)
2910    {    {
2911    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2912    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2913      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
2914    }    }
2915    
2916  if (common->nltype == NLTYPE_FIXED && common->newline > 255)  if (common->nltype == NLTYPE_FIXED && common->newline > 255)
# Line 1811  if (common->nltype == NLTYPE_FIXED && co Line 2921  if (common->nltype == NLTYPE_FIXED && co
2921    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
2922    firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);    firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);
2923    
2924    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2);    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
2925    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, TMP1, 0);
2926    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
2927    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2928      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
2929    #endif
2930    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2931    
2932    loop = LABEL();    loop = LABEL();
2933    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2934    leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2935    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -2);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
2936    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), -1);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
2937    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);
2938    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);
2939    
2940    JUMPHERE(leave);    JUMPHERE(quit);
2941    JUMPHERE(firstchar);    JUMPHERE(firstchar);
2942    JUMPHERE(lastchar);    JUMPHERE(lastchar);
2943    
# Line 1848  set_jumps(newline, loop); Line 2961  set_jumps(newline, loop);
2961    
2962  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
2963    {    {
2964    leave = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
2965    JUMPHERE(foundcr);    JUMPHERE(foundcr);
2966    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2967    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2968    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);
2969    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2970    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2971      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2972    #endif
2973    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2974    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
2975    JUMPHERE(leave);    JUMPHERE(quit);
2976    }    }
2977  JUMPHERE(lastchar);  JUMPHERE(lastchar);
2978  JUMPHERE(firstchar);  JUMPHERE(firstchar);
2979    
2980  if (firstline)  if (firstline)
2981    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2982  }  }
2983    
2984    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
2985    
2986  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)
2987  {  {
2988  DEFINE_COMPILER;  DEFINE_COMPILER;
2989  struct sljit_label *start;  struct sljit_label *start;
2990  struct sljit_jump *leave;  struct sljit_jump *quit;
2991  struct sljit_jump *found;  struct sljit_jump *found = NULL;
2992    jump_list *matches = NULL;
2993    pcre_uint8 inverted_start_bits[32];
2994    int i;
2995    #ifndef COMPILE_PCRE8
2996    struct sljit_jump *jump;
2997    #endif
2998    
2999    for (i = 0; i < 32; ++i)
3000      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3001    
3002  if (firstline)  if (firstline)
3003    {    {
3004    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3005    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
3006      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3007      }
3008    
3009    start = LABEL();
3010    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3011    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3012    #ifdef SUPPORT_UTF
3013    if (common->utf)
3014      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3015    #endif
3016    
3017    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3018      {
3019    #ifndef COMPILE_PCRE8
3020      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3021      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3022      JUMPHERE(jump);
3023    #endif
3024      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3025      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3026      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3027      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3028      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
3029      found = JUMP(SLJIT_C_NOT_ZERO);
3030    }    }
3031    
3032  start = LABEL();  #ifdef SUPPORT_UTF
3033  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  if (common->utf)
3034  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
 #ifdef SUPPORT_UTF8  
 if (common->utf8)  
   OP1(SLJIT_MOV_UB, TMP3, 0, SLJIT_MEM1(TMP1), (sljit_w)_pcre_utf8_char_sizes);  
 #endif  
 OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);  
 OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);  
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);  
 OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);  
 OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);  
 found = JUMP(SLJIT_C_NOT_ZERO);  
   
 #ifdef SUPPORT_UTF8  
 if (common->utf8)  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP3, 0);  
 else  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  
 #else  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  
3035  #endif  #endif
3036    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3037    #ifdef SUPPORT_UTF
3038    #if defined COMPILE_PCRE8
3039    if (common->utf)
3040      {
3041      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3042      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
3043      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3044      }
3045    #elif defined COMPILE_PCRE16
3046    if (common->utf)
3047      {
3048      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3049      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3050      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
3051      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3052      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3053      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3054      }
3055    #endif /* COMPILE_PCRE[8|16] */
3056    #endif /* SUPPORT_UTF */
3057  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3058  JUMPHERE(found);  if (found != NULL)
3059  JUMPHERE(leave);    JUMPHERE(found);
3060    if (matches != NULL)
3061      set_jumps(matches, LABEL());
3062    JUMPHERE(quit);
3063    
3064  if (firstline)  if (firstline)
3065    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
3066  }  }
3067    
3068  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uint16 reqbyte, BOOL has_firstbyte)  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar req_char, BOOL caseless, BOOL has_firstchar)
3069  {  {
3070  DEFINE_COMPILER;  DEFINE_COMPILER;
3071  struct sljit_label *loop;  struct sljit_label *loop;
# Line 1917  struct sljit_jump *alreadyfound; Line 3074  struct sljit_jump *alreadyfound;
3074  struct sljit_jump *found;  struct sljit_jump *found;
3075  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3076  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3077  pcre_uint16 oc, bit;  pcre_uint32 oc, bit;
3078    
3079  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_BYTE_PTR);  SLJIT_ASSERT(common->req_char_ptr != 0);
3080    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
3081  OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, REQ_BYTE_MAX);  OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, REQ_BYTE_MAX);
3082  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);
3083  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);
3084    
3085  if (has_firstbyte)  if (has_firstchar)
3086    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3087  else  else
3088    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);
3089    
3090  loop = LABEL();  loop = LABEL();
3091  notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);  notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);
3092    
3093  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3094  if ((reqbyte & REQ_CASELESS) == 0)  oc = req_char;
3095    found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte & 0xff);  if (caseless)
3096      {
3097      oc = TABLE_GET(req_char, common->fcc, req_char);
3098    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
3099      if (req_char > 127 && common->utf)
3100        oc = UCD_OTHERCASE(req_char);
3101    #endif
3102      }
3103    if (req_char == oc)
3104      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
3105  else  else
3106    {    {
3107    reqbyte &= 0xff;    bit = req_char ^ oc;
3108    oc = common->fcc[reqbyte];    if (is_powerof2(bit))
   bit = reqbyte ^ oc;  
   if (ispowerof2(bit))  
3109      {      {
3110      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3111      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
3112      }      }
3113    else    else
3114      {      {
3115      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
3116      foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);      foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);
3117      }      }
3118    }    }
3119  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
3120  JUMPTO(SLJIT_JUMP, loop);  JUMPTO(SLJIT_JUMP, loop);
3121    
3122  JUMPHERE(found);  JUMPHERE(found);
3123  if (foundoc)  if (foundoc)
3124    JUMPHERE(foundoc);    JUMPHERE(foundoc);
3125  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_BYTE_PTR, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr, TMP1, 0);
3126  JUMPHERE(alreadyfound);  JUMPHERE(alreadyfound);
3127  JUMPHERE(toolong);  JUMPHERE(toolong);
3128  return notfound;  return notfound;
# Line 1966  return notfound; Line 3131  return notfound;
3131  static void do_revertframes(compiler_common *common)  static void do_revertframes(compiler_common *common)
3132  {  {
3133  DEFINE_COMPILER;  DEFINE_COMPILER;
 struct sljit_jump *earlyexit;  
3134  struct sljit_jump *jump;  struct sljit_jump *jump;
3135  struct sljit_label *mainloop;  struct sljit_label *mainloop;
3136    
3137  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3138  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS_HEAD);  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);
3139    GET_LOCAL_BASE(TMP3, 0, 0);
3140    
3141  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
 earlyexit = CMP(SLJIT_C_LESS, TMP1, 0, STACK_TOP, 0);  
3142  mainloop = LABEL();  mainloop = LABEL();
3143  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3144  jump = CMP(SLJIT_C_SIG_LESS_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0);
3145  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_LOCALS_REG, 0);  jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3146  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
3147  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3148  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3149    OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
3150    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
3151  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3152    
3153  JUMPHERE(jump);  JUMPHERE(jump);
3154  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3155  /* End of dropping frames. */  /* End of dropping frames. */
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS_HEAD, TMP1, 0);  
 CMPTO(SLJIT_C_GREATER_EQUAL, TMP1, 0, STACK_TOP, 0, mainloop);  
 JUMPHERE(earlyexit);  
3156  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3157    
3158  JUMPHERE(jump);  JUMPHERE(jump);
3159  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3160  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3161  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3162  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), TMP2, 0);  
 JUMPTO(SLJIT_JUMP, mainloop);  
   
 JUMPHERE(jump);  
 /* Unknown command. */  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
3163  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3164  }  }
3165    
3166  static void check_wordboundary(compiler_common *common)  static void check_wordboundary(compiler_common *common)
3167  {  {
3168  DEFINE_COMPILER;  DEFINE_COMPILER;
3169  struct sljit_jump *beginend;  struct sljit_jump *skipread;
3170  #ifdef SUPPORT_UTF8  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3171  struct sljit_jump *jump;  struct sljit_jump *jump;
3172  #endif  #endif
3173    
3174  SLJIT_ASSERT(ctype_word == 0x10);  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
3175    
3176  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3177  /* Get type of the previous char, and put it to LOCALS1. */  /* Get type of the previous char, and put it to LOCALS1. */
3178  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
3179  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
3180  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);
3181  beginend = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);  skipread = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3182  skip_char_back(common);  skip_char_back(common);
3183    check_start_used_ptr(common);
3184  read_char(common);  read_char(common);
3185    
3186  /* Testing char type. */  /* Testing char type. */
3187  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3188  if (common->useucp)  if (common->use_ucp)
3189    {    {
3190    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
3191    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
3192    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3193    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3194    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
3195    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3196    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);
3197    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
3198    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3199    JUMPHERE(jump);    JUMPHERE(jump);
3200    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3201    }    }
3202  else  else
3203  #endif  #endif
3204    {    {
3205  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3206      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3207    #elif defined SUPPORT_UTF
3208    /* Here LOCALS1 has already been zeroed. */    /* Here LOCALS1 has already been zeroed. */
3209    jump = NULL;    jump = NULL;
3210    if (common->utf8)    if (common->utf)
3211      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3212  #endif  #endif /* COMPILE_PCRE8 */
3213    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);
3214    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);
3215    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3216    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
3217  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3218      JUMPHERE(jump);
3219    #elif defined SUPPORT_UTF
3220    if (jump != NULL)    if (jump != NULL)
3221      JUMPHERE(jump);      JUMPHERE(jump);
3222  #endif  #endif /* COMPILE_PCRE8 */
3223    }    }
3224  JUMPHERE(beginend);  JUMPHERE(skipread);
3225    
3226  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3227  beginend = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  skipread = check_str_end(common);
3228  peek_char(common);  peek_char(common);
3229    
3230  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
3231  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3232  if (common->useucp)  if (common->use_ucp)
3233    {    {
3234    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
3235    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
3236    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3237    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3238    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
3239    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3240    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);
3241    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
3242    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3243    JUMPHERE(jump);    JUMPHERE(jump);
3244    }    }
3245  else  else
3246  #endif  #endif
3247    {    {
3248  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3249      /* TMP2 may be destroyed by peek_char. */
3250      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3251      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3252    #elif defined SUPPORT_UTF
3253    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3254    jump = NULL;    jump = NULL;
3255    if (common->utf8)    if (common->utf)
3256      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3257  #endif  #endif
3258    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);
3259    OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);    OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);
3260    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
3261  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3262      JUMPHERE(jump);
3263    #elif defined SUPPORT_UTF
3264    if (jump != NULL)    if (jump != NULL)
3265      JUMPHERE(jump);      JUMPHERE(jump);
3266  #endif  #endif /* COMPILE_PCRE8 */
3267    }    }
3268  JUMPHERE(beginend);  JUMPHERE(skipread);
3269    
3270  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3271  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3272  }  }
3273    
3274    /*
3275      range format:
3276    
3277      ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).
3278      ranges[1] = first bit (0 or 1)
3279      ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)
3280    */
3281    
3282    static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3283    {
3284    DEFINE_COMPILER;
3285    struct sljit_jump *jump;
3286    
3287    if (ranges[0] < 0)
3288      return FALSE;
3289    
3290    switch(ranges[0])
3291      {
3292      case 1:
3293      if (readch)
3294        read_char(common);
3295      add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3296      return TRUE;
3297    
3298      case 2:
3299      if (readch)
3300        read_char(common);
3301      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3302      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3303      return TRUE;
3304    
3305      case 4:
3306      if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])
3307        {
3308        if (readch)
3309          read_char(common);
3310        if (ranges[1] != 0)
3311          {
3312          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3313          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3314          }
3315        else
3316          {
3317          jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);
3318          add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3319          JUMPHERE(jump);
3320          }
3321        return TRUE;
3322        }
3323      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))
3324        {
3325        if (readch)
3326          read_char(common);
3327        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3328        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3329        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3330        return TRUE;
3331        }
3332      return FALSE;
3333    
3334      default:
3335      return FALSE;
3336      }
3337    }
3338    
3339    static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)
3340    {
3341    int i, bit, length;
3342    const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;
3343    
3344    bit = ctypes[0] & flag;
3345    ranges[0] = -1;
3346    ranges[1] = bit != 0 ? 1 : 0;
3347    length = 0;
3348    
3349    for (i = 1; i < 256; i++)
3350      if ((ctypes[i] & flag) != bit)
3351        {
3352        if (length >= MAX_RANGE_SIZE)
3353          return;
3354        ranges[2 + length] = i;
3355        length++;
3356        bit ^= flag;
3357        }
3358    
3359    if (bit != 0)
3360      {
3361      if (length >= MAX_RANGE_SIZE)
3362        return;
3363      ranges[2 + length] = 256;
3364      length++;
3365      }
3366    ranges[0] = length;
3367    }
3368    
3369    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)
3370    {
3371    int ranges[2 + MAX_RANGE_SIZE];
3372    pcre_uint8 bit, cbit, all;
3373    int i, byte, length = 0;
3374    
3375    bit = bits[0] & 0x1;
3376    ranges[1] = bit;
3377    /* Can be 0 or 255. */
3378    all = -bit;
3379    
3380    for (i = 0; i < 256; )
3381      {
3382      byte = i >> 3;
3383      if ((i & 0x7) == 0 && bits[byte] == all)
3384        i += 8;
3385      else
3386        {
3387        cbit = (bits[byte] >> (i & 0x7)) & 0x1;
3388        if (cbit != bit)
3389          {
3390          if (length >= MAX_RANGE_SIZE)
3391            return FALSE;
3392          ranges[2 + length] = i;
3393          length++;
3394          bit = cbit;
3395          all = -cbit;
3396          }
3397        i++;
3398        }
3399      }
3400    
3401    if (((bit == 0) && nclass) || ((bit == 1) && !nclass))
3402      {
3403      if (length >= MAX_RANGE_SIZE)
3404        return FALSE;
3405      ranges[2 + length] = 256;
3406      length++;
3407      }
3408    ranges[0] = length;
3409    
3410    return check_ranges(common, ranges, backtracks, FALSE);
3411    }
3412    
3413  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
3414  {  {
3415  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3416  DEFINE_COMPILER;  DEFINE_COMPILER;
3417    
3418  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3419    
3420  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3421  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
3422  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3423  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
3424  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3425  if (common->utf8)  #ifdef COMPILE_PCRE8
3426    if (common->utf)
3427    {    {
3428    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  #endif
3429      OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3430    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3431    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
3432    #ifdef COMPILE_PCRE8
3433    }    }
3434  #endif  #endif
3435  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3436    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3437  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3438  }  }
3439    
# Line 2132  static void check_hspace(compiler_common Line 3442  static void check_hspace(compiler_common
3442  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3443  DEFINE_COMPILER;  DEFINE_COMPILER;
3444    
3445  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3446    
3447  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);
3448  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3449  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
3450  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3451  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);
3452  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3453  if (common->utf8)  #ifdef COMPILE_PCRE8
3454    if (common->utf)
3455    {    {
3456    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  #endif
3457      OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3458    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);
3459    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3460    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);
3461    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3462    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3463    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);
3464    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3465    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);
3466    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3467    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);
3468    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3469    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);
3470    #ifdef COMPILE_PCRE8
3471    }    }
3472  #endif  #endif
3473  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3474    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3475    
3476  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3477  }  }
# Line 2167  static void check_vspace(compiler_common Line 3481  static void check_vspace(compiler_common
3481  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3482  DEFINE_COMPILER;  DEFINE_COMPILER;
3483    
3484  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3485    
3486  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3487  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
3488  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3489  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
3490  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3491  if (common->utf8)  #ifdef COMPILE_PCRE8
3492    if (common->utf)
3493    {    {
3494    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  #endif
3495      OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3496    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3497    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
3498    #ifdef COMPILE_PCRE8
3499    }    }
3500  #endif  #endif
3501  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3502    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3503    
3504  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3505  }  }
# Line 2195  DEFINE_COMPILER; Line 3513  DEFINE_COMPILER;
3513  struct sljit_jump *jump;  struct sljit_jump *jump;
3514  struct sljit_label *label;  struct sljit_label *label;
3515    
3516  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3517  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3518  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);
3519  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);
3520  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
3521  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3522    
3523  label = LABEL();  label = LABEL();
3524  OP1(SLJIT_MOVU_UB, CHAR1, 0, SLJIT_MEM1(TMP1), 1);  OP1(MOVU_UCHAR, CHAR1, 0, SLJIT_MEM1(TMP1), IN_UCHARS(1));
3525  OP1(SLJIT_MOVU_UB, CHAR2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOVU_UCHAR, CHAR2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3526  jump = CMP(SLJIT_C_NOT_EQUAL, CHAR1, 0, CHAR2, 0);  jump = CMP(SLJIT_C_NOT_EQUAL,