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

Diff of /code/trunk/pcre_jit_compile.c

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

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