/[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 993 by zherczeg, Tue Jul 10 04:33:00 2012 UTC revision 1290 by zherczeg, Sat Mar 16 18:45:51 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 89  vertical (sub-expression) (See struct ba Line 101  vertical (sub-expression) (See struct ba
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 try 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 'backtrack' 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 try path.  branches on the matching path.
107    
108   Greedy star operator (*) :   Greedy star operator (*) :
109     Try path: match happens.     Matching path: match happens.
110     Backtrack path: match failed.     Backtrack path: match failed.
111   Non-greedy star operator (*?) :   Non-greedy star operator (*?) :
112     Try path: no need to perform a match.     Matching path: no need to perform a match.
113     Backtrack 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
# 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 try path   A matching path
124   '(' try path (pushing arguments to the stack)   '(' matching path (pushing arguments to the stack)
125   B try path   B matching path
126   ')' try path (pushing arguments to the stack)   ')' matching path (pushing arguments to the stack)
127   D try path   D matching path
128   return with successful match   return with successful match
129    
130   D backtrack path   D backtrack path
131   ')' backtrack path (If we arrived from "C" jump to the backtrack of "C")   ')' backtrack path (If we arrived from "C" jump to the backtrack of "C")
132   B backtrack path   B backtrack path
133   C expected path   C expected path
134   jump to D try path   jump to D matching path
135   C backtrack path   C backtrack path
136   A backtrack path   A backtrack path
137    
# Line 127  The generated code will be the following Line 139  The generated code will be the following
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 backtrack code path. The backtrack 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 try 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 backtrack 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 backtrack 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 *quit;    struct sljit_label *quit;
196    struct stub_list *next;    struct stub_list *next;
197  } stub_list;  } stub_list;
198    
199    enum frame_types {
200      no_frame = -1,
201      no_stack = -2
202    };
203    
204    enum control_types {
205      type_mark = 0,
206      type_then_trap = 1
207    };
208    
209  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
210    
211  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
212  code generator. It is allocated by compile_trypath, and contains  code generator. It is allocated by compile_matchingpath, and contains
213  the aguments for compile_backtrackpath. Must be the first member  the aguments for compile_backtrackingpath. Must be the first member
214  of its descendants. */  of its descendants. */
215  typedef struct backtrack_common {  typedef struct backtrack_common {
216    /* Concatenation stack. */    /* Concatenation stack. */
# Line 205  typedef struct backtrack_common { Line 226  typedef struct backtrack_common {
226  typedef struct assert_backtrack {  typedef struct assert_backtrack {
227    backtrack_common common;    backtrack_common common;
228    jump_list *condfailed;    jump_list *condfailed;
229    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
230    int framesize;    int framesize;
231    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
232    int localptr;    int private_data_ptr;
233    /* For iterators. */    /* For iterators. */
234    struct sljit_label *trypath;    struct sljit_label *matchingpath;
235  } assert_backtrack;  } assert_backtrack;
236    
237  typedef struct bracket_backtrack {  typedef struct bracket_backtrack {
238    backtrack_common common;    backtrack_common common;
239    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
240    struct sljit_label *alttrypath;    struct sljit_label *alternative_matchingpath;
241    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
242    struct sljit_label *recursivetrypath;    struct sljit_label *recursive_matchingpath;
243    /* For greedy ? operator. */    /* For greedy ? operator. */
244    struct sljit_label *zerotrypath;    struct sljit_label *zero_matchingpath;
245    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
246    union {    union {
247      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
248      jump_list *condfailed;      jump_list *condfailed;
249      assert_backtrack *assert;      assert_backtrack *assert;
250      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
251      int framesize;      int framesize;
252    } u;    } u;
253    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
254    int localptr;    int private_data_ptr;
255  } bracket_backtrack;  } bracket_backtrack;
256    
257  typedef struct bracketpos_backtrack {  typedef struct bracketpos_backtrack {
258    backtrack_common common;    backtrack_common common;
259    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
260    int localptr;    int private_data_ptr;
261    /* Reverting stack is needed. */    /* Reverting stack is needed. */
262    int framesize;    int framesize;
263    /* Allocated stack size. */    /* Allocated stack size. */
# Line 245  typedef struct bracketpos_backtrack { Line 266  typedef struct bracketpos_backtrack {
266    
267  typedef struct braminzero_backtrack {  typedef struct braminzero_backtrack {
268    backtrack_common common;    backtrack_common common;
269    struct sljit_label *trypath;    struct sljit_label *matchingpath;
270  } braminzero_backtrack;  } braminzero_backtrack;
271    
272  typedef struct iterator_backtrack {  typedef struct iterator_backtrack {
273    backtrack_common common;    backtrack_common common;
274    /* Next iteration. */    /* Next iteration. */
275    struct sljit_label *trypath;    struct sljit_label *matchingpath;
276  } iterator_backtrack;  } iterator_backtrack;
277    
278  typedef struct recurse_entry {  typedef struct recurse_entry {
# Line 261  typedef struct recurse_entry { Line 282  typedef struct recurse_entry {
282    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
283    jump_list *calls;    jump_list *calls;
284    /* Points to the starting opcode. */    /* Points to the starting opcode. */
285    int start;    sljit_sw start;
286  } recurse_entry;  } recurse_entry;
287    
288  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
289    backtrack_common common;    backtrack_common common;
290      BOOL inlined_pattern;
291  } recurse_backtrack;  } recurse_backtrack;
292    
293    #define OP_THEN_TRAP OP_TABLE_LENGTH
294    
295    typedef struct then_trap_backtrack {
296      backtrack_common common;
297      /* If then_trap is not NULL, this structure contains the real
298      then_trap for the backtracking path. */
299      struct then_trap_backtrack *then_trap;
300      /* Points to the starting opcode. */
301      sljit_sw start;
302      /* Exit point for the then opcodes of this alternative. */
303      jump_list *quit;
304      /* Frame size of the current alternative. */
305      int framesize;
306    } then_trap_backtrack;
307    
308  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 6
309    
310  typedef struct compiler_common {  typedef struct compiler_common {
311      /* The sljit ceneric compiler. */
312    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
313      /* First byte code. */
314    pcre_uchar *start;    pcre_uchar *start;
315      /* Maps private data offset to each opcode. */
316    /* Opcode local area direct map. */    int *private_data_ptrs;
317    int *localptrs;    /* Tells whether the capturing bracket is optimized. */
318    int cbraptr;    pcre_uint8 *optimized_cbracket;
319    /* OVector starting point. Must be divisible by 2. */    /* Tells whether the starting offset is a target of then. */
320      pcre_uint8 *then_offsets;
321      /* Current position where a THEN must jump. */
322      then_trap_backtrack *then_trap;
323      /* Starting offset of private data for capturing brackets. */
324      int cbra_ptr;
325      /* Output vector starting point. Must be divisible by 2. */
326    int ovector_start;    int ovector_start;
327    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
328    int req_char_ptr;    int req_char_ptr;
329    /* Head of the last recursion. */    /* Head of the last recursion. */
330    int recursive_head;    int recursive_head_ptr;
331    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
332    int start_used_ptr;    int start_used_ptr;
333    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 291  typedef struct compiler_common { Line 336  typedef struct compiler_common {
336    int first_line_end;    int first_line_end;
337    /* Points to the marked string. */    /* Points to the marked string. */
338    int mark_ptr;    int mark_ptr;
339      /* Recursive control verb management chain. */
340      int control_head_ptr;
341      /* Points to the last matched capture block index. */
342      int capture_last_ptr;
343      /* Points to the starting position of the current match. */
344      int start_ptr;
345    
346    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
347    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
348    sljit_w lcc;    sljit_sw lcc;
349    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
350    int mode;    int mode;
351      /* \K is found in the pattern. */
352      BOOL has_set_som;
353      /* (*SKIP:arg) is found in the pattern. */
354      BOOL has_skip_arg;
355      /* (*THEN) is found in the pattern. */
356      BOOL has_then;
357      /* Needs to know the start position anytime. */
358      BOOL needs_start_ptr;
359      /* Currently in recurse or assert. */
360      BOOL local_exit;
361    /* Newline control. */    /* Newline control. */
362    int nltype;    int nltype;
363    int newline;    int newline;
364    int bsr_nltype;    int bsr_nltype;
365    /* Dollar endonly. */    /* Dollar endonly. */
366    int endonly;    int endonly;
   BOOL has_set_som;  
367    /* Tables. */    /* Tables. */
368    sljit_w ctypes;    sljit_sw ctypes;
369    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
370    /* Named capturing brackets. */    /* Named capturing brackets. */
371    sljit_uw name_table;    sljit_uw name_table;
372    sljit_w name_count;    sljit_sw name_count;
373    sljit_w name_entry_size;    sljit_sw name_entry_size;
374    
375    /* Labels and jump lists. */    /* Labels and jump lists. */
376    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
377    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
378    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
379      struct sljit_label *accept_label;
380    stub_list *stubs;    stub_list *stubs;
381    recurse_entry *entries;    recurse_entry *entries;
382    recurse_entry *currententry;    recurse_entry *currententry;
383    jump_list *partialmatch;    jump_list *partialmatch;
384    jump_list *quit;    jump_list *quit;
385      jump_list *forced_quit;
386    jump_list *accept;    jump_list *accept;
387    jump_list *calllimit;    jump_list *calllimit;
388    jump_list *stackalloc;    jump_list *stackalloc;
# Line 331  typedef struct compiler_common { Line 393  typedef struct compiler_common {
393    jump_list *vspace;    jump_list *vspace;
394    jump_list *casefulcmp;    jump_list *casefulcmp;
395    jump_list *caselesscmp;    jump_list *caselesscmp;
396      jump_list *reset_match;
397    BOOL jscript_compat;    BOOL jscript_compat;
398  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
399    BOOL utf;    BOOL utf;
400  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
401    BOOL use_ucp;    BOOL use_ucp;
402  #endif  #endif
403    #ifndef COMPILE_PCRE32
404    jump_list *utfreadchar;    jump_list *utfreadchar;
405    #endif
406  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
407    jump_list *utfreadtype8;    jump_list *utfreadtype8;
408  #endif  #endif
# Line 355  typedef struct compare_context { Line 420  typedef struct compare_context {
420  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
421    int ucharptr;    int ucharptr;
422    union {    union {
423      sljit_i asint;      sljit_si asint;
424      sljit_uh asushort;      sljit_uh asushort;
425  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
426      sljit_ub asbyte;      sljit_ub asbyte;
427      sljit_ub asuchars[4];      sljit_ub asuchars[4];
428  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
429      sljit_uh asuchars[2];      sljit_uh asuchars[2];
430  #endif  #elif defined COMPILE_PCRE32
431        sljit_ui asuchars[1];
432  #endif  #endif
433    } c;    } c;
434    union {    union {
435      sljit_i asint;      sljit_si asint;
436      sljit_uh asushort;      sljit_uh asushort;
437  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
438      sljit_ub asbyte;      sljit_ub asbyte;
439      sljit_ub asuchars[4];      sljit_ub asuchars[4];
440  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
441      sljit_uh asuchars[2];      sljit_uh asuchars[2];
442  #endif  #elif defined COMPILE_PCRE32
443        sljit_ui asuchars[1];
444  #endif  #endif
445    } oc;    } oc;
446  #endif  #endif
447  } compare_context;  } compare_context;
448    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
449  /* Undefine sljit macros. */  /* Undefine sljit macros. */
450  #undef CMP  #undef CMP
451    
452  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
453  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
454    
455  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
456  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
457  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
458  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
459  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
460  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
461  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
462  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
463  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
464  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
465    
466  /* Locals layout. */  /* Local space layout. */
467  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
468  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
469  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
470  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
471  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
472  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
473  /* Max limit of recursions. */  /* Max limit of recursions. */
474  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
475  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
476  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
477  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
478  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. */
479  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
480  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
481  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))
482  #define PRIV_DATA(cc)    (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
483    
484  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
485  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
486  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
487  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
488  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
489  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
490    #elif defined COMPILE_PCRE32
491    #define MOV_UCHAR  SLJIT_MOV_UI
492    #define MOVU_UCHAR SLJIT_MOVU_UI
493  #else  #else
494  #error Unsupported compiling mode  #error Unsupported compiling mode
495  #endif  #endif
 #endif  
496    
497  /* Shortcuts. */  /* Shortcuts. */
498  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 449  the start pointers when the end of the c Line 509  the start pointers when the end of the c
509    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
510  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
511    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
512    #define SET_LABEL(jump, label) \
513      sljit_set_label((jump), (label))
514  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
515    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
516  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
517    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))
518  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
519    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
520  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
521    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
522    
# Line 469  return cc; Line 531  return cc;
531    
532  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
533   next_opcode   next_opcode
534   get_localspace   get_private_data_length
535   set_localptrs   set_private_data_ptrs
536   get_framesize   get_framesize
537   init_frame   init_frame
538   get_localsize   get_private_data_copy_length
539   copy_locals   copy_private_data
540   compile_trypath   compile_matchingpath
541   compile_backtrackpath   compile_backtrackingpath
542  */  */
543    
544  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
# Line 497  switch(*cc) Line 559  switch(*cc)
559    case OP_WORDCHAR:    case OP_WORDCHAR:
560    case OP_ANY:    case OP_ANY:
561    case OP_ALLANY:    case OP_ALLANY:
562      case OP_NOTPROP:
563      case OP_PROP:
564    case OP_ANYNL:    case OP_ANYNL:
565    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
566    case OP_HSPACE:    case OP_HSPACE:
# Line 509  switch(*cc) Line 573  switch(*cc)
573    case OP_CIRCM:    case OP_CIRCM:
574    case OP_DOLL:    case OP_DOLL:
575    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:  
576    case OP_CRSTAR:    case OP_CRSTAR:
577    case OP_CRMINSTAR:    case OP_CRMINSTAR:
578    case OP_CRPLUS:    case OP_CRPLUS:
579    case OP_CRMINPLUS:    case OP_CRMINPLUS:
580    case OP_CRQUERY:    case OP_CRQUERY:
581    case OP_CRMINQUERY:    case OP_CRMINQUERY:
582      case OP_CRRANGE:
583      case OP_CRMINRANGE:
584      case OP_CLASS:
585      case OP_NCLASS:
586      case OP_REF:
587      case OP_REFI:
588      case OP_RECURSE:
589      case OP_CALLOUT:
590      case OP_ALT:
591      case OP_KET:
592      case OP_KETRMAX:
593      case OP_KETRMIN:
594      case OP_KETRPOS:
595      case OP_REVERSE:
596      case OP_ASSERT:
597      case OP_ASSERT_NOT:
598      case OP_ASSERTBACK:
599      case OP_ASSERTBACK_NOT:
600      case OP_ONCE:
601      case OP_ONCE_NC:
602      case OP_BRA:
603      case OP_BRAPOS:
604      case OP_CBRA:
605      case OP_CBRAPOS:
606      case OP_COND:
607      case OP_SBRA:
608      case OP_SBRAPOS:
609      case OP_SCBRA:
610      case OP_SCBRAPOS:
611      case OP_SCOND:
612      case OP_CREF:
613      case OP_NCREF:
614      case OP_RREF:
615      case OP_NRREF:
616    case OP_DEF:    case OP_DEF:
617    case OP_BRAZERO:    case OP_BRAZERO:
618    case OP_BRAMINZERO:    case OP_BRAMINZERO:
619    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
620      case OP_PRUNE:
621      case OP_SKIP:
622      case OP_THEN:
623    case OP_COMMIT:    case OP_COMMIT:
624    case OP_FAIL:    case OP_FAIL:
625    case OP_ACCEPT:    case OP_ACCEPT:
626    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
627      case OP_CLOSE:
628    case OP_SKIPZERO:    case OP_SKIPZERO:
629    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
630    
631    case OP_CHAR:    case OP_CHAR:
632    case OP_CHARI:    case OP_CHARI:
# Line 551  switch(*cc) Line 638  switch(*cc)
638    case OP_MINPLUS:    case OP_MINPLUS:
639    case OP_QUERY:    case OP_QUERY:
640    case OP_MINQUERY:    case OP_MINQUERY:
641      case OP_UPTO:
642      case OP_MINUPTO:
643      case OP_EXACT:
644    case OP_POSSTAR:    case OP_POSSTAR:
645    case OP_POSPLUS:    case OP_POSPLUS:
646    case OP_POSQUERY:    case OP_POSQUERY:
647      case OP_POSUPTO:
648    case OP_STARI:    case OP_STARI:
649    case OP_MINSTARI:    case OP_MINSTARI:
650    case OP_PLUSI:    case OP_PLUSI:
651    case OP_MINPLUSI:    case OP_MINPLUSI:
652    case OP_QUERYI:    case OP_QUERYI:
653    case OP_MINQUERYI:    case OP_MINQUERYI:
654      case OP_UPTOI:
655      case OP_MINUPTOI:
656      case OP_EXACTI:
657    case OP_POSSTARI:    case OP_POSSTARI:
658    case OP_POSPLUSI:    case OP_POSPLUSI:
659    case OP_POSQUERYI:    case OP_POSQUERYI:
660      case OP_POSUPTOI:
661    case OP_NOTSTAR:    case OP_NOTSTAR:
662    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
663    case OP_NOTPLUS:    case OP_NOTPLUS:
664    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
665    case OP_NOTQUERY:    case OP_NOTQUERY:
666    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
667      case OP_NOTUPTO:
668      case OP_NOTMINUPTO:
669      case OP_NOTEXACT:
670    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
671    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
672    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
673      case OP_NOTPOSUPTO:
674    case OP_NOTSTARI:    case OP_NOTSTARI:
675    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
676    case OP_NOTPLUSI:    case OP_NOTPLUSI:
677    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
678    case OP_NOTQUERYI:    case OP_NOTQUERYI:
679    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:  
680    case OP_NOTUPTOI:    case OP_NOTUPTOI:
681    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
682    case OP_NOTEXACTI:    case OP_NOTEXACTI:
683      case OP_NOTPOSSTARI:
684      case OP_NOTPOSPLUSI:
685      case OP_NOTPOSQUERYI:
686    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
687    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
688  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
689    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
690  #endif  #endif
691    return cc;    return cc;
692    
693    case OP_NOTPROP:    /* Special cases. */
694    case OP_PROP:    case OP_TYPESTAR:
695    return cc + 1 + 2;    case OP_TYPEMINSTAR:
696      case OP_TYPEPLUS:
697      case OP_TYPEMINPLUS:
698      case OP_TYPEQUERY:
699      case OP_TYPEMINQUERY:
700    case OP_TYPEUPTO:    case OP_TYPEUPTO:
701    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
702    case OP_TYPEEXACT:    case OP_TYPEEXACT:
703      case OP_TYPEPOSSTAR:
704      case OP_TYPEPOSPLUS:
705      case OP_TYPEPOSQUERY:
706    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
707    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;  
708    
709    case OP_CLASS:    case OP_ANYBYTE:
710    case OP_NCLASS:  #ifdef SUPPORT_UTF
711    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
712    #endif
713      return cc + 1;
714    
715  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
716    case OP_XCLASS:    case OP_XCLASS:
717    return cc + GET(cc, 1);    return cc + GET(cc, 1);
718  #endif  #endif
719    
   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;  
   
720    case OP_MARK:    case OP_MARK:
721      case OP_PRUNE_ARG:
722      case OP_SKIP_ARG:
723      case OP_THEN_ARG:
724    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
725    
726    default:    default:
727      /* All opcodes are supported now! */
728      SLJIT_ASSERT_STOP();
729    return NULL;    return NULL;
730    }    }
731  }  }
732    
733  #define CASE_ITERATOR_LOCAL1 \  #define CASE_ITERATOR_PRIVATE_DATA_1 \
734      case OP_MINSTAR: \      case OP_MINSTAR: \
735      case OP_MINPLUS: \      case OP_MINPLUS: \
736      case OP_QUERY: \      case OP_QUERY: \
# Line 693  switch(*cc) Line 748  switch(*cc)
748      case OP_NOTQUERYI: \      case OP_NOTQUERYI: \
749      case OP_NOTMINQUERYI:      case OP_NOTMINQUERYI:
750    
751  #define CASE_ITERATOR_LOCAL2A \  #define CASE_ITERATOR_PRIVATE_DATA_2A \
752      case OP_STAR: \      case OP_STAR: \
753      case OP_PLUS: \      case OP_PLUS: \
754      case OP_STARI: \      case OP_STARI: \
# Line 703  switch(*cc) Line 758  switch(*cc)
758      case OP_NOTSTARI: \      case OP_NOTSTARI: \
759      case OP_NOTPLUSI:      case OP_NOTPLUSI:
760    
761  #define CASE_ITERATOR_LOCAL2B \  #define CASE_ITERATOR_PRIVATE_DATA_2B \
762      case OP_UPTO: \      case OP_UPTO: \
763      case OP_MINUPTO: \      case OP_MINUPTO: \
764      case OP_UPTOI: \      case OP_UPTOI: \
# Line 713  switch(*cc) Line 768  switch(*cc)
768      case OP_NOTUPTOI: \      case OP_NOTUPTOI: \
769      case OP_NOTMINUPTOI:      case OP_NOTMINUPTOI:
770    
771  #define CASE_ITERATOR_TYPE_LOCAL1 \  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
772      case OP_TYPEMINSTAR: \      case OP_TYPEMINSTAR: \
773      case OP_TYPEMINPLUS: \      case OP_TYPEMINPLUS: \
774      case OP_TYPEQUERY: \      case OP_TYPEQUERY: \
775      case OP_TYPEMINQUERY:      case OP_TYPEMINQUERY:
776    
777  #define CASE_ITERATOR_TYPE_LOCAL2A \  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
778      case OP_TYPESTAR: \      case OP_TYPESTAR: \
779      case OP_TYPEPLUS:      case OP_TYPEPLUS:
780    
781  #define CASE_ITERATOR_TYPE_LOCAL2B \  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
782      case OP_TYPEUPTO: \      case OP_TYPEUPTO: \
783      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
784    
# Line 752  switch(*cc) Line 807  switch(*cc)
807    }    }
808  }  }
809    
810  static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
811  {  {
812  int localspace = 0;  int private_data_length = 0;
813  pcre_uchar *alternative;  pcre_uchar *alternative;
814    pcre_uchar *name;
815  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
816  int space, size, bracketlen;  int space, size, i;
817    pcre_uint32 bracketlen;
818    
819  /* 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. */
820  while (cc < ccend)  while (cc < ccend)
# Line 772  while (cc < ccend) Line 829  while (cc < ccend)
829      cc += 1;      cc += 1;
830      break;      break;
831    
832        case OP_REF:
833        case OP_REFI:
834        common->optimized_cbracket[GET2(cc, 1)] = 0;
835        cc += 1 + IMM2_SIZE;
836        break;
837    
838      case OP_ASSERT:      case OP_ASSERT:
839      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
840      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 781  while (cc < ccend) Line 844  while (cc < ccend)
844      case OP_BRAPOS:      case OP_BRAPOS:
845      case OP_SBRA:      case OP_SBRA:
846      case OP_SBRAPOS:      case OP_SBRAPOS:
847      case OP_SCOND:      private_data_length += sizeof(sljit_sw);
     localspace += sizeof(sljit_w);  
848      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
849      break;      break;
850    
851      case OP_CBRAPOS:      case OP_CBRAPOS:
852      case OP_SCBRAPOS:      case OP_SCBRAPOS:
853      localspace += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
854        common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
855      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
856      break;      break;
857    
858      case OP_COND:      case OP_COND:
859      /* Might be a hidden SCOND. */      case OP_SCOND:
860      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
861      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
862        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
863          return -1;
864    
865        if (*cc == OP_COND)
866          {
867          /* Might be a hidden SCOND. */
868          alternative = cc + GET(cc, 1);
869          if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
870            private_data_length += sizeof(sljit_sw);
871          }
872        else
873          private_data_length += sizeof(sljit_sw);
874      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
875      break;      break;
876    
877        case OP_CREF:
878        i = GET2(cc, 1);
879        common->optimized_cbracket[i] = 0;
880        cc += 1 + IMM2_SIZE;
881        break;
882    
883        case OP_NCREF:
884        bracketlen = GET2(cc, 1);
885        name = (pcre_uchar *)common->name_table;
886        alternative = name;
887        for (i = 0; i < common->name_count; i++)
888          {
889          if (GET2(name, 0) == bracketlen) break;
890          name += common->name_entry_size;
891          }
892        SLJIT_ASSERT(i != common->name_count);
893    
894        for (i = 0; i < common->name_count; i++)
895          {
896          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
897            common->optimized_cbracket[GET2(alternative, 0)] = 0;
898          alternative += common->name_entry_size;
899          }
900        bracketlen = 0;
901        cc += 1 + IMM2_SIZE;
902        break;
903    
904      case OP_BRA:      case OP_BRA:
905      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
906      break;      break;
# Line 809  while (cc < ccend) Line 910  while (cc < ccend)
910      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
911      break;      break;
912    
913      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
914      space = 1;      space = 1;
915      size = -2;      size = -2;
916      break;      break;
917    
918      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
919      space = 2;      space = 2;
920      size = -2;      size = -2;
921      break;      break;
922    
923      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
924      space = 2;      space = 2;
925      size = -(2 + IMM2_SIZE);      size = -(2 + IMM2_SIZE);
926      break;      break;
927    
928      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
929      space = 1;      space = 1;
930      size = 1;      size = 1;
931      break;      break;
932    
933      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
934      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
935        space = 2;        space = 2;
936      size = 1;      size = 1;
937      break;      break;
938    
939      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
940      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
941        space = 2;        space = 2;
942      size = 1 + IMM2_SIZE;      size = 1 + IMM2_SIZE;
# Line 856  while (cc < ccend) Line 957  while (cc < ccend)
957    
958      case OP_RECURSE:      case OP_RECURSE:
959      /* Set its value only once. */      /* Set its value only once. */
960      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
961        {        {
962        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
963        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
964        }        }
965      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
966      break;      break;
967    
968        case OP_CALLOUT:
969        if (common->capture_last_ptr == 0)
970          {
971          common->capture_last_ptr = common->ovector_start;
972          common->ovector_start += sizeof(sljit_sw);
973          }
974        cc += 2 + 2 * LINK_SIZE;
975        break;
976    
977        case OP_THEN_ARG:
978        common->has_then = TRUE;
979        common->control_head_ptr = 1;
980        /* Fall through. */
981    
982        case OP_PRUNE_ARG:
983        common->needs_start_ptr = TRUE;
984        /* Fall through. */
985    
986      case OP_MARK:      case OP_MARK:
987      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
988        {        {
989        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
990        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
991        }        }
992      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
993      break;      break;
994    
995        case OP_THEN:
996        common->has_then = TRUE;
997        common->control_head_ptr = 1;
998        /* Fall through. */
999    
1000        case OP_PRUNE:
1001        case OP_SKIP:
1002        common->needs_start_ptr = TRUE;
1003        cc += 1;
1004        break;
1005    
1006        case OP_SKIP_ARG:
1007        common->control_head_ptr = 1;
1008        common->has_skip_arg = TRUE;
1009        cc += 1 + 2 + cc[1];
1010        break;
1011    
1012      default:      default:
1013      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1014      if (cc == NULL)      if (cc == NULL)
# Line 881  while (cc < ccend) Line 1017  while (cc < ccend)
1017      }      }
1018    
1019    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1020      localspace += sizeof(sljit_w) * space;      private_data_length += sizeof(sljit_sw) * space;
1021    
1022    if (size != 0)    if (size != 0)
1023      {      {
# Line 896  while (cc < ccend) Line 1032  while (cc < ccend)
1032        cc += size;        cc += size;
1033      }      }
1034    
1035    if (bracketlen > 0)    if (bracketlen != 0)
1036      {      {
1037      if (cc >= end)      if (cc >= end)
1038        {        {
# Line 907  while (cc < ccend) Line 1043  while (cc < ccend)
1043      cc += bracketlen;      cc += bracketlen;
1044      }      }
1045    }    }
1046  return localspace;  return private_data_length;
1047  }  }
1048    
1049  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)
1050  {  {
1051  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1052  pcre_uchar *alternative;  pcre_uchar *alternative;
# Line 934  while (cc < ccend) Line 1070  while (cc < ccend)
1070      case OP_SBRA:      case OP_SBRA:
1071      case OP_SBRAPOS:      case OP_SBRAPOS:
1072      case OP_SCOND:      case OP_SCOND:
1073      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1074      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1075      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1076      break;      break;
1077    
1078      case OP_CBRAPOS:      case OP_CBRAPOS:
1079      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1080      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1081      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1082      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1083      break;      break;
1084    
# Line 951  while (cc < ccend) Line 1087  while (cc < ccend)
1087      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1088      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1089        {        {
1090        common->localptrs[cc - common->start] = localptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1091        localptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1092        }        }
1093      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1094      break;      break;
# Line 966  while (cc < ccend) Line 1102  while (cc < ccend)
1102      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1103      break;      break;
1104    
1105      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
1106      space = 1;      space = 1;
1107      size = -2;      size = -2;
1108      break;      break;
1109    
1110      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
1111      space = 2;      space = 2;
1112      size = -2;      size = -2;
1113      break;      break;
1114    
1115      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
1116      space = 2;      space = 2;
1117      size = -(2 + IMM2_SIZE);      size = -(2 + IMM2_SIZE);
1118      break;      break;
1119    
1120      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1121      space = 1;      space = 1;
1122      size = 1;      size = 1;
1123      break;      break;
1124    
1125      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1126      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1127        space = 2;        space = 2;
1128      size = 1;      size = 1;
1129      break;      break;
1130    
1131      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1132      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1133        space = 2;        space = 2;
1134      size = 1 + IMM2_SIZE;      size = 1 + IMM2_SIZE;
# Line 1019  while (cc < ccend) Line 1155  while (cc < ccend)
1155    
1156    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1157      {      {
1158      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1159      localptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1160      }      }
1161    
1162    if (size != 0)    if (size != 0)
# Line 1049  while (cc < ccend) Line 1185  while (cc < ccend)
1185    }    }
1186  }  }
1187    
1188  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1189  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)
1190  {  {
 pcre_uchar *ccend = bracketend(cc);  
1191  int length = 0;  int length = 0;
1192  BOOL possessive = FALSE;  int possessive = 0;
1193    BOOL stack_restore = FALSE;
1194  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1195  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1196    /* The last capture is a local variable even for recursions. */
1197    BOOL capture_last_found = FALSE;
1198    
1199  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1200    SLJIT_ASSERT(common->control_head_ptr != 0);
1201    *needs_control_head = TRUE;
1202    #else
1203    *needs_control_head = FALSE;
1204    #endif
1205    
1206    if (ccend == NULL)
1207    {    {
1208    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1209    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1210        {
1211        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1212        /* This is correct regardless of common->capture_last_ptr. */
1213        capture_last_found = TRUE;
1214        }
1215      cc = next_opcode(common, cc);
1216    }    }
1217    
 cc = next_opcode(common, cc);  
1218  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1219  while (cc < ccend)  while (cc < ccend)
1220    switch(*cc)    switch(*cc)
1221      {      {
1222      case OP_SET_SOM:      case OP_SET_SOM:
1223      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1224        stack_restore = TRUE;
1225      if (!setsom_found)      if (!setsom_found)
1226        {        {
1227        length += 2;        length += 2;
# Line 1080  while (cc < ccend) Line 1231  while (cc < ccend)
1231      break;      break;
1232    
1233      case OP_MARK:      case OP_MARK:
1234        case OP_PRUNE_ARG:
1235        case OP_THEN_ARG:
1236      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1237        stack_restore = TRUE;
1238      if (!setmark_found)      if (!setmark_found)
1239        {        {
1240        length += 2;        length += 2;
1241        setmark_found = TRUE;        setmark_found = TRUE;
1242        }        }
1243        if (common->control_head_ptr != 0)
1244          *needs_control_head = TRUE;
1245      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1246      break;      break;
1247    
1248      case OP_RECURSE:      case OP_RECURSE:
1249        stack_restore = TRUE;
1250      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1251        {        {
1252        length += 2;        length += 2;
# Line 1100  while (cc < ccend) Line 1257  while (cc < ccend)
1257        length += 2;        length += 2;
1258        setmark_found = TRUE;        setmark_found = TRUE;
1259        }        }
1260        if (common->capture_last_ptr != 0 && !capture_last_found)
1261          {
1262          length += 2;
1263          capture_last_found = TRUE;
1264          }
1265      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1266      break;      break;
1267    
# Line 1107  while (cc < ccend) Line 1269  while (cc < ccend)
1269      case OP_CBRAPOS:      case OP_CBRAPOS:
1270      case OP_SCBRA:      case OP_SCBRA:
1271      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1272        stack_restore = TRUE;
1273        if (common->capture_last_ptr != 0 && !capture_last_found)
1274          {
1275          length += 2;
1276          capture_last_found = TRUE;
1277          }
1278      length += 3;      length += 3;
1279      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1280      break;      break;
1281    
1282      default:      default:
1283        stack_restore = TRUE;
1284        /* Fall through. */
1285    
1286        case OP_NOT_WORD_BOUNDARY:
1287        case OP_WORD_BOUNDARY:
1288        case OP_NOT_DIGIT:
1289        case OP_DIGIT:
1290        case OP_NOT_WHITESPACE:
1291        case OP_WHITESPACE:
1292        case OP_NOT_WORDCHAR:
1293        case OP_WORDCHAR:
1294        case OP_ANY:
1295        case OP_ALLANY:
1296        case OP_ANYBYTE:
1297        case OP_NOTPROP:
1298        case OP_PROP:
1299        case OP_ANYNL:
1300        case OP_NOT_HSPACE:
1301        case OP_HSPACE:
1302        case OP_NOT_VSPACE:
1303        case OP_VSPACE:
1304        case OP_EXTUNI:
1305        case OP_EODN:
1306        case OP_EOD:
1307        case OP_CIRC:
1308        case OP_CIRCM:
1309        case OP_DOLL:
1310        case OP_DOLLM:
1311        case OP_CHAR:
1312        case OP_CHARI:
1313        case OP_NOT:
1314        case OP_NOTI:
1315    
1316        case OP_EXACT:
1317        case OP_POSSTAR:
1318        case OP_POSPLUS:
1319        case OP_POSQUERY:
1320        case OP_POSUPTO:
1321    
1322        case OP_EXACTI:
1323        case OP_POSSTARI:
1324        case OP_POSPLUSI:
1325        case OP_POSQUERYI:
1326        case OP_POSUPTOI:
1327    
1328        case OP_NOTEXACT:
1329        case OP_NOTPOSSTAR:
1330        case OP_NOTPOSPLUS:
1331        case OP_NOTPOSQUERY:
1332        case OP_NOTPOSUPTO:
1333    
1334        case OP_NOTEXACTI:
1335        case OP_NOTPOSSTARI:
1336        case OP_NOTPOSPLUSI:
1337        case OP_NOTPOSQUERYI:
1338        case OP_NOTPOSUPTOI:
1339    
1340        case OP_TYPEEXACT:
1341        case OP_TYPEPOSSTAR:
1342        case OP_TYPEPOSPLUS:
1343        case OP_TYPEPOSQUERY:
1344        case OP_TYPEPOSUPTO:
1345    
1346        case OP_CLASS:
1347        case OP_NCLASS:
1348        case OP_XCLASS:
1349    
1350      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1351      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1352      break;      break;
1353      }      }
1354    
1355  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1356  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1357    return -1;    return stack_restore ? no_frame : no_stack;
1358    
1359  if (length > 0)  if (length > 0)
1360    return length + 1;    return length + 1;
1361  return -1;  return stack_restore ? no_frame : no_stack;
1362  }  }
1363    
1364  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)
1365  {  {
1366  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1367  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1368  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1369    /* The last capture is a local variable even for recursions. */
1370    BOOL capture_last_found = FALSE;
1371  int offset;  int offset;
1372    
1373  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1139  SLJIT_UNUSED_ARG(stacktop); Line 1375  SLJIT_UNUSED_ARG(stacktop);
1375  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1376    
1377  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1378  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1379    cc = next_opcode(common, cc);    {
1380      ccend = bracketend(cc) - (1 + LINK_SIZE);
1381      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1382        cc = next_opcode(common, cc);
1383      }
1384    
1385  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1386  while (cc < ccend)  while (cc < ccend)
1387    switch(*cc)    switch(*cc)
# Line 1150  while (cc < ccend) Line 1391  while (cc < ccend)
1391      if (!setsom_found)      if (!setsom_found)
1392        {        {
1393        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1394        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1395        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1396        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1397        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1398        setsom_found = TRUE;        setsom_found = TRUE;
1399        }        }
1400      cc += 1;      cc += 1;
1401      break;      break;
1402    
1403      case OP_MARK:      case OP_MARK:
1404        case OP_PRUNE_ARG:
1405        case OP_THEN_ARG:
1406      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1407      if (!setmark_found)      if (!setmark_found)
1408        {        {
1409        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);
1410        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);
1411        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1412        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1413        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1414        setmark_found = TRUE;        setmark_found = TRUE;
1415        }        }
1416      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1177  while (cc < ccend) Line 1420  while (cc < ccend)
1420      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1421        {        {
1422        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1423        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1424        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1425        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1426        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1427        setsom_found = TRUE;        setsom_found = TRUE;
1428        }        }
1429      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1430        {        {
1431        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);
1432        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);
1433        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1434        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1435        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1436        setmark_found = TRUE;        setmark_found = TRUE;
1437        }        }
1438        if (common->capture_last_ptr != 0 && !capture_last_found)
1439          {
1440          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1441          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1442          stackpos += (int)sizeof(sljit_sw);
1443          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1444          stackpos += (int)sizeof(sljit_sw);
1445          capture_last_found = TRUE;
1446          }
1447      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1448      break;      break;
1449    
# Line 1199  while (cc < ccend) Line 1451  while (cc < ccend)
1451      case OP_CBRAPOS:      case OP_CBRAPOS:
1452      case OP_SCBRA:      case OP_SCBRA:
1453      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1454        if (common->capture_last_ptr != 0 && !capture_last_found)
1455          {
1456          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1457          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1458          stackpos += (int)sizeof(sljit_sw);
1459          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1460          stackpos += (int)sizeof(sljit_sw);
1461          capture_last_found = TRUE;
1462          }
1463      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1464      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1465      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1466      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1467      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));
1468      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1469      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1470      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1471      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1472    
1473      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1474      break;      break;
# Line 1218  while (cc < ccend) Line 1479  while (cc < ccend)
1479      break;      break;
1480      }      }
1481    
1482  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1483  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1484  }  }
1485    
1486  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)
1487  {  {
1488  int localsize = 2;  int private_data_length = needs_control_head ? 3 : 2;
1489  int size;  int size;
1490  pcre_uchar *alternative;  pcre_uchar *alternative;
1491  /* Calculate the sum of the local variables. */  /* Calculate the sum of the private machine words. */
1492  while (cc < ccend)  while (cc < ccend)
1493    {    {
1494    size = 0;    size = 0;
# Line 1243  while (cc < ccend) Line 1504  while (cc < ccend)
1504      case OP_SBRA:      case OP_SBRA:
1505      case OP_SBRAPOS:      case OP_SBRAPOS:
1506      case OP_SCOND:      case OP_SCOND:
1507      localsize++;      private_data_length++;
1508      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1509      break;      break;
1510    
1511      case OP_CBRA:      case OP_CBRA:
1512      case OP_SCBRA:      case OP_SCBRA:
1513      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1514          private_data_length++;
1515      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1516      break;      break;
1517    
1518      case OP_CBRAPOS:      case OP_CBRAPOS:
1519      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1520      localsize += 2;      private_data_length += 2;
1521      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1522      break;      break;
1523    
# Line 1263  while (cc < ccend) Line 1525  while (cc < ccend)
1525      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1526      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1527      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1528        localsize++;        private_data_length++;
1529      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1530      break;      break;
1531    
1532      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
1533      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1534        localsize++;        private_data_length++;
1535      cc += 2;      cc += 2;
1536  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1537      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1538  #endif  #endif
1539      break;      break;
1540    
1541      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
1542      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1543        localsize += 2;        private_data_length += 2;
1544      cc += 2;      cc += 2;
1545  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1546      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1547  #endif  #endif
1548      break;      break;
1549    
1550      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
1551      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1552        localsize += 2;        private_data_length += 2;
1553      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1554  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1555      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1556  #endif  #endif
1557      break;      break;
1558    
1559      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1560      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1561        localsize++;        private_data_length++;
1562      cc += 1;      cc += 1;
1563      break;      break;
1564    
1565      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1566      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1567        localsize += 2;        private_data_length += 2;
1568      cc += 1;      cc += 1;
1569      break;      break;
1570    
1571      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1572      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1573        localsize += 2;        private_data_length += 2;
1574      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
1575      break;      break;
1576    
# Line 1320  while (cc < ccend) Line 1582  while (cc < ccend)
1582  #else  #else
1583      size = 1 + 32 / (int)sizeof(pcre_uchar);      size = 1 + 32 / (int)sizeof(pcre_uchar);
1584  #endif  #endif
1585      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1586        localsize += get_class_iterator_size(cc + size);        private_data_length += get_class_iterator_size(cc + size);
1587      cc += size;      cc += size;
1588      break;      break;
1589    
# Line 1332  while (cc < ccend) Line 1594  while (cc < ccend)
1594      }      }
1595    }    }
1596  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1597  return localsize;  return private_data_length;
1598  }  }
1599    
1600  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,
1601    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1602  {  {
1603  DEFINE_COMPILER;  DEFINE_COMPILER;
1604  int srcw[2];  int srcw[2];
# Line 1357  stacktop = STACK(stacktop - 1); Line 1619  stacktop = STACK(stacktop - 1);
1619    
1620  if (!save)  if (!save)
1621    {    {
1622    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1623    if (stackptr < stacktop)    if (stackptr < stacktop)
1624      {      {
1625      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1626      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1627      tmp1empty = FALSE;      tmp1empty = FALSE;
1628      }      }
1629    if (stackptr < stacktop)    if (stackptr < stacktop)
1630      {      {
1631      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1632      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1633      tmp2empty = FALSE;      tmp2empty = FALSE;
1634      }      }
1635    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1636    }    }
1637    
1638  while (status != end)  do
1639    {    {
1640    count = 0;    count = 0;
1641    switch(status)    switch(status)
1642      {      {
1643      case start:      case start:
1644      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1645      count = 1;      count = 1;
1646      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1647        if (needs_control_head)
1648          {
1649          SLJIT_ASSERT(common->control_head_ptr != 0);
1650          count = 2;
1651          srcw[1] = common->control_head_ptr;
1652          }
1653      status = loop;      status = loop;
1654      break;      break;
1655    
# Line 1405  while (status != end) Line 1673  while (status != end)
1673        case OP_SBRAPOS:        case OP_SBRAPOS:
1674        case OP_SCOND:        case OP_SCOND:
1675        count = 1;        count = 1;
1676        srcw[0] = PRIV_DATA(cc);        srcw[0] = PRIVATE_DATA(cc);
1677        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1678        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1679        break;        break;
1680    
1681        case OP_CBRA:        case OP_CBRA:
1682        case OP_SCBRA:        case OP_SCBRA:
1683        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1684        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1685            count = 1;
1686            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1687            }
1688        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1689        break;        break;
1690    
1691        case OP_CBRAPOS:        case OP_CBRAPOS:
1692        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1693        count = 2;        count = 2;
1694        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[0] = PRIVATE_DATA(cc);
1695        srcw[1] = PRIV_DATA(cc);        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1696        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
1697        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1698        break;        break;
1699    
# Line 1432  while (status != end) Line 1703  while (status != end)
1703        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1704          {          {
1705          count = 1;          count = 1;
1706          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1707          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1708          }          }
1709        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1710        break;        break;
1711    
1712        CASE_ITERATOR_LOCAL1        CASE_ITERATOR_PRIVATE_DATA_1
1713        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1714          {          {
1715          count = 1;          count = 1;
1716          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1717          }          }
1718        cc += 2;        cc += 2;
1719  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1450  while (status != end) Line 1721  while (status != end)
1721  #endif  #endif
1722        break;        break;
1723    
1724        CASE_ITERATOR_LOCAL2A        CASE_ITERATOR_PRIVATE_DATA_2A
1725        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1726          {          {
1727          count = 2;          count = 2;
1728          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1729          srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1730          }          }
1731        cc += 2;        cc += 2;
1732  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1463  while (status != end) Line 1734  while (status != end)
1734  #endif  #endif
1735        break;        break;
1736    
1737        CASE_ITERATOR_LOCAL2B        CASE_ITERATOR_PRIVATE_DATA_2B
1738        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1739          {          {
1740          count = 2;          count = 2;
1741          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1742          srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1743          }          }
1744        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1745  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1476  while (status != end) Line 1747  while (status != end)
1747  #endif  #endif
1748        break;        break;
1749    
1750        CASE_ITERATOR_TYPE_LOCAL1        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1751        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1752          {          {
1753          count = 1;          count = 1;
1754          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1755          }          }
1756        cc += 1;        cc += 1;
1757        break;        break;
1758    
1759        CASE_ITERATOR_TYPE_LOCAL2A        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1760        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1761          {          {
1762          count = 2;          count = 2;
1763          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1764          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1765          }          }
1766        cc += 1;        cc += 1;
1767        break;        break;
1768    
1769        CASE_ITERATOR_TYPE_LOCAL2B        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1770        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1771          {          {
1772          count = 2;          count = 2;
1773          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1774          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1775          }          }
1776        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1777        break;        break;
# Line 1513  while (status != end) Line 1784  while (status != end)
1784  #else  #else
1785        size = 1 + 32 / (int)sizeof(pcre_uchar);        size = 1 + 32 / (int)sizeof(pcre_uchar);
1786  #endif  #endif
1787        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1788          switch(get_class_iterator_size(cc + size))          switch(get_class_iterator_size(cc + size))
1789            {            {
1790            case 1:            case 1:
1791            count = 1;            count = 1;
1792            srcw[0] = PRIV_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1793            break;            break;
1794    
1795            case 2:            case 2:
1796            count = 2;            count = 2;
1797            srcw[0] = PRIV_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1798            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1799            break;            break;
1800    
1801            default:            default:
# Line 1556  while (status != end) Line 1827  while (status != end)
1827          if (!tmp1empty)          if (!tmp1empty)
1828            {            {
1829            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1830            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1831            }            }
1832          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1833          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1567  while (status != end) Line 1838  while (status != end)
1838          if (!tmp2empty)          if (!tmp2empty)
1839            {            {
1840            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1841            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1842            }            }
1843          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1844          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1584  while (status != end) Line 1855  while (status != end)
1855          if (!tmp1empty)          if (!tmp1empty)
1856            {            {
1857            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1858            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1859            }            }
1860          tmp1next = FALSE;          tmp1next = FALSE;
1861          }          }
# Line 1596  while (status != end) Line 1867  while (status != end)
1867          if (!tmp2empty)          if (!tmp2empty)
1868            {            {
1869            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1870            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1871            }            }
1872          tmp1next = TRUE;          tmp1next = TRUE;
1873          }          }
1874        }        }
1875      }      }
1876    }    }
1877    while (status != end);
1878    
1879  if (save)  if (save)
1880    {    {
# Line 1611  if (save) Line 1883  if (save)
1883      if (!tmp1empty)      if (!tmp1empty)
1884        {        {
1885        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1886        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1887        }        }
1888      if (!tmp2empty)      if (!tmp2empty)
1889        {        {
1890        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1891        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1892        }        }
1893      }      }
1894    else    else
# Line 1624  if (save) Line 1896  if (save)
1896      if (!tmp2empty)      if (!tmp2empty)
1897        {        {
1898        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1899        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1900        }        }
1901      if (!tmp1empty)      if (!tmp1empty)
1902        {        {
1903        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1904        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1905        }        }
1906      }      }
1907    }    }
1908  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1909  }  }
1910    
1911  #undef CASE_ITERATOR_LOCAL1  static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1912  #undef CASE_ITERATOR_LOCAL2A  {
1913  #undef CASE_ITERATOR_LOCAL2B  pcre_uchar *end = bracketend(cc);
1914  #undef CASE_ITERATOR_TYPE_LOCAL1  BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1915  #undef CASE_ITERATOR_TYPE_LOCAL2A  
1916  #undef CASE_ITERATOR_TYPE_LOCAL2B  /* Assert captures then. */
1917    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1918      current_offset = NULL;
1919    /* Conditional block does not. */
1920    if (*cc == OP_COND || *cc == OP_SCOND)
1921      has_alternatives = FALSE;
1922    
1923    cc = next_opcode(common, cc);
1924    if (has_alternatives)
1925      current_offset = common->then_offsets + (cc - common->start);
1926    
1927    while (cc < end)
1928      {
1929      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1930        cc = set_then_offsets(common, cc, current_offset);
1931      else
1932        {
1933        if (*cc == OP_ALT && has_alternatives)
1934          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1935        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1936          *current_offset = 1;
1937        cc = next_opcode(common, cc);
1938        }
1939      }
1940    
1941    return end;
1942    }
1943    
1944    #undef CASE_ITERATOR_PRIVATE_DATA_1
1945    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1946    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1947    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1948    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1949    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1950    
1951  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1952  {  {
1953  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1954  }  }
# Line 1653  static SLJIT_INLINE void set_jumps(jump_ Line 1958  static SLJIT_INLINE void set_jumps(jump_
1958  while (list)  while (list)
1959    {    {
1960    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1961    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1962    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1963    list = list->next;    list = list->next;
1964    }    }
1965  }  }
# Line 1670  if (list_item) Line 1975  if (list_item)
1975    }    }
1976  }  }
1977    
1978  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)
1979  {  {
1980  DEFINE_COMPILER;  DEFINE_COMPILER;
1981  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1982    
1983  if (list_item)  if (list_item)
1984    {    {
   list_item->type = type;  
   list_item->data = data;  
1985    list_item->start = start;    list_item->start = start;
1986    list_item->quit = LABEL();    list_item->quit = LABEL();
1987    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1694  stub_list* list_item = common->stubs; Line 1997  stub_list* list_item = common->stubs;
1997  while (list_item)  while (list_item)
1998    {    {
1999    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2000    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
     {  
     case stack_alloc:  
     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));  
     break;  
     }  
2001    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2002    list_item = list_item->next;    list_item = list_item->next;
2003    }    }
# Line 1719  static SLJIT_INLINE void allocate_stack( Line 2017  static SLJIT_INLINE void allocate_stack(
2017  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2018  DEFINE_COMPILER;  DEFINE_COMPILER;
2019    
2020  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));
2021  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2022  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2023  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1727  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2025  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2025  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2026  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2027  #endif  #endif
2028  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));
2029  }  }
2030    
2031  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2032  {  {
2033  DEFINE_COMPILER;  DEFINE_COMPILER;
2034  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));
2035    }
2036    
2037    static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
2038    {
2039    DEFINE_COMPILER;
2040    struct sljit_label *loop;
2041    int i;
2042    
2043    /* At this point we can freely use all temporary registers. */
2044    SLJIT_ASSERT(length > 1);
2045    /* TMP1 returns with begin - 1. */
2046    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
2047    if (length < 8)
2048      {
2049      for (i = 1; i < length; i++)
2050        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2051      }
2052    else
2053      {
2054      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2055      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2056      loop = LABEL();
2057      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2058      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2059      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2060      }
2061  }  }
2062    
2063  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2064  {  {
2065  DEFINE_COMPILER;  DEFINE_COMPILER;
2066  struct sljit_label *loop;  struct sljit_label *loop;
2067  int i;  int i;
2068  /* At this point we can freely use all temporary registers. */  
2069  /* TMP1 returns with begin - 1. */  SLJIT_ASSERT(length > 1);
2070  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));  /* OVECTOR(1) contains the "string begin - 1" constant. */
2071    if (length > 2)
2072      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2073  if (length < 8)  if (length < 8)
2074    {    {
2075    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2076      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);
2077    }    }
2078  else  else
2079    {    {
2080    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2081    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2082    loop = LABEL();    loop = LABEL();
2083    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);
2084    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);
2085    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2086    }    }
2087    
2088    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2089    if (common->mark_ptr != 0)
2090      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2091    if (common->control_head_ptr != 0)
2092      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2093    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2094    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2095    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2096    }
2097    
2098    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2099    {
2100    while (current != NULL)
2101      {
2102      switch (current[-2])
2103        {
2104        case type_then_trap:
2105        break;
2106    
2107        case type_mark:
2108        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2109          return current[-4];
2110        break;
2111    
2112        default:
2113        SLJIT_ASSERT_STOP();
2114        break;
2115        }
2116      current = (sljit_sw*)current[-1];
2117      }
2118    return -1;
2119    }
2120    
2121    static sljit_sw SLJIT_CALL do_search_then_trap(sljit_sw *current, sljit_sw start)
2122    {
2123    do
2124      {
2125      SLJIT_ASSERT(current != NULL);
2126      switch (current[-2])
2127        {
2128        case type_then_trap:
2129        if (current[-3] == start)
2130          return (sljit_sw)current;
2131        break;
2132    
2133        case type_mark:
2134        break;
2135    
2136        default:
2137        SLJIT_ASSERT_STOP();
2138        break;
2139        }
2140      current = (sljit_sw*)current[-1];
2141      }
2142    while (TRUE);
2143  }  }
2144    
2145  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2146  {  {
2147  DEFINE_COMPILER;  DEFINE_COMPILER;
2148  struct sljit_label *loop;  struct sljit_label *loop;
2149  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2150    
2151  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2152  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));
2153  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);
2154    
2155  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2156  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2157    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);
2158  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));
2159  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2160    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);
2161  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));
2162  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));
2163  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2164  /* Unlikely, but possible */  /* Unlikely, but possible */
2165  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);
2166  loop = LABEL();  loop = LABEL();
2167  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);
2168  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));
2169  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2170  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2171  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);
2172  #endif  #endif
2173  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);
2174  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);
2175  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2176  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2177    
2178  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2179  if (topbracket > 1)  if (topbracket > 1)
2180    {    {
2181    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
2182    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2183    
2184    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2185    loop = LABEL();    loop = LABEL();
2186    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)));
2187    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);
2188    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);
2189    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2190    }    }
2191  else  else
2192    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1813  else Line 2195  else
2195  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2196  {  {
2197  DEFINE_COMPILER;  DEFINE_COMPILER;
2198    struct sljit_jump *jump;
2199    
2200  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);
2201  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
2202      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2203    
2204  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2205  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2206  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));
2207  CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, quit);  CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2208    
2209  /* Store match begin and end. */  /* Store match begin and end. */
2210  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));
2211  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));
2212  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);  
2213    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2214    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);
2215    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2216    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2217    #endif
2218    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2219    JUMPHERE(jump);
2220    
2221    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);
2222  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);
2223  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2224  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);
2225  #endif  #endif
2226  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);
2227    
2228  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);
2229  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2230  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);
2231  #endif  #endif
2232  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);
2233    
2234  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2235  }  }
# Line 1949  if (c <= 127 && bit == 0x20) Line 2342  if (c <= 127 && bit == 0x20)
2342    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2343    
2344  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2345  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2346    return 0;    return 0;
2347    
2348  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2349    
2350  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2351  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 1968  if (common->utf && c > 127) Line 2361  if (common->utf && c > 127)
2361  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2362  return (0 << 8) | bit;  return (0 << 8) | bit;
2363    
2364  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2365    
 #ifdef COMPILE_PCRE16  
2366  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2367  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2368    {    {
# Line 1981  if (common->utf && c > 65535) Line 2373  if (common->utf && c > 65535)
2373    }    }
2374  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2375  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2376    
2377  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2378  }  }
2379    
2380  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
# Line 2003  else if (common->mode == JIT_PARTIAL_SOF Line 2394  else if (common->mode == JIT_PARTIAL_SOF
2394    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);
2395    
2396  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2397    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);
2398  else  else
2399    {    {
2400    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2016  if (jump != NULL) Line 2407  if (jump != NULL)
2407    JUMPHERE(jump);    JUMPHERE(jump);
2408  }  }
2409    
2410  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2411  {  {
2412  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2413  DEFINE_COMPILER;  DEFINE_COMPILER;
2414  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2415    
2416  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2417    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2418      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2419      return;
2420      }
2421    
2422  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2423  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2424    {    {
2425    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));
2426    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);
2427    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2428    }    }
2429  else  else
2430    {    {
2431    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));
2432    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2433      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2434    else    else
2435      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2436    }    }
2437  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2438  }  }
2439    
2440  static void detect_partial_match(compiler_common *common, jump_list **backtracks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
# Line 2063  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR Line 2453  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2453  add_jump(compiler, backtracks, 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));
2454  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2455    {    {
2456    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);
2457    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2458    }    }
2459  else  else
# Line 2081  static void read_char(compiler_common *c Line 2471  static void read_char(compiler_common *c
2471  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2472  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2473  DEFINE_COMPILER;  DEFINE_COMPILER;
2474  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2475  struct sljit_jump *jump;  struct sljit_jump *jump;
2476  #endif  #endif
2477    
2478  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2479  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2480  if (common->utf)  if (common->utf)
2481    {    {
2482  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2483    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2484  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2485    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2486  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2487    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2488    JUMPHERE(jump);    JUMPHERE(jump);
2489    }    }
2490  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2491  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));
2492  }  }
2493    
# Line 2108  static void peek_char(compiler_common *c Line 2496  static void peek_char(compiler_common *c
2496  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2497  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2498  DEFINE_COMPILER;  DEFINE_COMPILER;
2499  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2500  struct sljit_jump *jump;  struct sljit_jump *jump;
2501  #endif  #endif
2502    
2503  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2504  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2505  if (common->utf)  if (common->utf)
2506    {    {
2507  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2508    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2509  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2510    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2511  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2512    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2513    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2514    JUMPHERE(jump);    JUMPHERE(jump);
2515    }    }
2516  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2517  }  }
2518    
2519  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2520  {  {
2521  /* 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. */
2522  DEFINE_COMPILER;  DEFINE_COMPILER;
2523  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2524  struct sljit_jump *jump;  struct sljit_jump *jump;
2525  #endif  #endif
2526    
# Line 2143  if (common->utf) Line 2529  if (common->utf)
2529    {    {
2530    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2531    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));
2532  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2533    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2534    it is needed in most cases. */    it is needed in most cases. */
2535    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2536    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2537    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2538    JUMPHERE(jump);    JUMPHERE(jump);
2539  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2540    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2541    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2542    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
# Line 2159  if (common->utf) Line 2544  if (common->utf)
2544    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2545    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2546    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);
2547    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2548    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2549    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2550  #endif  #elif defined COMPILE_PCRE32
2551  #endif /* COMPILE_PCRE8 */    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2552      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2553      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2554      JUMPHERE(jump);
2555    #endif /* COMPILE_PCRE[8|16|32] */
2556    return;    return;
2557    }    }
2558  #endif  #endif /* SUPPORT_UTF */
2559  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2560  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));
2561  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2562  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2563  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2564  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2565  #endif  #endif
2566  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2567  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2568  JUMPHERE(jump);  JUMPHERE(jump);
2569  #endif  #endif
2570  }  }
# Line 2184  static void skip_char_back(compiler_comm Line 2573  static void skip_char_back(compiler_comm
2573  {  {
2574  /* 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. */
2575  DEFINE_COMPILER;  DEFINE_COMPILER;
2576  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2577    #if defined COMPILE_PCRE8
2578  struct sljit_label *label;  struct sljit_label *label;
2579    
2580  if (common->utf)  if (common->utf)
# Line 2196  if (common->utf) Line 2586  if (common->utf)
2586    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2587    return;    return;
2588    }    }
2589  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2590  if (common->utf)  if (common->utf)
2591    {    {
2592    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 2205  if (common->utf) Line 2594  if (common->utf)
2594    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2595    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2596    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);
2597    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2598    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2599    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2600    return;    return;
2601    }    }
2602  #endif  #endif /* COMPILE_PCRE[8|16] */
2603    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2604  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));
2605  }  }
2606    
# Line 2227  if (nltype == NLTYPE_ANY) Line 2617  if (nltype == NLTYPE_ANY)
2617  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2618    {    {
2619    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);
2620    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2621    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);
2622    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);
2623    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2624    }    }
2625  else  else
# Line 2241  else Line 2631  else
2631    
2632  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2633    
2634  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2635  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2636  {  {
2637  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
# Line 2329  sljit_emit_fast_return(compiler, RETURN_ Line 2719  sljit_emit_fast_return(compiler, RETURN_
2719  JUMPHERE(jump);  JUMPHERE(jump);
2720    
2721  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2722  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);
2723  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2724  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2725  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2726  }  }
2727    
2728  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2729    
 #ifdef COMPILE_PCRE16  
2730  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2731  {  {
2732  /* 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 2362  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC Line 2751  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2751  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2752  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2753  }  }
 #endif /* COMPILE_PCRE16 */  
2754    
2755  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2756    
2757  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2758    
# Line 2384  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2772  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2772    
2773  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2774  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2775  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));
2776  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2777  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2778  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2779  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2780  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2781  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));
2782  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2783  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2784  }  }
# Line 2404  struct sljit_label *newlinelabel = NULL; Line 2792  struct sljit_label *newlinelabel = NULL;
2792  struct sljit_jump *start;  struct sljit_jump *start;
2793  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2794  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2795  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2796  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2797  #endif  #endif
2798  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2420  if (firstline) Line 2808  if (firstline)
2808    /* Search for the end of the first line. */    /* Search for the end of the first line. */
2809    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
2810    OP1(SLJIT_MOV, TMP3, 0, 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);  
2811    
2812    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2813      {      {
# Line 2431  if (firstline) Line 2818  if (firstline)
2818      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2819      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);
2820      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);
2821        JUMPHERE(end);
2822      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));
2823      }      }
2824    else    else
# Line 2442  if (firstline) Line 2830  if (firstline)
2830      read_char(common);      read_char(common);
2831      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
2832      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2833        JUMPHERE(end);
2834      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);
2835      set_jumps(newline, LABEL());      set_jumps(newline, LABEL());
2836      }      }
2837    
   JUMPHERE(end);  
2838    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
2839    }    }
2840    
# Line 2459  if (newlinecheck) Line 2847  if (newlinecheck)
2847    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2848    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2849    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);
2850    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2851  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2852    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2853  #endif  #endif
2854    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2855    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2482  if (newlinecheck) Line 2870  if (newlinecheck)
2870    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);
2871    
2872  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));
2873  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2874    #if defined COMPILE_PCRE8
2875  if (common->utf)  if (common->utf)
2876    {    {
2877    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2878    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);
2879    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2880    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2881    }    }
2882  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2883  if (common->utf)  if (common->utf)
2884    {    {
2885    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2886    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2887    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);
2888    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2889    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2890    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2891    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2892    }    }
2893  #endif  #endif /* COMPILE_PCRE[8|16] */
2894    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2895  JUMPHERE(start);  JUMPHERE(start);
2896    
2897  if (newlinecheck)  if (newlinecheck)
# Line 2514  if (newlinecheck) Line 2903  if (newlinecheck)
2903  return mainloop;  return mainloop;
2904  }  }
2905    
2906  static SLJIT_INLINE BOOL fast_forward_first_two_chars(compiler_common *common, BOOL firstline)  #define MAX_N_CHARS 3
2907    
2908    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2909  {  {
2910  DEFINE_COMPILER;  DEFINE_COMPILER;
2911  struct sljit_label *start;  struct sljit_label *start;
2912  struct sljit_jump *quit;  struct sljit_jump *quit;
2913  struct sljit_jump *found;  pcre_uint32 chars[MAX_N_CHARS * 2];
2914  pcre_int32 chars[4];  pcre_uchar *cc = common->start + 1 + LINK_SIZE;
 pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  
2915  int location = 0;  int location = 0;
2916  pcre_int32 len, c, bit, caseless;  pcre_int32 len, c, bit, caseless;
2917  BOOL must_end;  int must_stop;
   
 #ifdef COMPILE_PCRE8  
 union {  
     sljit_uh ascombined;  
     sljit_ub asuchars[2];  
 } pair;  
 #else  
 union {  
     sljit_ui ascombined;  
     sljit_uh asuchars[2];  
 } pair;  
 #endif  
2918    
2919    /* We do not support alternatives now. */
2920  if (*(common->start + GET(common->start, 1)) == OP_ALT)  if (*(common->start + GET(common->start, 1)) == OP_ALT)
2921    return FALSE;    return FALSE;
2922    
2923  while (TRUE)  while (TRUE)
2924    {    {
2925    caseless = 0;    caseless = 0;
2926    must_end = TRUE;    must_stop = 1;
2927    switch(*cc)    switch(*cc)
2928      {      {
2929      case OP_CHAR:      case OP_CHAR:
2930      must_end = FALSE;      must_stop = 0;
2931      cc++;      cc++;
2932      break;      break;
2933    
2934      case OP_CHARI:      case OP_CHARI:
2935      caseless = 1;      caseless = 1;
2936      must_end = FALSE;      must_stop = 0;
2937      cc++;      cc++;
2938      break;      break;
2939    
# Line 2596  while (TRUE) Line 2975  while (TRUE)
2975      break;      break;
2976    
2977      default:      default:
2978      return FALSE;      must_stop = 2;
2979        break;
2980      }      }
2981    
2982      if (must_stop == 2)
2983          break;
2984    
2985    len = 1;    len = 1;
2986  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2987    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
# Line 2621  while (TRUE) Line 3004  while (TRUE)
3004    else    else
3005      caseless = 0;      caseless = 0;
3006    
3007    while (len > 0 && location < 2 * 2)    while (len > 0 && location < MAX_N_CHARS * 2)
3008      {      {
3009      c = *cc;      c = *cc;
3010      bit = 0;      bit = 0;
# Line 2639  while (TRUE) Line 3022  while (TRUE)
3022      cc++;      cc++;
3023      }      }
3024    
3025    if (location == 2 * 2)    if (location >= MAX_N_CHARS * 2 || must_stop != 0)
3026      break;      break;
   else if (must_end)  
     return FALSE;  
3027    }    }
3028    
3029    /* At least two characters are required. */
3030    if (location < 2 * 2)
3031        return FALSE;
3032    
3033  if (firstline)  if (firstline)
3034    {    {
3035    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3036    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3037    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, 1);    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3038    }    }
3039  else  else
3040    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3041    
3042  start = LABEL();  start = LABEL();
3043  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  
 #ifdef COMPILE_PCRE8  
 OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #else /* COMPILE_PCRE8 */  
 OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #endif  
3044    
3045  #else /* SLJIT_UNALIGNED */  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
   
 #if defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 #else /* SLJIT_BIG_ENDIAN */  
3046  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3047  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3048  #endif /* SLJIT_BIG_ENDIAN */  if (chars[1] != 0)
3049      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3050  #ifdef COMPILE_PCRE8  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3051  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 8);  if (location > 2 * 2)
3052  #else /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3053  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 16);  if (chars[3] != 0)
3054  #endif    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
3055  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
3056    if (location > 2 * 2)
3057  #endif    {
3058      if (chars[5] != 0)
3059  if (chars[1] != 0 || chars[3] != 0)      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
3060    {    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);
   pair.asuchars[0] = chars[1];  
   pair.asuchars[1] = chars[3];  
   OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, pair.ascombined);  
3061    }    }
3062    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3063    
 pair.asuchars[0] = chars[0];  
 pair.asuchars[1] = chars[2];  
 found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, pair.ascombined);  
   
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 JUMPTO(SLJIT_JUMP, start);  
 JUMPHERE(found);  
3064  JUMPHERE(quit);  JUMPHERE(quit);
3065    
3066  if (firstline)  if (firstline)
3067    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3068  else  else
3069    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3070  return TRUE;  return TRUE;
3071  }  }
3072    
3073    #undef MAX_N_CHARS
3074    
3075  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)
3076  {  {
3077  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2738  if (first_char == oc) Line 3105  if (first_char == oc)
3105  else  else
3106    {    {
3107    bit = first_char ^ oc;    bit = first_char ^ oc;
3108    if (ispowerof2(bit))    if (is_powerof2(bit))
3109      {      {
3110      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3111      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 2746  else Line 3113  else
3113    else    else
3114      {      {
3115      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);
3116      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3117      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);
3118      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);
3119      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3120      }      }
3121    }    }
# Line 2790  if (common->nltype == NLTYPE_FIXED && co Line 3157  if (common->nltype == NLTYPE_FIXED && co
3157    
3158    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3159    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);
3160    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3161  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3162    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3163  #endif  #endif
3164    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3165    
# Line 2833  if (common->nltype == NLTYPE_ANY || comm Line 3200  if (common->nltype == NLTYPE_ANY || comm
3200    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3201    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3202    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);
3203    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3204  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3205    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3206  #endif  #endif
3207    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3208    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
# Line 2848  if (firstline) Line 3215  if (firstline)
3215    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3216  }  }
3217    
3218    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3219    
3220  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)
3221  {  {
3222  DEFINE_COMPILER;  DEFINE_COMPILER;
3223  struct sljit_label *start;  struct sljit_label *start;
3224  struct sljit_jump *quit;  struct sljit_jump *quit;
3225  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3226    jump_list *matches = NULL;
3227    pcre_uint8 inverted_start_bits[32];
3228    int i;
3229  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3230  struct sljit_jump *jump;  struct sljit_jump *jump;
3231  #endif  #endif
3232    
3233    for (i = 0; i < 32; ++i)
3234      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3235    
3236  if (firstline)  if (firstline)
3237    {    {
3238    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3239    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
3240    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);
3241    }    }
3242    
# Line 2872  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3247  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3247  if (common->utf)  if (common->utf)
3248    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3249  #endif  #endif
3250    
3251    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3252      {
3253  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3254  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3255  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3256  JUMPHERE(jump);    JUMPHERE(jump);
3257  #endif  #endif
3258  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3259  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3260  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3261  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3262  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);
3263  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3264      }
3265    
3266  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3267  if (common->utf)  if (common->utf)
3268    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3269  #endif  #endif
3270  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));
3271  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3272    #if defined COMPILE_PCRE8
3273  if (common->utf)  if (common->utf)
3274    {    {
3275    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3276    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);
3277    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3278    }    }
3279  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3280  if (common->utf)  if (common->utf)
3281    {    {
3282    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3283    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3284    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);
3285    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3286    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3287    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3288    }    }
3289  #endif  #endif /* COMPILE_PCRE[8|16] */
3290    #endif /* SUPPORT_UTF */
3291  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3292  JUMPHERE(found);  if (found != NULL)
3293      JUMPHERE(found);
3294    if (matches != NULL)
3295      set_jumps(matches, LABEL());
3296  JUMPHERE(quit);  JUMPHERE(quit);
3297    
3298  if (firstline)  if (firstline)
3299    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
3300  }  }
3301    
3302  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 2925  struct sljit_jump *alreadyfound; Line 3308  struct sljit_jump *alreadyfound;
3308  struct sljit_jump *found;  struct sljit_jump *found;
3309  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3310  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3311  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3312    
3313  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3314  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 2956  if (req_char == oc) Line 3339  if (req_char == oc)
3339  else  else
3340    {    {
3341    bit = req_char ^ oc;    bit = req_char ^ oc;
3342    if (ispowerof2(bit))    if (is_powerof2(bit))
3343      {      {
3344      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3345      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 2992  GET_LOCAL_BASE(TMP3, 0, 0); Line 3375  GET_LOCAL_BASE(TMP3, 0, 0);
3375  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3376  mainloop = LABEL();  mainloop = LABEL();
3377  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3378  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);
3379    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3380    
3381  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3382  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3383  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
3384  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
3385  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3386    
3387  JUMPHERE(jump);  JUMPHERE(jump);
3388  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3389  /* End of dropping frames. */  /* End of dropping frames. */
3390  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3391    
3392  JUMPHERE(jump);  JUMPHERE(jump);
3393  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3394  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3395  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3396  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));  
3397  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3398  }  }
3399    
# Line 3033  static void check_wordboundary(compiler_ Line 3401  static void check_wordboundary(compiler_
3401  {  {
3402  DEFINE_COMPILER;  DEFINE_COMPILER;
3403  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3404    jump_list *skipread_list = NULL;
3405  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3406  struct sljit_jump *jump;  struct sljit_jump *jump;
3407  #endif  #endif
# Line 3058  if (common->use_ucp) Line 3427  if (common->use_ucp)
3427    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3428    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3429    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);
3430    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3431    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);
3432    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);
3433    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3434    JUMPHERE(jump);    JUMPHERE(jump);
3435    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3436    }    }
# Line 3090  else Line 3459  else
3459  JUMPHERE(skipread);  JUMPHERE(skipread);
3460    
3461  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3462  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3463  peek_char(common);  peek_char(common);
3464    
3465  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3102  if (common->use_ucp) Line 3471  if (common->use_ucp)
3471    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3472    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3473    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);
3474    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3475    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);
3476    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);
3477    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3478    JUMPHERE(jump);    JUMPHERE(jump);
3479    }    }
3480  else  else
# Line 3131  else Line 3500  else
3500      JUMPHERE(jump);      JUMPHERE(jump);
3501  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3502    }    }
3503  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3504    
3505  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3506  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
# Line 3186  switch(ranges[0]) Line 3555  switch(ranges[0])
3555        }        }
3556      return TRUE;      return TRUE;
3557      }      }
3558    if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && ispowerof2(ranges[4] - ranges[2]))    if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))
3559      {      {
3560      if (readch)      if (readch)
3561        read_char(common);        read_char(common);
# Line 3285  sljit_emit_fast_enter(compiler, RETURN_A Line 3654  sljit_emit_fast_enter(compiler, RETURN_A
3654    
3655  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3656  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);
3657  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3658  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);
3659  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3660  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3661  if (common->utf)  if (common->utf)
3662    {    {
3663  #endif  #endif
3664    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3665    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3666    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);
3667  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3668    }    }
3669  #endif  #endif
3670  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3671  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);
3672  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3673  }  }
3674    
# Line 3311  DEFINE_COMPILER; Line 3680  DEFINE_COMPILER;
3680  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3681    
3682  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);
3683  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3684  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);
3685  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3686  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);
3687  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3688  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3689  if (common->utf)  if (common->utf)
3690    {    {
3691  #endif  #endif
3692    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3693    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);
3694    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3695    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);
3696    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3697    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3698    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);
3699    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3700    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);
3701    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3702    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);
3703    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3704    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);
3705  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3706    }    }
3707  #endif  #endif
3708  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3709  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);
3710    
3711  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3712  }  }
# Line 3351  sljit_emit_fast_enter(compiler, RETURN_A Line 3720  sljit_emit_fast_enter(compiler, RETURN_A
3720    
3721  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3722  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);
3723  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3724  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);
3725  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3726  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3727  if (common->utf)  if (common->utf)
3728    {    {
3729  #endif  #endif
3730    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);
3731    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3732    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);
3733  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3734    }    }
3735  #endif  #endif
3736  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3737  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);
3738    
3739  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3740  }  }
# Line 3451  sljit_emit_fast_return(compiler, RETURN_ Line 3820  sljit_emit_fast_return(compiler, RETURN_
3820    
3821  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3822    
3823  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)
3824  {  {
3825  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3826  int c1, c2;  pcre_uint32 c1, c2;
3827  const pcre_uchar *src2 = args->uchar_ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3828  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
3829    const ucd_record *ur;
3830    const pcre_uint32 *pp;
3831    
3832  while (src1 < end1)  while (src1 < end1)
3833    {    {
# Line 3464  while (src1 < end1) Line 3835  while (src1 < end1)
3835      return (pcre_uchar*)1;      return (pcre_uchar*)1;
3836    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3837    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3838    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return NULL;    ur = GET_UCD(c2);
3839      if (c1 != c2 && c1 != c2 + ur->other_case)
3840        {
3841        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3842        for (;;)
3843          {
3844          if (c1 < *pp) return NULL;
3845          if (c1 == *pp++) break;
3846          }
3847        }
3848    }    }
3849  return src2;  return src2;
3850  }  }
# Line 3486  if (caseless && char_has_othercase(commo Line 3866  if (caseless && char_has_othercase(commo
3866    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3867    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3868    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3869  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3870    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3871    othercasebit &= 0xff;    othercasebit &= 0xff;
3872  #else  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3873  #ifdef COMPILE_PCRE16    /* Note that this code only handles characters in the BMP. If there
3874      ever are characters outside the BMP whose othercase differs in only one
3875      bit from itself (there currently are none), this code will need to be
3876      revised for COMPILE_PCRE32. */
3877    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3878    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3879      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
3880    else    else
3881      othercasebit &= 0xff;      othercasebit &= 0xff;
3882  #endif  #endif /* COMPILE_PCRE[8|16|32] */
 #endif  
3883    }    }
3884    
3885  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3886    {    {
3887  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3888  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3889    if (context->length >= 4)    if (context->length >= 4)
3890      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 3511  if (context->sourcereg == -1) Line 3893  if (context->sourcereg == -1)
3893    else    else
3894  #endif  #endif
3895      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3896  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
3897  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3898    if (context->length >= 4)    if (context->length >= 4)
3899      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3900    else    else
3901  #endif  #endif
3902      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3903  #endif  #elif defined COMPILE_PCRE32
3904  #endif /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3905    #endif /* COMPILE_PCRE[8|16|32] */
3906    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3907    }    }
3908    
# Line 3534  do Line 3916  do
3916  #endif  #endif
3917    
3918    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3919  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3920    
3921    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3922    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3549  do Line 3931  do
3931      }      }
3932    context->ucharptr++;    context->ucharptr++;
3933    
3934  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3935    if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))    if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))
3936  #else  #else
3937    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
# Line 3557  do Line 3939  do
3939      {      {
3940      if (context->length >= 4)      if (context->length >= 4)
3941        OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
 #ifdef COMPILE_PCRE8  
3942      else if (context->length >= 2)      else if (context->length >= 2)
3943        OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3944    #if defined COMPILE_PCRE8
3945      else if (context->length >= 1)      else if (context->length >= 1)
3946        OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3947  #else  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3948      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3949    
3950      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3599  do Line 3978  do
3978    
3979  #else  #else
3980    
3981    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3982  #ifdef COMPILE_PCRE8    if (context->length >= 1)
3983    if (context->length > 0)      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3984      OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #else  
   if (context->length > 0)  
     OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3985    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3986    
3987    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3651  return cc; Line 4026  return cc;
4026      } \      } \
4027    charoffset = (value);    charoffset = (value);
4028    
4029  static void compile_xclass_trypath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)  static void compile_xclass_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)
4030  {  {
4031  DEFINE_COMPILER;  DEFINE_COMPILER;
4032  jump_list *found = NULL;  jump_list *found = NULL;
4033  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;
4034  unsigned int c;  pcre_int32 c, charoffset;
4035  int compares;  const pcre_uint32 *other_cases;
4036  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4037  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4038    int compares, invertcmp, numberofcmps;
4039  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4040  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4041  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4042  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4043  unsigned int typeoffset;  pcre_int32 typeoffset;
4044  #endif  #endif
 int invertcmp, numberofcmps;  
 unsigned int charoffset;  
4045    
4046  /* Although SUPPORT_UTF must be defined, we are  /* Although SUPPORT_UTF must be defined, we are
4047     not necessary in utf mode even in 8 bit mode. */     not necessary in utf mode even in 8 bit mode. */
# Line 3688  if ((*cc++ & XCL_MAP) != 0) Line 4062  if ((*cc++ & XCL_MAP) != 0)
4062      {      {
4063      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4064      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4065      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4066      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4067      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);
4068      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
# Line 3765  while (*cc != XCL_END) Line 4139  while (*cc != XCL_END)
4139        needschar = TRUE;        needschar = TRUE;
4140        break;        break;
4141    
4142          case PT_CLIST:
4143          case PT_UCNC:
4144          needschar = TRUE;
4145          break;
4146    
4147        default:        default:
4148        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
4149        break;        break;
# Line 3801  if (needstype || needsscript) Line 4180  if (needstype || needsscript)
4180      {      {
4181      if (scriptreg == TMP1)      if (scriptreg == TMP1)
4182        {        {
4183        OP1(SLJIT_MOV, scriptreg, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));        OP1(SLJIT_MOV, scriptreg, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));
4184        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
4185        }        }
4186      else      else
4187        {        {
4188        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
4189        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));
4190        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
4191        }        }
4192      }      }
# Line 3843  while (*cc != XCL_END) Line 4222  while (*cc != XCL_END)
4222      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4223        {        {
4224        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
4225        COND_VALUE(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_EQUAL);
4226        numberofcmps++;        numberofcmps++;
4227        }        }
4228      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4229        {        {
4230        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
4231        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);
4232        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4233        numberofcmps = 0;        numberofcmps = 0;
4234        }        }
# Line 3882  while (*cc != XCL_END) Line 4261  while (*cc != XCL_END)
4261      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4262        {        {
4263        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
4264        COND_VALUE(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_LESS_EQUAL);
4265        numberofcmps++;        numberofcmps++;
4266        }        }
4267      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4268        {        {
4269        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
4270        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4271        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4272        numberofcmps = 0;        numberofcmps = 0;
4273        }        }
# Line 3919  while (*cc != XCL_END) Line 4298  while (*cc != XCL_END)
4298    
4299        case PT_LAMP:        case PT_LAMP:
4300        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - typeoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - typeoffset);
4301        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4302        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ll - typeoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ll - typeoffset);
4303        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4304        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lt - typeoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lt - typeoffset);
4305        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);
4306        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4307        break;        break;
4308    
# Line 3950  while (*cc != XCL_END) Line 4329  while (*cc != XCL_END)
4329          }          }
4330        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4331        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 13 - 9);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 13 - 9);
4332        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4333        if (*cc == PT_SPACE)        if (*cc == PT_SPACE)
4334          JUMPHERE(jump);          JUMPHERE(jump);
4335    
4336        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4337        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);
4338        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4339        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4340        break;        break;
4341    
4342        case PT_WORD:        case PT_WORD:
4343        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE - charoffset);
4344        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4345        /* ... fall through */        /* Fall through. */
4346    
4347        case PT_ALNUM:        case PT_ALNUM:
4348        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
4349        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
4350        COND_VALUE((*cc == PT_ALNUM) ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS((*cc == PT_ALNUM) ? SLJIT_MOV : SLJIT_OR, TMP2, 0, (*cc == PT_ALNUM) ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_LESS_EQUAL);
4351        SET_TYPE_OFFSET(ucp_Nd);        SET_TYPE_OFFSET(ucp_Nd);
4352        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_No - ucp_Nd);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_No - ucp_Nd);
4353        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4354          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4355          break;
4356    
4357          case PT_CLIST:
4358          other_cases = PRIV(ucd_caseless_sets) + cc[1];
4359    
4360          /* At least three characters are required.
4361             Otherwise this case would be handled by the normal code path. */
4362          SLJIT_ASSERT(other_cases[0] != NOTACHAR && other_cases[1] != NOTACHAR && other_cases[2] != NOTACHAR);
4363          SLJIT_ASSERT(other_cases[0] < other_cases[1] && other_cases[1] < other_cases[2]);
4364    
4365          /* Optimizing character pairs, if their difference is power of 2. */
4366          if (is_powerof2(other_cases[1] ^ other_cases[0]))
4367            {
4368            if (charoffset == 0)
4369              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4370            else
4371              {
4372              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4373              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4374              }
4375            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[1]);
4376            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4377            other_cases += 2;
4378            }
4379          else if (is_powerof2(other_cases[2] ^ other_cases[1]))
4380            {
4381            if (charoffset == 0)
4382              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[2] ^ other_cases[1]);
4383            else
4384              {
4385              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4386              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4387              }
4388            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[2]);
4389            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4390    
4391            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, other_cases[0] - charoffset);
4392            OP_FLAGS(SLJIT_OR | ((other_cases[3] == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4393    
4394            other_cases += 3;
4395            }
4396          else
4397            {
4398            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4399            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4400            }
4401    
4402          while (*other_cases != NOTACHAR)
4403            {
4404            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4405            OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4406            }
4407          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4408          break;
4409    
4410          case PT_UCNC:
4411          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);
4412          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4413          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);
4414          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4415          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);
4416          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4417    
4418          SET_CHAR_OFFSET(0xa0);
4419          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);
4420          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4421          SET_CHAR_OFFSET(0);
4422          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4423          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4424        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4425        break;        break;
4426        }        }
# Line 3992  if (found != NULL) Line 4441  if (found != NULL)
4441    
4442  #endif  #endif
4443    
4444  static pcre_uchar *compile_char1_trypath(compiler_common *common, pcre_uchar type, pcre_uchar *cc, jump_list **backtracks)  static pcre_uchar *compile_char1_matchingpath(compiler_common *common, pcre_uchar type, pcre_uchar *cc, jump_list **backtracks)
4445  {  {
4446  DEFINE_COMPILER;  DEFINE_COMPILER;
4447  int length;  int length;
4448  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4449  compare_context context;  compare_context context;
4450  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4451    jump_list *end_list;
4452  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4453  struct sljit_label *label;  struct sljit_label *label;
4454  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4067  switch(type) Line 4517  switch(type)
4517    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4518      {      {
4519      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
4520        end_list = NULL;
4521      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4522        jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);        add_jump(compiler, &end_list, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
4523      else      else
4524        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
4525    
4526      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4527      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));
4528      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
4529      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4530      }      }
4531    else    else
# Line 4089  switch(type) Line 4539  switch(type)
4539      {      {
4540      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4541      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));
4542  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
4543    #if defined COMPILE_PCRE8
4544      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4545      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);
4546      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4547  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
4548      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
4549      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4550      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);
4551      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4552      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4553      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4554  #endif /* COMPILE_PCRE16 */  #endif
 #endif /* COMPILE_PCRE8 */  
4555      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4556    #endif /* COMPILE_PCRE[8|16] */
4557      return cc;      return cc;
4558      }      }
4559  #endif  #endif
# Line 4124  switch(type) Line 4574  switch(type)
4574    propdata[2] = cc[0];    propdata[2] = cc[0];
4575    propdata[3] = cc[1];    propdata[3] = cc[1];
4576    propdata[4] = XCL_END;    propdata[4] = XCL_END;
4577    compile_xclass_trypath(common, propdata, backtracks);    compile_xclass_matchingpath(common, propdata, backtracks);
4578    return cc + 2;    return cc + 2;
4579  #endif  #endif
4580  #endif  #endif
# Line 4134  switch(type) Line 4584  switch(type)
4584    read_char(common);    read_char(common);
4585    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
4586    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
4587      end_list = NULL;
4588    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4589      jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      add_jump(compiler, &end_list, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
4590    else    else
4591      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
4592    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4593    jump[2] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);    jump[1] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);
4594    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));
4595    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
4596    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4597    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
4598      set_jumps(end_list, LABEL());
4599    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4600    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
4601    return cc;    return cc;
4602    
4603    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
# Line 4170  switch(type) Line 4621  switch(type)
4621    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4622    read_char(common);    read_char(common);
4623    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4624    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Mc);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));
4625    add_jump(compiler, backtracks, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, ucp_Mn - ucp_Mc));    /* Optimize register allocation: use a real register. */
4626      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4627      OP1(SLJIT_MOV_UB, STACK_TOP, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4628    
4629    label = LABEL();    label = LABEL();
4630    jump[0] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    jump[0] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
4631    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
4632    read_char(common);    read_char(common);
4633    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4634    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Mc);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));
4635    CMPTO(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, ucp_Mn - ucp_Mc, label);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4636    
4637      OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);
4638      OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STACK_TOP), (sljit_sw)PRIV(ucp_gbtable));
4639      OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);
4640      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4641      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4642      JUMPTO(SLJIT_C_NOT_ZERO, label);
4643    
4644    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
4645    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4646      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
4647    
4648    if (common->mode == JIT_PARTIAL_HARD_COMPILE)    if (common->mode == JIT_PARTIAL_HARD_COMPILE)
4649      {      {
4650      jump[0] = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);      jump[0] = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
# Line 4206  switch(type) Line 4668  switch(type)
4668        {        {
4669        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);
4670        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP2, 0, STR_END, 0);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP2, 0, STR_END, 0);
4671        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS);
4672        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
4673        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_NOT_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_NOT_EQUAL);
4674        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));
4675        check_partial(common, TRUE);        check_partial(common, TRUE);
4676        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
# Line 4308  switch(type) Line 4770  switch(type)
4770    add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
4771    
4772    if (!common->endonly)    if (!common->endonly)
4773      compile_char1_trypath(common, OP_EODN, cc, backtracks);      compile_char1_matchingpath(common, OP_EODN, cc, backtracks);
4774    else    else
4775      {      {
4776      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0));      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0));
# Line 4388  switch(type) Line 4850  switch(type)
4850      }      }
4851    oc = char_othercase(common, c);    oc = char_othercase(common, c);
4852    bit = c ^ oc;    bit = c ^ oc;
4853    if (ispowerof2(bit))    if (is_powerof2(bit))
4854      {      {
4855      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4856      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));
4857      return cc + length;      return cc + length;
4858      }      }
4859    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c);
4860    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4861    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, char_othercase(common, c));    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);
4862    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);
4863    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4864    return cc + length;    return cc + length;
4865    
# Line 4424  switch(type) Line 4886  switch(type)
4886        /* Skip the variable-length character. */        /* Skip the variable-length character. */
4887        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));
4888        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4889        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
4890        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4891        JUMPHERE(jump[0]);        JUMPHERE(jump[0]);
4892        return cc + 1;        return cc + 1;
# Line 4449  switch(type) Line 4911  switch(type)
4911      {      {
4912      oc = char_othercase(common, c);      oc = char_othercase(common, c);
4913      bit = c ^ oc;      bit = c ^ oc;
4914      if (ispowerof2(bit))      if (is_powerof2(bit))
4915        {        {
4916        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4917        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));
# Line 4487  switch(type) Line 4949  switch(type)
4949  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4950    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4951    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4952    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4953    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4954    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);
4955    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 4497  switch(type) Line 4959  switch(type)
4959  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4960    return cc + 32 / sizeof(pcre_uchar);    return cc + 32 / sizeof(pcre_uchar);
4961    
4962  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4963    case OP_XCLASS:    case OP_XCLASS:
4964    compile_xclass_trypath(common, cc + LINK_SIZE, backtracks);    compile_xclass_matchingpath(common, cc + LINK_SIZE, backtracks);
4965    return cc + GET(cc, 0) - 1;    return cc + GET(cc, 0) - 1;
4966  #endif  #endif
4967    
# Line 4533  SLJIT_ASSERT_STOP(); Line 4995  SLJIT_ASSERT_STOP();
4995  return cc;  return cc;
4996  }  }
4997    
4998  static SLJIT_INLINE pcre_uchar *compile_charn_trypath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, jump_list **backtracks)  static SLJIT_INLINE pcre_uchar *compile_charn_matchingpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, jump_list **backtracks)
4999  {  {
5000  /* This function consumes at least one input character. */  /* This function consumes at least one input character. */
5001  /* To decrease the number of length checks, we try to concatenate the fixed length character sequences. */  /* To decrease the number of length checks, we try to concatenate the fixed length character sequences. */
# Line 4596  if (context.length > 0) Line 5058  if (context.length > 0)
5058    }    }
5059    
5060  /* A non-fixed length character will be checked if length == 0. */  /* A non-fixed length character will be checked if length == 0. */
5061  return compile_char1_trypath(common, *cc, cc + 1, backtracks);  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
5062  }  }
5063    
5064  static struct sljit_jump *compile_ref_checks(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)  static struct sljit_jump *compile_ref_checks(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)
# Line 4611  if (!common->jscript_compat) Line 5073  if (!common->jscript_compat)
5073      {      {
5074      /* OVECTOR(1) contains the "string begin - 1" constant. */      /* OVECTOR(1) contains the "string begin - 1" constant. */
5075      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5076      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
5077      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5078      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);
5079      return JUMP(SLJIT_C_NOT_ZERO);      return JUMP(SLJIT_C_NOT_ZERO);
5080      }      }
5081    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
# Line 4622  return CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT Line 5084  return CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT
5084  }  }
5085    
5086  /* Forward definitions. */  /* Forward definitions. */
5087  static void compile_trypath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
5088  static void compile_backtrackpath(compiler_common *, struct backtrack_common *);  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);