/[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 941 by zherczeg, Tue Feb 28 11:33:34 2012 UTC revision 1279 by zherczeg, Tue Mar 12 17:27:34 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-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 154  typedef struct jit_arguments { Line 166  typedef struct jit_arguments {
166    int *offsets;    int *offsets;
167    pcre_uchar *uchar_ptr;    pcre_uchar *uchar_ptr;
168    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
169      void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171    int offsetcount;    int real_offset_count;
172    int calllimit;    int offset_count;
173      int call_limit;
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 167  typedef struct executable_functions { Line 181  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184      pcre_uint32 top_bracket;
185    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
186  } executable_functions;  } executable_functions;
187    
# Line 175  typedef struct jump_list { Line 190  typedef struct jump_list {
190    struct jump_list *next;    struct jump_list *next;
191  } jump_list;  } jump_list;
192    
 enum stub_types { stack_alloc };  
   
193  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
194    struct sljit_jump *start;    struct sljit_jump *start;
195    struct sljit_label *leave;    struct sljit_label *quit;
196    struct stub_list *next;    struct stub_list *next;
197  } stub_list;  } stub_list;
198    
199    enum bytecode_flag_types {
200      flag_optimized_cbracket = 1,
201      flag_then_start = 2,
202    };
203    
204    enum frame_types {
205      no_frame = -1,
206      no_stack = -2
207    };
208    
209    enum control_types {
210      type_commit = 0,
211      type_prune = 1,
212      type_skip = 2,
213      type_skip_arg = 3,
214      type_mark = 4,
215      type_then_trap = 5
216    };
217    
218  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
219    
220  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
221  code generator. It is allocated by compile_hotpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
222  the aguments for compile_fallbackpath. Must be the first member  the aguments for compile_backtrackingpath. Must be the first member
223  of its descendants. */  of its descendants. */
224  typedef struct fallback_common {  typedef struct backtrack_common {
225    /* Concatenation stack. */    /* Concatenation stack. */
226    struct fallback_common *prev;    struct backtrack_common *prev;
227    jump_list *nextfallbacks;    jump_list *nextbacktracks;
228    /* Internal stack (for component operators). */    /* Internal stack (for component operators). */
229    struct fallback_common *top;    struct backtrack_common *top;
230    jump_list *topfallbacks;    jump_list *topbacktracks;
231    /* Opcode pointer. */    /* Opcode pointer. */
232    pcre_uchar *cc;    pcre_uchar *cc;
233  } fallback_common;  } backtrack_common;
234    
235  typedef struct assert_fallback {  typedef struct assert_backtrack {
236    fallback_common common;    backtrack_common common;
237    jump_list *condfailed;    jump_list *condfailed;
238    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
239    int framesize;    int framesize;
240    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
241    int localptr;    int private_data_ptr;
242    /* For iterators. */    /* For iterators. */
243    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
244  } assert_fallback;  } assert_backtrack;
245    
246  typedef struct bracket_fallback {  typedef struct bracket_backtrack {
247    fallback_common common;    backtrack_common common;
248    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
249    struct sljit_label *althotpath;    struct sljit_label *alternative_matchingpath;
250    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
251    struct sljit_label *recursivehotpath;    struct sljit_label *recursive_matchingpath;
252    /* For greedy ? operator. */    /* For greedy ? operator. */
253    struct sljit_label *zerohotpath;    struct sljit_label *zero_matchingpath;
254    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
255    union {    union {
256      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
257      jump_list *condfailed;      jump_list *condfailed;
258      assert_fallback *assert;      assert_backtrack *assert;
259      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
260      int framesize;      int framesize;
261    } u;    } u;
262    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
263    int localptr;    int private_data_ptr;
264  } bracket_fallback;  } bracket_backtrack;
265    
266  typedef struct bracketpos_fallback {  typedef struct bracketpos_backtrack {
267    fallback_common common;    backtrack_common common;
268    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
269    int localptr;    int private_data_ptr;
270    /* Reverting stack is needed. */    /* Reverting stack is needed. */
271    int framesize;    int framesize;
272    /* Allocated stack size. */    /* Allocated stack size. */
273    int stacksize;    int stacksize;
274  } bracketpos_fallback;  } bracketpos_backtrack;
275    
276  typedef struct braminzero_fallback {  typedef struct braminzero_backtrack {
277    fallback_common common;    backtrack_common common;
278    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
279  } braminzero_fallback;  } braminzero_backtrack;
280    
281  typedef struct iterator_fallback {  typedef struct iterator_backtrack {
282    fallback_common common;    backtrack_common common;
283    /* Next iteration. */    /* Next iteration. */
284    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
285  } iterator_fallback;  } iterator_backtrack;
286    
287  typedef struct recurse_entry {  typedef struct recurse_entry {
288    struct recurse_entry *next;    struct recurse_entry *next;
# Line 264  typedef struct recurse_entry { Line 294  typedef struct recurse_entry {
294    int start;    int start;
295  } recurse_entry;  } recurse_entry;
296    
297  typedef struct recurse_fallback {  typedef struct recurse_backtrack {
298    fallback_common common;    backtrack_common common;
299  } recurse_fallback;    BOOL inlined_pattern;
300    } recurse_backtrack;
301    
302    typedef struct then_trap_backtrack {
303      backtrack_common common;
304      struct then_trap_backtrack *then_trap;
305      jump_list *quit;
306      int framesize;
307    } then_trap_backtrack;
308    
309    #define MAX_RANGE_SIZE 6
310    
311  typedef struct compiler_common {  typedef struct compiler_common {
312      /* The sljit ceneric compiler. */
313    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
314      /* First byte code. */
315    pcre_uchar *start;    pcre_uchar *start;
316      /* Maps private data offset to each opcode. */
317    /* Local stack area size and variable pointers. */    int *private_data_ptrs;
318    int localsize;    /* Tells whether the capturing bracket is optimized. */
319    int *localptrs;    pcre_uint8 *optimized_cbracket;
320    int cbraptr;    /* Tells whether the starting offset is a target of then. */
321    /* OVector starting point. Must be divisible by 2. */    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;    int ovector_start;
328    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
329    int req_char_ptr;    int req_char_ptr;
330    /* Head of the last recursion. */    /* Head of the last recursion. */
331    int recursive_head;    int recursive_head_ptr;
332    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
333    int start_used_ptr;    int start_used_ptr;
334    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 290  typedef struct compiler_common { Line 337  typedef struct compiler_common {
337    int first_line_end;    int first_line_end;
338    /* Points to the marked string. */    /* Points to the marked string. */
339    int mark_ptr;    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    /* Other  */    /* Flipped and lower case tables. */
348    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
349    sljit_w lcc;    sljit_sw lcc;
350      /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
351    int mode;    int mode;
352      /* \K is found in the pattern. */
353      BOOL has_set_som;
354      /* (*SKIP:arg) is found in the pattern. */
355      BOOL has_skip_arg;
356      /* (*THEN) is found in the pattern. */
357      BOOL has_then;
358      /* Needs to know the start position anytime. */
359      BOOL needs_start_ptr;
360      /* Currently in recurse or assert. */
361      BOOL local_exit;
362      /* Newline control. */
363    int nltype;    int nltype;
364    int newline;    int newline;
365    int bsr_nltype;    int bsr_nltype;
366      /* Dollar endonly. */
367    int endonly;    int endonly;
368    BOOL has_set_som;    /* Tables. */
369    sljit_w ctypes;    sljit_sw ctypes;
370      int digits[2 + MAX_RANGE_SIZE];
371      /* Named capturing brackets. */
372    sljit_uw name_table;    sljit_uw name_table;
373    sljit_w name_count;    sljit_sw name_count;
374    sljit_w name_entry_size;    sljit_sw name_entry_size;
375    
376    /* Labels and jump lists. */    /* Labels and jump lists. */
377    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
378    struct sljit_label *leavelabel;    struct sljit_label *quit_label;
379    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
380      struct sljit_label *accept_label;
381    stub_list *stubs;    stub_list *stubs;
382    recurse_entry *entries;    recurse_entry *entries;
383    recurse_entry *currententry;    recurse_entry *currententry;
384    jump_list *partialmatch;    jump_list *partialmatch;
385    jump_list *leave;    jump_list *quit;
386      jump_list *forced_quit;
387    jump_list *accept;    jump_list *accept;
388    jump_list *calllimit;    jump_list *calllimit;
389    jump_list *stackalloc;    jump_list *stackalloc;
# Line 324  typedef struct compiler_common { Line 394  typedef struct compiler_common {
394    jump_list *vspace;    jump_list *vspace;
395    jump_list *casefulcmp;    jump_list *casefulcmp;
396    jump_list *caselesscmp;    jump_list *caselesscmp;
397      jump_list *reset_match;
398    BOOL jscript_compat;    BOOL jscript_compat;
399  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
400    BOOL utf;    BOOL utf;
401  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
402    BOOL use_ucp;    BOOL use_ucp;
403  #endif  #endif
404    #ifndef COMPILE_PCRE32
405    jump_list *utfreadchar;    jump_list *utfreadchar;
406    #endif
407  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
408    jump_list *utfreadtype8;    jump_list *utfreadtype8;
409  #endif  #endif
# Line 348  typedef struct compare_context { Line 421  typedef struct compare_context {
421  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
422    int ucharptr;    int ucharptr;
423    union {    union {
424      sljit_i asint;      sljit_si asint;
425      sljit_uh asushort;      sljit_uh asushort;
426  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
427      sljit_ub asbyte;      sljit_ub asbyte;
428      sljit_ub asuchars[4];      sljit_ub asuchars[4];
429  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
430      sljit_uh asuchars[2];      sljit_uh asuchars[2];
431  #endif  #elif defined COMPILE_PCRE32
432        sljit_ui asuchars[1];
433  #endif  #endif
434    } c;    } c;
435    union {    union {
436      sljit_i asint;      sljit_si asint;
437      sljit_uh asushort;      sljit_uh asushort;
438  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
439      sljit_ub asbyte;      sljit_ub asbyte;
440      sljit_ub asuchars[4];      sljit_ub asuchars[4];
441  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
442      sljit_uh asuchars[2];      sljit_uh asuchars[2];
443  #endif  #elif defined COMPILE_PCRE32
444        sljit_ui asuchars[1];
445  #endif  #endif
446    } oc;    } oc;
447  #endif  #endif
448  } compare_context;  } compare_context;
449    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
450  /* Undefine sljit macros. */  /* Undefine sljit macros. */
451  #undef CMP  #undef CMP
452    
453  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
454  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
455    
456  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
457  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
458  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
459  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
460  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
461  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
462  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
463  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
464  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
465  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
466    
467  /* Locals layout. */  /* Local space layout. */
468  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
469  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
470  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
471  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
472  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
473  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
474  /* Max limit of recursions. */  /* Max limit of recursions. */
475  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
476  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
477  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
478  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
479  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
480  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
481  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
482  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))
483  #define PRIV_DATA(cc)    (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
484    
485  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
486  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
487  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
488  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
489  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
490  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
491    #elif defined COMPILE_PCRE32
492    #define MOV_UCHAR  SLJIT_MOV_UI
493    #define MOVU_UCHAR SLJIT_MOVU_UI
494  #else  #else
495  #error Unsupported compiling mode  #error Unsupported compiling mode
496  #endif  #endif
 #endif  
497    
498  /* Shortcuts. */  /* Shortcuts. */
499  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 442  the start pointers when the end of the c Line 510  the start pointers when the end of the c
510    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
511  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
512    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
513    #define SET_LABEL(jump, label) \
514      sljit_set_label((jump), (label))
515  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
516    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
517  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
518    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))
519  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
520    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
521    #define GET_LOCAL_BASE(dst, dstw, offset) \
522      sljit_get_local_base(compiler, (dst), (dstw), (offset))
523    
524  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
525  {  {
# Line 460  return cc; Line 532  return cc;
532    
533  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
534   next_opcode   next_opcode
535   get_localspace   get_private_data_length
536   set_localptrs   set_private_data_ptrs
537   get_framesize   get_framesize
538   init_frame   init_frame
539   get_localsize   get_private_data_copy_length
540   copy_locals   copy_private_data
541   compile_hotpath   compile_matchingpath
542   compile_fallbackpath   compile_backtrackingpath
543  */  */
544    
545  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
# Line 488  switch(*cc) Line 560  switch(*cc)
560    case OP_WORDCHAR:    case OP_WORDCHAR:
561    case OP_ANY:    case OP_ANY:
562    case OP_ALLANY:    case OP_ALLANY:
563      case OP_NOTPROP:
564      case OP_PROP:
565    case OP_ANYNL:    case OP_ANYNL:
566    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
567    case OP_HSPACE:    case OP_HSPACE:
# Line 500  switch(*cc) Line 574  switch(*cc)
574    case OP_CIRCM:    case OP_CIRCM:
575    case OP_DOLL:    case OP_DOLL:
576    case OP_DOLLM:    case OP_DOLLM:
   case OP_TYPESTAR:  
   case OP_TYPEMINSTAR:  
   case OP_TYPEPLUS:  
   case OP_TYPEMINPLUS:  
   case OP_TYPEQUERY:  
   case OP_TYPEMINQUERY:  
   case OP_TYPEPOSSTAR:  
   case OP_TYPEPOSPLUS:  
   case OP_TYPEPOSQUERY:  
577    case OP_CRSTAR:    case OP_CRSTAR:
578    case OP_CRMINSTAR:    case OP_CRMINSTAR:
579    case OP_CRPLUS:    case OP_CRPLUS:
580    case OP_CRMINPLUS:    case OP_CRMINPLUS:
581    case OP_CRQUERY:    case OP_CRQUERY:
582    case OP_CRMINQUERY:    case OP_CRMINQUERY:
583      case OP_CRRANGE:
584      case OP_CRMINRANGE:
585      case OP_CLASS:
586      case OP_NCLASS:
587      case OP_REF:
588      case OP_REFI:
589      case OP_RECURSE:
590      case OP_CALLOUT:
591      case OP_ALT:
592      case OP_KET:
593      case OP_KETRMAX:
594      case OP_KETRMIN:
595      case OP_KETRPOS:
596      case OP_REVERSE:
597      case OP_ASSERT:
598      case OP_ASSERT_NOT:
599      case OP_ASSERTBACK:
600      case OP_ASSERTBACK_NOT:
601      case OP_ONCE:
602      case OP_ONCE_NC:
603      case OP_BRA:
604      case OP_BRAPOS:
605      case OP_CBRA:
606      case OP_CBRAPOS:
607      case OP_COND:
608      case OP_SBRA:
609      case OP_SBRAPOS:
610      case OP_SCBRA:
611      case OP_SCBRAPOS:
612      case OP_SCOND:
613      case OP_CREF:
614      case OP_NCREF:
615      case OP_RREF:
616      case OP_NRREF:
617    case OP_DEF:    case OP_DEF:
618    case OP_BRAZERO:    case OP_BRAZERO:
619    case OP_BRAMINZERO:    case OP_BRAMINZERO:
620    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
621      case OP_PRUNE:
622      case OP_SKIP:
623      case OP_THEN:
624    case OP_COMMIT:    case OP_COMMIT:
625    case OP_FAIL:    case OP_FAIL:
626    case OP_ACCEPT:    case OP_ACCEPT:
627    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
628      case OP_CLOSE:
629    case OP_SKIPZERO:    case OP_SKIPZERO:
630    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
631    
632    case OP_CHAR:    case OP_CHAR:
633    case OP_CHARI:    case OP_CHARI:
# Line 542  switch(*cc) Line 639  switch(*cc)
639    case OP_MINPLUS:    case OP_MINPLUS:
640    case OP_QUERY:    case OP_QUERY:
641    case OP_MINQUERY:    case OP_MINQUERY:
642      case OP_UPTO:
643      case OP_MINUPTO:
644      case OP_EXACT:
645    case OP_POSSTAR:    case OP_POSSTAR:
646    case OP_POSPLUS:    case OP_POSPLUS:
647    case OP_POSQUERY:    case OP_POSQUERY:
648      case OP_POSUPTO:
649    case OP_STARI:    case OP_STARI:
650    case OP_MINSTARI:    case OP_MINSTARI:
651    case OP_PLUSI:    case OP_PLUSI:
652    case OP_MINPLUSI:    case OP_MINPLUSI:
653    case OP_QUERYI:    case OP_QUERYI:
654    case OP_MINQUERYI:    case OP_MINQUERYI:
655      case OP_UPTOI:
656      case OP_MINUPTOI:
657      case OP_EXACTI:
658    case OP_POSSTARI:    case OP_POSSTARI:
659    case OP_POSPLUSI:    case OP_POSPLUSI:
660    case OP_POSQUERYI:    case OP_POSQUERYI:
661      case OP_POSUPTOI:
662    case OP_NOTSTAR:    case OP_NOTSTAR:
663    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
664    case OP_NOTPLUS:    case OP_NOTPLUS:
665    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
666    case OP_NOTQUERY:    case OP_NOTQUERY:
667    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
668      case OP_NOTUPTO:
669      case OP_NOTMINUPTO:
670      case OP_NOTEXACT:
671    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
672    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
673    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
674      case OP_NOTPOSUPTO:
675    case OP_NOTSTARI:    case OP_NOTSTARI:
676    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
677    case OP_NOTPLUSI:    case OP_NOTPLUSI:
678    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
679    case OP_NOTQUERYI:    case OP_NOTQUERYI:
680    case OP_NOTMINQUERYI:    case OP_NOTMINQUERYI:
   case OP_NOTPOSSTARI:  
   case OP_NOTPOSPLUSI:  
   case OP_NOTPOSQUERYI:  
   cc += 2;  
 #ifdef SUPPORT_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:  
681    case OP_NOTUPTOI:    case OP_NOTUPTOI:
682    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
683    case OP_NOTEXACTI:    case OP_NOTEXACTI:
684      case OP_NOTPOSSTARI:
685      case OP_NOTPOSPLUSI:
686      case OP_NOTPOSQUERYI:
687    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
688    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
689  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
690    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
691  #endif  #endif
692    return cc;    return cc;
693    
694    case OP_NOTPROP:    /* Special cases. */
695    case OP_PROP:    case OP_TYPESTAR:
696    return cc + 1 + 2;    case OP_TYPEMINSTAR:
697      case OP_TYPEPLUS:
698      case OP_TYPEMINPLUS:
699      case OP_TYPEQUERY:
700      case OP_TYPEMINQUERY:
701    case OP_TYPEUPTO:    case OP_TYPEUPTO:
702    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
703    case OP_TYPEEXACT:    case OP_TYPEEXACT:
704      case OP_TYPEPOSSTAR:
705      case OP_TYPEPOSPLUS:
706      case OP_TYPEPOSQUERY:
707    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
708    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_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;  
709    
710    case OP_CLASS:    case OP_ANYBYTE:
711    case OP_NCLASS:  #ifdef SUPPORT_UTF
712    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
713    #endif
714      return cc + 1;
715    
716  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
717    case OP_XCLASS:    case OP_XCLASS:
718    return cc + GET(cc, 1);    return cc + GET(cc, 1);
719  #endif  #endif
720    
   case OP_RECURSE:  
   case OP_ASSERT:  
   case OP_ASSERT_NOT:  
   case OP_ASSERTBACK:  
   case OP_ASSERTBACK_NOT:  
   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;  
   
721    case OP_MARK:    case OP_MARK:
722      case OP_PRUNE_ARG:
723      case OP_SKIP_ARG:
724      case OP_THEN_ARG:
725    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
726    
727    default:    default:
# Line 666  switch(*cc) Line 729  switch(*cc)
729    }    }
730  }  }
731    
732  static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
733        case OP_MINSTAR: \
734        case OP_MINPLUS: \
735        case OP_QUERY: \
736        case OP_MINQUERY: \
737        case OP_MINSTARI: \
738        case OP_MINPLUSI: \
739        case OP_QUERYI: \
740        case OP_MINQUERYI: \
741        case OP_NOTMINSTAR: \
742        case OP_NOTMINPLUS: \
743        case OP_NOTQUERY: \
744        case OP_NOTMINQUERY: \
745        case OP_NOTMINSTARI: \
746        case OP_NOTMINPLUSI: \
747        case OP_NOTQUERYI: \
748        case OP_NOTMINQUERYI:
749    
750    #define CASE_ITERATOR_PRIVATE_DATA_2A \
751        case OP_STAR: \
752        case OP_PLUS: \
753        case OP_STARI: \
754        case OP_PLUSI: \
755        case OP_NOTSTAR: \
756        case OP_NOTPLUS: \
757        case OP_NOTSTARI: \
758        case OP_NOTPLUSI:
759    
760    #define CASE_ITERATOR_PRIVATE_DATA_2B \
761        case OP_UPTO: \
762        case OP_MINUPTO: \
763        case OP_UPTOI: \
764        case OP_MINUPTOI: \
765        case OP_NOTUPTO: \
766        case OP_NOTMINUPTO: \
767        case OP_NOTUPTOI: \
768        case OP_NOTMINUPTOI:
769    
770    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
771        case OP_TYPEMINSTAR: \
772        case OP_TYPEMINPLUS: \
773        case OP_TYPEQUERY: \
774        case OP_TYPEMINQUERY:
775    
776    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
777        case OP_TYPESTAR: \
778        case OP_TYPEPLUS:
779    
780    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
781        case OP_TYPEUPTO: \
782        case OP_TYPEMINUPTO:
783    
784    static int get_class_iterator_size(pcre_uchar *cc)
785  {  {
786  int localspace = 0;  switch(*cc)
787      {
788      case OP_CRSTAR:
789      case OP_CRPLUS:
790      return 2;
791    
792      case OP_CRMINSTAR:
793      case OP_CRMINPLUS:
794      case OP_CRQUERY:
795      case OP_CRMINQUERY:
796      return 1;
797    
798      case OP_CRRANGE:
799      case OP_CRMINRANGE:
800      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
801        return 0;
802      return 2;
803    
804      default:
805      return 0;
806      }
807    }
808    
809    static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
810    {
811    int private_data_length = 0;
812  pcre_uchar *alternative;  pcre_uchar *alternative;
813    pcre_uchar *name;
814    pcre_uchar *end = NULL;
815    int space, size, i;
816    pcre_uint32 bracketlen;
817    
818  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
819  while (cc < ccend)  while (cc < ccend)
820    {    {
821      space = 0;
822      size = 0;
823      bracketlen = 0;
824    switch(*cc)    switch(*cc)
825      {      {
826      case OP_SET_SOM:      case OP_SET_SOM:
# Line 680  while (cc < ccend) Line 828  while (cc < ccend)
828      cc += 1;      cc += 1;
829      break;      break;
830    
831        case OP_REF:
832        case OP_REFI:
833        common->optimized_cbracket[GET2(cc, 1)] = 0;
834        cc += 1 + IMM2_SIZE;
835        break;
836    
837      case OP_ASSERT:      case OP_ASSERT:
838      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
839      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 689  while (cc < ccend) Line 843  while (cc < ccend)
843      case OP_BRAPOS:      case OP_BRAPOS:
844      case OP_SBRA:      case OP_SBRA:
845      case OP_SBRAPOS:      case OP_SBRAPOS:
846      case OP_SCOND:      private_data_length += sizeof(sljit_sw);
847      localspace += sizeof(sljit_w);      bracketlen = 1 + LINK_SIZE;
     cc += 1 + LINK_SIZE;  
848      break;      break;
849    
850      case OP_CBRAPOS:      case OP_CBRAPOS:
851      case OP_SCBRAPOS:      case OP_SCBRAPOS:
852      localspace += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
853      cc += 1 + LINK_SIZE + IMM2_SIZE;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
854        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
855      break;      break;
856    
857      case OP_COND:      case OP_COND:
858      /* Might be a hidden SCOND. */      case OP_SCOND:
859      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
860      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
861        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
862      cc += 1 + LINK_SIZE;        return -1;
863    
864        if (*cc == OP_COND)
865          {
866          /* Might be a hidden SCOND. */
867          alternative = cc + GET(cc, 1);
868          if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
869            private_data_length += sizeof(sljit_sw);
870          }
871        else
872          private_data_length += sizeof(sljit_sw);
873        bracketlen = 1 + LINK_SIZE;
874        break;
875    
876        case OP_CREF:
877        i = GET2(cc, 1);
878        common->optimized_cbracket[i] = 0;
879        cc += 1 + IMM2_SIZE;
880        break;
881    
882        case OP_NCREF:
883        bracketlen = GET2(cc, 1);
884        name = (pcre_uchar *)common->name_table;
885        alternative = name;
886        for (i = 0; i < common->name_count; i++)
887          {
888          if (GET2(name, 0) == bracketlen) break;
889          name += common->name_entry_size;
890          }
891        SLJIT_ASSERT(i != common->name_count);
892    
893        for (i = 0; i < common->name_count; i++)
894          {
895          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
896            common->optimized_cbracket[GET2(alternative, 0)] = 0;
897          alternative += common->name_entry_size;
898          }
899        bracketlen = 0;
900        cc += 1 + IMM2_SIZE;
901        break;
902    
903        case OP_BRA:
904        bracketlen = 1 + LINK_SIZE;
905        break;
906    
907        case OP_CBRA:
908        case OP_SCBRA:
909        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
910        break;
911    
912        CASE_ITERATOR_PRIVATE_DATA_1
913        space = 1;
914        size = -2;
915      break;      break;
916    
917        CASE_ITERATOR_PRIVATE_DATA_2A
918        space = 2;
919        size = -2;
920        break;
921    
922        CASE_ITERATOR_PRIVATE_DATA_2B
923        space = 2;
924        size = -(2 + IMM2_SIZE);
925        break;
926    
927        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
928        space = 1;
929        size = 1;
930        break;
931    
932        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
933        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
934          space = 2;
935        size = 1;
936        break;
937    
938        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
939        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
940          space = 2;
941        size = 1 + IMM2_SIZE;
942        break;
943    
944        case OP_CLASS:
945        case OP_NCLASS:
946        size += 1 + 32 / sizeof(pcre_uchar);
947        space = get_class_iterator_size(cc + size);
948        break;
949    
950    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
951        case OP_XCLASS:
952        size = GET(cc, 1);
953        space = get_class_iterator_size(cc + size);
954        break;
955    #endif
956    
957      case OP_RECURSE:      case OP_RECURSE:
958      /* Set its value only once. */      /* Set its value only once. */
959      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
960        {        {
961        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
962        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
963        }        }
964      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
965      break;      break;
966    
967        case OP_CALLOUT:
968        if (common->capture_last_ptr == 0)
969          {
970          common->capture_last_ptr = common->ovector_start;
971          common->ovector_start += sizeof(sljit_sw);
972          }
973        cc += 2 + 2 * LINK_SIZE;
974        break;
975    
976        case OP_THEN_ARG:
977        common->has_then = TRUE;
978        /* Fall through. */
979    
980        case OP_PRUNE_ARG:
981        common->needs_start_ptr = TRUE;
982        common->control_head_ptr = 1;
983        /* Fall through. */
984    
985      case OP_MARK:      case OP_MARK:
986      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
987        {        {
988        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
989        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
990        }        }
991      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
992      break;      break;
993    
994        case OP_THEN:
995        common->has_then = TRUE;
996        /* Fall through. */
997    
998        case OP_PRUNE:
999        case OP_SKIP:
1000        common->needs_start_ptr = TRUE;
1001        common->control_head_ptr = 1;
1002        cc += 1;
1003        break;
1004    
1005        case OP_SKIP_ARG:
1006        common->control_head_ptr = 1;
1007        common->has_skip_arg = TRUE;
1008        cc += 1 + 2 + cc[1];
1009        break;
1010    
1011      default:      default:
1012      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1013      if (cc == NULL)      if (cc == NULL)
1014        return -1;        return -1;
1015      break;      break;
1016      }      }
1017    
1018      if (space > 0 && cc >= end)
1019        private_data_length += sizeof(sljit_sw) * space;
1020    
1021      if (size != 0)
1022        {
1023        if (size < 0)
1024          {
1025          cc += -size;
1026    #ifdef SUPPORT_UTF
1027          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1028    #endif
1029          }
1030        else
1031          cc += size;
1032        }
1033    
1034      if (bracketlen != 0)
1035        {
1036        if (cc >= end)
1037          {
1038          end = bracketend(cc);
1039          if (end[-1 - LINK_SIZE] == OP_KET)
1040            end = NULL;
1041          }
1042        cc += bracketlen;
1043        }
1044    }    }
1045  return localspace;  return private_data_length;
1046  }  }
1047    
1048  static void set_localptrs(compiler_common *common, int localptr, pcre_uchar *ccend)  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)
1049  {  {
1050  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1051  pcre_uchar *alternative;  pcre_uchar *alternative;
1052    pcre_uchar *end = NULL;
1053    int space, size, bracketlen;
1054    
1055  while (cc < ccend)  while (cc < ccend)
1056    {    {
1057      space = 0;
1058      size = 0;
1059      bracketlen = 0;
1060    switch(*cc)    switch(*cc)
1061      {      {
1062      case OP_ASSERT:      case OP_ASSERT:
# Line 755  while (cc < ccend) Line 1069  while (cc < ccend)
1069      case OP_SBRA:      case OP_SBRA:
1070      case OP_SBRAPOS:      case OP_SBRAPOS:
1071      case OP_SCOND:      case OP_SCOND:
1072      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1073      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1074      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1075      break;      break;
1076    
1077      case OP_CBRAPOS:      case OP_CBRAPOS:
1078      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1079      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1080      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1081      cc += 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1082      break;      break;
1083    
1084      case OP_COND:      case OP_COND:
# Line 772  while (cc < ccend) Line 1086  while (cc < ccend)
1086      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1087      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1088        {        {
1089        common->localptrs[cc - common->start] = localptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1090        localptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1091        }        }
1092      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1093        break;
1094    
1095        case OP_BRA:
1096        bracketlen = 1 + LINK_SIZE;
1097      break;      break;
1098    
1099        case OP_CBRA:
1100        case OP_SCBRA:
1101        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1102        break;
1103    
1104        CASE_ITERATOR_PRIVATE_DATA_1
1105        space = 1;
1106        size = -2;
1107        break;
1108    
1109        CASE_ITERATOR_PRIVATE_DATA_2A
1110        space = 2;
1111        size = -2;
1112        break;
1113    
1114        CASE_ITERATOR_PRIVATE_DATA_2B
1115        space = 2;
1116        size = -(2 + IMM2_SIZE);
1117        break;
1118    
1119        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1120        space = 1;
1121        size = 1;
1122        break;
1123    
1124        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1125        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1126          space = 2;
1127        size = 1;
1128        break;
1129    
1130        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1131        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1132          space = 2;
1133        size = 1 + IMM2_SIZE;
1134        break;
1135    
1136        case OP_CLASS:
1137        case OP_NCLASS:
1138        size += 1 + 32 / sizeof(pcre_uchar);
1139        space = get_class_iterator_size(cc + size);
1140        break;
1141    
1142    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1143        case OP_XCLASS:
1144        size = GET(cc, 1);
1145        space = get_class_iterator_size(cc + size);
1146        break;
1147    #endif
1148    
1149      default:      default:
1150      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1151      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1152      break;      break;
1153      }      }
1154    
1155      if (space > 0 && cc >= end)
1156        {
1157        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1158        private_data_ptr += sizeof(sljit_sw) * space;
1159        }
1160    
1161      if (size != 0)
1162        {
1163        if (size < 0)
1164          {
1165          cc += -size;
1166    #ifdef SUPPORT_UTF
1167          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1168    #endif
1169          }
1170        else
1171          cc += size;
1172        }
1173    
1174      if (bracketlen > 0)
1175        {
1176        if (cc >= end)
1177          {
1178          end = bracketend(cc);
1179          if (end[-1 - LINK_SIZE] == OP_KET)
1180            end = NULL;
1181          }
1182        cc += bracketlen;
1183        }
1184    }    }
1185  }  }
1186    
1187  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1188  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head)
1189  {  {
 pcre_uchar *ccend = bracketend(cc);  
1190  int length = 0;  int length = 0;
1191  BOOL possessive = FALSE;  int possessive = 0;
1192    BOOL stack_restore = FALSE;
1193  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1194  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1195    /* The last capture is a local variable even for recursions. */
1196    BOOL capture_last_found = FALSE;
1197    
1198    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1199    SLJIT_ASSERT(common->control_head_ptr != 0);
1200    *needs_control_head = TRUE;
1201    #else
1202    *needs_control_head = FALSE;
1203    #endif
1204    
1205  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (ccend == NULL)
1206    {    {
1207    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1208    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1209        {
1210        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1211        /* This is correct regardless of common->capture_last_ptr. */
1212        capture_last_found = TRUE;
1213        }
1214      cc = next_opcode(common, cc);
1215    }    }
1216    
 cc = next_opcode(common, cc);  
1217  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1218  while (cc < ccend)  while (cc < ccend)
1219    switch(*cc)    switch(*cc)
1220      {      {
1221      case OP_SET_SOM:      case OP_SET_SOM:
1222      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1223        stack_restore = TRUE;
1224      if (!setsom_found)      if (!setsom_found)
1225        {        {
1226        length += 2;        length += 2;
# Line 816  while (cc < ccend) Line 1229  while (cc < ccend)
1229      cc += 1;      cc += 1;
1230      break;      break;
1231    
1232      case OP_MARK:      case OP_MARK:
1233      SLJIT_ASSERT(common->mark_ptr != 0);      case OP_PRUNE_ARG:
1234      if (!setmark_found)      case OP_THEN_ARG:
1235        {      SLJIT_ASSERT(common->mark_ptr != 0);
1236        length += 2;      stack_restore = TRUE;
1237        setmark_found = TRUE;      if (!setmark_found)
1238        }        {
1239      cc += 1 + 2 + cc[1];        length += 2;
1240      break;        setmark_found = TRUE;
1241          }
1242        if (common->control_head_ptr != 0)
1243          *needs_control_head = TRUE;
1244        cc += 1 + 2 + cc[1];
1245        break;
1246    
1247        case OP_RECURSE:
1248        stack_restore = TRUE;
1249        if (common->has_set_som && !setsom_found)
1250          {
1251          length += 2;
1252          setsom_found = TRUE;
1253          }
1254        if (common->mark_ptr != 0 && !setmark_found)
1255          {
1256          length += 2;
1257          setmark_found = TRUE;
1258          }
1259        if (common->capture_last_ptr != 0 && !capture_last_found)
1260          {
1261          length += 2;
1262          capture_last_found = TRUE;
1263          }
1264        cc += 1 + LINK_SIZE;
1265        break;
1266    
1267        case OP_CBRA:
1268        case OP_CBRAPOS:
1269        case OP_SCBRA:
1270        case OP_SCBRAPOS:
1271        stack_restore = TRUE;
1272        if (common->capture_last_ptr != 0 && !capture_last_found)
1273          {
1274          length += 2;
1275          capture_last_found = TRUE;
1276          }
1277        length += 3;
1278        cc += 1 + LINK_SIZE + IMM2_SIZE;
1279        break;
1280    
1281        case OP_PRUNE:
1282        case OP_SKIP:
1283        case OP_SKIP_ARG:
1284        case OP_COMMIT:
1285        if (common->control_head_ptr != 0)
1286          *needs_control_head = TRUE;
1287        /* Fall through. */
1288    
1289        default:
1290        stack_restore = TRUE;
1291        /* Fall through. */
1292    
1293        case OP_NOT_WORD_BOUNDARY:
1294        case OP_WORD_BOUNDARY:
1295        case OP_NOT_DIGIT:
1296        case OP_DIGIT:
1297        case OP_NOT_WHITESPACE:
1298        case OP_WHITESPACE:
1299        case OP_NOT_WORDCHAR:
1300        case OP_WORDCHAR:
1301        case OP_ANY:
1302        case OP_ALLANY:
1303        case OP_ANYBYTE:
1304        case OP_NOTPROP:
1305        case OP_PROP:
1306        case OP_ANYNL:
1307        case OP_NOT_HSPACE:
1308        case OP_HSPACE:
1309        case OP_NOT_VSPACE:
1310        case OP_VSPACE:
1311        case OP_EXTUNI:
1312        case OP_EODN:
1313        case OP_EOD:
1314        case OP_CIRC:
1315        case OP_CIRCM:
1316        case OP_DOLL:
1317        case OP_DOLLM:
1318        case OP_CHAR:
1319        case OP_CHARI:
1320        case OP_NOT:
1321        case OP_NOTI:
1322    
1323        case OP_EXACT:
1324        case OP_POSSTAR:
1325        case OP_POSPLUS:
1326        case OP_POSQUERY:
1327        case OP_POSUPTO:
1328    
1329        case OP_EXACTI:
1330        case OP_POSSTARI:
1331        case OP_POSPLUSI:
1332        case OP_POSQUERYI:
1333        case OP_POSUPTOI:
1334    
1335        case OP_NOTEXACT:
1336        case OP_NOTPOSSTAR:
1337        case OP_NOTPOSPLUS:
1338        case OP_NOTPOSQUERY:
1339        case OP_NOTPOSUPTO:
1340    
1341      case OP_RECURSE:      case OP_NOTEXACTI:
1342      if (common->has_set_som && !setsom_found)      case OP_NOTPOSSTARI:
1343        {      case OP_NOTPOSPLUSI:
1344        length += 2;      case OP_NOTPOSQUERYI:
1345        setsom_found = TRUE;      case OP_NOTPOSUPTOI:
       }  
     if (common->mark_ptr != 0 && !setmark_found)  
       {  
       length += 2;  
       setmark_found = TRUE;  
       }  
     cc += 1 + LINK_SIZE;  
     break;  
1346    
1347      case OP_CBRA:      case OP_TYPEEXACT:
1348      case OP_CBRAPOS:      case OP_TYPEPOSSTAR:
1349      case OP_SCBRA:      case OP_TYPEPOSPLUS:
1350      case OP_SCBRAPOS:      case OP_TYPEPOSQUERY:
1351      length += 3;      case OP_TYPEPOSUPTO:
1352      cc += 1 + LINK_SIZE + IMM2_SIZE;  
1353      break;      case OP_CLASS:
1354        case OP_NCLASS:
1355        case OP_XCLASS:
1356    
     default:  
1357      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1358      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1359      break;      break;
1360      }      }
1361    
1362  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1363  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1364    return -1;    return stack_restore ? no_frame : no_stack;
1365    
1366  if (length > 0)  if (length > 0)
1367    return length + 1;    return length + 1;
1368  return -1;  return stack_restore ? no_frame : no_stack;
1369  }  }
1370    
1371  static void init_frame(compiler_common *common, 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;
 pcre_uchar *ccend = bracketend(cc);  
1374  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1375  BOOL setmark_found = recursive;  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) */
# Line 876  SLJIT_UNUSED_ARG(stacktop); Line 1382  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)
# Line 887  while (cc < ccend) Line 1398  while (cc < ccend)
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);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1404        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1405        setsom_found = TRUE;        setsom_found = TRUE;
1406        }        }
1407      cc += 1;      cc += 1;
1408      break;      break;
1409    
1410      case OP_MARK:      case OP_MARK:
1411        case OP_PRUNE_ARG:
1412        case OP_THEN_ARG:
1413      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1414      if (!setmark_found)      if (!setmark_found)
1415        {        {
1416        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1417        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1418        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1419        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1420        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1421        setmark_found = TRUE;        setmark_found = TRUE;
1422        }        }
1423      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 914  while (cc < ccend) Line 1427  while (cc < ccend)
1427      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1428        {        {
1429        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1430        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1431        stackpos += (int)sizeof(sljit_w);        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      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1437        {        {
1438        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1439        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1440        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1441        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1442        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1443        setmark_found = TRUE;        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;      cc += 1 + LINK_SIZE;
1455      break;      break;
1456    
# Line 936  while (cc < ccend) Line 1458  while (cc < ccend)
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 955  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_ASSERT:      case OP_ASSERT:
# Line 978  while (cc < ccend) Line 1511  while (cc < ccend)
1511      case OP_SBRA:      case OP_SBRA:
1512      case OP_SBRAPOS:      case OP_SBRAPOS:
1513      case OP_SCOND:      case OP_SCOND:
1514      localsize++;      private_data_length++;
1515      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1516      break;      break;
1517    
1518      case OP_CBRA:      case OP_CBRA:
1519      case OP_SCBRA:      case OP_SCBRA:
1520      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1521          private_data_length++;
1522      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1523      break;      break;
1524    
1525      case OP_CBRAPOS:      case OP_CBRAPOS:
1526      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1527      localsize += 2;      private_data_length += 2;
1528      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1529      break;      break;
1530    
# Line 998  while (cc < ccend) Line 1532  while (cc < ccend)
1532      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1533      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1534      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1535        localsize++;        private_data_length++;
1536      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1537      break;      break;
1538    
1539        CASE_ITERATOR_PRIVATE_DATA_1
1540        if (PRIVATE_DATA(cc))
1541          private_data_length++;
1542        cc += 2;
1543    #ifdef SUPPORT_UTF
1544        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1545    #endif
1546        break;
1547    
1548        CASE_ITERATOR_PRIVATE_DATA_2A
1549        if (PRIVATE_DATA(cc))
1550          private_data_length += 2;
1551        cc += 2;
1552    #ifdef SUPPORT_UTF
1553        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1554    #endif
1555        break;
1556    
1557        CASE_ITERATOR_PRIVATE_DATA_2B
1558        if (PRIVATE_DATA(cc))
1559          private_data_length += 2;
1560        cc += 2 + IMM2_SIZE;
1561    #ifdef SUPPORT_UTF
1562        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1563    #endif
1564        break;
1565    
1566        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1567        if (PRIVATE_DATA(cc))
1568          private_data_length++;
1569        cc += 1;
1570        break;
1571    
1572        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1573        if (PRIVATE_DATA(cc))
1574          private_data_length += 2;
1575        cc += 1;
1576        break;
1577    
1578        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1579        if (PRIVATE_DATA(cc))
1580          private_data_length += 2;
1581        cc += 1 + IMM2_SIZE;
1582        break;
1583    
1584        case OP_CLASS:
1585        case OP_NCLASS:
1586    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1587        case OP_XCLASS:
1588        size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1589    #else
1590        size = 1 + 32 / (int)sizeof(pcre_uchar);
1591    #endif
1592        if (PRIVATE_DATA(cc))
1593          private_data_length += get_class_iterator_size(cc + size);
1594        cc += size;
1595        break;
1596    
1597      default:      default:
1598      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1599      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 1009  while (cc < ccend) Line 1601  while (cc < ccend)
1601      }      }
1602    }    }
1603  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1604  return localsize;  return private_data_length;
1605  }  }
1606    
1607  static void copy_locals(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,
1608    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1609  {  {
1610  DEFINE_COMPILER;  DEFINE_COMPILER;
1611  int srcw[2];  int srcw[2];
1612  int count;  int count, size;
1613  BOOL tmp1next = TRUE;  BOOL tmp1next = TRUE;
1614  BOOL tmp1empty = TRUE;  BOOL tmp1empty = TRUE;
1615  BOOL tmp2empty = TRUE;  BOOL tmp2empty = TRUE;
# Line 1034  stacktop = STACK(stacktop - 1); Line 1626  stacktop = STACK(stacktop - 1);
1626    
1627  if (!save)  if (!save)
1628    {    {
1629    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1630    if (stackptr < stacktop)    if (stackptr < stacktop)
1631      {      {
1632      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1633      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1634      tmp1empty = FALSE;      tmp1empty = FALSE;
1635      }      }
1636    if (stackptr < stacktop)    if (stackptr < stacktop)
1637      {      {
1638      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1639      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1640      tmp2empty = FALSE;      tmp2empty = FALSE;
1641      }      }
1642    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1643    }    }
1644    
1645  while (status != end)  do
1646    {    {
1647    count = 0;    count = 0;
1648    switch(status)    switch(status)
1649      {      {
1650      case start:      case start:
1651      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1652      count = 1;      count = 1;
1653      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1654        if (needs_control_head)
1655          {
1656          SLJIT_ASSERT(common->control_head_ptr != 0);
1657          count = 2;
1658          srcw[1] = common->control_head_ptr;
1659          }
1660      status = loop;      status = loop;
1661      break;      break;
1662    
# Line 1082  while (status != end) Line 1680  while (status != end)
1680        case OP_SBRAPOS:        case OP_SBRAPOS:
1681        case OP_SCOND:        case OP_SCOND:
1682        count = 1;        count = 1;
1683        srcw[0] = PRIV_DATA(cc);        srcw[0] = PRIVATE_DATA(cc);
1684        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1685        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1686        break;        break;
1687    
1688        case OP_CBRA:        case OP_CBRA:
1689        case OP_SCBRA:        case OP_SCBRA:
1690        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1691        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1692            count = 1;
1693            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1694            }
1695        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1696        break;        break;
1697    
1698        case OP_CBRAPOS:        case OP_CBRAPOS:
1699        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1700        count = 2;        count = 2;
1701          srcw[0] = PRIVATE_DATA(cc);
1702        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1703        srcw[0] = PRIV_DATA(cc);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
       SLJIT_ASSERT(srcw[0] != 0);  
1704        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1705        break;        break;
1706    
# Line 1109  while (status != end) Line 1710  while (status != end)
1710        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1711          {          {
1712          count = 1;          count = 1;
1713          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1714          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1715          }          }
1716        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1717        break;        break;
1718    
1719          CASE_ITERATOR_PRIVATE_DATA_1
1720          if (PRIVATE_DATA(cc))
1721            {
1722            count = 1;
1723            srcw[0] = PRIVATE_DATA(cc);
1724            }
1725          cc += 2;
1726    #ifdef SUPPORT_UTF
1727          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1728    #endif
1729          break;
1730    
1731          CASE_ITERATOR_PRIVATE_DATA_2A
1732          if (PRIVATE_DATA(cc))
1733            {
1734            count = 2;
1735            srcw[0] = PRIVATE_DATA(cc);
1736            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1737            }
1738          cc += 2;
1739    #ifdef SUPPORT_UTF
1740          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1741    #endif
1742          break;
1743    
1744          CASE_ITERATOR_PRIVATE_DATA_2B
1745          if (PRIVATE_DATA(cc))
1746            {
1747            count = 2;
1748            srcw[0] = PRIVATE_DATA(cc);
1749            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1750            }
1751          cc += 2 + IMM2_SIZE;
1752    #ifdef SUPPORT_UTF
1753          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1754    #endif
1755          break;
1756    
1757          CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1758          if (PRIVATE_DATA(cc))
1759            {
1760            count = 1;
1761            srcw[0] = PRIVATE_DATA(cc);
1762            }
1763          cc += 1;
1764          break;
1765    
1766          CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1767          if (PRIVATE_DATA(cc))
1768            {
1769            count = 2;
1770            srcw[0] = PRIVATE_DATA(cc);
1771            srcw[1] = srcw[0] + sizeof(sljit_sw);
1772            }
1773          cc += 1;
1774          break;
1775    
1776          CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1777          if (PRIVATE_DATA(cc))
1778            {
1779            count = 2;
1780            srcw[0] = PRIVATE_DATA(cc);
1781            srcw[1] = srcw[0] + sizeof(sljit_sw);
1782            }
1783          cc += 1 + IMM2_SIZE;
1784          break;
1785    
1786          case OP_CLASS:
1787          case OP_NCLASS:
1788    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1789          case OP_XCLASS:
1790          size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1791    #else
1792          size = 1 + 32 / (int)sizeof(pcre_uchar);
1793    #endif
1794          if (PRIVATE_DATA(cc))
1795            switch(get_class_iterator_size(cc + size))
1796              {
1797              case 1:
1798              count = 1;
1799              srcw[0] = PRIVATE_DATA(cc);
1800              break;
1801    
1802              case 2:
1803              count = 2;
1804              srcw[0] = PRIVATE_DATA(cc);
1805              srcw[1] = srcw[0] + sizeof(sljit_sw);
1806              break;
1807    
1808              default:
1809              SLJIT_ASSERT_STOP();
1810              break;
1811              }
1812          cc += size;
1813          break;
1814    
1815        default:        default:
1816        cc = next_opcode(common, cc);        cc = next_opcode(common, cc);
1817        SLJIT_ASSERT(cc != NULL);        SLJIT_ASSERT(cc != NULL);
# Line 1137  while (status != end) Line 1834  while (status != end)
1834          if (!tmp1empty)          if (!tmp1empty)
1835            {            {
1836            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1837            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1838            }            }
1839          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1840          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1148  while (status != end) Line 1845  while (status != end)
1845          if (!tmp2empty)          if (!tmp2empty)
1846            {            {
1847            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1848            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1849            }            }
1850          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1851          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1165  while (status != end) Line 1862  while (status != end)
1862          if (!tmp1empty)          if (!tmp1empty)
1863            {            {
1864            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1865            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1866            }            }
1867          tmp1next = FALSE;          tmp1next = FALSE;
1868          }          }
# Line 1177  while (status != end) Line 1874  while (status != end)
1874          if (!tmp2empty)          if (!tmp2empty)
1875            {            {
1876            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1877            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1878            }            }
1879          tmp1next = TRUE;          tmp1next = TRUE;
1880          }          }
1881        }        }
1882      }      }
1883    }    }
1884    while (status != end);
1885    
1886  if (save)  if (save)
1887    {    {
# Line 1192  if (save) Line 1890  if (save)
1890      if (!tmp1empty)      if (!tmp1empty)
1891        {        {
1892        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1893        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1894        }        }
1895      if (!tmp2empty)      if (!tmp2empty)
1896        {        {
1897        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1898        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1899        }        }
1900      }      }
1901    else    else
# Line 1205  if (save) Line 1903  if (save)
1903      if (!tmp2empty)      if (!tmp2empty)
1904        {        {
1905        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1906        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1907        }        }
1908      if (!tmp1empty)      if (!tmp1empty)
1909        {        {
1910        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1911        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1912        }        }
1913      }      }
1914    }    }
1915  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1916  }  }
1917    
1918  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1919    {
1920    pcre_uchar *end = bracketend(cc);
1921    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1922    
1923    /* Assert captures then. */
1924    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1925      current_offset = NULL;
1926    /* Conditional block does not. */
1927    if (*cc == OP_COND || *cc == OP_SCOND)
1928      has_alternatives = FALSE;
1929    
1930    cc = next_opcode(common, cc);
1931    if (has_alternatives)
1932      current_offset = common->then_offsets + (cc - common->start);
1933    
1934    while (cc < end)
1935      {
1936      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1937        cc = set_then_offsets(common, cc, current_offset);
1938      else
1939        {
1940        if (*cc == OP_ALT && has_alternatives)
1941          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1942        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1943          *current_offset = 1;
1944        cc = next_opcode(common, cc);
1945        }
1946      }
1947    
1948    return end;
1949    }
1950    
1951    #undef CASE_ITERATOR_PRIVATE_DATA_1
1952    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1953    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1954    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1955    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1956    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1957    
1958    static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1959  {  {
1960  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1961  }  }
# Line 1227  static SLJIT_INLINE void set_jumps(jump_ Line 1965  static SLJIT_INLINE void set_jumps(jump_
1965  while (list)  while (list)
1966    {    {
1967    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1968    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1969    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1970    list = list->next;    list = list->next;
1971    }    }
1972  }  }
# Line 1244  if (list_item) Line 1982  if (list_item)
1982    }    }
1983  }  }
1984    
1985  static void add_stub(compiler_common *common, enum stub_types type, int data, struct sljit_jump *start)  static void add_stub(compiler_common *common, struct sljit_jump *start)
1986  {  {
1987  DEFINE_COMPILER;  DEFINE_COMPILER;
1988  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1989    
1990  if (list_item)  if (list_item)
1991    {    {
   list_item->type = type;  
   list_item->data = data;  
1992    list_item->start = start;    list_item->start = start;
1993    list_item->leave = LABEL();    list_item->quit = LABEL();
1994    list_item->next = common->stubs;    list_item->next = common->stubs;
1995    common->stubs = list_item;    common->stubs = list_item;
1996    }    }
# Line 1268  stub_list* list_item = common->stubs; Line 2004  stub_list* list_item = common->stubs;
2004  while (list_item)  while (list_item)
2005    {    {
2006    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2007    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
2008      {    JUMPTO(SLJIT_JUMP, list_item->quit);
     case stack_alloc:  
     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));  
     break;  
     }  
   JUMPTO(SLJIT_JUMP, list_item->leave);  
2009    list_item = list_item->next;    list_item = list_item->next;
2010    }    }
2011  common->stubs = NULL;  common->stubs = NULL;
# Line 1293  static SLJIT_INLINE void allocate_stack( Line 2024  static SLJIT_INLINE void allocate_stack(
2024  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2025  DEFINE_COMPILER;  DEFINE_COMPILER;
2026    
2027  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
2028  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2029  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2030  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1301  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2032  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2032  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2033  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2034  #endif  #endif
2035  add_stub(common, stack_alloc, 0, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));  add_stub(common, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));
2036  }  }
2037    
2038  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2039  {  {
2040  DEFINE_COMPILER;  DEFINE_COMPILER;
2041  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
2042  }  }
2043    
2044  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1315  static SLJIT_INLINE void reset_ovector(c Line 2046  static SLJIT_INLINE void reset_ovector(c
2046  DEFINE_COMPILER;  DEFINE_COMPILER;
2047  struct sljit_label *loop;  struct sljit_label *loop;
2048  int i;  int i;
2049    
2050  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2051    SLJIT_ASSERT(length > 1);
2052  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2053  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_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));
2054    if (length < 8)
2055      {
2056      for (i = 1; i < length; i++)
2057        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2058      }
2059    else
2060      {
2061      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2062      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2063      loop = LABEL();
2064      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2065      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2066      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2067      }
2068    }
2069    
2070    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2071    {
2072    DEFINE_COMPILER;
2073    struct sljit_label *loop;
2074    int i;
2075    
2076    SLJIT_ASSERT(length > 1);
2077    /* OVECTOR(1) contains the "string begin - 1" constant. */
2078    if (length > 2)
2079      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2080  if (length < 8)  if (length < 8)
2081    {    {
2082    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2083      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);
2084    }    }
2085  else  else
2086    {    {
2087    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));
2088    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2089    loop = LABEL();    loop = LABEL();
2090    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);
2091    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);
2092    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2093    }    }
2094    
2095    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2096    if (common->mark_ptr != 0)
2097      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2098    SLJIT_ASSERT(common->control_head_ptr != 0);
2099    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2100    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2101    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2102    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2103    }
2104    
2105    static sljit_sw SLJIT_CALL do_check_control_chain(sljit_sw *current)
2106    {
2107    sljit_sw return_value = 0;
2108    const pcre_uchar *skip_arg = NULL;
2109    
2110    SLJIT_ASSERT(current != NULL);
2111    do
2112      {
2113      switch (current[-2])
2114        {
2115        case type_commit:
2116        /* Commit overwrites all. */
2117        return -1;
2118    
2119        case type_prune:
2120        case type_then_trap:
2121        break;
2122    
2123        case type_skip:
2124        /* Overwrites prune, but not other skips. */
2125        if (return_value == 0 && skip_arg == NULL)
2126          return_value = current[-3];
2127        break;
2128    
2129        case type_skip_arg:
2130        if (return_value == 0 && skip_arg == NULL)
2131          skip_arg = (pcre_uchar *)current[-3];
2132        break;
2133    
2134        case type_mark:
2135        if (return_value == 0 && skip_arg != NULL)
2136          if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2137            return_value = current[-4];
2138        break;
2139    
2140        default:
2141        SLJIT_ASSERT_STOP();
2142        break;
2143        }
2144      current = (sljit_sw*)current[-1];
2145      }
2146    while (current != NULL);
2147    return (return_value != 0 || skip_arg == NULL) ? return_value : -2;
2148    }
2149    
2150    static sljit_sw SLJIT_CALL do_search_then_trap(sljit_sw *current)
2151    {
2152    do
2153      {
2154      switch (current[-2])
2155        {
2156        case type_commit:
2157        /* Commit overwrites all. */
2158        return 0;
2159    
2160        case type_then_trap:
2161        return (sljit_sw)current;
2162    
2163        case type_prune:
2164        case type_skip:
2165        case type_skip_arg:
2166        case type_mark:
2167        break;
2168    
2169        default:
2170        SLJIT_ASSERT_STOP();
2171        break;
2172        }
2173      current = (sljit_sw*)current[-1];
2174      SLJIT_ASSERT(current != NULL);
2175      }
2176    while (TRUE);
2177  }  }
2178    
2179  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2180  {  {
2181  DEFINE_COMPILER;  DEFINE_COMPILER;
2182  struct sljit_label *loop;  struct sljit_label *loop;
2183  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2184    
2185  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2186  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2187  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);
2188    
2189  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2190  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2191    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
2192  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offset_count));
2193  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2194    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_TEMPORARY_REG3, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);
2195  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
2196  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
2197  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2198  /* Unlikely, but possible */  /* Unlikely, but possible */
2199  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);
2200  loop = LABEL();  loop = LABEL();
2201  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
2202  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_w));  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
2203  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2204  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2205  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2206  #endif  #endif
2207  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
2208  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);
2209  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2210  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2211    
2212  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2213  if (topbracket > 1)  if (topbracket > 1)
2214    {    {
2215    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));
2216    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2217    
2218    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2219    loop = LABEL();    loop = LABEL();
2220    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)));
2221    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);
2222    CMPTO(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG3, 0, loop);    CMPTO(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG3, 0, loop);
2223    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2224    }    }
2225  else  else
2226    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
2227  }  }
2228    
2229  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *leave)  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2230  {  {
2231  DEFINE_COMPILER;  DEFINE_COMPILER;
2232    struct sljit_jump *jump;
2233    
2234  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
2235  SLJIT_ASSERT(common->start_used_ptr != 0 && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));  SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0
2236      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2237    
2238  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2239  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2240  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
2241  CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, leave);  CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2242    
2243  /* Store match begin and end. */  /* Store match begin and end. */
2244  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));
2245  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
2246  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);  
2247    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2248    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);
2249    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2250    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2251    #endif
2252    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2253    JUMPHERE(jump);
2254    
2255    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);
2256  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);
2257  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2258  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2259  #endif  #endif
2260  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);
2261    
2262  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);
2263  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2264  OP2(SLJIT_ASHR, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2265  #endif  #endif
2266  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), 0, SLJIT_TEMPORARY_REG3, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0);
2267    
2268  JUMPTO(SLJIT_JUMP, leave);  JUMPTO(SLJIT_JUMP, quit);
2269  }  }
2270    
2271  static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)  static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)
# Line 1523  if (c <= 127 && bit == 0x20) Line 2376  if (c <= 127 && bit == 0x20)
2376    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2377    
2378  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2379  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2380    return 0;    return 0;
2381    
2382  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2383    
2384  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2385  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 1542  if (common->utf && c > 127) Line 2395  if (common->utf && c > 127)
2395  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2396  return (0 << 8) | bit;  return (0 << 8) | bit;
2397    
2398  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2399    
 #ifdef COMPILE_PCRE16  
2400  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2401  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2402    {    {
# Line 1555  if (common->utf && c > 65535) Line 2407  if (common->utf && c > 65535)
2407    }    }
2408  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2409  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2410    
2411  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2412  }  }
2413    
2414  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
# Line 1577  else if (common->mode == JIT_PARTIAL_SOF Line 2428  else if (common->mode == JIT_PARTIAL_SOF
2428    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2429    
2430  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2431    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2432  else  else
2433    {    {
2434    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 1590  if (jump != NULL) Line 2441  if (jump != NULL)
2441    JUMPHERE(jump);    JUMPHERE(jump);
2442  }  }
2443    
2444  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2445  {  {
2446  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2447  DEFINE_COMPILER;  DEFINE_COMPILER;
2448  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2449    
2450  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2451    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2452      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2453      return;
2454      }
2455    
2456  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2457  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2458    {    {
2459    nohit = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2460    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2461    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2462    }    }
2463  else  else
2464    {    {
2465    return_value = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2466    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2467      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2468    else    else
2469      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2470    }    }
2471  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2472  }  }
2473    
2474  static void fallback_at_str_end(compiler_common *common, jump_list **fallbacks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
2475  {  {
2476  DEFINE_COMPILER;  DEFINE_COMPILER;
2477  struct sljit_jump *jump;  struct sljit_jump *jump;
2478    
2479  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2480    {    {
2481    add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2482    return;    return;
2483    }    }
2484    
2485  /* Partial matching mode. */  /* Partial matching mode. */
2486  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2487  add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2488  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2489    {    {
2490    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2491    add_jump(compiler, fallbacks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2492    }    }
2493  else  else
2494    {    {
# Line 1655  static void read_char(compiler_common *c Line 2505  static void read_char(compiler_common *c
2505  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2506  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2507  DEFINE_COMPILER;  DEFINE_COMPILER;
2508  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2509  struct sljit_jump *jump;  struct sljit_jump *jump;
2510  #endif  #endif
2511    
2512  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2513  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2514  if (common->utf)  if (common->utf)
2515    {    {
2516  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2517    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2518  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2519    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2520  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2521    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2522    JUMPHERE(jump);    JUMPHERE(jump);
2523    }    }
2524  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2525  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2526  }  }
2527    
# Line 1682  static void peek_char(compiler_common *c Line 2530  static void peek_char(compiler_common *c
2530  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2531  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2532  DEFINE_COMPILER;  DEFINE_COMPILER;
2533  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2534  struct sljit_jump *jump;  struct sljit_jump *jump;
2535  #endif  #endif
2536    
2537  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2538  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2539  if (common->utf)  if (common->utf)
2540    {    {
2541  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2542    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2543  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2544    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2545  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2546    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2547    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2548    JUMPHERE(jump);    JUMPHERE(jump);
2549    }    }
2550  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2551  }  }
2552    
2553  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2554  {  {
2555  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */
2556  DEFINE_COMPILER;  DEFINE_COMPILER;
2557  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2558  struct sljit_jump *jump;  struct sljit_jump *jump;
2559  #endif  #endif
2560    
# Line 1717  if (common->utf) Line 2563  if (common->utf)
2563    {    {
2564    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2565    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2566  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2567    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2568    it is needed in most cases. */    it is needed in most cases. */
2569    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2570    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2571    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2572    JUMPHERE(jump);    JUMPHERE(jump);
2573  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2574    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2575    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2576    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
# Line 1733  if (common->utf) Line 2578  if (common->utf)
2578    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2579    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2580    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2581    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2582    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2583    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2584  #endif  #elif defined COMPILE_PCRE32
2585  #endif /* COMPILE_PCRE8 */    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2586      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2587      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2588      JUMPHERE(jump);
2589    #endif /* COMPILE_PCRE[8|16|32] */
2590    return;    return;
2591    }    }
2592  #endif  #endif /* SUPPORT_UTF */
2593  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2594  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2595  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2596  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2597  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2598  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2599  #endif  #endif
2600  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2601  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2602  JUMPHERE(jump);  JUMPHERE(jump);
2603  #endif  #endif
2604  }  }
# Line 1758  static void skip_char_back(compiler_comm Line 2607  static void skip_char_back(compiler_comm
2607  {  {
2608  /* 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. */
2609  DEFINE_COMPILER;  DEFINE_COMPILER;
2610  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2611    #if defined COMPILE_PCRE8
2612  struct sljit_label *label;  struct sljit_label *label;
2613    
2614  if (common->utf)  if (common->utf)
# Line 1770  if (common->utf) Line 2620  if (common->utf)
2620    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2621    return;    return;
2622    }    }
2623  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2624  if (common->utf)  if (common->utf)
2625    {    {
2626    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 1779  if (common->utf) Line 2628  if (common->utf)
2628    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2629    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2630    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);
2631    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2632    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2633    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2634    return;    return;
2635    }    }
2636  #endif  #endif /* COMPILE_PCRE[8|16] */
2637    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2638  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2639  }  }
2640    
2641  static void check_newlinechar(compiler_common *common, int nltype, jump_list **fallbacks, BOOL jumpiftrue)  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpiftrue)
2642  {  {
2643  /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */  /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */
2644  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1796  DEFINE_COMPILER; Line 2646  DEFINE_COMPILER;
2646  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2647    {    {
2648    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2649    add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2650    }    }
2651  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2652    {    {
2653    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);
2654    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2655    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);
2656    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
2657    add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2658    }    }
2659  else  else
2660    {    {
2661    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2662    add_jump(compiler, fallbacks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));    add_jump(compiler, backtracks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
2663    }    }
2664  }  }
2665    
2666  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2667    
2668  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2669  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2670  {  {
2671  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
# Line 1823  of the character (>= 0xc0). Return char Line 2673  of the character (>= 0xc0). Return char
2673  DEFINE_COMPILER;  DEFINE_COMPILER;
2674  struct sljit_jump *jump;  struct sljit_jump *jump;
2675    
2676  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2677  /* Searching for the first zero. */  /* Searching for the first zero. */
2678  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
2679  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
# Line 1882  DEFINE_COMPILER; Line 2732  DEFINE_COMPILER;
2732  struct sljit_jump *jump;  struct sljit_jump *jump;
2733  struct sljit_jump *compare;  struct sljit_jump *compare;
2734    
2735  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2736    
2737  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);
2738  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
# Line 1903  sljit_emit_fast_return(compiler, RETURN_ Line 2753  sljit_emit_fast_return(compiler, RETURN_
2753  JUMPHERE(jump);  JUMPHERE(jump);
2754    
2755  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2756  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2757  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2758  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2759  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2760  }  }
2761    
2762  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2763    
 #ifdef COMPILE_PCRE16  
2764  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2765  {  {
2766  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char
# Line 1919  of the character (>= 0xd800). Return cha Line 2768  of the character (>= 0xd800). Return cha
2768  DEFINE_COMPILER;  DEFINE_COMPILER;
2769  struct sljit_jump *jump;  struct sljit_jump *jump;
2770    
2771  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2772  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);
2773  /* Do nothing, only return. */  /* Do nothing, only return. */
2774  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
# Line 1936  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC Line 2785  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2785  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2786  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2787  }  }
 #endif /* COMPILE_PCRE16 */  
2788    
2789  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2790    
2791  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2792    
# Line 1956  DEFINE_COMPILER; Line 2804  DEFINE_COMPILER;
2804    
2805  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);
2806    
2807  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2808  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2809  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(ucd_stage1));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(ucd_stage1));
2810  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2811  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2812  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2813  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2814  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2815  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)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));
2816  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2817  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2818  }  }
# Line 1978  struct sljit_label *newlinelabel = NULL; Line 2826  struct sljit_label *newlinelabel = NULL;
2826  struct sljit_jump *start;  struct sljit_jump *start;
2827  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2828  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2829  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2830  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2831  #endif  #endif
2832  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 1993  if (firstline) Line 2841  if (firstline)
2841    {    {
2842    /* Search for the end of the first line. */    /* Search for the end of the first line. */
2843    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
2844    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_END, 0);  
2845    
2846    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2847      {      {
# Line 2005  if (firstline) Line 2852  if (firstline)
2852      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2853      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);
2854      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);
2855        JUMPHERE(end);
2856      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2857      }      }
2858    else    else
# Line 2016  if (firstline) Line 2864  if (firstline)
2864      read_char(common);      read_char(common);
2865      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
2866      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2867        JUMPHERE(end);
2868      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2869      set_jumps(newline, LABEL());      set_jumps(newline, LABEL());
2870      }      }
2871    
2872    JUMPHERE(end);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
   OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
2873    }    }
2874    
2875  start = JUMP(SLJIT_JUMP);  start = JUMP(SLJIT_JUMP);
# Line 2033  if (newlinecheck) Line 2881  if (newlinecheck)
2881    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2882    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2883    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);
2884    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2885  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2886    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2887  #endif  #endif
2888    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2889    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2056  if (newlinecheck) Line 2904  if (newlinecheck)
2904    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);
2905    
2906  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2907  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2908    #if defined COMPILE_PCRE8
2909  if (common->utf)  if (common->utf)
2910    {    {
2911    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2912    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2913    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2914    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2915    }    }
2916  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2917  if (common->utf)  if (common->utf)
2918    {    {
2919    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2920    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2921    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2922    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2923    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2924    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2925    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2926    }    }
2927  #endif  #endif /* COMPILE_PCRE[8|16] */
2928    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2929  JUMPHERE(start);  JUMPHERE(start);
2930    
2931  if (newlinecheck)  if (newlinecheck)
# Line 2088  if (newlinecheck) Line 2937  if (newlinecheck)
2937  return mainloop;  return mainloop;
2938  }  }
2939    
2940    #define MAX_N_CHARS 3
2941    
2942    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2943    {
2944    DEFINE_COMPILER;
2945    struct sljit_label *start;
2946    struct sljit_jump *quit;
2947    pcre_uint32 chars[MAX_N_CHARS * 2];
2948    pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2949    int location = 0;
2950    pcre_int32 len, c, bit, caseless;
2951    int must_stop;
2952    
2953    /* We do not support alternatives now. */
2954    if (*(common->start + GET(common->start, 1)) == OP_ALT)
2955      return FALSE;
2956    
2957    while (TRUE)
2958      {
2959      caseless = 0;
2960      must_stop = 1;
2961      switch(*cc)
2962        {
2963        case OP_CHAR:
2964        must_stop = 0;
2965        cc++;
2966        break;
2967    
2968        case OP_CHARI:
2969        caseless = 1;
2970        must_stop = 0;
2971        cc++;
2972        break;
2973    
2974        case OP_SOD:
2975        case OP_SOM:
2976        case OP_SET_SOM:
2977        case OP_NOT_WORD_BOUNDARY:
2978        case OP_WORD_BOUNDARY:
2979        case OP_EODN:
2980        case OP_EOD:
2981        case OP_CIRC:
2982        case OP_CIRCM:
2983        case OP_DOLL:
2984        case OP_DOLLM:
2985        /* Zero width assertions. */
2986        cc++;
2987        continue;
2988    
2989        case OP_PLUS:
2990        case OP_MINPLUS:
2991        case OP_POSPLUS:
2992        cc++;
2993        break;
2994    
2995        case OP_EXACT:
2996        cc += 1 + IMM2_SIZE;
2997        break;
2998    
2999        case OP_PLUSI:
3000        case OP_MINPLUSI:
3001        case OP_POSPLUSI:
3002        caseless = 1;
3003        cc++;
3004        break;
3005    
3006        case OP_EXACTI:
3007        caseless = 1;
3008        cc += 1 + IMM2_SIZE;
3009        break;
3010    
3011        default:
3012        must_stop = 2;
3013        break;
3014        }
3015    
3016      if (must_stop == 2)
3017          break;
3018    
3019      len = 1;
3020    #ifdef SUPPORT_UTF
3021      if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
3022    #endif
3023    
3024      if (caseless && char_has_othercase(common, cc))
3025        {
3026        caseless = char_get_othercase_bit(common, cc);
3027        if (caseless == 0)
3028          return FALSE;
3029    #ifdef COMPILE_PCRE8
3030        caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
3031    #else
3032        if ((caseless & 0x100) != 0)
3033          caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
3034        else
3035          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
3036    #endif
3037        }
3038      else
3039        caseless = 0;
3040    
3041      while (len > 0 && location < MAX_N_CHARS * 2)
3042        {
3043        c = *cc;
3044        bit = 0;
3045        if (len == (caseless & 0xff))
3046          {
3047          bit = caseless >> 8;
3048          c |= bit;
3049          }
3050    
3051        chars[location] = c;
3052        chars[location + 1] = bit;
3053    
3054        len--;
3055        location += 2;
3056        cc++;
3057        }
3058    
3059      if (location >= MAX_N_CHARS * 2 || must_stop != 0)
3060        break;
3061      }
3062    
3063    /* At least two characters are required. */
3064    if (location < 2 * 2)
3065        return FALSE;
3066    
3067    if (firstline)
3068      {
3069      SLJIT_ASSERT(common->first_line_end != 0);
3070      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3071      OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3072      }
3073    else
3074      OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3075    
3076    start = LABEL();
3077    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3078    
3079    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
3080    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3081    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3082    if (chars[1] != 0)
3083      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3084    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3085    if (location > 2 * 2)
3086      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3087    if (chars[3] != 0)
3088      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
3089    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
3090    if (location > 2 * 2)
3091      {
3092      if (chars[5] != 0)
3093        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
3094      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);
3095      }
3096    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3097    
3098    JUMPHERE(quit);
3099    
3100    if (firstline)
3101      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3102    else
3103      OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3104    return TRUE;
3105    }
3106    
3107    #undef MAX_N_CHARS
3108    
3109  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
3110  {  {
3111  DEFINE_COMPILER;  DEFINE_COMPILER;
3112  struct sljit_label *start;  struct sljit_label *start;
3113  struct sljit_jump *leave;  struct sljit_jump *quit;
3114  struct sljit_jump *found;  struct sljit_jump *found;
3115  pcre_uchar oc, bit;  pcre_uchar oc, bit;
3116    
3117  if (firstline)  if (firstline)
3118    {    {
3119    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3120      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3121    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3122    }    }
3123    
3124  start = LABEL();  start = LABEL();
3125  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3126  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3127    
3128  oc = first_char;  oc = first_char;
# Line 2120  if (first_char == oc) Line 3139  if (first_char == oc)
3139  else  else
3140    {    {
3141    bit = first_char ^ oc;    bit = first_char ^ oc;
3142    if (ispowerof2(bit))    if (is_powerof2(bit))
3143      {      {
3144      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3145      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
# Line 2128  else Line 3147  else
3147    else    else
3148      {      {
3149      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);
3150      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3151      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);
3152      COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3153      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3154      }      }
3155    }    }
3156    
3157  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 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  
3158  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3159  JUMPHERE(found);  JUMPHERE(found);
3160  JUMPHERE(leave);  JUMPHERE(quit);
3161    
3162  if (firstline)  if (firstline)
3163    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3164  }  }
3165    
3166  static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline)  static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline)
# Line 2169  DEFINE_COMPILER; Line 3169  DEFINE_COMPILER;
3169  struct sljit_label *loop;  struct sljit_label *loop;
3170  struct sljit_jump *lastchar;  struct sljit_jump *lastchar;
3171  struct sljit_jump *firstchar;  struct sljit_jump *firstchar;
3172  struct sljit_jump *leave;  struct sljit_jump *quit;
3173  struct sljit_jump *foundcr = NULL;  struct sljit_jump *foundcr = NULL;
3174  struct sljit_jump *notfoundnl;  struct sljit_jump *notfoundnl;
3175  jump_list *newline = NULL;  jump_list *newline = NULL;
3176    
3177  if (firstline)  if (firstline)
3178    {    {
3179    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3180      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3181    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3182    }    }
3183    
# Line 2190  if (common->nltype == NLTYPE_FIXED && co Line 3191  if (common->nltype == NLTYPE_FIXED && co
3191    
3192    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3193    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, TMP1, 0);
3194    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3195  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3196    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3197  #endif  #endif
3198    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3199    
3200    loop = LABEL();    loop = LABEL();
3201    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3202    leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3203    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
3204    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
3205    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);
3206    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);
3207    
3208    JUMPHERE(leave);    JUMPHERE(quit);
3209    JUMPHERE(firstchar);    JUMPHERE(firstchar);
3210    JUMPHERE(lastchar);    JUMPHERE(lastchar);
3211    
# Line 2228  set_jumps(newline, loop); Line 3229  set_jumps(newline, loop);
3229    
3230  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3231    {    {
3232    leave = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
3233    JUMPHERE(foundcr);    JUMPHERE(foundcr);
3234    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3235    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3236    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);
3237    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3238  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3239    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3240  #endif  #endif
3241    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3242    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
3243    JUMPHERE(leave);    JUMPHERE(quit);
3244    }    }
3245  JUMPHERE(lastchar);  JUMPHERE(lastchar);
3246  JUMPHERE(firstchar);  JUMPHERE(firstchar);
3247    
3248  if (firstline)  if (firstline)
3249    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3250  }  }
3251    
3252    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3253    
3254  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)
3255  {  {
3256  DEFINE_COMPILER;  DEFINE_COMPILER;
3257  struct sljit_label *start;  struct sljit_label *start;
3258  struct sljit_jump *leave;  struct sljit_jump *quit;
3259  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3260    jump_list *matches = NULL;
3261    pcre_uint8 inverted_start_bits[32];
3262    int i;
3263  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3264  struct sljit_jump *jump;  struct sljit_jump *jump;
3265  #endif  #endif
3266    
3267    for (i = 0; i < 32; ++i)
3268      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3269    
3270  if (firstline)  if (firstline)
3271    {    {
3272    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3273      OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
3274    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3275    }    }
3276    
3277  start = LABEL();  start = LABEL();
3278  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3279  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3280  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3281  if (common->utf)  if (common->utf)
3282    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3283  #endif  #endif
3284    
3285    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3286      {
3287  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3288  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3289  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3290  JUMPHERE(jump);    JUMPHERE(jump);
3291  #endif  #endif
3292  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3293  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3294  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3295  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3296  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
3297  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3298      }
3299    
3300  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3301  if (common->utf)  if (common->utf)
3302    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3303  #endif  #endif
3304  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3305  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3306    #if defined COMPILE_PCRE8
3307  if (common->utf)  if (common->utf)
3308    {    {
3309    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3310    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
3311    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3312    }    }
3313  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3314  if (common->utf)  if (common->utf)
3315    {    {
3316    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3317    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3318    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
3319    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3320    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3321    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3322    }    }
3323  #endif  #endif /* COMPILE_PCRE[8|16] */
3324    #endif /* SUPPORT_UTF */
3325  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3326  JUMPHERE(found);  if (found != NULL)
3327  JUMPHERE(leave);    JUMPHERE(found);
3328    if (matches != NULL)
3329      set_jumps(matches, LABEL());
3330    JUMPHERE(quit);
3331    
3332  if (firstline)  if (firstline)
3333    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
3334  }  }
3335    
3336  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar req_char, BOOL caseless, BOOL has_firstchar)  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar req_char, BOOL caseless, BOOL has_firstchar)
# Line 2324  struct sljit_jump *alreadyfound; Line 3342  struct sljit_jump *alreadyfound;
3342  struct sljit_jump *found;  struct sljit_jump *found;
3343  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3344  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3345  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3346    
3347  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3348  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
# Line 2355  if (req_char == oc) Line 3373  if (req_char == oc)
3373  else  else
3374    {    {
3375    bit = req_char ^ oc;    bit = req_char ^ oc;
3376    if (ispowerof2(bit))    if (is_powerof2(bit))
3377      {      {
3378      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3379      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
# Line 2384  DEFINE_COMPILER; Line 3402  DEFINE_COMPILER;
3402  struct sljit_jump *jump;  struct sljit_jump *jump;
3403  struct sljit_label *mainloop;  struct sljit_label *mainloop;
3404    
3405  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3406  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);
3407    GET_LOCAL_BASE(TMP3, 0, 0);
3408    
3409  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3410  mainloop = LABEL();  mainloop = LABEL();
3411  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3412  jump = CMP(SLJIT_C_SIG_LESS_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0);
3413  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_LOCALS_REG, 0);  jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3414  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
3415  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3416  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3417    OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
3418    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
3419  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3420    
3421  JUMPHERE(jump);  JUMPHERE(jump);
3422  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3423  /* End of dropping frames. */  /* End of dropping frames. */
3424  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3425    
3426  JUMPHERE(jump);  JUMPHERE(jump);
3427  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3428  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3429  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3430  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), TMP2, 0);  
 JUMPTO(SLJIT_JUMP, mainloop);  
   
 JUMPHERE(jump);  
 if (common->mark_ptr != 0)  
   {  
   jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setmark);  
   OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
   OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);  
   JUMPTO(SLJIT_JUMP, mainloop);  
   
   JUMPHERE(jump);  
   }  
   
 /* Unknown command. */  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
3431  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3432  }  }
3433    
# Line 2431  static void check_wordboundary(compiler_ Line 3435  static void check_wordboundary(compiler_
3435  {  {
3436  DEFINE_COMPILER;  DEFINE_COMPILER;
3437  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3438    jump_list *skipread_list = NULL;
3439  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3440  struct sljit_jump *jump;  struct sljit_jump *jump;
3441  #endif  #endif
3442    
3443  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
3444    
3445  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3446  /* Get type of the previous char, and put it to LOCALS1. */  /* Get type of the previous char, and put it to LOCALS1. */
3447  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
3448  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
# Line 2456  if (common->use_ucp) Line 3461  if (common->use_ucp)
3461    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3462    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3463    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
3464    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3465    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);
3466    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
3467    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3468    JUMPHERE(jump);    JUMPHERE(jump);
3469    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3470    }    }
# Line 2488  else Line 3493  else
3493  JUMPHERE(skipread);  JUMPHERE(skipread);
3494    
3495  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3496  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3497  peek_char(common);  peek_char(common);
3498    
3499  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
3500  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3501  if (common->use_ucp)  if (common->use_ucp)
3502      {
3503      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
3504      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
3505      add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3506      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3507      OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
3508      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3509      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);
3510      OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
3511      OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3512      JUMPHERE(jump);
3513      }
3514    else
3515    #endif
3516      {
3517    #ifndef COMPILE_PCRE8
3518      /* TMP2 may be destroyed by peek_char. */
3519      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3520      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3521    #elif defined SUPPORT_UTF
3522      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3523      jump = NULL;
3524      if (common->utf)
3525        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3526    #endif
3527      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);
3528      OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);
3529      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
3530    #ifndef COMPILE_PCRE8
3531      JUMPHERE(jump);
3532    #elif defined SUPPORT_UTF
3533      if (jump != NULL)
3534        JUMPHERE(jump);
3535    #endif /* COMPILE_PCRE8 */
3536      }
3537    set_jumps(skipread_list, LABEL());
3538    
3539    OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3540    sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3541    }
3542    
3543    /*
3544      range format:
3545    
3546      ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).
3547      ranges[1] = first bit (0 or 1)
3548      ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)
3549    */
3550    
3551    static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3552    {
3553    DEFINE_COMPILER;
3554    struct sljit_jump *jump;
3555    
3556    if (ranges[0] < 0)
3557      return FALSE;
3558    
3559    switch(ranges[0])
3560      {
3561      case 1:
3562      if (readch)
3563        read_char(common);
3564      add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3565      return TRUE;
3566    
3567      case 2:
3568      if (readch)
3569        read_char(common);
3570      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3571      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3572      return TRUE;
3573    
3574      case 4:
3575      if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])
3576        {
3577        if (readch)
3578          read_char(common);
3579        if (ranges[1] != 0)
3580          {
3581          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3582          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3583          }
3584        else
3585          {
3586          jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);
3587          add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3588          JUMPHERE(jump);
3589          }
3590        return TRUE;
3591        }
3592      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))
3593        {
3594        if (readch)
3595          read_char(common);
3596        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3597        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3598        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3599        return TRUE;
3600        }
3601      return FALSE;
3602    
3603      default:
3604      return FALSE;
3605      }
3606    }
3607    
3608    static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)
3609    {
3610    int i, bit, length;
3611    const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;
3612    
3613    bit = ctypes[0] & flag;
3614    ranges[0] = -1;
3615    ranges[1] = bit != 0 ? 1 : 0;
3616    length = 0;
3617    
3618    for (i = 1; i < 256; i++)
3619      if ((ctypes[i] & flag) != bit)
3620        {
3621        if (length >= MAX_RANGE_SIZE)
3622          return;
3623        ranges[2 + length] = i;
3624        length++;
3625        bit ^= flag;
3626        }
3627    
3628    if (bit != 0)
3629      {
3630      if (length >= MAX_RANGE_SIZE)
3631        return;
3632      ranges[2 + length] = 256;
3633      length++;
3634      }
3635    ranges[0] = length;
3636    }
3637    
3638    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)
3639    {
3640    int ranges[2 + MAX_RANGE_SIZE];
3641    pcre_uint8 bit, cbit, all;
3642    int i, byte, length = 0;
3643    
3644    bit = bits[0] & 0x1;
3645    ranges[1] = bit;
3646    /* Can be 0 or 255. */
3647    all = -bit;
3648    
3649    for (i = 0; i < 256; )
3650    {    {
3651    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);    byte = i >> 3;
3652    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);    if ((i & 0x7) == 0 && bits[byte] == all)
3653    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));      i += 8;
3654    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    else
3655    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);      {
3656    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);      cbit = (bits[byte] >> (i & 0x7)) & 0x1;
3657    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);      if (cbit != bit)
3658    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);        {
3659    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);        if (length >= MAX_RANGE_SIZE)
3660    JUMPHERE(jump);          return FALSE;
3661          ranges[2 + length] = i;
3662          length++;
3663          bit = cbit;
3664          all = -cbit;
3665          }
3666        i++;
3667        }
3668    }    }
3669  else  
3670  #endif  if (((bit == 0) && nclass) || ((bit == 1) && !nclass))
3671    {    {
3672  #ifndef COMPILE_PCRE8    if (length >= MAX_RANGE_SIZE)
3673    /* TMP2 may be destroyed by peek_char. */      return FALSE;
3674    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);    ranges[2 + length] = 256;
3675    jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);    length++;
 #elif defined SUPPORT_UTF  
   OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  
   jump = NULL;  
   if (common->utf)  
     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
 #endif  
   OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);  
   OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);  
   OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);  
 #ifndef COMPILE_PCRE8  
   JUMPHERE(jump);  
 #elif defined SUPPORT_UTF  
   if (jump != NULL)  
     JUMPHERE(jump);  
 #endif /* COMPILE_PCRE8 */  
3676    }    }
3677  JUMPHERE(skipread);  ranges[0] = length;
3678    
3679  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  return check_ranges(common, ranges, backtracks, FALSE);
 sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
3680  }  }
3681    
3682  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
# Line 2540  static void check_anynewline(compiler_co Line 3684  static void check_anynewline(compiler_co
3684  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3685  DEFINE_COMPILER;  DEFINE_COMPILER;
3686    
3687  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3688    
3689  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3690  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
3691  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3692  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
3693  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3694  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3695  if (common->utf)  if (common->utf)
3696    {    {
3697  #endif  #endif
3698    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3699    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3700    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
3701  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3702    }    }
3703  #endif  #endif
3704  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3705  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);
3706  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3707  }  }
3708    
# Line 2567  static void check_hspace(compiler_common Line 3711  static void check_hspace(compiler_common
3711  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3712  DEFINE_COMPILER;  DEFINE_COMPILER;
3713    
3714  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3715    
3716  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);
3717  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3718  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
3719  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3720  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);
3721  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3722  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3723  if (common->utf)  if (common->utf)
3724    {    {
3725  #endif  #endif
3726    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3727    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);
3728    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3729    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);
3730    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3731    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3732    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);
3733    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3734    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);
3735    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3736    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);
3737    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3738    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);
3739  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3740    }    }
3741  #endif  #endif
3742  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3743  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);
3744    
3745  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3746  }  }
# Line 2606  static void check_vspace(compiler_common Line 3750  static void check_vspace(compiler_common
3750  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3751  DEFINE_COMPILER;  DEFINE_COMPILER;
3752    
3753  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3754    
3755  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3756  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
3757  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3758  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
3759  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3760  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3761  if (common->utf)  if (common->utf)
3762    {    {
3763  #endif  #endif
3764    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);
3765    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3766    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
3767  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3768    }    }
3769  #endif  #endif
3770  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3771  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);
3772    
3773  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3774  }  }
# Line 2638  DEFINE_COMPILER; Line 3782  DEFINE_COMPILER;
3782  struct sljit_jump *jump;  struct sljit_jump *jump;
3783  struct sljit_label *label;  struct sljit_label *label;
3784    
3785  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3786  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3787  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);
3788  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);
# Line 2667  DEFINE_COMPILER; Line 3811  DEFINE_COMPILER;
3811  struct sljit_jump *jump;  struct sljit_jump *jump;
3812  struct sljit_label *label;  struct sljit_label *label;
3813    
3814  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3815  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3816    
3817  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);
# Line 2710  sljit_emit_fast_return(compiler, RETURN_ Line 3854  sljit_emit_fast_return(compiler, RETURN_
3854    
3855  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3856    
3857  static const pcre_uchar *SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)  static const pcre_uchar * SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)
3858  {  {
3859  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3860  int c1, c2;  pcre_uint32 c1, c2;
3861  const pcre_uchar *src2 = args->uchar_ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3862  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
3863    const ucd_record *ur;
3864    const pcre_uint32 *pp;
3865    
3866  while (src1 < end1)  while (src1 < end1)
3867    {    {
# Line 2723  while (src1 < end1) Line 3869  while (src1 < end1)
3869      return (pcre_uchar*)1;      return (pcre_uchar*)1;
3870    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3871    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3872    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return NULL;    ur = GET_UCD(c2);
3873      if (c1 != c2 && c1 != c2 + ur->other_case)
3874        {
3875        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3876        for (;;)
3877          {
3878          if (c1 < *pp) return NULL;
3879          if (c1 == *pp++) break;
3880          }
3881        }
3882    }    }
3883  return src2;  return src2;
3884  }  }
# Line 2731  return src2; Line 3886  return src2;
3886  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
3887    
3888  static pcre_uchar *byte_sequence_compare(compiler_common *common, BOOL caseless, pcre_uchar *cc,  static pcre_uchar *byte_sequence_compare(compiler_common *common, BOOL caseless, pcre_uchar *cc,
3889      compare_context* context, jump_list **fallbacks)      compare_context* context, jump_list **backtracks)
3890  {  {
3891  DEFINE_COMPILER;  DEFINE_COMPILER;
3892  unsigned int othercasebit = 0;  unsigned int othercasebit = 0;
# Line 2745  if (caseless && char_has_othercase(commo Line 3900  if (caseless && char_has_othercase(commo
3900    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3901    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3902    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3903  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3904    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3905    othercasebit &= 0xff;    othercasebit &= 0xff;
3906  #else  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3907  #ifdef COMPILE_PCRE16    /* Note that this code only handles characters in the BMP. If there
3908      ever are characters outside the BMP whose othercase differs in only one
3909      bit from itself (there currently are none), this code will need to be
3910      revised for COMPILE_PCRE32. */
3911    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3912    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3913      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
3914    else    else
3915      othercasebit &= 0xff;      othercasebit &= 0xff;
3916  #endif  #endif /* COMPILE_PCRE[8|16|32] */
 #endif  
3917    }    }
3918    
3919  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3920    {    {
3921  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3922  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3923    if (context->length >= 4)    if (context->length >= 4)
3924      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
# Line 2770  if (context->sourcereg == -1) Line 3927  if (context->sourcereg == -1)
3927    else    else
3928  #endif  #endif
3929      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3930  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
3931  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3932    if (context->length >= 4)    if (context->length >= 4)
3933      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3934    else    else
3935  #endif  #endif
3936      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3937  #endif  #elif defined COMPILE_PCRE32
3938  #endif /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3939    #endif /* COMPILE_PCRE[8|16|32] */
3940    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3941    }    }
3942    
# Line 2793  do Line 3950  do
3950  #endif  #endif
3951    
3952    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);