/[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 860 by zherczeg, Mon Jan 9 20:12:58 2012 UTC revision 1423 by zherczeg, Tue Dec 31 07:57:56 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-2012 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-2012                        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
# Line 65  system files. */ Line 65  system files. */
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 82  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 108  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 {
# Line 152  typedef struct jit_arguments { Line 164  typedef struct jit_arguments {
164    const pcre_uchar *begin;    const pcre_uchar *begin;
165    const pcre_uchar *end;    const pcre_uchar *end;
166    int *offsets;    int *offsets;
167    pcre_uchar *ptr;    pcre_uchar *uchar_ptr;
168      pcre_uchar *mark_ptr;
169      void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171    int offsetcount;    pcre_uint32 limit_match;
172    int calllimit;    int real_offset_count;
173      int offset_count;
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
177    pcre_uint8 notempty_atstart;    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    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184    sljit_uw executable_size;    pcre_uint32 top_bracket;
185  } executable_function;    pcre_uint32 limit_match;
186      sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
187    } executable_functions;
188    
189  typedef struct jump_list {  typedef struct jump_list {
190    struct sljit_jump *jump;    struct sljit_jump *jump;
191    struct jump_list *next;    struct jump_list *next;
192  } jump_list;  } jump_list;
193    
 enum stub_types { stack_alloc };  
   
194  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
195    struct sljit_jump *start;    struct sljit_jump *start;
196    struct sljit_label *leave;    struct sljit_label *quit;
197    struct stub_list *next;    struct stub_list *next;
198  } stub_list;  } stub_list;
199    
200    enum frame_types {
201      no_frame = -1,
202      no_stack = -2
203    };
204    
205    enum control_types {
206      type_mark = 0,
207      type_then_trap = 1
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
213  code generator. It is allocated by compile_hotpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_fallbackpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct fallback_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
218    struct fallback_common *prev;    struct backtrack_common *prev;
219    jump_list *nextfallbacks;    jump_list *nextbacktracks;
220    /* Internal stack (for component operators). */    /* Internal stack (for component operators). */
221    struct fallback_common *top;    struct backtrack_common *top;
222    jump_list *topfallbacks;    jump_list *topbacktracks;
223    /* Opcode pointer. */    /* Opcode pointer. */
224    pcre_uchar *cc;    pcre_uchar *cc;
225  } fallback_common;  } backtrack_common;
226    
227  typedef struct assert_fallback {  typedef struct assert_backtrack {
228    fallback_common common;    backtrack_common common;
229    jump_list *condfailed;    jump_list *condfailed;
230    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
231    int framesize;    int framesize;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int localptr;    int private_data_ptr;
234    /* For iterators. */    /* For iterators. */
235    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
236  } assert_fallback;  } assert_backtrack;
237    
238  typedef struct bracket_fallback {  typedef struct bracket_backtrack {
239    fallback_common common;    backtrack_common common;
240    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
241    struct sljit_label *althotpath;    struct sljit_label *alternative_matchingpath;
242    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
243    struct sljit_label *recursivehotpath;    struct sljit_label *recursive_matchingpath;
244    /* For greedy ? operator. */    /* For greedy ? operator. */
245    struct sljit_label *zerohotpath;    struct sljit_label *zero_matchingpath;
246    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
247    union {    union {
248      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
249      jump_list *condfailed;      jump_list *condfailed;
250      assert_fallback *assert;      assert_backtrack *assert;
251      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
252      int framesize;      int framesize;
253    } u;    } u;
254    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
255    int localptr;    int private_data_ptr;
256  } bracket_fallback;  } bracket_backtrack;
257    
258  typedef struct bracketpos_fallback {  typedef struct bracketpos_backtrack {
259    fallback_common common;    backtrack_common common;
260    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
261    int localptr;    int private_data_ptr;
262    /* Reverting stack is needed. */    /* Reverting stack is needed. */
263    int framesize;    int framesize;
264    /* Allocated stack size. */    /* Allocated stack size. */
265    int stacksize;    int stacksize;
266  } bracketpos_fallback;  } bracketpos_backtrack;
267    
268  typedef struct braminzero_fallback {  typedef struct braminzero_backtrack {
269    fallback_common common;    backtrack_common common;
270    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
271  } braminzero_fallback;  } braminzero_backtrack;
272    
273  typedef struct iterator_fallback {  typedef struct iterator_backtrack {
274    fallback_common common;    backtrack_common common;
275    /* Next iteration. */    /* Next iteration. */
276    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
277  } iterator_fallback;  } iterator_backtrack;
278    
279  typedef struct recurse_entry {  typedef struct recurse_entry {
280    struct recurse_entry *next;    struct recurse_entry *next;
# Line 260  typedef struct recurse_entry { Line 283  typedef struct recurse_entry {
283    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
284    jump_list *calls;    jump_list *calls;
285    /* Points to the starting opcode. */    /* Points to the starting opcode. */
286    int start;    sljit_sw start;
287  } recurse_entry;  } recurse_entry;
288    
289  typedef struct recurse_fallback {  typedef struct recurse_backtrack {
290    fallback_common common;    backtrack_common common;
291  } recurse_fallback;    BOOL inlined_pattern;
292    } recurse_backtrack;
293    
294    #define OP_THEN_TRAP OP_TABLE_LENGTH
295    
296    typedef struct then_trap_backtrack {
297      backtrack_common common;
298      /* If then_trap is not NULL, this structure contains the real
299      then_trap for the backtracking path. */
300      struct then_trap_backtrack *then_trap;
301      /* Points to the starting opcode. */
302      sljit_sw start;
303      /* Exit point for the then opcodes of this alternative. */
304      jump_list *quit;
305      /* Frame size of the current alternative. */
306      int framesize;
307    } then_trap_backtrack;
308    
309    #define MAX_RANGE_SIZE 4
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      /* First byte code. */
315    pcre_uchar *start;    pcre_uchar *start;
316    int localsize;    /* Maps private data offset to each opcode. */
317    int *localptrs;    sljit_si *private_data_ptrs;
318      /* Tells whether the capturing bracket is optimized. */
319      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;    const pcre_uint8 *fcc;
349    sljit_w lcc;    sljit_sw lcc;
350    int cbraptr;    /* 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 negative assert. */
361      BOOL local_exit;
362      /* Currently in a positive assert. */
363      BOOL positive_assert;
364      /* Newline control. */
365    int nltype;    int nltype;
366      pcre_uint32 nlmax;
367    int newline;    int newline;
368    int bsr_nltype;    int bsr_nltype;
369      pcre_uint32 bsr_nlmax;
370      /* Dollar endonly. */
371    int endonly;    int endonly;
372    sljit_w ctypes;    /* Tables. */
373    sljit_uw name_table;    sljit_sw ctypes;
374    sljit_w name_count;    /* Named capturing brackets. */
375    sljit_w name_entry_size;    pcre_uchar *name_table;
376    struct sljit_label *acceptlabel;    sljit_sw name_count;
377      sljit_sw name_entry_size;
378    
379      /* Labels and jump lists. */
380      struct sljit_label *partialmatchlabel;
381      struct sljit_label *quit_label;
382      struct sljit_label *forced_quit_label;
383      struct sljit_label *accept_label;
384    stub_list *stubs;    stub_list *stubs;
385    recurse_entry *entries;    recurse_entry *entries;
386    recurse_entry *currententry;    recurse_entry *currententry;
387      jump_list *partialmatch;
388      jump_list *quit;
389      jump_list *positive_assert_quit;
390      jump_list *forced_quit;
391    jump_list *accept;    jump_list *accept;
392    jump_list *calllimit;    jump_list *calllimit;
393    jump_list *stackalloc;    jump_list *stackalloc;
# Line 297  typedef struct compiler_common { Line 398  typedef struct compiler_common {
398    jump_list *vspace;    jump_list *vspace;
399    jump_list *casefulcmp;    jump_list *casefulcmp;
400    jump_list *caselesscmp;    jump_list *caselesscmp;
401      jump_list *reset_match;
402    BOOL jscript_compat;    BOOL jscript_compat;
403  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
404    BOOL utf;    BOOL utf;
405  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
406    BOOL use_ucp;    BOOL use_ucp;
407  #endif  #endif
   jump_list *utfreadchar;  
408  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
409      jump_list *utfreadchar;
410      jump_list *utfreadchar16;
411    jump_list *utfreadtype8;    jump_list *utfreadtype8;
412  #endif  #endif
413  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
# Line 321  typedef struct compare_context { Line 424  typedef struct compare_context {
424  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
425    int ucharptr;    int ucharptr;
426    union {    union {
427      sljit_i asint;      sljit_si asint;
428      sljit_uh asushort;      sljit_uh asushort;
429  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
430      sljit_ub asbyte;      sljit_ub asbyte;
431      sljit_ub asuchars[4];      sljit_ub asuchars[4];
432  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
433      sljit_uh asuchars[2];      sljit_uh asuchars[2];
434  #endif  #elif defined COMPILE_PCRE32
435        sljit_ui asuchars[1];
436  #endif  #endif
437    } c;    } c;
438    union {    union {
439      sljit_i asint;      sljit_si asint;
440      sljit_uh asushort;      sljit_uh asushort;
441  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
442      sljit_ub asbyte;      sljit_ub asbyte;
443      sljit_ub asuchars[4];      sljit_ub asuchars[4];
444  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
445      sljit_uh asuchars[2];      sljit_uh asuchars[2];
446  #endif  #elif defined COMPILE_PCRE32
447        sljit_ui asuchars[1];
448  #endif  #endif
449    } oc;    } oc;
450  #endif  #endif
451  } compare_context;  } compare_context;
452    
453  enum {  /* Undefine sljit macros. */
454    frame_end = 0,  #undef CMP
   frame_setstrbegin = -1  
 };  
455    
456  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
457  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
458    
459  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
460  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
461  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
462  #define STR_PTR       SLJIT_GENERAL_REG1  #define STR_PTR       SLJIT_SAVED_REG1
463  #define STR_END       SLJIT_GENERAL_REG2  #define STR_END       SLJIT_SAVED_REG2
464  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
465  #define STACK_LIMIT   SLJIT_GENERAL_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
466  #define ARGUMENTS     SLJIT_GENERAL_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
467  #define CALL_COUNT    SLJIT_GENERAL_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
468  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
469    
470  /* Locals layout. */  /* Local space layout. */
471  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
472  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
473  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
474  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
475  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
476  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
 /* Head of the last recursion. */  
 #define RECURSIVE_HEAD   (4 * sizeof(sljit_w))  
477  /* Max limit of recursions. */  /* Max limit of recursions. */
478  #define CALL_LIMIT       (5 * sizeof(sljit_w))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
 /* Last known position of the requested byte. */  
 #define REQ_CHAR_PTR     (6 * sizeof(sljit_w))  
 /* End pointer of the first line. */  
 #define FIRSTLINE_END    (7 * sizeof(sljit_w))  
479  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
480  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
481  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
482  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. */
483  #define OVECTOR_START    (8 * sizeof(sljit_w))  #define OVECTOR_START    (common->ovector_start)
484  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
485  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
486  #define PRIV_DATA(cc)    (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
487    
488  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
489  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
490  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
491  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
492  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
493  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
494    #elif defined COMPILE_PCRE32
495    #define MOV_UCHAR  SLJIT_MOV_UI
496    #define MOVU_UCHAR SLJIT_MOVU_UI
497  #else  #else
498  #error Unsupported compiling mode  #error Unsupported compiling mode
499  #endif  #endif
 #endif  
500    
501  /* Shortcuts. */  /* Shortcuts. */
502  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 417  the start pointers when the end of the c Line 513  the start pointers when the end of the c
513    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
514  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
515    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
516    #define SET_LABEL(jump, label) \
517      sljit_set_label((jump), (label))
518  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
519    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
520  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
521    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))
522  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
523    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
524    #define GET_LOCAL_BASE(dst, dstw, offset) \
525      sljit_get_local_base(compiler, (dst), (dstw), (offset))
526    
527    #define READ_CHAR_ANY 0x7fffffff
528    
529  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
530  {  {
# Line 433  cc += 1 + LINK_SIZE; Line 535  cc += 1 + LINK_SIZE;
535  return cc;  return cc;
536  }  }
537    
538    static int ones_in_half_byte[16] = {
539      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
540      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
541    };
542    
543  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
544   next_opcode   next_opcode
545   get_localspace   check_opcode_types
546   set_localptrs   set_private_data_ptrs
547   get_framesize   get_framesize
548   init_frame   init_frame
549   get_localsize   get_private_data_copy_length
550   copy_locals   copy_private_data
551   compile_hotpath   compile_matchingpath
552   compile_fallbackpath   compile_backtrackingpath
553  */  */
554    
555  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
# Line 463  switch(*cc) Line 570  switch(*cc)
570    case OP_WORDCHAR:    case OP_WORDCHAR:
571    case OP_ANY:    case OP_ANY:
572    case OP_ALLANY:    case OP_ALLANY:
573      case OP_NOTPROP:
574      case OP_PROP:
575    case OP_ANYNL:    case OP_ANYNL:
576    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
577    case OP_HSPACE:    case OP_HSPACE:
# Line 475  switch(*cc) Line 584  switch(*cc)
584    case OP_CIRCM:    case OP_CIRCM:
585    case OP_DOLL:    case OP_DOLL:
586    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:  
587    case OP_CRSTAR:    case OP_CRSTAR:
588    case OP_CRMINSTAR:    case OP_CRMINSTAR:
589    case OP_CRPLUS:    case OP_CRPLUS:
590    case OP_CRMINPLUS:    case OP_CRMINPLUS:
591    case OP_CRQUERY:    case OP_CRQUERY:
592    case OP_CRMINQUERY:    case OP_CRMINQUERY:
593      case OP_CRRANGE:
594      case OP_CRMINRANGE:
595      case OP_CRPOSSTAR:
596      case OP_CRPOSPLUS:
597      case OP_CRPOSQUERY:
598      case OP_CRPOSRANGE:
599      case OP_CLASS:
600      case OP_NCLASS:
601      case OP_REF:
602      case OP_REFI:
603      case OP_DNREF:
604      case OP_DNREFI:
605      case OP_RECURSE:
606      case OP_CALLOUT:
607      case OP_ALT:
608      case OP_KET:
609      case OP_KETRMAX:
610      case OP_KETRMIN:
611      case OP_KETRPOS:
612      case OP_REVERSE:
613      case OP_ASSERT:
614      case OP_ASSERT_NOT:
615      case OP_ASSERTBACK:
616      case OP_ASSERTBACK_NOT:
617      case OP_ONCE:
618      case OP_ONCE_NC:
619      case OP_BRA:
620      case OP_BRAPOS:
621      case OP_CBRA:
622      case OP_CBRAPOS:
623      case OP_COND:
624      case OP_SBRA:
625      case OP_SBRAPOS:
626      case OP_SCBRA:
627      case OP_SCBRAPOS:
628      case OP_SCOND:
629      case OP_CREF:
630      case OP_DNCREF:
631      case OP_RREF:
632      case OP_DNRREF:
633    case OP_DEF:    case OP_DEF:
634    case OP_BRAZERO:    case OP_BRAZERO:
635    case OP_BRAMINZERO:    case OP_BRAMINZERO:
636    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
637      case OP_PRUNE:
638      case OP_SKIP:
639      case OP_THEN:
640      case OP_COMMIT:
641    case OP_FAIL:    case OP_FAIL:
642    case OP_ACCEPT:    case OP_ACCEPT:
643    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
644      case OP_CLOSE:
645    case OP_SKIPZERO:    case OP_SKIPZERO:
646    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
647    
648    case OP_CHAR:    case OP_CHAR:
649    case OP_CHARI:    case OP_CHARI:
# Line 516  switch(*cc) Line 655  switch(*cc)
655    case OP_MINPLUS:    case OP_MINPLUS:
656    case OP_QUERY:    case OP_QUERY:
657    case OP_MINQUERY:    case OP_MINQUERY:
658      case OP_UPTO:
659      case OP_MINUPTO:
660      case OP_EXACT:
661    case OP_POSSTAR:    case OP_POSSTAR:
662    case OP_POSPLUS:    case OP_POSPLUS:
663    case OP_POSQUERY:    case OP_POSQUERY:
664      case OP_POSUPTO:
665    case OP_STARI:    case OP_STARI:
666    case OP_MINSTARI:    case OP_MINSTARI:
667    case OP_PLUSI:    case OP_PLUSI:
668    case OP_MINPLUSI:    case OP_MINPLUSI:
669    case OP_QUERYI:    case OP_QUERYI:
670    case OP_MINQUERYI:    case OP_MINQUERYI:
671      case OP_UPTOI:
672      case OP_MINUPTOI:
673      case OP_EXACTI:
674    case OP_POSSTARI:    case OP_POSSTARI:
675    case OP_POSPLUSI:    case OP_POSPLUSI:
676    case OP_POSQUERYI:    case OP_POSQUERYI:
677      case OP_POSUPTOI:
678    case OP_NOTSTAR:    case OP_NOTSTAR:
679    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
680    case OP_NOTPLUS:    case OP_NOTPLUS:
681    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
682    case OP_NOTQUERY:    case OP_NOTQUERY:
683    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
684      case OP_NOTUPTO:
685      case OP_NOTMINUPTO:
686      case OP_NOTEXACT:
687    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
688    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
689    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
690      case OP_NOTPOSUPTO:
691    case OP_NOTSTARI:    case OP_NOTSTARI:
692    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
693    case OP_NOTPLUSI:    case OP_NOTPLUSI:
694    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
695    case OP_NOTQUERYI:    case OP_NOTQUERYI:
696    case OP_NOTMINQUERYI:    case OP_NOTMINQUERYI:
   case OP_NOTPOSSTARI:  
   case OP_NOTPOSPLUSI:  
   case OP_NOTPOSQUERYI:  
   cc += 2;  
 #ifdef SUPPORT_UTF  
   if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #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:  
697    case OP_NOTUPTOI:    case OP_NOTUPTOI:
698    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
699    case OP_NOTEXACTI:    case OP_NOTEXACTI:
700      case OP_NOTPOSSTARI:
701      case OP_NOTPOSPLUSI:
702      case OP_NOTPOSQUERYI:
703    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
704    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
705  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
706    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
707  #endif  #endif
708    return cc;    return cc;
709    
710    case OP_NOTPROP:    /* Special cases. */
711    case OP_PROP:    case OP_TYPESTAR:
712    return cc + 1 + 2;    case OP_TYPEMINSTAR:
713      case OP_TYPEPLUS:
714      case OP_TYPEMINPLUS:
715      case OP_TYPEQUERY:
716      case OP_TYPEMINQUERY:
717    case OP_TYPEUPTO:    case OP_TYPEUPTO:
718    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
719    case OP_TYPEEXACT:    case OP_TYPEEXACT:
720      case OP_TYPEPOSSTAR:
721      case OP_TYPEPOSPLUS:
722      case OP_TYPEPOSQUERY:
723    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
724    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_NCREF:  
   case OP_RREF:  
   case OP_NRREF:  
   case OP_CLOSE:  
   cc += 1 + IMM2_SIZE;  
   return cc;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   return cc + 1 + 2 * IMM2_SIZE;  
725    
726    case OP_CLASS:    case OP_ANYBYTE:
727    case OP_NCLASS:  #ifdef SUPPORT_UTF
728    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
729    #endif
730      return cc + 1;
731    
732  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
733    case OP_XCLASS:    case OP_XCLASS:
734    return cc + GET(cc, 1);    return cc + GET(cc, 1);
735  #endif  #endif
736    
737    case OP_RECURSE:    case OP_MARK:
738    case OP_ASSERT:    case OP_PRUNE_ARG:
739    case OP_ASSERT_NOT:    case OP_SKIP_ARG:
740    case OP_ASSERTBACK:    case OP_THEN_ARG:
741    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 + IMM2_SIZE;  
742    
743    default:    default:
744      /* All opcodes are supported now! */
745      SLJIT_ASSERT_STOP();
746    return NULL;    return NULL;
747    }    }
748  }  }
749    
750  static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
751  {  {
752  int localspace = 0;  int count;
753  pcre_uchar *alternative;  pcre_uchar *slot;
754    
755  /* 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. */
756  while (cc < ccend)  while (cc < ccend)
757    {    {
758    switch(*cc)    switch(*cc)
759      {      {
760      case OP_ASSERT:      case OP_SET_SOM:
761      case OP_ASSERT_NOT:      common->has_set_som = TRUE;
762      case OP_ASSERTBACK:      cc += 1;
763      case OP_ASSERTBACK_NOT:      break;
764      case OP_ONCE:  
765      case OP_ONCE_NC:      case OP_REF:
766      case OP_BRAPOS:      case OP_REFI:
767      case OP_SBRA:      common->optimized_cbracket[GET2(cc, 1)] = 0;
768      case OP_SBRAPOS:      cc += 1 + IMM2_SIZE;
     case OP_SCOND:  
     localspace += sizeof(sljit_w);  
     cc += 1 + LINK_SIZE;  
769      break;      break;
770    
771      case OP_CBRAPOS:      case OP_CBRAPOS:
772      case OP_SCBRAPOS:      case OP_SCBRAPOS:
773      localspace += sizeof(sljit_w);      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
774      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
775      break;      break;
776    
777      case OP_COND:      case OP_COND:
778      /* Might be a hidden SCOND. */      case OP_SCOND:
779      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
780      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
781        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
782          return FALSE;
783      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
784      break;      break;
785    
786      default:      case OP_CREF:
787      cc = next_opcode(common, cc);      common->optimized_cbracket[GET2(cc, 1)] = 0;
788      if (cc == NULL)      cc += 1 + IMM2_SIZE;
789        return -1;      break;
790    
791        case OP_DNREF:
792        case OP_DNREFI:
793        case OP_DNCREF:
794        count = GET2(cc, 1 + IMM2_SIZE);
795        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
796        while (count-- > 0)
797          {
798          common->optimized_cbracket[GET2(slot, 0)] = 0;
799          slot += common->name_entry_size;
800          }
801        cc += 1 + 2 * IMM2_SIZE;
802      break;      break;
     }  
   }  
 return localspace;  
 }  
803    
804  static void set_localptrs(compiler_common *common, int localptr, pcre_uchar *ccend)      case OP_RECURSE:
805  {      /* Set its value only once. */
806  pcre_uchar *cc = common->start;      if (common->recursive_head_ptr == 0)
807  pcre_uchar *alternative;        {
808  while (cc < ccend)        common->recursive_head_ptr = common->ovector_start;
809    {        common->ovector_start += sizeof(sljit_sw);
810    switch(*cc)        }
     {  
     case OP_ASSERT:  
     case OP_ASSERT_NOT:  
     case OP_ASSERTBACK:  
     case OP_ASSERTBACK_NOT:  
     case OP_ONCE:  
     case OP_ONCE_NC:  
     case OP_BRAPOS:  
     case OP_SBRA:  
     case OP_SBRAPOS:  
     case OP_SCOND:  
     common->localptrs[cc - common->start] = localptr;  
     localptr += sizeof(sljit_w);  
811      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
812      break;      break;
813    
814      case OP_CBRAPOS:      case OP_CALLOUT:
815      case OP_SCBRAPOS:      if (common->capture_last_ptr == 0)
816      common->localptrs[cc - common->start] = localptr;        {
817      localptr += sizeof(sljit_w);        common->capture_last_ptr = common->ovector_start;
818      cc += 1 + LINK_SIZE + IMM2_SIZE;        common->ovector_start += sizeof(sljit_sw);
819          }
820        cc += 2 + 2 * LINK_SIZE;
821      break;      break;
822    
823      case OP_COND:      case OP_THEN_ARG:
824      /* Might be a hidden SCOND. */      common->has_then = TRUE;
825      alternative = cc + GET(cc, 1);      common->control_head_ptr = 1;
826      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      /* Fall through. */
827    
828        case OP_PRUNE_ARG:
829        common->needs_start_ptr = TRUE;
830        /* Fall through. */
831    
832        case OP_MARK:
833        if (common->mark_ptr == 0)
834        {        {
835        common->localptrs[cc - common->start] = localptr;        common->mark_ptr = common->ovector_start;
836        localptr += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
837        }        }
838      cc += 1 + LINK_SIZE;      cc += 1 + 2 + cc[1];
839        break;
840    
841        case OP_THEN:
842        common->has_then = TRUE;
843        common->control_head_ptr = 1;
844        /* Fall through. */
845    
846        case OP_PRUNE:
847        case OP_SKIP:
848        common->needs_start_ptr = TRUE;
849        cc += 1;
850        break;
851    
852        case OP_SKIP_ARG:
853        common->control_head_ptr = 1;
854        common->has_skip_arg = TRUE;
855        cc += 1 + 2 + cc[1];
856      break;      break;
857    
858      default:      default:
859      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
860      SLJIT_ASSERT(cc != NULL);      if (cc == NULL)
861          return FALSE;
862      break;      break;
863      }      }
864    }    }
865    return TRUE;
866  }  }
867    
868  /* Returns with -1 if no need for frame. */  static int get_class_iterator_size(pcre_uchar *cc)
 static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  
869  {  {
870  pcre_uchar *ccend = bracketend(cc);  switch(*cc)
 int length = 0;  
 BOOL possessive = FALSE;  
 BOOL setsom_found = FALSE;  
   
 if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  
871    {    {
872    length = 3;    case OP_CRSTAR:
873    possessive = TRUE;    case OP_CRPLUS:
874      return 2;
875    
876      case OP_CRMINSTAR:
877      case OP_CRMINPLUS:
878      case OP_CRQUERY:
879      case OP_CRMINQUERY:
880      return 1;
881    
882      case OP_CRRANGE:
883      case OP_CRMINRANGE:
884      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
885        return 0;
886      return 2;
887    
888      default:
889      return 0;
890      }
891    }
892    
893    static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
894    {
895    pcre_uchar *end = bracketend(begin);
896    pcre_uchar *next;
897    pcre_uchar *next_end;
898    pcre_uchar *max_end;
899    pcre_uchar type;
900    sljit_sw length = end - begin;
901    int min, max, i;
902    
903    /* Detect fixed iterations first. */
904    if (end[-(1 + LINK_SIZE)] != OP_KET)
905      return FALSE;
906    
907    /* Already detected repeat. */
908    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
909      return TRUE;
910    
911    next = end;
912    min = 1;
913    while (1)
914      {
915      if (*next != *begin)
916        break;
917      next_end = bracketend(next);
918      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
919        break;
920      next = next_end;
921      min++;
922      }
923    
924    if (min == 2)
925      return FALSE;
926    
927    max = 0;
928    max_end = next;
929    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
930      {
931      type = *next;
932      while (1)
933        {
934        if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
935          break;
936        next_end = bracketend(next + 2 + LINK_SIZE);
937        if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
938          break;
939        next = next_end;
940        max++;
941        }
942    
943      if (next[0] == type && next[1] == *begin && max >= 1)
944        {
945        next_end = bracketend(next + 1);
946        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
947          {
948          for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
949            if (*next_end != OP_KET)
950              break;
951    
952          if (i == max)
953            {
954            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
955            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
956            /* +2 the original and the last. */
957            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
958            if (min == 1)
959              return TRUE;
960            min--;
961            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
962            }
963          }
964        }
965      }
966    
967    if (min >= 3)
968      {
969      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
970      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
971      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
972      return TRUE;
973      }
974    
975    return FALSE;
976    }
977    
978    #define CASE_ITERATOR_PRIVATE_DATA_1 \
979        case OP_MINSTAR: \
980        case OP_MINPLUS: \
981        case OP_QUERY: \
982        case OP_MINQUERY: \
983        case OP_MINSTARI: \
984        case OP_MINPLUSI: \
985        case OP_QUERYI: \
986        case OP_MINQUERYI: \
987        case OP_NOTMINSTAR: \
988        case OP_NOTMINPLUS: \
989        case OP_NOTQUERY: \
990        case OP_NOTMINQUERY: \
991        case OP_NOTMINSTARI: \
992        case OP_NOTMINPLUSI: \
993        case OP_NOTQUERYI: \
994        case OP_NOTMINQUERYI:
995    
996    #define CASE_ITERATOR_PRIVATE_DATA_2A \
997        case OP_STAR: \
998        case OP_PLUS: \
999        case OP_STARI: \
1000        case OP_PLUSI: \
1001        case OP_NOTSTAR: \
1002        case OP_NOTPLUS: \
1003        case OP_NOTSTARI: \
1004        case OP_NOTPLUSI:
1005    
1006    #define CASE_ITERATOR_PRIVATE_DATA_2B \
1007        case OP_UPTO: \
1008        case OP_MINUPTO: \
1009        case OP_UPTOI: \
1010        case OP_MINUPTOI: \
1011        case OP_NOTUPTO: \
1012        case OP_NOTMINUPTO: \
1013        case OP_NOTUPTOI: \
1014        case OP_NOTMINUPTOI:
1015    
1016    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1017        case OP_TYPEMINSTAR: \
1018        case OP_TYPEMINPLUS: \
1019        case OP_TYPEQUERY: \
1020        case OP_TYPEMINQUERY:
1021    
1022    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1023        case OP_TYPESTAR: \
1024        case OP_TYPEPLUS:
1025    
1026    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1027        case OP_TYPEUPTO: \
1028        case OP_TYPEMINUPTO:
1029    
1030    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1031    {
1032    pcre_uchar *cc = common->start;
1033    pcre_uchar *alternative;
1034    pcre_uchar *end = NULL;
1035    int private_data_ptr = *private_data_start;
1036    int space, size, bracketlen;
1037    
1038    while (cc < ccend)
1039      {
1040      space = 0;
1041      size = 0;
1042      bracketlen = 0;
1043      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1044        return;
1045    
1046      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1047        if (detect_repeat(common, cc))
1048          {
1049          /* These brackets are converted to repeats, so no global
1050          based single character repeat is allowed. */
1051          if (cc >= end)
1052            end = bracketend(cc);
1053          }
1054    
1055      switch(*cc)
1056        {
1057        case OP_KET:
1058        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1059          {
1060          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1061          private_data_ptr += sizeof(sljit_sw);
1062          cc += common->private_data_ptrs[cc + 1 - common->start];
1063          }
1064        cc += 1 + LINK_SIZE;
1065        break;
1066    
1067        case OP_ASSERT:
1068        case OP_ASSERT_NOT:
1069        case OP_ASSERTBACK:
1070        case OP_ASSERTBACK_NOT:
1071        case OP_ONCE:
1072        case OP_ONCE_NC:
1073        case OP_BRAPOS:
1074        case OP_SBRA:
1075        case OP_SBRAPOS:
1076        case OP_SCOND:
1077        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1078        private_data_ptr += sizeof(sljit_sw);
1079        bracketlen = 1 + LINK_SIZE;
1080        break;
1081    
1082        case OP_CBRAPOS:
1083        case OP_SCBRAPOS:
1084        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1085        private_data_ptr += sizeof(sljit_sw);
1086        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1087        break;
1088    
1089        case OP_COND:
1090        /* Might be a hidden SCOND. */
1091        alternative = cc + GET(cc, 1);
1092        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1093          {
1094          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1095          private_data_ptr += sizeof(sljit_sw);
1096          }
1097        bracketlen = 1 + LINK_SIZE;
1098        break;
1099    
1100        case OP_BRA:
1101        bracketlen = 1 + LINK_SIZE;
1102        break;
1103    
1104        case OP_CBRA:
1105        case OP_SCBRA:
1106        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1107        break;
1108    
1109        CASE_ITERATOR_PRIVATE_DATA_1
1110        space = 1;
1111        size = -2;
1112        break;
1113    
1114        CASE_ITERATOR_PRIVATE_DATA_2A
1115        space = 2;
1116        size = -2;
1117        break;
1118    
1119        CASE_ITERATOR_PRIVATE_DATA_2B
1120        space = 2;
1121        size = -(2 + IMM2_SIZE);
1122        break;
1123    
1124        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1125        space = 1;
1126        size = 1;
1127        break;
1128    
1129        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1130        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1131          space = 2;
1132        size = 1;
1133        break;
1134    
1135        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1136        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1137          space = 2;
1138        size = 1 + IMM2_SIZE;
1139        break;
1140    
1141        case OP_CLASS:
1142        case OP_NCLASS:
1143        size += 1 + 32 / sizeof(pcre_uchar);
1144        space = get_class_iterator_size(cc + size);
1145        break;
1146    
1147    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1148        case OP_XCLASS:
1149        size = GET(cc, 1);
1150        space = get_class_iterator_size(cc + size);
1151        break;
1152    #endif
1153    
1154        default:
1155        cc = next_opcode(common, cc);
1156        SLJIT_ASSERT(cc != NULL);
1157        break;
1158        }
1159    
1160      /* Character iterators, which are not inside a repeated bracket,
1161         gets a private slot instead of allocating it on the stack. */
1162      if (space > 0 && cc >= end)
1163        {
1164        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1165        private_data_ptr += sizeof(sljit_sw) * space;
1166        }
1167    
1168      if (size != 0)
1169        {
1170        if (size < 0)
1171          {
1172          cc += -size;
1173    #ifdef SUPPORT_UTF
1174          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1175    #endif
1176          }
1177        else
1178          cc += size;
1179        }
1180    
1181      if (bracketlen > 0)
1182        {
1183        if (cc >= end)
1184          {
1185          end = bracketend(cc);
1186          if (end[-1 - LINK_SIZE] == OP_KET)
1187            end = NULL;
1188          }
1189        cc += bracketlen;
1190        }
1191      }
1192    *private_data_start = private_data_ptr;
1193    }
1194    
1195    /* Returns with a frame_types (always < 0) if no need for frame. */
1196    static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head)
1197    {
1198    int length = 0;
1199    int possessive = 0;
1200    BOOL stack_restore = FALSE;
1201    BOOL setsom_found = recursive;
1202    BOOL setmark_found = recursive;
1203    /* The last capture is a local variable even for recursions. */
1204    BOOL capture_last_found = FALSE;
1205    
1206    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1207    SLJIT_ASSERT(common->control_head_ptr != 0);
1208    *needs_control_head = TRUE;
1209    #else
1210    *needs_control_head = FALSE;
1211    #endif
1212    
1213    if (ccend == NULL)
1214      {
1215      ccend = bracketend(cc) - (1 + LINK_SIZE);
1216      if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1217        {
1218        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1219        /* This is correct regardless of common->capture_last_ptr. */
1220        capture_last_found = TRUE;
1221        }
1222      cc = next_opcode(common, cc);
1223    }    }
1224    
 cc = next_opcode(common, cc);  
1225  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1226  while (cc < ccend)  while (cc < ccend)
1227    switch(*cc)    switch(*cc)
1228      {      {
1229      case OP_SET_SOM:      case OP_SET_SOM:
1230      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1231        stack_restore = TRUE;
1232      if (!setsom_found)      if (!setsom_found)
1233        {        {
1234        length += 2;        length += 2;
1235        setsom_found = TRUE;        setsom_found = TRUE;
1236        }        }
1237      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      cc += 1;
1238        break;
1239    
1240        case OP_MARK:
1241        case OP_PRUNE_ARG:
1242        case OP_THEN_ARG:
1243        SLJIT_ASSERT(common->mark_ptr != 0);
1244        stack_restore = TRUE;
1245        if (!setmark_found)
1246          {
1247          length += 2;
1248          setmark_found = TRUE;
1249          }
1250        if (common->control_head_ptr != 0)
1251          *needs_control_head = TRUE;
1252        cc += 1 + 2 + cc[1];
1253        break;
1254    
1255        case OP_RECURSE:
1256        stack_restore = TRUE;
1257        if (common->has_set_som && !setsom_found)
1258          {
1259          length += 2;
1260          setsom_found = TRUE;
1261          }
1262        if (common->mark_ptr != 0 && !setmark_found)
1263          {
1264          length += 2;
1265          setmark_found = TRUE;
1266          }
1267        if (common->capture_last_ptr != 0 && !capture_last_found)
1268          {
1269          length += 2;
1270          capture_last_found = TRUE;
1271          }
1272        cc += 1 + LINK_SIZE;
1273      break;      break;
1274    
1275      case OP_CBRA:      case OP_CBRA:
1276      case OP_CBRAPOS:      case OP_CBRAPOS:
1277      case OP_SCBRA:      case OP_SCBRA:
1278      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1279        stack_restore = TRUE;
1280        if (common->capture_last_ptr != 0 && !capture_last_found)
1281          {
1282          length += 2;
1283          capture_last_found = TRUE;
1284          }
1285      length += 3;      length += 3;
1286      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1287      break;      break;
1288    
1289      default:      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        case OP_NOTEXACT:
1336        case OP_NOTPOSSTAR:
1337        case OP_NOTPOSPLUS:
1338        case OP_NOTPOSQUERY:
1339        case OP_NOTPOSUPTO:
1340    
1341        case OP_NOTEXACTI:
1342        case OP_NOTPOSSTARI:
1343        case OP_NOTPOSPLUSI:
1344        case OP_NOTPOSQUERYI:
1345        case OP_NOTPOSUPTOI:
1346    
1347        case OP_TYPEEXACT:
1348        case OP_TYPEPOSSTAR:
1349        case OP_TYPEPOSPLUS:
1350        case OP_TYPEPOSQUERY:
1351        case OP_TYPEPOSUPTO:
1352    
1353        case OP_CLASS:
1354        case OP_NCLASS:
1355        case OP_XCLASS:
1356    
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, pcre_uchar *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  pcre_uchar *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 + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1481      break;      break;
# Line 839  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, pcre_uchar *cc, pcre_uchar *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    int size;
1497  pcre_uchar *alternative;  pcre_uchar *alternative;
1498  /* Calculate the sum of the local variables. */  /* 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_KET:
1505        if (PRIVATE_DATA(cc) != 0)
1506          private_data_length++;
1507        cc += 1 + LINK_SIZE;
1508        break;
1509    
1510      case OP_ASSERT:      case OP_ASSERT:
1511      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1512      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 862  while (cc < ccend) Line 1517  while (cc < ccend)
1517      case OP_SBRA:      case OP_SBRA:
1518      case OP_SBRAPOS:      case OP_SBRAPOS:
1519      case OP_SCOND:      case OP_SCOND:
1520      localsize++;      private_data_length++;
1521      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1522      break;      break;
1523    
1524      case OP_CBRA:      case OP_CBRA:
1525      case OP_SCBRA:      case OP_SCBRA:
1526      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1527          private_data_length++;
1528      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1529      break;      break;
1530    
1531      case OP_CBRAPOS:      case OP_CBRAPOS:
1532      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1533      localsize += 2;      private_data_length += 2;
1534      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1535      break;      break;
1536    
# Line 882  while (cc < ccend) Line 1538  while (cc < ccend)
1538      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1539      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1540      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1541        localsize++;        private_data_length++;
1542      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1543      break;      break;
1544    
1545        CASE_ITERATOR_PRIVATE_DATA_1
1546        if (PRIVATE_DATA(cc))
1547          private_data_length++;
1548        cc += 2;
1549    #ifdef SUPPORT_UTF
1550        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1551    #endif
1552        break;
1553    
1554        CASE_ITERATOR_PRIVATE_DATA_2A
1555        if (PRIVATE_DATA(cc))
1556          private_data_length += 2;
1557        cc += 2;
1558    #ifdef SUPPORT_UTF
1559        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1560    #endif
1561        break;
1562    
1563        CASE_ITERATOR_PRIVATE_DATA_2B
1564        if (PRIVATE_DATA(cc))
1565          private_data_length += 2;
1566        cc += 2 + IMM2_SIZE;
1567    #ifdef SUPPORT_UTF
1568        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1569    #endif
1570        break;
1571    
1572        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1573        if (PRIVATE_DATA(cc))
1574          private_data_length++;
1575        cc += 1;
1576        break;
1577    
1578        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1579        if (PRIVATE_DATA(cc))
1580          private_data_length += 2;
1581        cc += 1;
1582        break;
1583    
1584        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1585        if (PRIVATE_DATA(cc))
1586          private_data_length += 2;
1587        cc += 1 + IMM2_SIZE;
1588        break;
1589    
1590        case OP_CLASS:
1591        case OP_NCLASS:
1592    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1593        case OP_XCLASS:
1594        size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1595    #else
1596        size = 1 + 32 / (int)sizeof(pcre_uchar);
1597    #endif
1598        if (PRIVATE_DATA(cc))
1599          private_data_length += get_class_iterator_size(cc + size);
1600        cc += size;
1601        break;
1602    
1603      default:      default:
1604      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1605      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 893  while (cc < ccend) Line 1607  while (cc < ccend)
1607      }      }
1608    }    }
1609  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1610  return localsize;  return private_data_length;
1611  }  }
1612    
1613  static void copy_locals(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,
1614    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1615  {  {
1616  DEFINE_COMPILER;  DEFINE_COMPILER;
1617  int srcw[2];  int srcw[2];
1618  int count;  int count, size;
1619  BOOL tmp1next = TRUE;  BOOL tmp1next = TRUE;
1620  BOOL tmp1empty = TRUE;  BOOL tmp1empty = TRUE;
1621  BOOL tmp2empty = TRUE;  BOOL tmp2empty = TRUE;
# Line 918  stacktop = STACK(stacktop - 1); Line 1632  stacktop = STACK(stacktop - 1);
1632    
1633  if (!save)  if (!save)
1634    {    {
1635    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1636    if (stackptr < stacktop)    if (stackptr < stacktop)
1637      {      {
1638      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1639      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1640      tmp1empty = FALSE;      tmp1empty = FALSE;
1641      }      }
1642    if (stackptr < stacktop)    if (stackptr < stacktop)
1643      {      {
1644      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1645      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1646      tmp2empty = FALSE;      tmp2empty = FALSE;
1647      }      }
1648    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1649    }    }
1650    
1651  while (status != end)  do
1652    {    {
1653    count = 0;    count = 0;
1654    switch(status)    switch(status)
1655      {      {
1656      case start:      case start:
1657      SLJIT_ASSERT(save);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1658      count = 1;      count = 1;
1659      srcw[0] = RECURSIVE_HEAD;      srcw[0] = common->recursive_head_ptr;
1660        if (needs_control_head)
1661          {
1662          SLJIT_ASSERT(common->control_head_ptr != 0);
1663          count = 2;
1664          srcw[1] = common->control_head_ptr;
1665          }
1666      status = loop;      status = loop;
1667      break;      break;
1668    
# Line 955  while (status != end) Line 1675  while (status != end)
1675    
1676      switch(*cc)      switch(*cc)
1677        {        {
1678          case OP_KET:
1679          if (PRIVATE_DATA(cc) != 0)
1680            {
1681            count = 1;
1682            srcw[0] = PRIVATE_DATA(cc);
1683            }
1684          cc += 1 + LINK_SIZE;
1685          break;
1686    
1687        case OP_ASSERT:        case OP_ASSERT:
1688        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1689        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 966  while (status != end) Line 1695  while (status != end)
1695        case OP_SBRAPOS:        case OP_SBRAPOS:
1696        case OP_SCOND:        case OP_SCOND:
1697        count = 1;        count = 1;
1698        srcw[0] = PRIV_DATA(cc);        srcw[0] = PRIVATE_DATA(cc);
1699        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1700        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1701        break;        break;
1702    
1703        case OP_CBRA:        case OP_CBRA:
1704        case OP_SCBRA:        case OP_SCBRA:
1705        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1706        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1707            count = 1;
1708            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1709            }
1710        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1711        break;        break;
1712    
1713        case OP_CBRAPOS:        case OP_CBRAPOS:
1714        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1715        count = 2;        count = 2;
1716          srcw[0] = PRIVATE_DATA(cc);
1717        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1718        srcw[0] = PRIV_DATA(cc);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
       SLJIT_ASSERT(srcw[0] != 0);  
1719        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1720        break;        break;
1721    
# Line 993  while (status != end) Line 1725  while (status != end)
1725        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1726          {          {
1727          count = 1;          count = 1;
1728          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1729          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1730          }          }
1731        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1732        break;        break;
1733    
1734          CASE_ITERATOR_PRIVATE_DATA_1
1735          if (PRIVATE_DATA(cc))
1736            {
1737            count = 1;
1738            srcw[0] = PRIVATE_DATA(cc);
1739            }
1740          cc += 2;
1741    #ifdef SUPPORT_UTF
1742          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1743    #endif
1744          break;
1745    
1746          CASE_ITERATOR_PRIVATE_DATA_2A
1747          if (PRIVATE_DATA(cc))
1748            {
1749            count = 2;
1750            srcw[0] = PRIVATE_DATA(cc);
1751            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1752            }
1753          cc += 2;
1754    #ifdef SUPPORT_UTF
1755          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1756    #endif
1757          break;
1758    
1759          CASE_ITERATOR_PRIVATE_DATA_2B
1760          if (PRIVATE_DATA(cc))
1761            {
1762            count = 2;
1763            srcw[0] = PRIVATE_DATA(cc);
1764            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1765            }
1766          cc += 2 + IMM2_SIZE;
1767    #ifdef SUPPORT_UTF
1768          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1769    #endif
1770          break;
1771    
1772          CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1773          if (PRIVATE_DATA(cc))
1774            {
1775            count = 1;
1776            srcw[0] = PRIVATE_DATA(cc);
1777            }
1778          cc += 1;
1779          break;
1780    
1781          CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1782          if (PRIVATE_DATA(cc))
1783            {
1784            count = 2;
1785            srcw[0] = PRIVATE_DATA(cc);
1786            srcw[1] = srcw[0] + sizeof(sljit_sw);
1787            }
1788          cc += 1;
1789          break;
1790    
1791          CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1792          if (PRIVATE_DATA(cc))
1793            {
1794            count = 2;
1795            srcw[0] = PRIVATE_DATA(cc);
1796            srcw[1] = srcw[0] + sizeof(sljit_sw);
1797            }
1798          cc += 1 + IMM2_SIZE;
1799          break;
1800    
1801          case OP_CLASS:
1802          case OP_NCLASS:
1803    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1804          case OP_XCLASS:
1805          size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1806    #else
1807          size = 1 + 32 / (int)sizeof(pcre_uchar);
1808    #endif
1809          if (PRIVATE_DATA(cc))
1810            switch(get_class_iterator_size(cc + size))
1811              {
1812              case 1:
1813              count = 1;
1814              srcw[0] = PRIVATE_DATA(cc);
1815              break;
1816    
1817              case 2:
1818              count = 2;
1819              srcw[0] = PRIVATE_DATA(cc);
1820              srcw[1] = srcw[0] + sizeof(sljit_sw);
1821              break;
1822    
1823              default:
1824              SLJIT_ASSERT_STOP();
1825              break;
1826              }
1827          cc += size;
1828          break;
1829    
1830        default:        default:
1831        cc = next_opcode(common, cc);        cc = next_opcode(common, cc);
1832        SLJIT_ASSERT(cc != NULL);        SLJIT_ASSERT(cc != NULL);
# Line 1021  while (status != end) Line 1849  while (status != end)
1849          if (!tmp1empty)          if (!tmp1empty)
1850            {            {
1851            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1852            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1853            }            }
1854          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1855          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1032  while (status != end) Line 1860  while (status != end)
1860          if (!tmp2empty)          if (!tmp2empty)
1861            {            {
1862            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1863            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1864            }            }
1865          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1866          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1049  while (status != end) Line 1877  while (status != end)
1877          if (!tmp1empty)          if (!tmp1empty)
1878            {            {
1879            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1880            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1881            }            }
1882          tmp1next = FALSE;          tmp1next = FALSE;
1883          }          }
# Line 1061  while (status != end) Line 1889  while (status != end)
1889          if (!tmp2empty)          if (!tmp2empty)
1890            {            {
1891            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1892            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1893            }            }
1894          tmp1next = TRUE;          tmp1next = TRUE;
1895          }          }
1896        }        }
1897      }      }
1898    }    }
1899    while (status != end);
1900    
1901  if (save)  if (save)
1902    {    {
# Line 1076  if (save) Line 1905  if (save)
1905      if (!tmp1empty)      if (!tmp1empty)
1906        {        {
1907        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1908        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1909        }        }
1910      if (!tmp2empty)      if (!tmp2empty)
1911        {        {
1912        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1913        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1914        }        }
1915      }      }
1916    else    else
# Line 1089  if (save) Line 1918  if (save)
1918      if (!tmp2empty)      if (!tmp2empty)
1919        {        {
1920        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1921        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1922        }        }
1923      if (!tmp1empty)      if (!tmp1empty)
1924        {        {
1925        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1926        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1927        }        }
1928      }      }
1929    }    }
1930  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1931  }  }
1932    
1933  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)
1934    {
1935    pcre_uchar *end = bracketend(cc);
1936    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1937    
1938    /* Assert captures then. */
1939    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1940      current_offset = NULL;
1941    /* Conditional block does not. */
1942    if (*cc == OP_COND || *cc == OP_SCOND)
1943      has_alternatives = FALSE;
1944    
1945    cc = next_opcode(common, cc);
1946    if (has_alternatives)
1947      current_offset = common->then_offsets + (cc - common->start);
1948    
1949    while (cc < end)
1950      {
1951      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1952        cc = set_then_offsets(common, cc, current_offset);
1953      else
1954        {
1955        if (*cc == OP_ALT && has_alternatives)
1956          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1957        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1958          *current_offset = 1;
1959        cc = next_opcode(common, cc);
1960        }
1961      }
1962    
1963    return end;
1964    }
1965    
1966    #undef CASE_ITERATOR_PRIVATE_DATA_1
1967    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1968    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1969    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1970    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1971    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1972    
1973    static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1974  {  {
1975  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1976  }  }
# Line 1111  static SLJIT_INLINE void set_jumps(jump_ Line 1980  static SLJIT_INLINE void set_jumps(jump_
1980  while (list)  while (list)
1981    {    {
1982    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1983    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1984    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1985    list = list->next;    list = list->next;
1986    }    }
1987  }  }
# Line 1128  if (list_item) Line 1997  if (list_item)
1997    }    }
1998  }  }
1999    
2000  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)
2001  {  {
2002  DEFINE_COMPILER;  DEFINE_COMPILER;
2003  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
2004    
2005  if (list_item)  if (list_item)
2006    {    {
   list_item->type = type;  
   list_item->data = data;  
2007    list_item->start = start;    list_item->start = start;
2008    list_item->leave = LABEL();    list_item->quit = LABEL();
2009    list_item->next = common->stubs;    list_item->next = common->stubs;
2010    common->stubs = list_item;    common->stubs = list_item;
2011    }    }
# Line 1152  stub_list* list_item = common->stubs; Line 2019  stub_list* list_item = common->stubs;
2019  while (list_item)  while (list_item)
2020    {    {
2021    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2022    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
2023      {    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);  
2024    list_item = list_item->next;    list_item = list_item->next;
2025    }    }
2026  common->stubs = NULL;  common->stubs = NULL;
2027  }  }
2028    
2029  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2030  {  {
2031  DEFINE_COMPILER;  DEFINE_COMPILER;
2032    
2033  OP2(SLJIT_SUB | SLJIT_SET_E, CALL_COUNT, 0, CALL_COUNT, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1);
2034  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2035  }  }
2036    
# Line 1177  static SLJIT_INLINE void allocate_stack( Line 2039  static SLJIT_INLINE void allocate_stack(
2039  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2040  DEFINE_COMPILER;  DEFINE_COMPILER;
2041    
2042  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));
2043  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2044  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2045  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1185  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2047  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2047  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2048  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2049  #endif  #endif
2050  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));
2051  }  }
2052    
2053  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2054  {  {
2055  DEFINE_COMPILER;  DEFINE_COMPILER;
2056  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));
2057  }  }
2058    
2059  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1199  static SLJIT_INLINE void reset_ovector(c Line 2061  static SLJIT_INLINE void reset_ovector(c
2061  DEFINE_COMPILER;  DEFINE_COMPILER;
2062  struct sljit_label *loop;  struct sljit_label *loop;
2063  int i;  int i;
2064    
2065  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2066    SLJIT_ASSERT(length > 1);
2067  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2068  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_GENERAL_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
2069    if (length < 8)
2070      {
2071      for (i = 1; i < length; i++)
2072        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2073      }
2074    else
2075      {
2076      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2077      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2078      loop = LABEL();
2079      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2080      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2081      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2082      }
2083    }
2084    
2085    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2086    {
2087    DEFINE_COMPILER;
2088    struct sljit_label *loop;
2089    int i;
2090    
2091    SLJIT_ASSERT(length > 1);
2092    /* OVECTOR(1) contains the "string begin - 1" constant. */
2093    if (length > 2)
2094      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2095  if (length < 8)  if (length < 8)
2096    {    {
2097    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2098      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_TEMPORARY_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
2099    }    }
2100  else  else
2101    {    {
2102    OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2103    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2104    loop = LABEL();    loop = LABEL();
2105    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2106    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2107    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2108    }    }
2109    
2110    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2111    if (common->mark_ptr != 0)
2112      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2113    if (common->control_head_ptr != 0)
2114      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2115    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2116    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2117    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2118    }
2119    
2120    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2121    {
2122    while (current != NULL)
2123      {
2124      switch (current[-2])
2125        {
2126        case type_then_trap:
2127        break;
2128    
2129        case type_mark:
2130        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2131          return current[-4];
2132        break;
2133    
2134        default:
2135        SLJIT_ASSERT_STOP();
2136        break;
2137        }
2138      current = (sljit_sw*)current[-1];
2139      }
2140    return -1;
2141  }  }
2142    
2143  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2144  {  {
2145  DEFINE_COMPILER;  DEFINE_COMPILER;
2146  struct sljit_label *loop;  struct sljit_label *loop;
2147  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2148    
2149  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2150  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));
2151  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);
2152    
2153  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2154  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  if (common->mark_ptr != 0)
2155  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);
2156  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));
2157  OP2(SLJIT_ADD, SLJIT_GENERAL_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START);  if (common->mark_ptr != 0)
2158      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);
2159    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
2160    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
2161    GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2162  /* Unlikely, but possible */  /* Unlikely, but possible */
2163  earlyexit = CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0);  early_quit = CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
2164  loop = LABEL();  loop = LABEL();
2165  OP2(SLJIT_SUB, SLJIT_GENERAL_REG2, 0, SLJIT_MEM1(SLJIT_GENERAL_REG1), 0, SLJIT_TEMPORARY_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
2166  OP2(SLJIT_ADD, SLJIT_GENERAL_REG1, 0, SLJIT_GENERAL_REG1, 0, SLJIT_IMM, sizeof(sljit_w));  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
2167  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2168  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2169  OP2(SLJIT_ASHR, SLJIT_GENERAL_REG2, 0, SLJIT_GENERAL_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2170  #endif  #endif
2171  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_GENERAL_REG2, 0);  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
2172  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2173  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2174  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2175    
2176  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2177  if (topbracket > 1)  if (topbracket > 1)
2178    {    {
2179    OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START + topbracket * 2 * sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
2180    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2181    
2182    /* OVECTOR(0) is never equal to SLJIT_GENERAL_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2183    loop = LABEL();    loop = LABEL();
2184    OP1(SLJIT_MOVU, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), -(2 * (sljit_w)sizeof(sljit_w)));    OP1(SLJIT_MOVU, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -(2 * (sljit_sw)sizeof(sljit_sw)));
2185    OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2186    CMPTO(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG3, 0, SLJIT_GENERAL_REG3, 0, loop);    CMPTO(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG3, 0, loop);
2187    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2188    }    }
2189  else  else
2190    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
2191  }  }
2192    
2193    static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2194    {
2195    DEFINE_COMPILER;
2196    struct sljit_jump *jump;
2197    
2198    SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
2199    SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0
2200      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2201    
2202    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2203    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2204    OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
2205    CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2206    
2207    /* Store match begin and end. */
2208    OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));
2209    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
2210    
2211    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2212    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);
2213    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2214    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2215    #endif
2216    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2217    JUMPHERE(jump);
2218    
2219    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);
2220    OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);
2221    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2222    OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2223    #endif
2224    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);
2225    
2226    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);
2227    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2228    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2229    #endif
2230    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0);
2231    
2232    JUMPTO(SLJIT_JUMP, quit);
2233    }
2234    
2235    static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)
2236    {
2237    /* May destroy TMP1. */
2238    DEFINE_COMPILER;
2239    struct sljit_jump *jump;
2240    
2241    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2242      {
2243      /* The value of -1 must be kept for start_used_ptr! */
2244      OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, 1);
2245      /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting
2246      is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */
2247      jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_PTR, 0);
2248      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2249      JUMPHERE(jump);
2250      }
2251    else if (common->mode == JIT_PARTIAL_HARD_COMPILE)
2252      {
2253      jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2254      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2255      JUMPHERE(jump);
2256      }
2257    }
2258    
2259  static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar* cc)  static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar* cc)
2260  {  {
2261  /* Detects if the character has an othercase. */  /* Detects if the character has an othercase. */
# Line 1348  if (c <= 127 && bit == 0x20) Line 2340  if (c <= 127 && bit == 0x20)
2340    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2341    
2342  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2343  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2344    return 0;    return 0;
2345    
2346  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2347    
2348  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2349  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 1367  if (common->utf && c > 127) Line 2359  if (common->utf && c > 127)
2359  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2360  return (0 << 8) | bit;  return (0 << 8) | bit;
2361    
2362  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2363    
 #ifdef COMPILE_PCRE16  
2364  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2365  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2366    {    {
# Line 1380  if (common->utf && c > 65535) Line 2371  if (common->utf && c > 65535)
2371    }    }
2372  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2373  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2374    
2375  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2376    }
2377    
2378    static void check_partial(compiler_common *common, BOOL force)
2379    {
2380    /* Checks whether a partial matching is occurred. Does not modify registers. */
2381    DEFINE_COMPILER;
2382    struct sljit_jump *jump = NULL;
2383    
2384    SLJIT_ASSERT(!force || common->mode != JIT_COMPILE);
2385    
2386    if (common->mode == JIT_COMPILE)
2387      return;
2388    
2389    if (!force)
2390      jump = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2391    else if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2392      jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2393    
2394    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2395      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2396    else
2397      {
2398      if (common->partialmatchlabel != NULL)
2399        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2400      else
2401        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2402      }
2403    
2404    if (jump != NULL)
2405      JUMPHERE(jump);
2406    }
2407    
2408    static void check_str_end(compiler_common *common, jump_list **end_reached)
2409    {
2410    /* Does not affect registers. Usually used in a tight spot. */
2411    DEFINE_COMPILER;
2412    struct sljit_jump *jump;
2413    
2414    if (common->mode == JIT_COMPILE)
2415      {
2416      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2417      return;
2418      }
2419    
2420    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2421    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2422      {
2423      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2424      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2425      add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
2426      }
2427    else
2428      {
2429      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2430      if (common->partialmatchlabel != NULL)
2431        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2432      else
2433        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2434      }
2435    JUMPHERE(jump);
2436  }  }
2437    
2438  static SLJIT_INLINE void check_input_end(compiler_common *common, jump_list **fallbacks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
2439  {  {
2440  DEFINE_COMPILER;  DEFINE_COMPILER;
2441  add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));  struct sljit_jump *jump;
2442    
2443    if (common->mode == JIT_COMPILE)
2444      {
2445      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2446      return;
2447      }
2448    
2449    /* Partial matching mode. */
2450    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2451    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2452    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2453      {
2454      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2455      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2456      }
2457    else
2458      {
2459      if (common->partialmatchlabel != NULL)
2460        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2461      else
2462        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2463      }
2464    JUMPHERE(jump);
2465  }  }
2466    
2467  static void read_char(compiler_common *common)  static void peek_char(compiler_common *common)
2468  {  {
2469  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2470  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2471  DEFINE_COMPILER;  DEFINE_COMPILER;
2472  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2473  struct sljit_jump *jump;  struct sljit_jump *jump;
2474  #endif  #endif
2475    
2476  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2477  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2478  if (common->utf)  if (common->utf)
2479    {    {
 #ifdef COMPILE_PCRE8  
2480    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2481  #else    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 #ifdef COMPILE_PCRE16  
   jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);  
 #endif  
 #endif /* COMPILE_PCRE8 */  
2482    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2483      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2484      JUMPHERE(jump);
2485      }
2486    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2487    
2488    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2489    if (common->utf)
2490      {
2491      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2492      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2493      /* TMP2 contains the high surrogate. */
2494      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2495      OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2496      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2497      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2498      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2499    JUMPHERE(jump);    JUMPHERE(jump);
2500    }    }
2501  #endif  #endif
2502    }
2503    
2504    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2505    
2506    static BOOL is_char7_bitset(const pcre_uint8* bitset, BOOL nclass)
2507    {
2508    /* Tells whether the character codes below 128 are enough
2509    to determine a match. */
2510    const pcre_uint8 value = nclass ? 0xff : 0;
2511    const pcre_uint8* end = bitset + 32;
2512    
2513    bitset += 16;
2514    do
2515      {
2516      if (*bitset++ != value)
2517        return FALSE;
2518      }
2519    while (bitset < end);
2520    return TRUE;
2521    }
2522    
2523    static void read_char7_type(compiler_common *common, BOOL full_read)
2524    {
2525    /* Reads the precise character type of a character into TMP1, if the character
2526    is less than 128. Otherwise it returns with zero. Does not check STR_END. The
2527    full_read argument tells whether characters above max are accepted or not. */
2528    DEFINE_COMPILER;
2529    struct sljit_jump *jump;
2530    
2531    SLJIT_ASSERT(common->utf);
2532    
2533    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2534  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2535    
2536    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2537    
2538    if (full_read)
2539      {
2540      jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2541      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2542      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2543      JUMPHERE(jump);
2544      }
2545  }  }
2546    
2547  static void peek_char(compiler_common *common)  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2548    
2549    static void read_char_max(compiler_common *common, pcre_uint32 max, BOOL full_read)
2550  {  {
2551  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the precise value of a character into TMP1, if the character is
2552  Does not check STR_END. TMP2 Destroyed. */  less than or equal to max. Otherwise it returns with a value greater than max.
2553    Does not check STR_END. The full_read argument tells whether characters above
2554    max are accepted or not. */
2555  DEFINE_COMPILER;  DEFINE_COMPILER;
2556  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2557  struct sljit_jump *jump;  struct sljit_jump *jump;
2558  #endif  #endif
2559    
2560    SLJIT_UNUSED_ARG(full_read);
2561    SLJIT_UNUSED_ARG(max);
2562    
2563  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2564  #ifdef SUPPORT_UTF  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2565    
2566    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2567  if (common->utf)  if (common->utf)
2568    {    {
2569  #ifdef COMPILE_PCRE8    if (max < 128 && !full_read)
2570        return;
2571    
2572    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2573  #else    if (max >= 0x800)
2574  #ifdef COMPILE_PCRE16      add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2575    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    else if (max < 128)
2576        {
2577        OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2578        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2579        }
2580      else
2581        {
2582        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2583        if (!full_read)
2584          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2585        else
2586          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2587        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2588        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2589        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2590        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2591        if (full_read)
2592          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2593        }
2594      JUMPHERE(jump);
2595      }
2596  #endif  #endif
2597  #endif /* COMPILE_PCRE8 */  
2598    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));  #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2599    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  if (common->utf)
2600      {
2601      if (max >= 0x10000)
2602        {
2603        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2604        jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2605        /* TMP2 contains the high surrogate. */
2606        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2607        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2608        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2609        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2610        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2611        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2612        JUMPHERE(jump);
2613        return;
2614        }
2615    
2616      if (max < 0xd800 && !full_read)
2617        return;
2618    
2619      /* Skip low surrogate if necessary. */
2620      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2621      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2622      if (full_read)
2623        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2624      if (max >= 0xd800)
2625        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
2626    JUMPHERE(jump);    JUMPHERE(jump);
2627    }    }
2628  #endif  #endif
2629  }  }
2630    
2631  static void read_char8_type(compiler_common *common)  static SLJIT_INLINE void read_char(compiler_common *common)
2632    {
2633    read_char_max(common, READ_CHAR_ANY, TRUE);
2634    }
2635    
2636    static void read_char8_type(compiler_common *common, BOOL full_read)
2637  {  {
2638  /* 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.
2639    The full_read argument tells whether characters above max are accepted or not. */
2640  DEFINE_COMPILER;  DEFINE_COMPILER;
2641  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2642  struct sljit_jump *jump;  struct sljit_jump *jump;
2643  #endif  #endif
2644    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2645    struct sljit_jump *jump2;
2646    #endif
2647    
2648  #ifdef SUPPORT_UTF  SLJIT_UNUSED_ARG(full_read);
2649    
2650    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2651    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2652    
2653    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2654  if (common->utf)  if (common->utf)
2655    {    {
   OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 #ifdef COMPILE_PCRE8  
2656    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2657    it is needed in most cases. */    it is needed in most cases. */
2658    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2659    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2660    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    if (!full_read)
2661    JUMPHERE(jump);      {
2662  #else      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2663  #ifdef COMPILE_PCRE16      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2664    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2665    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2666    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2667        OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
2668        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2669        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2670        OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2671        JUMPHERE(jump2);
2672        }
2673      else
2674        add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2675    JUMPHERE(jump);    JUMPHERE(jump);
   /* Skip low surrogate if necessary. */  
   OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);  
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);  
   COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  
   OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  
 #endif  
 #endif /* COMPILE_PCRE8 */  
2676    return;    return;
2677    }    }
2678  #endif  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2679  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
2680  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  #if !defined COMPILE_PCRE8
 #ifdef COMPILE_PCRE16  
2681  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2682  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2683  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2684  #endif  #endif
2685  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2686  #ifdef COMPILE_PCRE16  #if !defined COMPILE_PCRE8
2687  JUMPHERE(jump);  JUMPHERE(jump);
2688  #endif  #endif
2689    
2690    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2691    if (common->utf && full_read)
2692      {
2693      /* Skip low surrogate if necessary. */
2694      OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2695      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2696      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2697      JUMPHERE(jump);
2698      }
2699    #endif /* SUPPORT_UTF && COMPILE_PCRE16 */
2700  }  }
2701    
2702  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
2703  {  {
2704  /* Goes one character back. Affects STR_PTR and TMP1. Does not check begin. */  /* Goes one character back. Affects STR_PTR and TMP1. Does not check begin. */
2705  DEFINE_COMPILER;  DEFINE_COMPILER;
2706  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2707    #if defined COMPILE_PCRE8
2708  struct sljit_label *label;  struct sljit_label *label;
2709    
2710  if (common->utf)  if (common->utf)
# Line 1511  if (common->utf) Line 2716  if (common->utf)
2716    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2717    return;    return;
2718    }    }
2719  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2720  if (common->utf)  if (common->utf)
2721    {    {
2722    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
# Line 1520  if (common->utf) Line 2724  if (common->utf)
2724    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2725    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2726    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);
2727    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2728    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2729    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2730    return;    return;
2731    }    }
2732  #endif  #endif /* COMPILE_PCRE[8|16] */
2733    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2734  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2735  }  }
2736    
2737  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 jumpifmatch)
2738  {  {
2739  /* 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. */
2740  DEFINE_COMPILER;  DEFINE_COMPILER;
2741    struct sljit_jump *jump;
2742    
2743  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2744    {    {
2745    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2746    add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpifmatch ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2747    }    }
2748  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2749    {    {
2750    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    if (jumpifmatch)
2751    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      {
2752    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR));
2753    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2754    add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));      }
2755      else
2756        {
2757        jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
2758        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2759        JUMPHERE(jump);
2760        }
2761    }    }
2762  else  else
2763    {    {
2764    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2765    add_jump(compiler, fallbacks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));    add_jump(compiler, backtracks, CMP(jumpifmatch ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
2766    }    }
2767  }  }
2768    
2769  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2770    
2771  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2772  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2773  {  {
2774  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2775  of the character (>= 0xc0). Return char value in TMP1, length - 1 in TMP2. */  of the character (>= 0xc0). Return char value in TMP1, length in TMP2. */
2776  DEFINE_COMPILER;  DEFINE_COMPILER;
2777  struct sljit_jump *jump;  struct sljit_jump *jump;
2778    
2779  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2780    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2781    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2782    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2783    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2784    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2785    
2786  /* Searching for the first zero. */  /* Searching for the first zero. */
2787  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2788  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2789  /* Two byte sequence. */  /* Two byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
2790  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2791  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2792    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2793    
2794    JUMPHERE(jump);
2795    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2796    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2797  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2798  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2799  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 JUMPHERE(jump);  
2800    
2801  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2802  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2803  /* Three byte sequence. */  /* Three byte sequence. */
2804  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2805  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
2806  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2807    
2808    /* Four byte sequence. */
2809    JUMPHERE(jump);
2810    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2811    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2812    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2813    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2814  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
2815  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2816  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(4));
2817  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2818    }
2819    
2820    static void do_utfreadchar16(compiler_common *common)
2821    {
2822    /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2823    of the character (>= 0xc0). Return value in TMP1. */
2824    DEFINE_COMPILER;
2825    struct sljit_jump *jump;
2826    
2827    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2828    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2829    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2830    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2831  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2832  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2833  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));  
2834    /* Searching for the first zero. */
2835    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2836    jump = JUMP(SLJIT_C_NOT_ZERO);
2837    /* Two byte sequence. */
2838    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2839  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2840    
2841  /* Four byte sequence. */  JUMPHERE(jump);
2842    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
2843    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
2844    /* This code runs only in 8 bit mode. No need to shift the value. */
2845    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2846  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2847  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2848  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
 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(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(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));  
2849  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2850  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2851  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));  /* Three byte sequence. */
2852    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2853  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2854  }  }
2855    
# Line 1623  DEFINE_COMPILER; Line 2861  DEFINE_COMPILER;
2861  struct sljit_jump *jump;  struct sljit_jump *jump;
2862  struct sljit_jump *compare;  struct sljit_jump *compare;
2863    
2864  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2865    
2866  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);
2867  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
# Line 1631  jump = JUMP(SLJIT_C_NOT_ZERO); Line 2869  jump = JUMP(SLJIT_C_NOT_ZERO);
2869  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2870  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2871  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2872    /* The upper 5 bits are known at this point. */
2873    compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x3);
2874  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2875  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2876  OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);  OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
 compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  
2877  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2878  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2879    
2880  JUMPHERE(compare);  JUMPHERE(compare);
2881  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2882  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2883    
2884  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0);  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 }  
   
 #else /* COMPILE_PCRE8 */  
   
 #ifdef COMPILE_PCRE16  
 static void do_utfreadchar(compiler_common *common)  
 {  
 /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  
 of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */  
 DEFINE_COMPILER;  
 struct sljit_jump *jump;  
   
 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  
 jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);  
 /* Do nothing, only return. */  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
   
2885  JUMPHERE(jump);  JUMPHERE(jump);
2886  /* Combine two 16 bit characters. */  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2887  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2888  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  
2889  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2890  }  }
 #endif /* COMPILE_PCRE16 */  
2891    
2892  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
2893    
# Line 1697  DEFINE_COMPILER; Line 2907  DEFINE_COMPILER;
2907    
2908  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);
2909    
2910  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2911  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2912  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(ucd_stage1));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(ucd_stage1));
2913  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2914  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2915  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2916  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2917  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2918  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));
2919  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2920  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2921  }  }
# Line 1719  struct sljit_label *newlinelabel = NULL; Line 2929  struct sljit_label *newlinelabel = NULL;
2929  struct sljit_jump *start;  struct sljit_jump *start;
2930  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2931  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2932  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2933  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2934  #endif  #endif
2935  jump_list *newline = NULL;  jump_list *newline = NULL;
2936  BOOL newlinecheck = FALSE;  BOOL newlinecheck = FALSE;
2937  BOOL readuchar = FALSE;  BOOL readuchar = FALSE;
2938    
2939  if (!(hascrorlf || firstline) && (common->nltype == NLTYPE_ANY ||  if (!(hascrorlf || firstline) && (common->nltype == NLTYPE_ANY ||
2940      common->nltype == NLTYPE_ANYCRLF || common->newline > 255))      common->nltype == NLTYPE_ANYCRLF || common->newline > 255))
2941    newlinecheck = TRUE;    newlinecheck = TRUE;
2942    
2943    if (firstline)
2944      {
2945      /* Search for the end of the first line. */
2946      SLJIT_ASSERT(common->first_line_end != 0);
2947      OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
2948    
2949      if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2950        {
2951        mainloop = LABEL();
2952        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2953        end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2954        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
2955        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2956        CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);
2957        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);
2958        JUMPHERE(end);
2959        OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2960        }
2961      else
2962        {
2963        end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2964        mainloop = LABEL();
2965        /* Continual stores does not cause data dependency. */
2966        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2967        read_char_max(common, common->nlmax, TRUE);
2968        check_newlinechar(common, common->nltype, &newline, TRUE);
2969        CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2970        JUMPHERE(end);
2971        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2972        set_jumps(newline, LABEL());
2973        }
2974    
2975      OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
2976      }
2977    
2978    start = JUMP(SLJIT_JUMP);
2979    
2980    if (newlinecheck)
2981      {
2982      newlinelabel = LABEL();
2983      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2984      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2985      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2986      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);
2987      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2988    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2989      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2990    #endif
2991      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2992      nl = JUMP(SLJIT_JUMP);
2993      }
2994    
2995    mainloop = LABEL();
2996    
2997    /* Increasing the STR_PTR here requires one less jump in the most common case. */
2998    #ifdef SUPPORT_UTF
2999    if (common->utf) readuchar = TRUE;
3000    #endif
3001    if (newlinecheck) readuchar = TRUE;
3002    
3003    if (readuchar)
3004      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3005    
3006    if (newlinecheck)
3007      CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);
3008    
3009    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3010    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3011    #if defined COMPILE_PCRE8
3012    if (common->utf)
3013      {
3014      singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
3015      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
3016      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3017      JUMPHERE(singlechar);
3018      }
3019    #elif defined COMPILE_PCRE16
3020    if (common->utf)
3021      {
3022      singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
3023      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3024      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
3025      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3026      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3027      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3028      JUMPHERE(singlechar);
3029      }
3030    #endif /* COMPILE_PCRE[8|16] */
3031    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
3032    JUMPHERE(start);
3033    
3034    if (newlinecheck)
3035      {
3036      JUMPHERE(end);
3037      JUMPHERE(nl);
3038      }
3039    
3040    return mainloop;
3041    }
3042    
3043    static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, int max_chars)
3044    {
3045    /* Recursive function, which scans prefix literals. */
3046    int len, repeat, len_save, consumed = 0;
3047    pcre_uint32 caseless, chr, mask;
3048    pcre_uchar *alternative, *cc_save;
3049    BOOL last, any;
3050    
3051    repeat = 1;
3052    while (TRUE)
3053      {
3054      last = TRUE;
3055      any = FALSE;
3056      caseless = 0;
3057      switch (*cc)
3058        {
3059        case OP_CHARI:
3060        caseless = 1;
3061        case OP_CHAR:
3062        last = FALSE;
3063        cc++;
3064        break;
3065    
3066        case OP_SOD:
3067        case OP_SOM:
3068        case OP_SET_SOM:
3069        case OP_NOT_WORD_BOUNDARY:
3070        case OP_WORD_BOUNDARY:
3071        case OP_EODN:
3072        case OP_EOD:
3073        case OP_CIRC:
3074        case OP_CIRCM:
3075        case OP_DOLL:
3076        case OP_DOLLM:
3077        /* Zero width assertions. */
3078        cc++;
3079        continue;
3080    
3081        case OP_PLUS:
3082        case OP_MINPLUS:
3083        case OP_POSPLUS:
3084        cc++;
3085        break;
3086    
3087        case OP_EXACTI:
3088        caseless = 1;
3089        case OP_EXACT:
3090        repeat = GET2(cc, 1);
3091        last = FALSE;
3092        cc += 1 + IMM2_SIZE;
3093        break;
3094    
3095        case OP_PLUSI:
3096        case OP_MINPLUSI:
3097        case OP_POSPLUSI:
3098        caseless = 1;
3099        cc++;
3100        break;
3101    
3102        case OP_KET:
3103        cc += 1 + LINK_SIZE;
3104        continue;
3105    
3106        case OP_ALT:
3107        cc += GET(cc, 1);
3108        continue;
3109    
3110        case OP_ONCE:
3111        case OP_ONCE_NC:
3112        case OP_BRA:
3113        case OP_BRAPOS:
3114        case OP_CBRA:
3115        case OP_CBRAPOS:
3116        alternative = cc + GET(cc, 1);
3117        while (*alternative == OP_ALT)
3118          {
3119          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, max_chars);
3120          if (max_chars == 0)
3121            return consumed;
3122          alternative += GET(alternative, 1);
3123          }
3124    
3125        if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
3126          cc += IMM2_SIZE;
3127        cc += 1 + LINK_SIZE;
3128        continue;
3129    
3130        case OP_CLASS:
3131        case OP_NCLASS:
3132        any = TRUE;
3133        cc += 1 + 32 / sizeof(pcre_uchar);
3134        break;
3135    
3136    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3137        case OP_XCLASS:
3138        any = TRUE;
3139        cc += GET(cc, 1);
3140        break;
3141    #endif
3142    
3143        case OP_NOT_DIGIT:
3144        case OP_DIGIT:
3145        case OP_NOT_WHITESPACE:
3146        case OP_WHITESPACE:
3147        case OP_NOT_WORDCHAR:
3148        case OP_WORDCHAR:
3149        case OP_ANY:
3150        case OP_ALLANY:
3151        any = TRUE;
3152        cc++;
3153        break;
3154    
3155    #ifdef SUPPORT_UCP
3156        case OP_NOTPROP:
3157        case OP_PROP:
3158        any = TRUE;
3159        cc += 1 + 2;
3160        break;
3161    #endif
3162    
3163        case OP_TYPEEXACT:
3164        repeat = GET2(cc, 1);
3165        cc += 1 + IMM2_SIZE;
3166        continue;
3167    
3168        default:
3169        return consumed;
3170        }
3171    
3172      if (any)
3173        {
3174    #ifdef SUPPORT_UTF
3175        if (common->utf) return consumed;
3176    #endif
3177    #if defined COMPILE_PCRE8
3178        mask = 0xff;
3179    #elif defined COMPILE_PCRE16
3180        mask = 0xffff;
3181    #elif defined COMPILE_PCRE32
3182        mask = 0xffffffff;
3183    #else
3184        SLJIT_ASSERT_STOP();
3185    #endif
3186    
3187        do
3188          {
3189          chars[0] = mask;
3190          chars[1] = mask;
3191    
3192          if (--max_chars == 0)
3193            return consumed;
3194          consumed++;
3195          chars += 2;
3196          }
3197        while (--repeat > 0);
3198    
3199        repeat = 1;
3200        continue;
3201        }
3202    
3203      len = 1;
3204    #ifdef SUPPORT_UTF
3205      if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3206    #endif
3207    
3208      if (caseless != 0 && char_has_othercase(common, cc))
3209        {
3210        caseless = char_get_othercase_bit(common, cc);
3211        if (caseless == 0)
3212          return consumed;
3213    #ifdef COMPILE_PCRE8
3214        caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
3215    #else
3216        if ((caseless & 0x100) != 0)
3217          caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
3218        else
3219          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
3220    #endif
3221        }
3222      else
3223        caseless = 0;
3224    
3225      len_save = len;
3226      cc_save = cc;
3227      while (TRUE)
3228        {
3229        do
3230          {
3231          chr = *cc;
3232    #ifdef COMPILE_PCRE32
3233          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3234            return consumed;
3235    #endif
3236          mask = 0;
3237          if (len == (caseless & 0xff))
3238            {
3239            mask = caseless >> 8;
3240            chr |= mask;
3241            }
3242    
3243          if (chars[0] == NOTACHAR)
3244            {
3245            chars[0] = chr;
3246            chars[1] = mask;
3247            }
3248          else
3249            {
3250            mask |= chars[0] ^ chr;
3251            chr |= mask;
3252            chars[0] = chr;
3253            chars[1] |= mask;
3254            }
3255    
3256          len--;
3257          if (--max_chars == 0)
3258            return consumed;
3259          consumed++;
3260          chars += 2;
3261          cc++;
3262          }
3263        while (len > 0);
3264    
3265        if (--repeat == 0)
3266          break;
3267    
3268        len = len_save;
3269        cc = cc_save;
3270        }
3271    
3272      repeat = 1;
3273      if (last)
3274        return consumed;
3275      }
3276    }
3277    
3278    #define MAX_N_CHARS 16
3279    
3280    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3281    {
3282    DEFINE_COMPILER;
3283    struct sljit_label *start;
3284    struct sljit_jump *quit;
3285    pcre_uint32 chars[MAX_N_CHARS * 2];
3286    pcre_uint8 ones[MAX_N_CHARS];
3287    pcre_uint32 mask;
3288    int i, max;
3289    int offsets[3];
3290    
3291  if (firstline)  for (i = 0; i < MAX_N_CHARS; i++)
3292    {    {
3293    /* Search for the end of the first line. */    chars[i << 1] = NOTACHAR;
3294    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);    chars[(i << 1) + 1] = 0;
3295    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_END, 0);    }
3296    
3297    if (common->nltype == NLTYPE_FIXED && common->newline > 255)  max = scan_prefix(common, common->start, chars, MAX_N_CHARS);
3298      {  
3299      mainloop = LABEL();  if (max <= 1)
3300      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    return FALSE;
3301      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  
3302      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));  for (i = 0; i < max; i++)
3303      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));    {
3304      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);    mask = chars[(i << 1) + 1];
3305      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);    ones[i] = ones_in_half_byte[mask & 0xf];
3306      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    mask >>= 4;
3307      }    while (mask != 0)
   else  
3308      {      {
3309      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      ones[i] += ones_in_half_byte[mask & 0xf];
3310      mainloop = LABEL();      mask >>= 4;
     /* Continual stores does not cause data dependency. */  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);  
     read_char(common);  
     check_newlinechar(common, common->nltype, &newline, TRUE);  
     CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);  
     set_jumps(newline, LABEL());  
3311      }      }
3312      }
3313    
3314    JUMPHERE(end);  offsets[0] = -1;
3315    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  /* Scan forward. */
3316    for (i = 0; i < max; i++)
3317      if (ones[i] <= 2) {
3318        offsets[0] = i;
3319        break;
3320    }    }
3321    
3322  start = JUMP(SLJIT_JUMP);  if (offsets[0] == -1)
3323      return FALSE;
3324    
3325  if (newlinecheck)  /* Scan backward. */
3326    {  offsets[1] = -1;
3327    newlinelabel = LABEL();  for (i = max - 1; i > offsets[0]; i--)
3328    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    if (ones[i] <= 2) {
3329    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      offsets[1] = i;
3330    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      break;
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);  
   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);  
 #ifdef COMPILE_PCRE16  
   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  
 #endif  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   nl = JUMP(SLJIT_JUMP);  
3331    }    }
3332    
3333  mainloop = LABEL();  offsets[2] = -1;
3334    if (offsets[1] >= 0)
3335      {
3336      /* Scan from middle. */
3337      for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3338        if (ones[i] <= 2)
3339          {
3340          offsets[2] = i;
3341          break;
3342          }
3343    
3344  /* Increasing the STR_PTR here requires one less jump in the most common case. */    if (offsets[2] == -1)
3345  #ifdef SUPPORT_UTF      {
3346  if (common->utf) readuchar = TRUE;      for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3347  #endif        if (ones[i] <= 2)
3348  if (newlinecheck) readuchar = TRUE;          {
3349            offsets[2] = i;
3350            break;
3351            }
3352        }
3353      }
3354    
3355  if (readuchar)  SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3356    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3357    
3358  if (newlinecheck)  chars[0] = chars[offsets[0] << 1];
3359    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);  chars[1] = chars[(offsets[0] << 1) + 1];
3360    if (offsets[2] >= 0)
3361      {
3362      chars[2] = chars[offsets[2] << 1];
3363      chars[3] = chars[(offsets[2] << 1) + 1];
3364      }
3365    if (offsets[1] >= 0)
3366      {
3367      chars[4] = chars[offsets[1] << 1];
3368      chars[5] = chars[(offsets[1] << 1) + 1];
3369      }
3370    
3371  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  max -= 1;
3372  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  if (firstline)
 if (common->utf)  
3373    {    {
3374    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    SLJIT_ASSERT(common->first_line_end != 0);
3375    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3376    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS(max));
   JUMPHERE(singlechar);  
3377    }    }
3378  #endif  else
3379  #if defined SUPPORT_UTF && defined COMPILE_PCRE16    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3380  if (common->utf)  
3381    start = LABEL();
3382    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3383    
3384    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3385    if (offsets[1] >= 0)
3386      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3387    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3388    
3389    if (chars[1] != 0)
3390      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3391    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3392    if (offsets[2] >= 0)
3393      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3394    
3395    if (offsets[1] >= 0)
3396    {    {
3397    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    if (chars[5] != 0)
3398    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3399    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);  
   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   JUMPHERE(singlechar);  
3400    }    }
 #endif  
 JUMPHERE(start);  
3401    
3402  if (newlinecheck)  if (offsets[2] >= 0)
3403    {    {
3404    JUMPHERE(end);    if (chars[3] != 0)
3405    JUMPHERE(nl);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3406      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3407    }    }
3408    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3409    
3410  return mainloop;  JUMPHERE(quit);
3411    
3412    if (firstline)
3413      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3414    else
3415      OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3416    return TRUE;
3417  }  }
3418    
3419    #undef MAX_N_CHARS
3420    
3421  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
3422  {  {
3423  DEFINE_COMPILER;  DEFINE_COMPILER;
3424  struct sljit_label *start;  struct sljit_label *start;
3425  struct sljit_jump *leave;  struct sljit_jump *quit;
3426  struct sljit_jump *found;  struct sljit_jump *found;
3427  pcre_uchar oc, bit;  pcre_uchar oc, bit;
3428    
3429  if (firstline)  if (firstline)
3430    {    {
3431    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3432    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3433      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3434    }    }
3435    
3436  start = LABEL();  start = LABEL();
3437  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3438  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3439    
3440  oc = first_char;  oc = first_char;
# Line 1860  if (first_char == oc) Line 3451  if (first_char == oc)
3451  else  else
3452    {    {
3453    bit = first_char ^ oc;    bit = first_char ^ oc;
3454    if (ispowerof2(bit))    if (is_powerof2(bit))
3455      {      {
3456      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3457      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
# Line 1868  else Line 3459  else
3459    else    else
3460      {      {
3461      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char);
3462      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3463      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);
3464      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);
3465      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3466      }      }
3467    }    }
3468    
3469  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 #if defined SUPPORT_UTF && defined COMPILE_PCRE8  
 if (common->utf)  
   {  
   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 #endif  
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
 if (common->utf)  
   {  
   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);  
   OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);  
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);  
   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);  
   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 #endif  
3470  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3471  JUMPHERE(found);  JUMPHERE(found);
3472  JUMPHERE(leave);  JUMPHERE(quit);
3473    
3474  if (firstline)  if (firstline)
3475    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3476  }  }
3477    
3478  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 1909  DEFINE_COMPILER; Line 3481  DEFINE_COMPILER;
3481  struct sljit_label *loop;  struct sljit_label *loop;
3482  struct sljit_jump *lastchar;  struct sljit_jump *lastchar;
3483  struct sljit_jump *firstchar;  struct sljit_jump *firstchar;
3484  struct sljit_jump *leave;  struct sljit_jump *quit;
3485  struct sljit_jump *foundcr = NULL;  struct sljit_jump *foundcr = NULL;
3486  struct sljit_jump *notfoundnl;  struct sljit_jump *notfoundnl;
3487  jump_list *newline = NULL;  jump_list *newline = NULL;
3488    
3489  if (firstline)  if (firstline)
3490    {    {
3491    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3492    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3493      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3494    }    }
3495    
3496  if (common->nltype == NLTYPE_FIXED && common->newline > 255)  if (common->nltype == NLTYPE_FIXED && common->newline > 255)
# Line 1930  if (common->nltype == NLTYPE_FIXED && co Line 3503  if (common->nltype == NLTYPE_FIXED && co
3503    
3504    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3505    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);
3506    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3507  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3508    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3509  #endif  #endif
3510    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3511    
3512    loop = LABEL();    loop = LABEL();
3513    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3514    leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3515    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
3516    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
3517    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);
3518    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);
3519    
3520    JUMPHERE(leave);    JUMPHERE(quit);
3521    JUMPHERE(firstchar);    JUMPHERE(firstchar);
3522    JUMPHERE(lastchar);    JUMPHERE(lastchar);
3523    
# Line 1959  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3532  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3532  skip_char_back(common);  skip_char_back(common);
3533    
3534  loop = LABEL();  loop = LABEL();
3535  read_char(common);  read_char_max(common, common->nlmax, TRUE);
3536  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3537  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3538    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
# Line 1968  set_jumps(newline, loop); Line 3541  set_jumps(newline, loop);
3541    
3542  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3543    {    {
3544    leave = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
3545    JUMPHERE(foundcr);    JUMPHERE(foundcr);
3546    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3547    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3548    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);
3549    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3550  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3551    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3552  #endif  #endif
3553    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3554    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
3555    JUMPHERE(leave);    JUMPHERE(quit);
3556    }    }
3557  JUMPHERE(lastchar);  JUMPHERE(lastchar);
3558  JUMPHERE(firstchar);  JUMPHERE(firstchar);
3559    
3560  if (firstline)  if (firstline)
3561    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3562  }  }
3563    
3564  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks);
3565    
3566    static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, pcre_uint8 *start_bits, BOOL firstline)
3567  {  {
3568  DEFINE_COMPILER;  DEFINE_COMPILER;
3569  struct sljit_label *start;  struct sljit_label *start;
3570  struct sljit_jump *leave;  struct sljit_jump *quit;
3571  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3572    jump_list *matches = NULL;
3573  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3574  struct sljit_jump *jump;  struct sljit_jump *jump;
3575  #endif  #endif
3576    
3577  if (firstline)  if (firstline)
3578    {    {
3579    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3580    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
3581      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3582    }    }
3583    
3584  start = LABEL();  start = LABEL();
3585  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3586  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3587  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3588  if (common->utf)  if (common->utf)
3589    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3590  #endif  #endif
3591    
3592    if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
3593      {
3594  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3595  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3596  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3597