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

Diff of /code/trunk/pcre_jit_compile.c

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

revision 941 by zherczeg, Tue Feb 28 11:33:34 2012 UTC revision 1275 by zherczeg, Sun Mar 10 05:32:10 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11    The machine code generator part (this module) was written by Zoltan Herczeg    The machine code generator part (this module) was written by Zoltan Herczeg
12                        Copyright (c) 2010-2012                        Copyright (c) 2010-2013
13    
14  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
15  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 46  POSSIBILITY OF SUCH DAMAGE. Line 46  POSSIBILITY OF SUCH DAMAGE.
46    
47  #include "pcre_internal.h"  #include "pcre_internal.h"
48    
49  #ifdef SUPPORT_JIT  #if defined SUPPORT_JIT
50    
51  /* All-in-one: Since we use the JIT compiler only from here,  /* All-in-one: Since we use the JIT compiler only from here,
52  we just include it. This way we don't need to touch the build  we just include it. This way we don't need to touch the build
# Line 65  system files. */ Line 65  system files. */
65  #error Unsupported architecture  #error Unsupported architecture
66  #endif  #endif
67    
68  /* Allocate memory on the stack. Fast, but limited size. */  /* Defines for debugging purposes. */
 #define LOCAL_SPACE_SIZE 32768  
69    
70    /* 1 - Use unoptimized capturing brackets.
71       2 - Enable capture_last_ptr (includes option 1). */
72    /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */
73    
74    /* 1 - Always have a control head. */
75    /* #define DEBUG_FORCE_CONTROL_HEAD 1 */
76    
77    /* Allocate memory for the regex stack on the real machine stack.
78    Fast, but limited size. */
79    #define MACHINE_STACK_SIZE 32768
80    
81    /* Growth rate for stack allocated by the OS. Should be the multiply
82    of page size. */
83  #define STACK_GROWTH_RATE 8192  #define STACK_GROWTH_RATE 8192
84    
85  /* Enable to check that the allocation could destroy temporaries. */  /* Enable to check that the allocation could destroy temporaries. */
# Line 82  The code generator follows the recursive Line 94  The code generator follows the recursive
94  expressions. The basic blocks of regular expressions are condition checkers  expressions. The basic blocks of regular expressions are condition checkers
95  whose execute different commands depending on the result of the condition check.  whose execute different commands depending on the result of the condition check.
96  The relationship between the operators can be horizontal (concatenation) and  The relationship between the operators can be horizontal (concatenation) and
97  vertical (sub-expression) (See struct fallback_common for more details).  vertical (sub-expression) (See struct backtrack_common for more details).
98    
99    'ab' - 'a' and 'b' regexps are concatenated    'ab' - 'a' and 'b' regexps are concatenated
100    'a+' - 'a' is the sub-expression of the '+' operator    'a+' - 'a' is the sub-expression of the '+' operator
101    
102  The condition checkers are boolean (true/false) checkers. Machine code is generated  The condition checkers are boolean (true/false) checkers. Machine code is generated
103  for the checker itself and for the actions depending on the result of the checker.  for the checker itself and for the actions depending on the result of the checker.
104  The 'true' case is called as the hot path (expected path), and the other is called as  The 'true' case is called as the matching path (expected path), and the other is called as
105  the 'fallback' path. Branch instructions are expesive for all CPUs, so we avoid taken  the 'backtrack' path. Branch instructions are expesive for all CPUs, so we avoid taken
106  branches on the hot path.  branches on the matching path.
107    
108   Greedy star operator (*) :   Greedy star operator (*) :
109     Hot path: match happens.     Matching path: match happens.
110     Fallback path: match failed.     Backtrack path: match failed.
111   Non-greedy star operator (*?) :   Non-greedy star operator (*?) :
112     Hot path: no need to perform a match.     Matching path: no need to perform a match.
113     Fallback path: match is required.     Backtrack path: match is required.
114    
115  The following example shows how the code generated for a capturing bracket  The following example shows how the code generated for a capturing bracket
116  with two alternatives. Let A, B, C, D are arbirary regular expressions, and  with two alternatives. Let A, B, C, D are arbirary regular expressions, and
# Line 108  we have the following regular expression Line 120  we have the following regular expression
120    
121  The generated code will be the following:  The generated code will be the following:
122    
123   A hot path   A matching path
124   '(' hot path (pushing arguments to the stack)   '(' matching path (pushing arguments to the stack)
125   B hot path   B matching path
126   ')' hot path (pushing arguments to the stack)   ')' matching path (pushing arguments to the stack)
127   D hot path   D matching path
128   return with successful match   return with successful match
129    
130   D fallback path   D backtrack path
131   ')' fallback path (If we arrived from "C" jump to the fallback of "C")   ')' backtrack path (If we arrived from "C" jump to the backtrack of "C")
132   B fallback path   B backtrack path
133   C expected path   C expected path
134   jump to D hot path   jump to D matching path
135   C fallback path   C backtrack path
136   A fallback path   A backtrack path
137    
138   Notice, that the order of fallback code paths are the opposite of the fast   Notice, that the order of backtrack code paths are the opposite of the fast
139   code paths. In this way the topmost value on the stack is always belong   code paths. In this way the topmost value on the stack is always belong
140   to the current fallback code path. The fallback code path must check   to the current backtrack code path. The backtrack path must check
141   whether there is a next alternative. If so, it needs to jump back to   whether there is a next alternative. If so, it needs to jump back to
142   the hot path eventually. Otherwise it needs to clear out its own stack   the matching path eventually. Otherwise it needs to clear out its own stack
143   frame and continue the execution on the fallback code paths.   frame and continue the execution on the backtrack code paths.
144  */  */
145    
146  /*  /*
147  Saved stack frames:  Saved stack frames:
148    
149  Atomic blocks and asserts require reloading the values of local variables  Atomic blocks and asserts require reloading the values of private data
150  when the fallback mechanism performed. Because of OP_RECURSE, the locals  when the backtrack mechanism performed. Because of OP_RECURSE, the data
151  are not necessarly known in compile time, thus we need a dynamic restore  are not necessarly known in compile time, thus we need a dynamic restore
152  mechanism.  mechanism.
153    
154  The stack frames are stored in a chain list, and have the following format:  The stack frames are stored in a chain list, and have the following format:
155  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]
156    
157  Thus we can restore the locals to a particular point in the stack.  Thus we can restore the private data to a particular point in the stack.
158  */  */
159    
160  typedef struct jit_arguments {  typedef struct jit_arguments {
# Line 154  typedef struct jit_arguments { Line 166  typedef struct jit_arguments {
166    int *offsets;    int *offsets;
167    pcre_uchar *uchar_ptr;    pcre_uchar *uchar_ptr;
168    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
169      void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171    int offsetcount;    int real_offset_count;
172    int calllimit;    int offset_count;
173      int call_limit;
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 167  typedef struct executable_functions { Line 181  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184      pcre_uint32 top_bracket;
185    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
186  } executable_functions;  } executable_functions;
187    
# Line 175  typedef struct jump_list { Line 190  typedef struct jump_list {
190    struct jump_list *next;    struct jump_list *next;
191  } jump_list;  } jump_list;
192    
 enum stub_types { stack_alloc };  
   
193  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
194    struct sljit_jump *start;    struct sljit_jump *start;
195    struct sljit_label *leave;    struct sljit_label *quit;
196    struct stub_list *next;    struct stub_list *next;
197  } stub_list;  } stub_list;
198    
199    enum frame_types {
200      no_frame = -1,
201      no_stack = -2
202    };
203    
204    enum control_types {
205      type_commit = 0,
206      type_prune = 1,
207      type_skip = 2
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
213  code generator. It is allocated by compile_hotpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_fallbackpath. Must be the first member  the aguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct fallback_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
218    struct fallback_common *prev;    struct backtrack_common *prev;
219    jump_list *nextfallbacks;    jump_list *nextbacktracks;
220    /* Internal stack (for component operators). */    /* Internal stack (for component operators). */
221    struct fallback_common *top;    struct backtrack_common *top;
222    jump_list *topfallbacks;    jump_list *topbacktracks;
223    /* Opcode pointer. */    /* Opcode pointer. */
224    pcre_uchar *cc;    pcre_uchar *cc;
225  } fallback_common;  } backtrack_common;
226    
227  typedef struct assert_fallback {  typedef struct assert_backtrack {
228    fallback_common common;    backtrack_common common;
229    jump_list *condfailed;    jump_list *condfailed;
230    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 (-1) if a frame is not needed. */
231    int framesize;    int framesize;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int localptr;    int private_data_ptr;
234    /* For iterators. */    /* For iterators. */
235    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
236  } assert_fallback;  } assert_backtrack;
237    
238  typedef struct bracket_fallback {  typedef struct bracket_backtrack {
239    fallback_common common;    backtrack_common common;
240    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
241    struct sljit_label *althotpath;    struct sljit_label *alternative_matchingpath;
242    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
243    struct sljit_label *recursivehotpath;    struct sljit_label *recursive_matchingpath;
244    /* For greedy ? operator. */    /* For greedy ? operator. */
245    struct sljit_label *zerohotpath;    struct sljit_label *zero_matchingpath;
246    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
247    union {    union {
248      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
249      jump_list *condfailed;      jump_list *condfailed;
250      assert_fallback *assert;      assert_backtrack *assert;
251      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. -1 if not needed. */
252      int framesize;      int framesize;
253    } u;    } u;
254    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
255    int localptr;    int private_data_ptr;
256  } bracket_fallback;  } bracket_backtrack;
257    
258  typedef struct bracketpos_fallback {  typedef struct bracketpos_backtrack {
259    fallback_common common;    backtrack_common common;
260    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
261    int localptr;    int private_data_ptr;
262    /* Reverting stack is needed. */    /* Reverting stack is needed. */
263    int framesize;    int framesize;
264    /* Allocated stack size. */    /* Allocated stack size. */
265    int stacksize;    int stacksize;
266  } bracketpos_fallback;  } bracketpos_backtrack;
267    
268  typedef struct braminzero_fallback {  typedef struct braminzero_backtrack {
269    fallback_common common;    backtrack_common common;
270    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
271  } braminzero_fallback;  } braminzero_backtrack;
272    
273  typedef struct iterator_fallback {  typedef struct iterator_backtrack {
274    fallback_common common;    backtrack_common common;
275    /* Next iteration. */    /* Next iteration. */
276    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
277  } iterator_fallback;  } iterator_backtrack;
278    
279  typedef struct recurse_entry {  typedef struct recurse_entry {
280    struct recurse_entry *next;    struct recurse_entry *next;
# Line 264  typedef struct recurse_entry { Line 286  typedef struct recurse_entry {
286    int start;    int start;
287  } recurse_entry;  } recurse_entry;
288    
289  typedef struct recurse_fallback {  typedef struct recurse_backtrack {
290    fallback_common common;    backtrack_common common;
291  } recurse_fallback;    BOOL inlined_pattern;
292    } recurse_backtrack;
293    
294    #define MAX_RANGE_SIZE 6
295    
296  typedef struct compiler_common {  typedef struct compiler_common {
297      /* The sljit ceneric compiler. */
298    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
299      /* First byte code. */
300    pcre_uchar *start;    pcre_uchar *start;
301      /* Maps private data offset to each opcode. */
302    /* Local stack area size and variable pointers. */    int *private_data_ptrs;
303    int localsize;    /* Tells whether the capturing bracket is optimized. */
304    int *localptrs;    pcre_uint8 *optimized_cbracket;
305    int cbraptr;    /* Starting offset of private data for capturing brackets. */
306    /* OVector starting point. Must be divisible by 2. */    int cbra_ptr;
307      /* Output vector starting point. Must be divisible by 2. */
308    int ovector_start;    int ovector_start;
309    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
310    int req_char_ptr;    int req_char_ptr;
311    /* Head of the last recursion. */    /* Head of the last recursion. */
312    int recursive_head;    int recursive_head_ptr;
313    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
314    int start_used_ptr;    int start_used_ptr;
315    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 290  typedef struct compiler_common { Line 318  typedef struct compiler_common {
318    int first_line_end;    int first_line_end;
319    /* Points to the marked string. */    /* Points to the marked string. */
320    int mark_ptr;    int mark_ptr;
321      /* Recursive control verb management chain. */
322      int control_head_ptr;
323      /* Points to the last matched capture block index. */
324      int capture_last_ptr;
325      /* Points to the starting position of the current match. */
326      int start_ptr;
327    
328    /* Other  */    /* Flipped and lower case tables. */
329    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
330    sljit_w lcc;    sljit_sw lcc;
331      /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
332    int mode;    int mode;
333      /* \K is in the pattern. */
334      BOOL has_set_som;
335      /* Needs to know the start position anytime. */
336      BOOL needs_start_ptr;
337      /* Currently in recurse or assert. */
338      BOOL local_exit;
339      /* Newline control. */
340    int nltype;    int nltype;
341    int newline;    int newline;
342    int bsr_nltype;    int bsr_nltype;
343      /* Dollar endonly. */
344    int endonly;    int endonly;
345    BOOL has_set_som;    /* Tables. */
346    sljit_w ctypes;    sljit_sw ctypes;
347      int digits[2 + MAX_RANGE_SIZE];
348      /* Named capturing brackets. */
349    sljit_uw name_table;    sljit_uw name_table;
350    sljit_w name_count;    sljit_sw name_count;
351    sljit_w name_entry_size;    sljit_sw name_entry_size;
352    
353    /* Labels and jump lists. */    /* Labels and jump lists. */
354    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
355    struct sljit_label *leavelabel;    struct sljit_label *quit_label;
356    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
357      struct sljit_label *accept_label;
358    stub_list *stubs;    stub_list *stubs;
359    recurse_entry *entries;    recurse_entry *entries;
360    recurse_entry *currententry;    recurse_entry *currententry;
361    jump_list *partialmatch;    jump_list *partialmatch;
362    jump_list *leave;    jump_list *quit;
363      jump_list *forced_quit;
364    jump_list *accept;    jump_list *accept;
365    jump_list *calllimit;    jump_list *calllimit;
366    jump_list *stackalloc;    jump_list *stackalloc;
# Line 324  typedef struct compiler_common { Line 371  typedef struct compiler_common {
371    jump_list *vspace;    jump_list *vspace;
372    jump_list *casefulcmp;    jump_list *casefulcmp;
373    jump_list *caselesscmp;    jump_list *caselesscmp;
374      jump_list *reset_match;
375    BOOL jscript_compat;    BOOL jscript_compat;
376  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
377    BOOL utf;    BOOL utf;
378  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
379    BOOL use_ucp;    BOOL use_ucp;
380  #endif  #endif
381    #ifndef COMPILE_PCRE32
382    jump_list *utfreadchar;    jump_list *utfreadchar;
383    #endif
384  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
385    jump_list *utfreadtype8;    jump_list *utfreadtype8;
386  #endif  #endif
# Line 348  typedef struct compare_context { Line 398  typedef struct compare_context {
398  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
399    int ucharptr;    int ucharptr;
400    union {    union {
401      sljit_i asint;      sljit_si asint;
402      sljit_uh asushort;      sljit_uh asushort;
403  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
404      sljit_ub asbyte;      sljit_ub asbyte;
405      sljit_ub asuchars[4];      sljit_ub asuchars[4];
406  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
407      sljit_uh asuchars[2];      sljit_uh asuchars[2];
408  #endif  #elif defined COMPILE_PCRE32
409        sljit_ui asuchars[1];
410  #endif  #endif
411    } c;    } c;
412    union {    union {
413      sljit_i asint;      sljit_si asint;
414      sljit_uh asushort;      sljit_uh asushort;
415  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
416      sljit_ub asbyte;      sljit_ub asbyte;
417      sljit_ub asuchars[4];      sljit_ub asuchars[4];
418  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
419      sljit_uh asuchars[2];      sljit_uh asuchars[2];
420  #endif  #elif defined COMPILE_PCRE32
421        sljit_ui asuchars[1];
422  #endif  #endif
423    } oc;    } oc;
424  #endif  #endif
425  } compare_context;  } compare_context;
426    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
427  /* Undefine sljit macros. */  /* Undefine sljit macros. */
428  #undef CMP  #undef CMP
429    
430  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
431  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
432    
433  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
434  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
435  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
436  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
437  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
438  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
439  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
440  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
441  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
442  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
443    
444  /* Locals layout. */  /* Local space layout. */
445  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
446  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
447  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
448  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
449  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
450  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
451  /* Max limit of recursions. */  /* Max limit of recursions. */
452  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
453  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
454  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
455  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
456  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. */
457  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
458  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
459  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))
460  #define PRIV_DATA(cc)    (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
461    
462  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
463  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
464  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
465  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
466  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
467  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
468    #elif defined COMPILE_PCRE32
469    #define MOV_UCHAR  SLJIT_MOV_UI
470    #define MOVU_UCHAR SLJIT_MOVU_UI
471  #else  #else
472  #error Unsupported compiling mode  #error Unsupported compiling mode
473  #endif  #endif
 #endif  
474    
475  /* Shortcuts. */  /* Shortcuts. */
476  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 442  the start pointers when the end of the c Line 487  the start pointers when the end of the c
487    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
488  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
489    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
490    #define SET_LABEL(jump, label) \
491      sljit_set_label((jump), (label))
492  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
493    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
494  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
495    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))
496  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
497    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
498    #define GET_LOCAL_BASE(dst, dstw, offset) \
499      sljit_get_local_base(compiler, (dst), (dstw), (offset))
500    
501  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
502  {  {
# Line 460  return cc; Line 509  return cc;
509    
510  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
511   next_opcode   next_opcode
512   get_localspace   get_private_data_length
513   set_localptrs   set_private_data_ptrs
514   get_framesize   get_framesize
515   init_frame   init_frame
516   get_localsize   get_private_data_length_for_copy
517   copy_locals   copy_private_data
518   compile_hotpath   compile_matchingpath
519   compile_fallbackpath   compile_backtrackingpath
520  */  */
521    
522  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
# Line 488  switch(*cc) Line 537  switch(*cc)
537    case OP_WORDCHAR:    case OP_WORDCHAR:
538    case OP_ANY:    case OP_ANY:
539    case OP_ALLANY:    case OP_ALLANY:
540      case OP_NOTPROP:
541      case OP_PROP:
542    case OP_ANYNL:    case OP_ANYNL:
543    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
544    case OP_HSPACE:    case OP_HSPACE:
# Line 500  switch(*cc) Line 551  switch(*cc)
551    case OP_CIRCM:    case OP_CIRCM:
552    case OP_DOLL:    case OP_DOLL:
553    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:  
554    case OP_CRSTAR:    case OP_CRSTAR:
555    case OP_CRMINSTAR:    case OP_CRMINSTAR:
556    case OP_CRPLUS:    case OP_CRPLUS:
557    case OP_CRMINPLUS:    case OP_CRMINPLUS:
558    case OP_CRQUERY:    case OP_CRQUERY:
559    case OP_CRMINQUERY:    case OP_CRMINQUERY:
560      case OP_CRRANGE:
561      case OP_CRMINRANGE:
562      case OP_CLASS:
563      case OP_NCLASS:
564      case OP_REF:
565      case OP_REFI:
566      case OP_RECURSE:
567      case OP_CALLOUT:
568      case OP_ALT:
569      case OP_KET:
570      case OP_KETRMAX:
571      case OP_KETRMIN:
572      case OP_KETRPOS:
573      case OP_REVERSE:
574      case OP_ASSERT:
575      case OP_ASSERT_NOT:
576      case OP_ASSERTBACK:
577      case OP_ASSERTBACK_NOT:
578      case OP_ONCE:
579      case OP_ONCE_NC:
580      case OP_BRA:
581      case OP_BRAPOS:
582      case OP_CBRA:
583      case OP_CBRAPOS:
584      case OP_COND:
585      case OP_SBRA:
586      case OP_SBRAPOS:
587      case OP_SCBRA:
588      case OP_SCBRAPOS:
589      case OP_SCOND:
590      case OP_CREF:
591      case OP_NCREF:
592      case OP_RREF:
593      case OP_NRREF:
594    case OP_DEF:    case OP_DEF:
595    case OP_BRAZERO:    case OP_BRAZERO:
596    case OP_BRAMINZERO:    case OP_BRAMINZERO:
597    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
598      case OP_PRUNE:
599      case OP_SKIP:
600    case OP_COMMIT:    case OP_COMMIT:
601    case OP_FAIL:    case OP_FAIL:
602    case OP_ACCEPT:    case OP_ACCEPT:
603    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
604      case OP_CLOSE:
605    case OP_SKIPZERO:    case OP_SKIPZERO:
606    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
607    
608    case OP_CHAR:    case OP_CHAR:
609    case OP_CHARI:    case OP_CHARI:
# Line 542  switch(*cc) Line 615  switch(*cc)
615    case OP_MINPLUS:    case OP_MINPLUS:
616    case OP_QUERY:    case OP_QUERY:
617    case OP_MINQUERY:    case OP_MINQUERY:
618      case OP_UPTO:
619      case OP_MINUPTO:
620      case OP_EXACT:
621    case OP_POSSTAR:    case OP_POSSTAR:
622    case OP_POSPLUS:    case OP_POSPLUS:
623    case OP_POSQUERY:    case OP_POSQUERY:
624      case OP_POSUPTO:
625    case OP_STARI:    case OP_STARI:
626    case OP_MINSTARI:    case OP_MINSTARI:
627    case OP_PLUSI:    case OP_PLUSI:
628    case OP_MINPLUSI:    case OP_MINPLUSI:
629    case OP_QUERYI:    case OP_QUERYI:
630    case OP_MINQUERYI:    case OP_MINQUERYI:
631      case OP_UPTOI:
632      case OP_MINUPTOI:
633      case OP_EXACTI:
634    case OP_POSSTARI:    case OP_POSSTARI:
635    case OP_POSPLUSI:    case OP_POSPLUSI:
636    case OP_POSQUERYI:    case OP_POSQUERYI:
637      case OP_POSUPTOI:
638    case OP_NOTSTAR:    case OP_NOTSTAR:
639    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
640    case OP_NOTPLUS:    case OP_NOTPLUS:
641    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
642    case OP_NOTQUERY:    case OP_NOTQUERY:
643    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
644      case OP_NOTUPTO:
645      case OP_NOTMINUPTO:
646      case OP_NOTEXACT:
647    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
648    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
649    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
650      case OP_NOTPOSUPTO:
651    case OP_NOTSTARI:    case OP_NOTSTARI:
652    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
653    case OP_NOTPLUSI:    case OP_NOTPLUSI:
654    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
655    case OP_NOTQUERYI:    case OP_NOTQUERYI:
656    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:  
657    case OP_NOTUPTOI:    case OP_NOTUPTOI:
658    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
659    case OP_NOTEXACTI:    case OP_NOTEXACTI:
660      case OP_NOTPOSSTARI:
661      case OP_NOTPOSPLUSI:
662      case OP_NOTPOSQUERYI:
663    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
664    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
665  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
666    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
667  #endif  #endif
668    return cc;    return cc;
669    
670    case OP_NOTPROP:    /* Special cases. */
671    case OP_PROP:    case OP_TYPESTAR:
672    return cc + 1 + 2;    case OP_TYPEMINSTAR:
673      case OP_TYPEPLUS:
674      case OP_TYPEMINPLUS:
675      case OP_TYPEQUERY:
676      case OP_TYPEMINQUERY:
677    case OP_TYPEUPTO:    case OP_TYPEUPTO:
678    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
679    case OP_TYPEEXACT:    case OP_TYPEEXACT:
680      case OP_TYPEPOSSTAR:
681      case OP_TYPEPOSPLUS:
682      case OP_TYPEPOSQUERY:
683    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
684    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;  
685    
686    case OP_CRRANGE:    case OP_ANYBYTE:
687    case OP_CRMINRANGE:  #ifdef SUPPORT_UTF
688    return cc + 1 + 2 * IMM2_SIZE;    if (common->utf) return NULL;
689    #endif
690    case OP_CLASS:    return cc + 1;
   case OP_NCLASS:  
   return cc + 1 + 32 / sizeof(pcre_uchar);  
691    
692  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
693    case OP_XCLASS:    case OP_XCLASS:
694    return cc + GET(cc, 1);    return cc + GET(cc, 1);
695  #endif  #endif
696    
   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;  
   
697    case OP_MARK:    case OP_MARK:
698      case OP_PRUNE_ARG:
699    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
700    
701    default:    default:
# Line 666  switch(*cc) Line 703  switch(*cc)
703    }    }
704  }  }
705    
706  static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
707        case OP_MINSTAR: \
708        case OP_MINPLUS: \
709        case OP_QUERY: \
710        case OP_MINQUERY: \
711        case OP_MINSTARI: \
712        case OP_MINPLUSI: \
713        case OP_QUERYI: \
714        case OP_MINQUERYI: \
715        case OP_NOTMINSTAR: \
716        case OP_NOTMINPLUS: \
717        case OP_NOTQUERY: \
718        case OP_NOTMINQUERY: \
719        case OP_NOTMINSTARI: \
720        case OP_NOTMINPLUSI: \
721        case OP_NOTQUERYI: \
722        case OP_NOTMINQUERYI:
723    
724    #define CASE_ITERATOR_PRIVATE_DATA_2A \
725        case OP_STAR: \
726        case OP_PLUS: \
727        case OP_STARI: \
728        case OP_PLUSI: \
729        case OP_NOTSTAR: \
730        case OP_NOTPLUS: \
731        case OP_NOTSTARI: \
732        case OP_NOTPLUSI:
733    
734    #define CASE_ITERATOR_PRIVATE_DATA_2B \
735        case OP_UPTO: \
736        case OP_MINUPTO: \
737        case OP_UPTOI: \
738        case OP_MINUPTOI: \
739        case OP_NOTUPTO: \
740        case OP_NOTMINUPTO: \
741        case OP_NOTUPTOI: \
742        case OP_NOTMINUPTOI:
743    
744    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
745        case OP_TYPEMINSTAR: \
746        case OP_TYPEMINPLUS: \
747        case OP_TYPEQUERY: \
748        case OP_TYPEMINQUERY:
749    
750    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
751        case OP_TYPESTAR: \
752        case OP_TYPEPLUS:
753    
754    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
755        case OP_TYPEUPTO: \
756        case OP_TYPEMINUPTO:
757    
758    static int get_class_iterator_size(pcre_uchar *cc)
759    {
760    switch(*cc)
761      {
762      case OP_CRSTAR:
763      case OP_CRPLUS:
764      return 2;
765    
766      case OP_CRMINSTAR:
767      case OP_CRMINPLUS:
768      case OP_CRQUERY:
769      case OP_CRMINQUERY:
770      return 1;
771    
772      case OP_CRRANGE:
773      case OP_CRMINRANGE:
774      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
775        return 0;
776      return 2;
777    
778      default:
779      return 0;
780      }
781    }
782    
783    static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
784  {  {
785  int localspace = 0;  int private_data_length = 0;
786  pcre_uchar *alternative;  pcre_uchar *alternative;
787    pcre_uchar *name;
788    pcre_uchar *end = NULL;
789    int space, size, i;
790    pcre_uint32 bracketlen;
791    
792  /* 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. */
793  while (cc < ccend)  while (cc < ccend)
794    {    {
795      space = 0;
796      size = 0;
797      bracketlen = 0;
798    switch(*cc)    switch(*cc)
799      {      {
800      case OP_SET_SOM:      case OP_SET_SOM:
# Line 680  while (cc < ccend) Line 802  while (cc < ccend)
802      cc += 1;      cc += 1;
803      break;      break;
804    
805        case OP_REF:
806        case OP_REFI:
807        common->optimized_cbracket[GET2(cc, 1)] = 0;
808        cc += 1 + IMM2_SIZE;
809        break;
810    
811      case OP_ASSERT:      case OP_ASSERT:
812      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
813      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 689  while (cc < ccend) Line 817  while (cc < ccend)
817      case OP_BRAPOS:      case OP_BRAPOS:
818      case OP_SBRA:      case OP_SBRA:
819      case OP_SBRAPOS:      case OP_SBRAPOS:
820      case OP_SCOND:      private_data_length += sizeof(sljit_sw);
821      localspace += sizeof(sljit_w);      bracketlen = 1 + LINK_SIZE;
     cc += 1 + LINK_SIZE;  
822      break;      break;
823    
824      case OP_CBRAPOS:      case OP_CBRAPOS:
825      case OP_SCBRAPOS:      case OP_SCBRAPOS:
826      localspace += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
827      cc += 1 + LINK_SIZE + IMM2_SIZE;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
828        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
829      break;      break;
830    
831      case OP_COND:      case OP_COND:
832      /* Might be a hidden SCOND. */      case OP_SCOND:
833      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
834      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
835        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
836      cc += 1 + LINK_SIZE;        return -1;
837    
838        if (*cc == OP_COND)
839          {
840          /* Might be a hidden SCOND. */
841          alternative = cc + GET(cc, 1);
842          if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
843            private_data_length += sizeof(sljit_sw);
844          }
845        else
846          private_data_length += sizeof(sljit_sw);
847        bracketlen = 1 + LINK_SIZE;
848        break;
849    
850        case OP_CREF:
851        i = GET2(cc, 1);
852        common->optimized_cbracket[i] = 0;
853        cc += 1 + IMM2_SIZE;
854      break;      break;
855    
856        case OP_NCREF:
857        bracketlen = GET2(cc, 1);
858        name = (pcre_uchar *)common->name_table;
859        alternative = name;
860        for (i = 0; i < common->name_count; i++)
861          {
862          if (GET2(name, 0) == bracketlen) break;
863          name += common->name_entry_size;
864          }
865        SLJIT_ASSERT(i != common->name_count);
866    
867        for (i = 0; i < common->name_count; i++)
868          {
869          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
870            common->optimized_cbracket[GET2(alternative, 0)] = 0;
871          alternative += common->name_entry_size;
872          }
873        bracketlen = 0;
874        cc += 1 + IMM2_SIZE;
875        break;
876    
877        case OP_BRA:
878        bracketlen = 1 + LINK_SIZE;
879        break;
880    
881        case OP_CBRA:
882        case OP_SCBRA:
883        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
884        break;
885    
886        CASE_ITERATOR_PRIVATE_DATA_1
887        space = 1;
888        size = -2;
889        break;
890    
891        CASE_ITERATOR_PRIVATE_DATA_2A
892        space = 2;
893        size = -2;
894        break;
895    
896        CASE_ITERATOR_PRIVATE_DATA_2B
897        space = 2;
898        size = -(2 + IMM2_SIZE);
899        break;
900    
901        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
902        space = 1;
903        size = 1;
904        break;
905    
906        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
907        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
908          space = 2;
909        size = 1;
910        break;
911    
912        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
913        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
914          space = 2;
915        size = 1 + IMM2_SIZE;
916        break;
917    
918        case OP_CLASS:
919        case OP_NCLASS:
920        size += 1 + 32 / sizeof(pcre_uchar);
921        space = get_class_iterator_size(cc + size);
922        break;
923    
924    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
925        case OP_XCLASS:
926        size = GET(cc, 1);
927        space = get_class_iterator_size(cc + size);
928        break;
929    #endif
930    
931      case OP_RECURSE:      case OP_RECURSE:
932      /* Set its value only once. */      /* Set its value only once. */
933      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
934        {        {
935        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
936        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
937        }        }
938      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
939      break;      break;
940    
941        case OP_CALLOUT:
942        if (common->capture_last_ptr == 0)
943          {
944          common->capture_last_ptr = common->ovector_start;
945          common->ovector_start += sizeof(sljit_sw);
946          }
947        cc += 2 + 2 * LINK_SIZE;
948        break;
949    
950        case OP_PRUNE_ARG:
951        common->needs_start_ptr = TRUE;
952        common->control_head_ptr = 1;
953        /* Fall through. */
954    
955      case OP_MARK:      case OP_MARK:
956      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
957        {        {
958        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
959        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
960        }        }
961      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
962      break;      break;
963    
964        case OP_PRUNE:
965        case OP_SKIP:
966        common->needs_start_ptr = TRUE;
967        /* Fall through. */
968    
969        case OP_COMMIT:
970        common->control_head_ptr = 1;
971        cc += 1;
972        break;
973    
974      default:      default:
975      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
976      if (cc == NULL)      if (cc == NULL)
977        return -1;        return -1;
978      break;      break;
979      }      }
980    
981      if (space > 0 && cc >= end)
982        private_data_length += sizeof(sljit_sw) * space;
983    
984      if (size != 0)
985        {
986        if (size < 0)
987          {
988          cc += -size;
989    #ifdef SUPPORT_UTF
990          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
991    #endif
992          }
993        else
994          cc += size;
995        }
996    
997      if (bracketlen != 0)
998        {
999        if (cc >= end)
1000          {
1001          end = bracketend(cc);
1002          if (end[-1 - LINK_SIZE] == OP_KET)
1003            end = NULL;
1004          }
1005        cc += bracketlen;
1006        }
1007    }    }
1008  return localspace;  return private_data_length;
1009  }  }
1010    
1011  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)
1012  {  {
1013  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1014  pcre_uchar *alternative;  pcre_uchar *alternative;
1015    pcre_uchar *end = NULL;
1016    int space, size, bracketlen;
1017    
1018  while (cc < ccend)  while (cc < ccend)
1019    {    {
1020      space = 0;
1021      size = 0;
1022      bracketlen = 0;
1023    switch(*cc)    switch(*cc)
1024      {      {
1025      case OP_ASSERT:      case OP_ASSERT:
# Line 755  while (cc < ccend) Line 1032  while (cc < ccend)
1032      case OP_SBRA:      case OP_SBRA:
1033      case OP_SBRAPOS:      case OP_SBRAPOS:
1034      case OP_SCOND:      case OP_SCOND:
1035      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1036      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1037      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1038        break;
1039    
1040        case OP_CBRAPOS:
1041        case OP_SCBRAPOS:
1042        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1043        private_data_ptr += sizeof(sljit_sw);
1044        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1045        break;
1046    
1047        case OP_COND:
1048        /* Might be a hidden SCOND. */
1049        alternative = cc + GET(cc, 1);
1050        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1051          {
1052          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1053          private_data_ptr += sizeof(sljit_sw);
1054          }
1055        bracketlen = 1 + LINK_SIZE;
1056        break;
1057    
1058        case OP_BRA:
1059        bracketlen = 1 + LINK_SIZE;
1060        break;
1061    
1062        case OP_CBRA:
1063        case OP_SCBRA:
1064        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1065        break;
1066    
1067        CASE_ITERATOR_PRIVATE_DATA_1
1068        space = 1;
1069        size = -2;
1070        break;
1071    
1072        CASE_ITERATOR_PRIVATE_DATA_2A
1073        space = 2;
1074        size = -2;
1075        break;
1076    
1077        CASE_ITERATOR_PRIVATE_DATA_2B
1078        space = 2;
1079        size = -(2 + IMM2_SIZE);
1080      break;      break;
1081    
1082      case OP_CBRAPOS:      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1083      case OP_SCBRAPOS:      space = 1;
1084      common->localptrs[cc - common->start] = localptr;      size = 1;
     localptr += sizeof(sljit_w);  
     cc += 1 + LINK_SIZE + IMM2_SIZE;  
1085      break;      break;
1086    
1087      case OP_COND:      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1088      /* Might be a hidden SCOND. */      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1089      alternative = cc + GET(cc, 1);        space = 2;
1090      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      size = 1;
1091        {      break;
1092        common->localptrs[cc - common->start] = localptr;  
1093        localptr += sizeof(sljit_w);      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1094        }      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1095      cc += 1 + LINK_SIZE;        space = 2;
1096        size = 1 + IMM2_SIZE;
1097        break;
1098    
1099        case OP_CLASS:
1100        case OP_NCLASS:
1101        size += 1 + 32 / sizeof(pcre_uchar);
1102        space = get_class_iterator_size(cc + size);
1103        break;
1104    
1105    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1106        case OP_XCLASS:
1107        size = GET(cc, 1);
1108        space = get_class_iterator_size(cc + size);
1109      break;      break;
1110    #endif
1111    
1112      default:      default:
1113      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1114      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1115      break;      break;
1116      }      }
1117    
1118      if (space > 0 && cc >= end)
1119        {
1120        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1121        private_data_ptr += sizeof(sljit_sw) * space;
1122        }
1123    
1124      if (size != 0)
1125        {
1126        if (size < 0)
1127          {
1128          cc += -size;
1129    #ifdef SUPPORT_UTF
1130          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1131    #endif
1132          }
1133        else
1134          cc += size;
1135        }
1136    
1137      if (bracketlen > 0)
1138        {
1139        if (cc >= end)
1140          {
1141          end = bracketend(cc);
1142          if (end[-1 - LINK_SIZE] == OP_KET)
1143            end = NULL;
1144          }
1145        cc += bracketlen;
1146        }
1147    }    }
1148  }  }
1149    
1150  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1151  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)
1152  {  {
1153  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1154  int length = 0;  int length = 0;
1155  BOOL possessive = FALSE;  int possessive = 0;
1156    BOOL stack_restore = FALSE;
1157  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1158  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1159    /* The last capture is a local variable even for recursions. */
1160    BOOL capture_last_found = FALSE;
1161    
1162  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1163    {    {
1164    length = 3;    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1165    possessive = TRUE;    /* This is correct regardless of common->capture_last_ptr. */
1166      capture_last_found = TRUE;
1167    }    }
1168    
1169  cc = next_opcode(common, cc);  cc = next_opcode(common, cc);
# Line 808  while (cc < ccend) Line 1173  while (cc < ccend)
1173      {      {
1174      case OP_SET_SOM:      case OP_SET_SOM:
1175      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1176        stack_restore = TRUE;
1177      if (!setsom_found)      if (!setsom_found)
1178        {        {
1179        length += 2;        length += 2;
# Line 817  while (cc < ccend) Line 1183  while (cc < ccend)
1183      break;      break;
1184    
1185      case OP_MARK:      case OP_MARK:
1186        case OP_PRUNE_ARG:
1187      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1188        stack_restore = TRUE;
1189      if (!setmark_found)      if (!setmark_found)
1190        {        {
1191        length += 2;        length += 2;
# Line 827  while (cc < ccend) Line 1195  while (cc < ccend)
1195      break;      break;
1196    
1197      case OP_RECURSE:      case OP_RECURSE:
1198        stack_restore = TRUE;
1199      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1200        {        {
1201        length += 2;        length += 2;
# Line 837  while (cc < ccend) Line 1206  while (cc < ccend)
1206        length += 2;        length += 2;
1207        setmark_found = TRUE;        setmark_found = TRUE;
1208        }        }
1209        if (common->capture_last_ptr != 0 && !capture_last_found)
1210          {
1211          length += 2;
1212          capture_last_found = TRUE;
1213          }
1214      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1215      break;      break;
1216    
# Line 844  while (cc < ccend) Line 1218  while (cc < ccend)
1218      case OP_CBRAPOS:      case OP_CBRAPOS:
1219      case OP_SCBRA:      case OP_SCBRA:
1220      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1221        stack_restore = TRUE;
1222        if (common->capture_last_ptr != 0 && !capture_last_found)
1223          {
1224          length += 2;
1225          capture_last_found = TRUE;
1226          }
1227      length += 3;      length += 3;
1228      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1229      break;      break;
1230    
1231      default:      default:
1232        stack_restore = TRUE;
1233        /* Fall through. */
1234    
1235        case OP_NOT_WORD_BOUNDARY:
1236        case OP_WORD_BOUNDARY:
1237        case OP_NOT_DIGIT:
1238        case OP_DIGIT:
1239        case OP_NOT_WHITESPACE:
1240        case OP_WHITESPACE:
1241        case OP_NOT_WORDCHAR:
1242        case OP_WORDCHAR:
1243        case OP_ANY:
1244        case OP_ALLANY:
1245        case OP_ANYBYTE:
1246        case OP_NOTPROP:
1247        case OP_PROP:
1248        case OP_ANYNL:
1249        case OP_NOT_HSPACE:
1250        case OP_HSPACE:
1251        case OP_NOT_VSPACE:
1252        case OP_VSPACE:
1253        case OP_EXTUNI:
1254        case OP_EODN:
1255        case OP_EOD:
1256        case OP_CIRC:
1257        case OP_CIRCM:
1258        case OP_DOLL:
1259        case OP_DOLLM:
1260        case OP_CHAR:
1261        case OP_CHARI:
1262        case OP_NOT:
1263        case OP_NOTI:
1264    
1265        case OP_EXACT:
1266        case OP_POSSTAR:
1267        case OP_POSPLUS:
1268        case OP_POSQUERY:
1269        case OP_POSUPTO:
1270    
1271        case OP_EXACTI:
1272        case OP_POSSTARI:
1273        case OP_POSPLUSI:
1274        case OP_POSQUERYI:
1275        case OP_POSUPTOI:
1276    
1277        case OP_NOTEXACT:
1278        case OP_NOTPOSSTAR:
1279        case OP_NOTPOSPLUS:
1280        case OP_NOTPOSQUERY:
1281        case OP_NOTPOSUPTO:
1282    
1283        case OP_NOTEXACTI:
1284        case OP_NOTPOSSTARI:
1285        case OP_NOTPOSPLUSI:
1286        case OP_NOTPOSQUERYI:
1287        case OP_NOTPOSUPTOI:
1288    
1289        case OP_TYPEEXACT:
1290        case OP_TYPEPOSSTAR:
1291        case OP_TYPEPOSPLUS:
1292        case OP_TYPEPOSQUERY:
1293        case OP_TYPEPOSUPTO:
1294    
1295        case OP_CLASS:
1296        case OP_NCLASS:
1297        case OP_XCLASS:
1298    
1299      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1300      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1301      break;      break;
1302      }      }
1303    
1304  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1305  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1306    return -1;    return stack_restore ? no_frame : no_stack;
1307    
1308  if (length > 0)  if (length > 0)
1309    return length + 1;    return length + 1;
1310  return -1;  return stack_restore ? no_frame : no_stack;
1311  }  }
1312    
1313  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, int stackpos, int stacktop, BOOL recursive)
1314  {  {
1315  DEFINE_COMPILER;  DEFINE_COMPILER;
1316  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1317  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1318  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1319    /* The last capture is a local variable even for recursions. */
1320    BOOL capture_last_found = FALSE;
1321  int offset;  int offset;
1322    
1323  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 887  while (cc < ccend) Line 1336  while (cc < ccend)
1336      if (!setsom_found)      if (!setsom_found)
1337        {        {
1338        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1339        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1340        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1341        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1342        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1343        setsom_found = TRUE;        setsom_found = TRUE;
1344        }        }
1345      cc += 1;      cc += 1;
1346      break;      break;
1347    
1348      case OP_MARK:      case OP_MARK:
1349        case OP_PRUNE_ARG:
1350      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1351      if (!setmark_found)      if (!setmark_found)
1352        {        {
1353        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);
1354        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);
1355        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1356        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1357        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1358        setmark_found = TRUE;        setmark_found = TRUE;
1359        }        }
1360      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 914  while (cc < ccend) Line 1364  while (cc < ccend)
1364      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1365        {        {
1366        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1367        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1368        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1369        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1370        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1371        setsom_found = TRUE;        setsom_found = TRUE;
1372        }        }
1373      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1374        {        {
1375        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);
1376        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);
1377        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1378        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1379        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1380        setmark_found = TRUE;        setmark_found = TRUE;
1381        }        }
1382        if (common->capture_last_ptr != 0 && !capture_last_found)
1383          {
1384          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1385          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1386          stackpos += (int)sizeof(sljit_sw);
1387          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1388          stackpos += (int)sizeof(sljit_sw);
1389          capture_last_found = TRUE;
1390          }
1391      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1392      break;      break;
1393    
# Line 936  while (cc < ccend) Line 1395  while (cc < ccend)
1395      case OP_CBRAPOS:      case OP_CBRAPOS:
1396      case OP_SCBRA:      case OP_SCBRA:
1397      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1398        if (common->capture_last_ptr != 0 && !capture_last_found)
1399          {
1400          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1401          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1402          stackpos += (int)sizeof(sljit_sw);
1403          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1404          stackpos += (int)sizeof(sljit_sw);
1405          capture_last_found = TRUE;
1406          }
1407      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1408      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1409      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1410      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1411      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));
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      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1415      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1416    
1417      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1418      break;      break;
# Line 955  while (cc < ccend) Line 1423  while (cc < ccend)
1423      break;      break;
1424      }      }
1425    
1426  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1427  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1428  }  }
1429    
1430  static SLJIT_INLINE int get_localsize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static SLJIT_INLINE int get_private_data_length_for_copy(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
1431  {  {
1432  int localsize = 2;  int private_data_length = common->control_head_ptr ? 3 : 2;
1433    int size;
1434  pcre_uchar *alternative;  pcre_uchar *alternative;
1435  /* Calculate the sum of the local variables. */  /* Calculate the sum of the private machine words. */
1436  while (cc < ccend)  while (cc < ccend)
1437    {    {
1438      size = 0;
1439    switch(*cc)    switch(*cc)
1440      {      {
1441      case OP_ASSERT:      case OP_ASSERT:
# Line 978  while (cc < ccend) Line 1448  while (cc < ccend)
1448      case OP_SBRA:      case OP_SBRA:
1449      case OP_SBRAPOS:      case OP_SBRAPOS:
1450      case OP_SCOND:      case OP_SCOND:
1451      localsize++;      private_data_length++;
1452      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1453      break;      break;
1454    
1455      case OP_CBRA:      case OP_CBRA:
1456      case OP_SCBRA:      case OP_SCBRA:
1457      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1458          private_data_length++;
1459      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1460      break;      break;
1461    
1462      case OP_CBRAPOS:      case OP_CBRAPOS:
1463      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1464      localsize += 2;      private_data_length += 2;
1465      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1466      break;      break;
1467    
# Line 998  while (cc < ccend) Line 1469  while (cc < ccend)
1469      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1470      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1471      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1472        localsize++;        private_data_length++;
1473      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1474      break;      break;
1475    
1476        CASE_ITERATOR_PRIVATE_DATA_1
1477        if (PRIVATE_DATA(cc))
1478          private_data_length++;
1479        cc += 2;
1480    #ifdef SUPPORT_UTF
1481        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1482    #endif
1483        break;
1484    
1485        CASE_ITERATOR_PRIVATE_DATA_2A
1486        if (PRIVATE_DATA(cc))
1487          private_data_length += 2;
1488        cc += 2;
1489    #ifdef SUPPORT_UTF
1490        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1491    #endif
1492        break;
1493    
1494        CASE_ITERATOR_PRIVATE_DATA_2B
1495        if (PRIVATE_DATA(cc))
1496          private_data_length += 2;
1497        cc += 2 + IMM2_SIZE;
1498    #ifdef SUPPORT_UTF
1499        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1500    #endif
1501        break;
1502    
1503        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1504        if (PRIVATE_DATA(cc))
1505          private_data_length++;
1506        cc += 1;
1507        break;
1508    
1509        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1510        if (PRIVATE_DATA(cc))
1511          private_data_length += 2;
1512        cc += 1;
1513        break;
1514    
1515        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1516        if (PRIVATE_DATA(cc))
1517          private_data_length += 2;
1518        cc += 1 + IMM2_SIZE;
1519        break;
1520    
1521        case OP_CLASS:
1522        case OP_NCLASS:
1523    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1524        case OP_XCLASS:
1525        size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1526    #else
1527        size = 1 + 32 / (int)sizeof(pcre_uchar);
1528    #endif
1529        if (PRIVATE_DATA(cc))
1530          private_data_length += get_class_iterator_size(cc + size);
1531        cc += size;
1532        break;
1533    
1534      default:      default:
1535      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1536      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 1009  while (cc < ccend) Line 1538  while (cc < ccend)
1538      }      }
1539    }    }
1540  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1541  return localsize;  return private_data_length;
1542  }  }
1543    
1544  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,
1545    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop)
1546  {  {
1547  DEFINE_COMPILER;  DEFINE_COMPILER;
1548  int srcw[2];  int srcw[2];
1549  int count;  int count, size;
1550  BOOL tmp1next = TRUE;  BOOL tmp1next = TRUE;
1551  BOOL tmp1empty = TRUE;  BOOL tmp1empty = TRUE;
1552  BOOL tmp2empty = TRUE;  BOOL tmp2empty = TRUE;
# Line 1034  stacktop = STACK(stacktop - 1); Line 1563  stacktop = STACK(stacktop - 1);
1563    
1564  if (!save)  if (!save)
1565    {    {
1566    stackptr += sizeof(sljit_w);    stackptr += (common->control_head_ptr ? 2 : 1) * sizeof(sljit_sw);
1567    if (stackptr < stacktop)    if (stackptr < stacktop)
1568      {      {
1569      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1570      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1571      tmp1empty = FALSE;      tmp1empty = FALSE;
1572      }      }
1573    if (stackptr < stacktop)    if (stackptr < stacktop)
1574      {      {
1575      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1576      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1577      tmp2empty = FALSE;      tmp2empty = FALSE;
1578      }      }
1579    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1580    }    }
1581    
1582  while (status != end)  do
1583    {    {
1584    count = 0;    count = 0;
1585    switch(status)    switch(status)
1586      {      {
1587      case start:      case start:
1588      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1589      count = 1;      count = 1;
1590      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1591        if (common->control_head_ptr != 0)
1592          {
1593          count = 2;
1594          srcw[1] = common->control_head_ptr;
1595          }
1596      status = loop;      status = loop;
1597      break;      break;
1598    
# Line 1082  while (status != end) Line 1616  while (status != end)
1616        case OP_SBRAPOS:        case OP_SBRAPOS:
1617        case OP_SCOND:        case OP_SCOND:
1618        count = 1;        count = 1;
1619        srcw[0] = PRIV_DATA(cc);        srcw[0] = PRIVATE_DATA(cc);
1620        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1621        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1622        break;        break;
1623    
1624        case OP_CBRA:        case OP_CBRA:
1625        case OP_SCBRA:        case OP_SCBRA:
1626        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1627        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1628            count = 1;
1629            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1630            }
1631        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1632        break;        break;
1633    
1634        case OP_CBRAPOS:        case OP_CBRAPOS:
1635        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1636        count = 2;        count = 2;
1637          srcw[0] = PRIVATE_DATA(cc);
1638        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1639        srcw[0] = PRIV_DATA(cc);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
       SLJIT_ASSERT(srcw[0] != 0);  
1640        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1641        break;        break;
1642    
# Line 1109  while (status != end) Line 1646  while (status != end)
1646        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1647          {          {
1648          count = 1;          count = 1;
1649          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1650          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1651          }          }
1652        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1653        break;        break;
1654    
1655          CASE_ITERATOR_PRIVATE_DATA_1
1656          if (PRIVATE_DATA(cc))
1657            {
1658            count = 1;
1659            srcw[0] = PRIVATE_DATA(cc);
1660            }
1661          cc += 2;
1662    #ifdef SUPPORT_UTF
1663          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1664    #endif
1665          break;
1666    
1667          CASE_ITERATOR_PRIVATE_DATA_2A
1668          if (PRIVATE_DATA(cc))
1669            {
1670            count = 2;
1671            srcw[0] = PRIVATE_DATA(cc);
1672            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1673            }
1674          cc += 2;
1675    #ifdef SUPPORT_UTF
1676          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1677    #endif
1678          break;
1679    
1680          CASE_ITERATOR_PRIVATE_DATA_2B
1681          if (PRIVATE_DATA(cc))
1682            {
1683            count = 2;
1684            srcw[0] = PRIVATE_DATA(cc);
1685            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1686            }
1687          cc += 2 + IMM2_SIZE;
1688    #ifdef SUPPORT_UTF
1689          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1690    #endif
1691          break;
1692    
1693          CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1694          if (PRIVATE_DATA(cc))
1695            {
1696            count = 1;
1697            srcw[0] = PRIVATE_DATA(cc);
1698            }
1699          cc += 1;
1700          break;
1701    
1702          CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1703          if (PRIVATE_DATA(cc))
1704            {
1705            count = 2;
1706            srcw[0] = PRIVATE_DATA(cc);
1707            srcw[1] = srcw[0] + sizeof(sljit_sw);
1708            }
1709          cc += 1;
1710          break;
1711    
1712          CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1713          if (PRIVATE_DATA(cc))
1714            {
1715            count = 2;
1716            srcw[0] = PRIVATE_DATA(cc);
1717            srcw[1] = srcw[0] + sizeof(sljit_sw);
1718            }
1719          cc += 1 + IMM2_SIZE;
1720          break;
1721    
1722          case OP_CLASS:
1723          case OP_NCLASS:
1724    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1725          case OP_XCLASS:
1726          size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1727    #else
1728          size = 1 + 32 / (int)sizeof(pcre_uchar);
1729    #endif
1730          if (PRIVATE_DATA(cc))
1731            switch(get_class_iterator_size(cc + size))
1732              {
1733              case 1:
1734              count = 1;
1735              srcw[0] = PRIVATE_DATA(cc);
1736              break;
1737    
1738              case 2:
1739              count = 2;
1740              srcw[0] = PRIVATE_DATA(cc);
1741              srcw[1] = srcw[0] + sizeof(sljit_sw);
1742              break;
1743    
1744              default:
1745              SLJIT_ASSERT_STOP();
1746              break;
1747              }
1748          cc += size;
1749          break;
1750    
1751        default:        default:
1752        cc = next_opcode(common, cc);        cc = next_opcode(common, cc);
1753        SLJIT_ASSERT(cc != NULL);        SLJIT_ASSERT(cc != NULL);
# Line 1137  while (status != end) Line 1770  while (status != end)
1770          if (!tmp1empty)          if (!tmp1empty)
1771            {            {
1772            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1773            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1774            }            }
1775          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1776          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1148  while (status != end) Line 1781  while (status != end)
1781          if (!tmp2empty)          if (!tmp2empty)
1782            {            {
1783            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1784            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1785            }            }
1786          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1787          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1165  while (status != end) Line 1798  while (status != end)
1798          if (!tmp1empty)          if (!tmp1empty)
1799            {            {
1800            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1801            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1802            }            }
1803          tmp1next = FALSE;          tmp1next = FALSE;
1804          }          }
# Line 1177  while (status != end) Line 1810  while (status != end)
1810          if (!tmp2empty)          if (!tmp2empty)
1811            {            {
1812            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1813            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1814            }            }
1815          tmp1next = TRUE;          tmp1next = TRUE;
1816          }          }
1817        }        }
1818      }      }
1819    }    }
1820    while (status != end);
1821    
1822  if (save)  if (save)
1823    {    {
# Line 1192  if (save) Line 1826  if (save)
1826      if (!tmp1empty)      if (!tmp1empty)
1827        {        {
1828        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1829        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1830        }        }
1831      if (!tmp2empty)      if (!tmp2empty)
1832        {        {
1833        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1834        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1835        }        }
1836      }      }
1837    else    else
# Line 1205  if (save) Line 1839  if (save)
1839      if (!tmp2empty)      if (!tmp2empty)
1840        {        {
1841        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1842        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1843        }        }
1844      if (!tmp1empty)      if (!tmp1empty)
1845        {        {
1846        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1847        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1848        }        }
1849      }      }
1850    }    }
1851  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1852  }  }
1853    
1854  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  #undef CASE_ITERATOR_PRIVATE_DATA_1
1855    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1856    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1857    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1858    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1859    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1860    
1861    static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1862  {  {
1863  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1864  }  }
# Line 1227  static SLJIT_INLINE void set_jumps(jump_ Line 1868  static SLJIT_INLINE void set_jumps(jump_
1868  while (list)  while (list)
1869    {    {
1870    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1871    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1872    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1873    list = list->next;    list = list->next;
1874    }    }
1875  }  }
# Line 1244  if (list_item) Line 1885  if (list_item)
1885    }    }
1886  }  }
1887    
1888  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)
1889  {  {
1890  DEFINE_COMPILER;  DEFINE_COMPILER;
1891  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1892    
1893  if (list_item)  if (list_item)
1894    {    {
   list_item->type = type;  
   list_item->data = data;  
1895    list_item->start = start;    list_item->start = start;
1896    list_item->leave = LABEL();    list_item->quit = LABEL();
1897    list_item->next = common->stubs;    list_item->next = common->stubs;
1898    common->stubs = list_item;    common->stubs = list_item;
1899    }    }
# Line 1268  stub_list* list_item = common->stubs; Line 1907  stub_list* list_item = common->stubs;
1907  while (list_item)  while (list_item)
1908    {    {
1909    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
1910    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
1911      {    JUMPTO(SLJIT_JUMP, list_item->quit);
     case stack_alloc:  
     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));  
     break;  
     }  
   JUMPTO(SLJIT_JUMP, list_item->leave);  
1912    list_item = list_item->next;    list_item = list_item->next;
1913    }    }
1914  common->stubs = NULL;  common->stubs = NULL;
# Line 1293  static SLJIT_INLINE void allocate_stack( Line 1927  static SLJIT_INLINE void allocate_stack(
1927  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
1928  DEFINE_COMPILER;  DEFINE_COMPILER;
1929    
1930  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));
1931  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
1932  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
1933  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1301  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 1935  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
1935  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
1936  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
1937  #endif  #endif
1938  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));
1939  }  }
1940    
1941  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
1942  {  {
1943  DEFINE_COMPILER;  DEFINE_COMPILER;
1944  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));
1945  }  }
1946    
1947  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1315  static SLJIT_INLINE void reset_ovector(c Line 1949  static SLJIT_INLINE void reset_ovector(c
1949  DEFINE_COMPILER;  DEFINE_COMPILER;
1950  struct sljit_label *loop;  struct sljit_label *loop;
1951  int i;  int i;
1952    
1953  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
1954    SLJIT_ASSERT(length > 1);
1955  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
1956  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
1957    if (length < 8)
1958      {
1959      for (i = 1; i < length; i++)
1960        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
1961      }
1962    else
1963      {
1964      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
1965      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
1966      loop = LABEL();
1967      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
1968      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
1969      JUMPTO(SLJIT_C_NOT_ZERO, loop);
1970      }
1971    }
1972    
1973    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
1974    {
1975    DEFINE_COMPILER;
1976    struct sljit_label *loop;
1977    int i;
1978    
1979    SLJIT_ASSERT(length > 1);
1980    /* OVECTOR(1) contains the "string begin - 1" constant. */
1981    if (length > 2)
1982      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
1983  if (length < 8)  if (length < 8)
1984    {    {
1985    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
1986      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);
1987    }    }
1988  else  else
1989    {    {
1990    OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
1991    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
1992    loop = LABEL();    loop = LABEL();
1993    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);
1994    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);
1995    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
1996    }    }
1997    
1998    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
1999    if (common->mark_ptr != 0)
2000      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2001    SLJIT_ASSERT(common->control_head_ptr != 0);
2002    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2003    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2004    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2005    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2006    }
2007    
2008    static sljit_sw do_check_control_chain(sljit_sw *current)
2009    {
2010    sljit_sw return_value = 0;
2011    
2012    SLJIT_ASSERT(current != NULL);
2013    do
2014      {
2015      switch (current[-2])
2016        {
2017        case type_commit:
2018        /* Commit overwrites all. */
2019        return -1;
2020    
2021        case type_prune:
2022        break;
2023    
2024        case type_skip:
2025        /* Overwrites prune, but not other skips. */
2026        if (return_value == 0)
2027          return_value = current[-3];
2028        break;
2029    
2030        default:
2031        SLJIT_ASSERT_STOP();
2032        break;
2033        }
2034      current = (sljit_sw*)current[-1];
2035      }
2036    while (current != NULL);
2037    return return_value;
2038  }  }
2039    
2040  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2041  {  {
2042  DEFINE_COMPILER;  DEFINE_COMPILER;
2043  struct sljit_label *loop;  struct sljit_label *loop;
2044  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2045    
2046  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2047  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));
2048  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);
2049    
2050  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2051  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2052    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);
2053  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));
2054  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2055    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);
2056  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));
2057  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));
2058  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2059  /* Unlikely, but possible */  /* Unlikely, but possible */
2060  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);
2061  loop = LABEL();  loop = LABEL();
2062  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);
2063  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));
2064  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2065  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2066  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);
2067  #endif  #endif
2068  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);
2069  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);
2070  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2071  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2072    
2073  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2074  if (topbracket > 1)  if (topbracket > 1)
2075    {    {
2076    OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START + topbracket * 2 * sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
2077    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2078    
2079    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2080    loop = LABEL();    loop = LABEL();
2081    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)));
2082    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);
2083    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);
2084    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2085    }    }
2086  else  else
2087    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
2088  }  }
2089    
2090  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *leave)  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2091  {  {
2092  DEFINE_COMPILER;  DEFINE_COMPILER;
2093    struct sljit_jump *jump;
2094    
2095  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);
2096  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
2097      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2098    
2099  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2100  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2101  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));
2102  CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, leave);  CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2103    
2104  /* Store match begin and end. */  /* Store match begin and end. */
2105  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));
2106  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));
2107  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);  
2108    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2109    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);
2110    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2111    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2112    #endif
2113    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2114    JUMPHERE(jump);
2115    
2116    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);
2117  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);
2118  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2119  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);
2120  #endif  #endif
2121  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);
2122    
2123  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);
2124  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2125  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);
2126  #endif  #endif
2127  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);
2128    
2129  JUMPTO(SLJIT_JUMP, leave);  JUMPTO(SLJIT_JUMP, quit);
2130  }  }
2131    
2132  static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)  static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)
# Line 1523  if (c <= 127 && bit == 0x20) Line 2237  if (c <= 127 && bit == 0x20)
2237    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2238    
2239  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2240  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2241    return 0;    return 0;
2242    
2243  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2244    
2245  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2246  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 1542  if (common->utf && c > 127) Line 2256  if (common->utf && c > 127)
2256  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2257  return (0 << 8) | bit;  return (0 << 8) | bit;
2258    
2259  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2260    
 #ifdef COMPILE_PCRE16  
2261  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2262  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2263    {    {
# Line 1555  if (common->utf && c > 65535) Line 2268  if (common->utf && c > 65535)
2268    }    }
2269  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2270  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2271    
2272  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2273  }  }
2274    
2275  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
# Line 1577  else if (common->mode == JIT_PARTIAL_SOF Line 2289  else if (common->mode == JIT_PARTIAL_SOF
2289    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);
2290    
2291  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2292    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);
2293  else  else
2294    {    {
2295    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 1590  if (jump != NULL) Line 2302  if (jump != NULL)
2302    JUMPHERE(jump);    JUMPHERE(jump);
2303  }  }
2304    
2305  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2306  {  {
2307  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2308  DEFINE_COMPILER;  DEFINE_COMPILER;
2309  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2310    
2311  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2312    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2313      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2314      return;
2315      }
2316    
2317  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2318  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2319    {    {
2320    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));
2321    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);
2322    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2323    }    }
2324  else  else
2325    {    {
2326    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));
2327    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2328      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2329    else    else
2330      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2331    }    }
2332  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2333  }  }
2334    
2335  static void fallback_at_str_end(compiler_common *common, jump_list **fallbacks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
2336  {  {
2337  DEFINE_COMPILER;  DEFINE_COMPILER;
2338  struct sljit_jump *jump;  struct sljit_jump *jump;
2339    
2340  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2341    {    {
2342    add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2343    return;    return;
2344    }    }
2345    
2346  /* Partial matching mode. */  /* Partial matching mode. */
2347  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2348  add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2349  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2350    {    {
2351    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);
2352    add_jump(compiler, fallbacks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2353    }    }
2354  else  else
2355    {    {
# Line 1655  static void read_char(compiler_common *c Line 2366  static void read_char(compiler_common *c
2366  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2367  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2368  DEFINE_COMPILER;  DEFINE_COMPILER;
2369  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2370  struct sljit_jump *jump;  struct sljit_jump *jump;
2371  #endif  #endif
2372    
2373  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2374  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2375  if (common->utf)  if (common->utf)
2376    {    {
2377  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2378    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2379  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2380    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2381  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2382    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2383    JUMPHERE(jump);    JUMPHERE(jump);
2384    }    }
2385  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2386  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));
2387  }  }
2388    
# Line 1682  static void peek_char(compiler_common *c Line 2391  static void peek_char(compiler_common *c
2391  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2392  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2393  DEFINE_COMPILER;  DEFINE_COMPILER;
2394  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2395  struct sljit_jump *jump;  struct sljit_jump *jump;
2396  #endif  #endif
2397    
2398  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2399  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2400  if (common->utf)  if (common->utf)
2401    {    {
2402  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2403    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2404  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2405    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2406  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2407    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2408    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2409    JUMPHERE(jump);    JUMPHERE(jump);
2410    }    }
2411  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2412  }  }
2413    
2414  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2415  {  {
2416  /* 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. */
2417  DEFINE_COMPILER;  DEFINE_COMPILER;
2418  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2419  struct sljit_jump *jump;  struct sljit_jump *jump;
2420  #endif  #endif
2421    
# Line 1717  if (common->utf) Line 2424  if (common->utf)
2424    {    {
2425    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2426    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));
2427  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2428    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2429    it is needed in most cases. */    it is needed in most cases. */
2430    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2431    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2432    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2433    JUMPHERE(jump);    JUMPHERE(jump);
2434  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2435    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2436    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2437    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
# Line 1733  if (common->utf) Line 2439  if (common->utf)
2439    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2440    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2441    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);
2442    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2443    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2444    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2445  #endif  #elif defined COMPILE_PCRE32
2446  #endif /* COMPILE_PCRE8 */    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2447      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2448      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2449      JUMPHERE(jump);
2450    #endif /* COMPILE_PCRE[8|16|32] */
2451    return;    return;
2452    }    }
2453  #endif  #endif /* SUPPORT_UTF */
2454  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2455  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));
2456  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2457  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2458  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2459  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2460  #endif  #endif
2461  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2462  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2463  JUMPHERE(jump);  JUMPHERE(jump);
2464  #endif  #endif
2465  }  }
# Line 1758  static void skip_char_back(compiler_comm Line 2468  static void skip_char_back(compiler_comm
2468  {  {
2469  /* 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. */
2470  DEFINE_COMPILER;  DEFINE_COMPILER;
2471  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2472    #if defined COMPILE_PCRE8
2473  struct sljit_label *label;  struct sljit_label *label;
2474    
2475  if (common->utf)  if (common->utf)
# Line 1770  if (common->utf) Line 2481  if (common->utf)
2481    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2482    return;    return;
2483    }    }
2484  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2485  if (common->utf)  if (common->utf)
2486    {    {
2487    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
# Line 1779  if (common->utf) Line 2489  if (common->utf)
2489    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2490    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2491    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);
2492    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2493    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2494    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2495    return;    return;
2496    }    }
2497  #endif  #endif /* COMPILE_PCRE[8|16] */
2498    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2499  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));
2500  }  }
2501    
2502  static void check_newlinechar(compiler_common *common, int nltype, jump_list **fallbacks, BOOL jumpiftrue)  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpiftrue)
2503  {  {
2504  /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */  /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */
2505  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1796  DEFINE_COMPILER; Line 2507  DEFINE_COMPILER;
2507  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2508    {    {
2509    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2510    add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2511    }    }
2512  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2513    {    {
2514    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);
2515    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2516    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);
2517    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);
2518    add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2519    }    }
2520  else  else
2521    {    {
2522    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2523    add_jump(compiler, fallbacks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));    add_jump(compiler, backtracks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
2524    }    }
2525  }  }
2526    
2527  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2528    
2529  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2530  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2531  {  {
2532  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
# Line 1823  of the character (>= 0xc0). Return char Line 2534  of the character (>= 0xc0). Return char
2534  DEFINE_COMPILER;  DEFINE_COMPILER;
2535  struct sljit_jump *jump;  struct sljit_jump *jump;
2536    
2537  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2538  /* Searching for the first zero. */  /* Searching for the first zero. */
2539  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
2540  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
# Line 1882  DEFINE_COMPILER; Line 2593  DEFINE_COMPILER;
2593  struct sljit_jump *jump;  struct sljit_jump *jump;
2594  struct sljit_jump *compare;  struct sljit_jump *compare;
2595    
2596  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2597    
2598  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);
2599  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
# Line 1903  sljit_emit_fast_return(compiler, RETURN_ Line 2614  sljit_emit_fast_return(compiler, RETURN_
2614  JUMPHERE(jump);  JUMPHERE(jump);
2615    
2616  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2617  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);
2618  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2619  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2620  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2621  }  }
2622    
2623  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2624    
 #ifdef COMPILE_PCRE16  
2625  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2626  {  {
2627  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char
# Line 1919  of the character (>= 0xd800). Return cha Line 2629  of the character (>= 0xd800). Return cha
2629  DEFINE_COMPILER;  DEFINE_COMPILER;
2630  struct sljit_jump *jump;  struct sljit_jump *jump;
2631    
2632  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2633  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);
2634  /* Do nothing, only return. */  /* Do nothing, only return. */
2635  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
# Line 1936  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC Line 2646  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2646  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2647  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2648  }  }
 #endif /* COMPILE_PCRE16 */  
2649    
2650  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2651    
2652  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2653    
# Line 1956  DEFINE_COMPILER; Line 2665  DEFINE_COMPILER;
2665    
2666  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);
2667    
2668  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2669  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2670  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));
2671  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2672  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2673  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2674  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2675  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2676  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));
2677  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2678  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2679  }  }
# Line 1978  struct sljit_label *newlinelabel = NULL; Line 2687  struct sljit_label *newlinelabel = NULL;
2687  struct sljit_jump *start;  struct sljit_jump *start;
2688  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2689  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2690  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2691  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2692  #endif  #endif
2693  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 1993  if (firstline) Line 2702  if (firstline)
2702    {    {
2703    /* Search for the end of the first line. */    /* Search for the end of the first line. */
2704    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
2705    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_END, 0);  
2706    
2707    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2708      {      {
# Line 2005  if (firstline) Line 2713  if (firstline)
2713      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2714      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);
2715      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);
2716        JUMPHERE(end);
2717      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));
2718      }      }
2719    else    else
# Line 2016  if (firstline) Line 2725  if (firstline)
2725      read_char(common);      read_char(common);
2726      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
2727      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2728        JUMPHERE(end);
2729      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);
2730      set_jumps(newline, LABEL());      set_jumps(newline, LABEL());
2731      }      }
2732    
2733    JUMPHERE(end);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
   OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
2734    }    }
2735    
2736  start = JUMP(SLJIT_JUMP);  start = JUMP(SLJIT_JUMP);
# Line 2033  if (newlinecheck) Line 2742  if (newlinecheck)
2742    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2743    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2744    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);
2745    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2746  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2747    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2748  #endif  #endif
2749    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2750    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2056  if (newlinecheck) Line 2765  if (newlinecheck)
2765    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);
2766    
2767  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));
2768  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2769    #if defined COMPILE_PCRE8
2770  if (common->utf)  if (common->utf)
2771    {    {
2772    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2773    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);
2774    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2775    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2776    }    }
2777  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2778  if (common->utf)  if (common->utf)
2779    {    {
2780    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2781    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2782    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);
2783    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2784    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2785    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2786    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2787    }    }
2788  #endif  #endif /* COMPILE_PCRE[8|16] */
2789    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2790  JUMPHERE(start);  JUMPHERE(start);
2791    
2792  if (newlinecheck)  if (newlinecheck)
# Line 2088  if (newlinecheck) Line 2798  if (newlinecheck)
2798  return mainloop;  return mainloop;
2799  }  }
2800    
2801    #define MAX_N_CHARS 3
2802    
2803    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2804    {
2805    DEFINE_COMPILER;
2806    struct sljit_label *start;
2807    struct sljit_jump *quit;
2808    pcre_uint32 chars[MAX_N_CHARS * 2];
2809    pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2810    int location = 0;
2811    pcre_int32 len, c, bit, caseless;
2812    int must_stop;
2813    
2814    /* We do not support alternatives now. */
2815    if (*(common->start + GET(common->start, 1)) == OP_ALT)
2816      return FALSE;
2817    
2818    while (TRUE)
2819      {
2820      caseless = 0;
2821      must_stop = 1;
2822      switch(*cc)
2823        {
2824        case OP_CHAR:
2825        must_stop = 0;
2826        cc++;
2827        break;
2828    
2829        case OP_CHARI:
2830        caseless = 1;
2831        must_stop = 0;
2832        cc++;
2833        break;
2834    
2835        case OP_SOD:
2836        case OP_SOM:
2837        case OP_SET_SOM:
2838        case OP_NOT_WORD_BOUNDARY:
2839        case OP_WORD_BOUNDARY:
2840        case OP_EODN:
2841        case OP_EOD:
2842        case OP_CIRC:
2843        case OP_CIRCM:
2844        case OP_DOLL:
2845        case OP_DOLLM:
2846        /* Zero width assertions. */
2847        cc++;
2848        continue;
2849    
2850        case OP_PLUS:
2851        case OP_MINPLUS:
2852        case OP_POSPLUS:
2853        cc++;
2854        break;
2855    
2856        case OP_EXACT:
2857        cc += 1 + IMM2_SIZE;
2858        break;
2859    
2860        case OP_PLUSI:
2861        case OP_MINPLUSI:
2862        case OP_POSPLUSI:
2863        caseless = 1;
2864        cc++;
2865        break;
2866    
2867        case OP_EXACTI:
2868        caseless = 1;
2869        cc += 1 + IMM2_SIZE;
2870        break;
2871    
2872        default:
2873        must_stop = 2;
2874        break;
2875        }
2876    
2877      if (must_stop == 2)
2878          break;
2879    
2880      len = 1;
2881    #ifdef SUPPORT_UTF
2882      if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
2883    #endif
2884    
2885      if (caseless && char_has_othercase(common, cc))
2886        {
2887        caseless = char_get_othercase_bit(common, cc);
2888        if (caseless == 0)
2889          return FALSE;
2890    #ifdef COMPILE_PCRE8
2891        caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
2892    #else
2893        if ((caseless & 0x100) != 0)
2894          caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
2895        else
2896          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
2897    #endif
2898        }
2899      else
2900        caseless = 0;
2901    
2902      while (len > 0 && location < MAX_N_CHARS * 2)
2903        {
2904        c = *cc;
2905        bit = 0;
2906        if (len == (caseless & 0xff))
2907          {
2908          bit = caseless >> 8;
2909          c |= bit;
2910          }
2911    
2912        chars[location] = c;
2913        chars[location + 1] = bit;
2914    
2915        len--;
2916        location += 2;
2917        cc++;
2918        }
2919    
2920      if (location >= MAX_N_CHARS * 2 || must_stop != 0)
2921        break;
2922      }
2923    
2924    /* At least two characters are required. */
2925    if (location < 2 * 2)
2926        return FALSE;
2927    
2928    if (firstline)
2929      {
2930      SLJIT_ASSERT(common->first_line_end != 0);
2931      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2932      OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2933      }
2934    else
2935      OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2936    
2937    start = LABEL();
2938    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2939    
2940    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2941    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2942    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2943    if (chars[1] != 0)
2944      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
2945    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
2946    if (location > 2 * 2)
2947      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2948    if (chars[3] != 0)
2949      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
2950    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
2951    if (location > 2 * 2)
2952      {
2953      if (chars[5] != 0)
2954        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
2955      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);
2956      }
2957    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2958    
2959    JUMPHERE(quit);
2960    
2961    if (firstline)
2962      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2963    else
2964      OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2965    return TRUE;
2966    }
2967    
2968    #undef MAX_N_CHARS
2969    
2970  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)
2971  {  {
2972  DEFINE_COMPILER;  DEFINE_COMPILER;
2973  struct sljit_label *start;  struct sljit_label *start;
2974  struct sljit_jump *leave;  struct sljit_jump *quit;
2975  struct sljit_jump *found;  struct sljit_jump *found;
2976  pcre_uchar oc, bit;  pcre_uchar oc, bit;
2977    
2978  if (firstline)  if (firstline)
2979    {    {
2980    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2981      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2982    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);
2983    }    }
2984    
2985  start = LABEL();  start = LABEL();
2986  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2987  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2988    
2989  oc = first_char;  oc = first_char;
# Line 2120  if (first_char == oc) Line 3000  if (first_char == oc)
3000  else  else
3001    {    {
3002    bit = first_char ^ oc;    bit = first_char ^ oc;
3003    if (ispowerof2(bit))    if (is_powerof2(bit))
3004      {      {
3005      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3006      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
# Line 2128  else Line 3008  else
3008    else    else
3009      {      {
3010      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);
3011      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3012      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);
3013      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);
3014      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3015      }      }
3016    }    }
3017    
3018  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 #if defined SUPPORT_UTF && defined COMPILE_PCRE8  
 if (common->utf)  
   {  
   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 #endif  
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
 if (common->utf)  
   {  
   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);  
   OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);  
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);  
   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);  
   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 #endif  
3019  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3020  JUMPHERE(found);  JUMPHERE(found);
3021  JUMPHERE(leave);  JUMPHERE(quit);
3022    
3023  if (firstline)  if (firstline)
3024    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3025  }  }
3026    
3027  static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline)  static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline)
# Line 2169  DEFINE_COMPILER; Line 3030  DEFINE_COMPILER;
3030  struct sljit_label *loop;  struct sljit_label *loop;
3031  struct sljit_jump *lastchar;  struct sljit_jump *lastchar;
3032  struct sljit_jump *firstchar;  struct sljit_jump *firstchar;
3033  struct sljit_jump *leave;  struct sljit_jump *quit;
3034  struct sljit_jump *foundcr = NULL;  struct sljit_jump *foundcr = NULL;
3035  struct sljit_jump *notfoundnl;  struct sljit_jump *notfoundnl;
3036  jump_list *newline = NULL;  jump_list *newline = NULL;
3037    
3038  if (firstline)  if (firstline)
3039    {    {
3040    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3041      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3042    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);
3043    }    }
3044    
# Line 2190  if (common->nltype == NLTYPE_FIXED && co Line 3052  if (common->nltype == NLTYPE_FIXED && co
3052    
3053    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3054    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);
3055    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3056  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3057    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3058  #endif  #endif
3059    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3060    
3061    loop = LABEL();    loop = LABEL();
3062    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));
3063    leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3064    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
3065    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
3066    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);
3067    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);
3068    
3069    JUMPHERE(leave);    JUMPHERE(quit);
3070    JUMPHERE(firstchar);    JUMPHERE(firstchar);
3071    JUMPHERE(lastchar);    JUMPHERE(lastchar);
3072    
# Line 2228  set_jumps(newline, loop); Line 3090  set_jumps(newline, loop);
3090    
3091  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3092    {    {
3093    leave = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
3094    JUMPHERE(foundcr);    JUMPHERE(foundcr);
3095    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3096    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3097    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);
3098    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3099  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3100    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3101  #endif  #endif
3102    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3103    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
3104    JUMPHERE(leave);    JUMPHERE(quit);
3105    }    }
3106  JUMPHERE(lastchar);  JUMPHERE(lastchar);
3107  JUMPHERE(firstchar);  JUMPHERE(firstchar);
3108    
3109  if (firstline)  if (firstline)
3110    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3111  }  }
3112    
3113    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3114    
3115  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)
3116  {  {
3117  DEFINE_COMPILER;  DEFINE_COMPILER;
3118  struct sljit_label *start;  struct sljit_label *start;
3119  struct sljit_jump *leave;  struct sljit_jump *quit;
3120  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3121    jump_list *matches = NULL;
3122    pcre_uint8 inverted_start_bits[32];
3123    int i;
3124  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3125  struct sljit_jump *jump;  struct sljit_jump *jump;
3126  #endif  #endif
3127    
3128    for (i = 0; i < 32; ++i)
3129      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3130    
3131  if (firstline)  if (firstline)
3132    {    {
3133    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3134      OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
3135    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);
3136    }    }
3137    
3138  start = LABEL();  start = LABEL();
3139  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3140  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3141  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3142  if (common->utf)  if (common->utf)
3143    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3144  #endif  #endif
3145    
3146    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3147      {
3148  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3149  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3150  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3151  JUMPHERE(jump);    JUMPHERE(jump);
3152  #endif  #endif
3153  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3154  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3155  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3156  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3157  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);
3158  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3159      }
3160    
3161  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3162  if (common->utf)  if (common->utf)
3163    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3164  #endif  #endif
3165  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));
3166  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3167    #if defined COMPILE_PCRE8
3168  if (common->utf)  if (common->utf)
3169    {    {
3170    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3171    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);
3172    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3173    }    }
3174  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3175  if (common->utf)  if (common->utf)
3176    {    {
3177    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3178    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3179    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);
3180    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3181    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3182    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3183    }    }
3184  #endif  #endif /* COMPILE_PCRE[8|16] */
3185    #endif /* SUPPORT_UTF */
3186  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3187  JUMPHERE(found);  if (found != NULL)
3188  JUMPHERE(leave);    JUMPHERE(found);
3189    if (matches != NULL)
3190      set_jumps(matches, LABEL());
3191    JUMPHERE(quit);
3192    
3193  if (firstline)  if (firstline)
3194    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
3195  }  }
3196    
3197  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar req_char, BOOL caseless, BOOL has_firstchar)  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar req_char, BOOL caseless, BOOL has_firstchar)
# Line 2324  struct sljit_jump *alreadyfound; Line 3203  struct sljit_jump *alreadyfound;
3203  struct sljit_jump *found;  struct sljit_jump *found;
3204  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3205  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3206  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3207    
3208  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3209  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
# Line 2355  if (req_char == oc) Line 3234  if (req_char == oc)
3234  else  else
3235    {    {
3236    bit = req_char ^ oc;    bit = req_char ^ oc;
3237    if (ispowerof2(bit))    if (is_powerof2(bit))
3238      {      {
3239      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3240      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
# Line 2384  DEFINE_COMPILER; Line 3263  DEFINE_COMPILER;
3263  struct sljit_jump *jump;  struct sljit_jump *jump;
3264  struct sljit_label *mainloop;  struct sljit_label *mainloop;
3265    
3266  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3267  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);
3268    GET_LOCAL_BASE(TMP3, 0, 0);
3269    
3270  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3271  mainloop = LABEL();  mainloop = LABEL();
3272  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3273  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);
3274  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_LOCALS_REG, 0);  jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3275  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
3276  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3277  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3278    OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
3279    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
3280  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3281    
3282  JUMPHERE(jump);  JUMPHERE(jump);
3283  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3284  /* End of dropping frames. */  /* End of dropping frames. */
3285  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3286    
3287  JUMPHERE(jump);  JUMPHERE(jump);
3288  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3289  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3290  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3291  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));  
3292  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3293  }  }
3294    
# Line 2431  static void check_wordboundary(compiler_ Line 3296  static void check_wordboundary(compiler_
3296  {  {
3297  DEFINE_COMPILER;  DEFINE_COMPILER;
3298  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3299    jump_list *skipread_list = NULL;
3300  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3301  struct sljit_jump *jump;  struct sljit_jump *jump;
3302  #endif  #endif
3303    
3304  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
3305    
3306  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3307  /* Get type of the previous char, and put it to LOCALS1. */  /* Get type of the previous char, and put it to LOCALS1. */
3308  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
3309  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
# Line 2456  if (common->use_ucp) Line 3322  if (common->use_ucp)
3322    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3323    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3324    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);
3325    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3326    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);
3327    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);
3328    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3329    JUMPHERE(jump);    JUMPHERE(jump);
3330    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3331    }    }
# Line 2488  else Line 3354  else
3354  JUMPHERE(skipread);  JUMPHERE(skipread);
3355    
3356  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3357  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3358  peek_char(common);  peek_char(common);
3359    
3360  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 2500  if (common->use_ucp) Line 3366  if (common->use_ucp)
3366    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3367    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3368    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);
3369    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3370    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);
3371    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);
3372    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3373    JUMPHERE(jump);    JUMPHERE(jump);
3374    }    }
3375  else  else
# Line 2529  else Line 3395  else
3395      JUMPHERE(jump);      JUMPHERE(jump);
3396  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3397    }    }
3398  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3399    
3400  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);
3401  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3402  }  }
3403    
3404    /*
3405      range format:
3406    
3407      ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).
3408      ranges[1] = first bit (0 or 1)
3409      ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)
3410    */
3411    
3412    static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3413    {
3414    DEFINE_COMPILER;
3415    struct sljit_jump *jump;
3416    
3417    if (ranges[0] < 0)
3418      return FALSE;
3419    
3420    switch(ranges[0])
3421      {
3422      case 1:
3423      if (readch)
3424        read_char(common);
3425      add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3426      return TRUE;
3427    
3428      case 2:
3429      if (readch)
3430        read_char(common);
3431      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3432      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3433      return TRUE;
3434    
3435      case 4:
3436      if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])
3437        {
3438        if (readch)
3439          read_char(common);
3440        if (ranges[1] != 0)
3441          {
3442          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3443          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3444          }
3445        else
3446          {
3447          jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);
3448          add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3449          JUMPHERE(jump);
3450          }
3451        return TRUE;
3452        }
3453      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))
3454        {
3455        if (readch)
3456          read_char(common);
3457        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3458        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3459        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3460        return TRUE;
3461        }
3462      return FALSE;
3463    
3464      default:
3465      return FALSE;
3466      }
3467    }
3468    
3469    static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)
3470    {
3471    int i, bit, length;
3472    const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;
3473    
3474    bit = ctypes[0] & flag;
3475    ranges[0] = -1;
3476    ranges[1] = bit != 0 ? 1 : 0;
3477    length = 0;
3478    
3479    for (i = 1; i < 256; i++)
3480      if ((ctypes[i] & flag) != bit)
3481        {
3482        if (length >= MAX_RANGE_SIZE)
3483          return;
3484        ranges[2 + length] = i;
3485        length++;
3486        bit ^= flag;
3487        }
3488    
3489    if (bit != 0)
3490      {
3491      if (length >= MAX_RANGE_SIZE)
3492        return;
3493      ranges[2 + length] = 256;
3494      length++;
3495      }
3496    ranges[0] = length;
3497    }
3498    
3499    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)
3500    {
3501    int ranges[2 + MAX_RANGE_SIZE];
3502    pcre_uint8 bit, cbit, all;
3503    int i, byte, length = 0;
3504    
3505    bit = bits[0] & 0x1;
3506    ranges[1] = bit;
3507    /* Can be 0 or 255. */
3508    all = -bit;
3509    
3510    for (i = 0; i < 256; )
3511      {
3512      byte = i >> 3;
3513      if ((i & 0x7) == 0 && bits[byte] == all)
3514        i += 8;
3515      else
3516        {
3517        cbit = (bits[byte] >> (i & 0x7)) & 0x1;
3518        if (cbit != bit)
3519          {
3520          if (length >= MAX_RANGE_SIZE)
3521            return FALSE;
3522          ranges[2 + length] = i;
3523          length++;
3524          bit = cbit;
3525          all = -cbit;
3526          }
3527        i++;
3528        }
3529      }
3530    
3531    if (((bit == 0) && nclass) || ((bit == 1) && !nclass))
3532      {
3533      if (length >= MAX_RANGE_SIZE)
3534        return FALSE;
3535      ranges[2 + length] = 256;
3536      length++;
3537      }
3538    ranges[0] = length;
3539    
3540    return check_ranges(common, ranges, backtracks, FALSE);
3541    }
3542    
3543  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
3544  {  {
3545  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3546  DEFINE_COMPILER;  DEFINE_COMPILER;
3547    
3548  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3549    
3550  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3551  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);
3552  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3553  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);
3554  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3555  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3556  if (common->utf)  if (common->utf)
3557    {    {
3558  #endif  #endif
3559    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3560    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3561    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);
3562  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3563    }    }
3564  #endif  #endif
3565  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3566  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);
3567  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3568  }  }
3569    
# Line 2567  static void check_hspace(compiler_common Line 3572  static void check_hspace(compiler_common
3572  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3573  DEFINE_COMPILER;  DEFINE_COMPILER;
3574    
3575  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3576    
3577  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);
3578  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3579  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);
3580  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3581  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);
3582  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3583  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3584  if (common->utf)  if (common->utf)
3585    {    {
3586  #endif  #endif
3587    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3588    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);
3589    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3590    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);
3591    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3592    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3593    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);
3594    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3595    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);
3596    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3597    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);
3598    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3599    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);
3600  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3601    }    }
3602  #endif  #endif
3603  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3604  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);
3605    
3606  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3607  }  }
# Line 2606  static void check_vspace(compiler_common Line 3611  static void check_vspace(compiler_common
3611  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3612  DEFINE_COMPILER;  DEFINE_COMPILER;
3613    
3614  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3615    
3616  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3617  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);
3618  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3619  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);
3620  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3621  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3622  if (common->utf)  if (common->utf)
3623    {    {
3624  #endif  #endif
3625    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);
3626    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3627    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);
3628  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3629    }    }
3630  #endif  #endif
3631  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3632  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);
3633    
3634  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3635  }  }
# Line 2638  DEFINE_COMPILER; Line 3643  DEFINE_COMPILER;
3643  struct sljit_jump *jump;  struct sljit_jump *jump;
3644  struct sljit_label *label;  struct sljit_label *label;
3645    
3646  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3647  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3648  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);
3649  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);
# Line 2667  DEFINE_COMPILER; Line 3672  DEFINE_COMPILER;
3672  struct sljit_jump *jump;  struct sljit_jump *jump;
3673  struct sljit_label *label;  struct sljit_label *label;
3674    
3675  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3676  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3677    
3678  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);
# Line 2710  sljit_emit_fast_return(compiler, RETURN_ Line 3715  sljit_emit_fast_return(compiler, RETURN_
3715    
3716  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3717    
3718  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)
3719  {  {
3720  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3721  int c1, c2;  pcre_uint32 c1, c2;
3722  const pcre_uchar *src2 = args->uchar_ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3723  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
3724    const ucd_record *ur;
3725    const pcre_uint32 *pp;
3726    
3727  while (src1 < end1)  while (src1 < end1)
3728    {    {
# Line 2723  while (src1 < end1) Line 3730  while (src1 < end1)
3730      return (pcre_uchar*)1;      return (pcre_uchar*)1;
3731    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3732    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3733    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return NULL;    ur = GET_UCD(c2);
3734      if (c1 != c2 && c1 != c2 + ur->other_case)
3735        {
3736        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3737        for (;;)
3738          {
3739          if (c1 < *pp) return NULL;
3740          if (c1 == *pp++) break;
3741          }
3742        }
3743    }    }
3744  return src2;  return src2;
3745  }  }
# Line 2731  return src2; Line 3747  return src2;
3747  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
3748    
3749  static pcre_uchar *byte_sequence_compare(compiler_common *common, BOOL caseless, pcre_uchar *cc,  static pcre_uchar *byte_sequence_compare(compiler_common *common, BOOL caseless, pcre_uchar *cc,
3750      compare_context* context, jump_list **fallbacks)      compare_context* context, jump_list **backtracks)
3751  {  {
3752  DEFINE_COMPILER;  DEFINE_COMPILER;
3753  unsigned int othercasebit = 0;  unsigned int othercasebit = 0;
# Line 2745  if (caseless && char_has_othercase(commo Line 3761  if (caseless && char_has_othercase(commo
3761    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3762    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3763    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3764  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3765    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3766    othercasebit &= 0xff;    othercasebit &= 0xff;
3767  #else  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3768  #ifdef COMPILE_PCRE16    /* Note that this code only handles characters in the BMP. If there
3769      ever are characters outside the BMP whose othercase differs in only one
3770      bit from itself (there currently are none), this code will need to be
3771      revised for COMPILE_PCRE32. */
3772    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3773    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3774      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
3775    else    else
3776      othercasebit &= 0xff;      othercasebit &= 0xff;
3777  #endif  #endif /* COMPILE_PCRE[8|16|32] */
 #endif  
3778    }    }
3779    
3780  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3781    {    {
3782  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3783  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3784    if (context->length >= 4)    if (context->length >= 4)
3785      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
# Line 2770  if (context->sourcereg == -1) Line 3788  if (context->sourcereg == -1)
3788    else    else
3789  #endif  #endif
3790      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3791  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
3792  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3793    if (context->length >= 4)    if (context->length >= 4)
3794      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3795    else    else
3796  #endif  #endif
3797      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3798  #endif  #elif defined COMPILE_PCRE32
3799  #endif /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3800    #endif /* COMPILE_PCRE[8|16|32] */
3801    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3802    }    }
3803    
# Line 2793  do Line 3811  do
3811  #endif  #endif
3812    
3813    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3814  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3815    
3816    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3817    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 2808  do Line 3826  do
3826      }      }
3827    context->ucharptr++;    context->ucharptr++;
3828    
3829  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3830    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))
3831  #else  #else
3832    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
# Line 2816  do Line 3834  do
3834      {      {
3835      if (context->length >= 4)      if (context->length >= 4)
3836        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  
3837      else if (context->length >= 2)      else if (context->length >= 2)
3838        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);
3839    #if defined COMPILE_PCRE8
3840      else if (context->length >= 1)      else if (context->length >= 1)
3841        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);
3842  #else  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3843      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3844    
3845      switch(context->ucharptr)      switch(context->ucharptr)
# Line 2832  do Line 3847  do
3847        case 4 / sizeof(pcre_uchar):        case 4 / sizeof(pcre_uchar):
3848        if (context->oc.asint != 0)        if (context->oc.asint != 0)
3849          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asint);          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asint);
3850        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asint | context->oc.asint));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asint | context->oc.asint));
3851        break;        break;
3852    
3853        case 2 / sizeof(pcre_uchar):        case 2 / sizeof(pcre_uchar):
3854        if (context->oc.asushort != 0)        if (context->oc.asushort != 0)
3855          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);
3856        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asushort | context->oc.asushort));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asushort | context->oc.asushort));
3857        break;        break;
3858    
3859  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3860        case 1:        case 1:
3861        if (context->oc.asbyte != 0)        if (context->oc.asbyte != 0)
3862          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asbyte);          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asbyte);
3863        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asbyte | context->oc.asbyte));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asbyte | context->oc.asbyte));
3864        break;        break;
3865  #endif  #endif
3866    
# Line 2858  do Line 3873  do
3873    
3874  #else  #else
3875    
3876    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3877  #ifdef COMPILE_PCRE8    if (context->length >= 1)
3878    if (context->length > 0)      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3879      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  
3880    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3881    
3882    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
3883      {      {
3884      OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, othercasebit);      OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, othercasebit);
3885      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc | othercasebit));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc | othercasebit));
3886      }      }
3887    else    else
3888      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc));
3889    
3890  #endif  #endif
3891    
# Line 2910  return cc; Line 3921  return cc;
3921      } \      } \
3922    charoffset = (value);    charoffset = (value);
3923    
3924  static void compile_xclass_hotpath(compiler_common *common, pcre_uchar *cc, jump_list **fallbacks)  static void compile_xclass_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)
3925  {  {
3926  DEFINE_COMPILER;  DEFINE_COMPILER;
3927  jump_list *found = NULL;  jump_list *found = NULL;
3928  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : fallbacks;  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;
3929  unsigned int c;  pcre_int32 c, charoffset;
3930  int compares;  const pcre_uint32 *other_cases;
3931  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
3932  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
3933    int compares, invertcmp, numberofcmps;
3934  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3935  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
3936  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
3937  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
3938  unsigned int typeoffset;  pcre_int32 typeoffset;
3939  #endif  #endif
 int invertcmp, numberofcmps;  
 unsigned int charoffset;  
3940    
3941  /* Although SUPPORT_UTF must be defined, we are not necessary in utf mode. */  /* Although SUPPORT_UTF must be defined, we are
3942  fallback_at_str_end(common, fallbacks);     not necessary in utf mode even in 8 bit mode. */
3943    detect_partial_match(common, backtracks);
3944  read_char(common);  read_char(common);
3945    
3946  if ((*cc++ & XCL_MAP) != 0)  if ((*cc++ & XCL_MAP) != 0)
# Line 2942  if ((*cc++ & XCL_MAP) != 0) Line 3953  if ((*cc++ & XCL_MAP) != 0)
3953      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3954  #endif  #endif
3955    
3956    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, list))
3957    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      {
3958    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3959    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3960    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
3961    add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3962        OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
3963        add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
3964        }
3965    
3966  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3967    JUMPHERE(jump);    JUMPHERE(jump);
# Line 3020  while (*cc != XCL_END) Line 4034  while (*cc != XCL_END)
4034        needschar = TRUE;        needschar = TRUE;
4035        break;        break;
4036    
4037          case PT_CLIST:
4038          case PT_UCNC:
4039          needschar = TRUE;
4040          break;
4041    
4042        default:        default:
4043        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
4044        break;        break;
# Line 3056  if (needstype || needsscript) Line 4075  if (needstype || needsscript)
4075      {      {
4076      if (scriptreg == TMP1)      if (scriptreg == TMP1)
4077        {        {
4078        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));
4079        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
4080        }        }
4081      else      else
4082        {        {
4083        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
4084        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));
4085        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
4086        }        }
4087      }      }
# Line 3080  typeoffset = 0; Line 4099  typeoffset = 0;
4099  while (*cc != XCL_END)  while (*cc != XCL_END)
4100    {    {
4101    compares--;    compares--;
4102    invertcmp = (compares == 0 && list != fallbacks);    invertcmp = (compares == 0 && list != backtracks);
4103    jump = NULL;    jump = NULL;
4104    
4105    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
# Line 3098  while (*cc != XCL_END) Line 4117  while (*cc != XCL_END)
4117      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4118        {        {
4119        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);
4120        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);
4121        numberofcmps++;        numberofcmps++;
4122        }        }
4123      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4124        {        {
4125        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);
4126        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);
4127        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4128        numberofcmps = 0;        numberofcmps = 0;
4129        }        }
# Line 3137  while (*cc != XCL_END) Line 4156  while (*cc != XCL_END)
4156      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4157        {        {
4158        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);
4159        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);
4160        numberofcmps++;        numberofcmps++;
4161        }        }
4162      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4163        {        {
4164        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);
4165        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);</