/[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 915 by zherczeg, Tue Feb 14 13:05:39 2012 UTC revision 1268 by zherczeg, Mon Mar 4 08:42:15 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    /* Allocate memory for the regex stack on the real machine stack.
75    Fast, but limited size. */
76    #define MACHINE_STACK_SIZE 32768
77    
78    /* Growth rate for stack allocated by the OS. Should be the multiply
79    of page size. */
80  #define STACK_GROWTH_RATE 8192  #define STACK_GROWTH_RATE 8192
81    
82  /* 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 91  The code generator follows the recursive
91  expressions. The basic blocks of regular expressions are condition checkers  expressions. The basic blocks of regular expressions are condition checkers
92  whose execute different commands depending on the result of the condition check.  whose execute different commands depending on the result of the condition check.
93  The relationship between the operators can be horizontal (concatenation) and  The relationship between the operators can be horizontal (concatenation) and
94  vertical (sub-expression) (See struct fallback_common for more details).  vertical (sub-expression) (See struct backtrack_common for more details).
95    
96    'ab' - 'a' and 'b' regexps are concatenated    'ab' - 'a' and 'b' regexps are concatenated
97    'a+' - 'a' is the sub-expression of the '+' operator    'a+' - 'a' is the sub-expression of the '+' operator
98    
99  The condition checkers are boolean (true/false) checkers. Machine code is generated  The condition checkers are boolean (true/false) checkers. Machine code is generated
100  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.
101  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
102  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
103  branches on the hot path.  branches on the matching path.
104    
105   Greedy star operator (*) :   Greedy star operator (*) :
106     Hot path: match happens.     Matching path: match happens.
107     Fallback path: match failed.     Backtrack path: match failed.
108   Non-greedy star operator (*?) :   Non-greedy star operator (*?) :
109     Hot path: no need to perform a match.     Matching path: no need to perform a match.
110     Fallback path: match is required.     Backtrack path: match is required.
111    
112  The following example shows how the code generated for a capturing bracket  The following example shows how the code generated for a capturing bracket
113  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 117  we have the following regular expression
117    
118  The generated code will be the following:  The generated code will be the following:
119    
120   A hot path   A matching path
121   '(' hot path (pushing arguments to the stack)   '(' matching path (pushing arguments to the stack)
122   B hot path   B matching path
123   ')' hot path (pushing arguments to the stack)   ')' matching path (pushing arguments to the stack)
124   D hot path   D matching path
125   return with successful match   return with successful match
126    
127   D fallback path   D backtrack path
128   ')' 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")
129   B fallback path   B backtrack path
130   C expected path   C expected path
131   jump to D hot path   jump to D matching path
132   C fallback path   C backtrack path
133   A fallback path   A backtrack path
134    
135   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
136   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
137   to the current fallback code path. The fallback code path must check   to the current backtrack code path. The backtrack path must check
138   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
139   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
140   frame and continue the execution on the fallback code paths.   frame and continue the execution on the backtrack code paths.
141  */  */
142    
143  /*  /*
144  Saved stack frames:  Saved stack frames:
145    
146  Atomic blocks and asserts require reloading the values of local variables  Atomic blocks and asserts require reloading the values of private data
147  when the fallback mechanism performed. Because of OP_RECURSE, the locals  when the backtrack mechanism performed. Because of OP_RECURSE, the data
148  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
149  mechanism.  mechanism.
150    
151  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:
152  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]
153    
154  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.
155  */  */
156    
157  typedef struct jit_arguments {  typedef struct jit_arguments {
# Line 152  typedef struct jit_arguments { Line 161  typedef struct jit_arguments {
161    const pcre_uchar *begin;    const pcre_uchar *begin;
162    const pcre_uchar *end;    const pcre_uchar *end;
163    int *offsets;    int *offsets;
164    pcre_uchar *ptr;    pcre_uchar *uchar_ptr;
165      pcre_uchar *mark_ptr;
166      void *callout_data;
167    /* Everything else after. */    /* Everything else after. */
168    int offsetcount;    int real_offset_count;
169    int calllimit;    int offset_count;
170      int call_limit;
171    pcre_uint8 notbol;    pcre_uint8 notbol;
172    pcre_uint8 noteol;    pcre_uint8 noteol;
173    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 166  typedef struct executable_functions { Line 178  typedef struct executable_functions {
178    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
179    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
180    void *userdata;    void *userdata;
181      pcre_uint32 top_bracket;
182    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
183  } executable_functions;  } executable_functions;
184    
# Line 174  typedef struct jump_list { Line 187  typedef struct jump_list {
187    struct jump_list *next;    struct jump_list *next;
188  } jump_list;  } jump_list;
189    
 enum stub_types { stack_alloc };  
   
190  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
191    struct sljit_jump *start;    struct sljit_jump *start;
192    struct sljit_label *leave;    struct sljit_label *quit;
193    struct stub_list *next;    struct stub_list *next;
194  } stub_list;  } stub_list;
195    
196    enum frame_types { no_frame = -1, no_stack = -2 };
197    
198  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
199    
200  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
201  code generator. It is allocated by compile_hotpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
202  the aguments for compile_fallbackpath. Must be the first member  the aguments for compile_backtrackingpath. Must be the first member
203  of its descendants. */  of its descendants. */
204  typedef struct fallback_common {  typedef struct backtrack_common {
205    /* Concatenation stack. */    /* Concatenation stack. */
206    struct fallback_common *prev;    struct backtrack_common *prev;
207    jump_list *nextfallbacks;    jump_list *nextbacktracks;
208    /* Internal stack (for component operators). */    /* Internal stack (for component operators). */
209    struct fallback_common *top;    struct backtrack_common *top;
210    jump_list *topfallbacks;    jump_list *topbacktracks;
211    /* Opcode pointer. */    /* Opcode pointer. */
212    pcre_uchar *cc;    pcre_uchar *cc;
213  } fallback_common;  } backtrack_common;
214    
215  typedef struct assert_fallback {  typedef struct assert_backtrack {
216    fallback_common common;    backtrack_common common;
217    jump_list *condfailed;    jump_list *condfailed;
218    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 (-1) if a frame is not needed. */
219    int framesize;    int framesize;
220    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
221    int localptr;    int private_data_ptr;
222    /* For iterators. */    /* For iterators. */
223    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
224  } assert_fallback;  } assert_backtrack;
225    
226  typedef struct bracket_fallback {  typedef struct bracket_backtrack {
227    fallback_common common;    backtrack_common common;
228    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
229    struct sljit_label *althotpath;    struct sljit_label *alternative_matchingpath;
230    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
231    struct sljit_label *recursivehotpath;    struct sljit_label *recursive_matchingpath;
232    /* For greedy ? operator. */    /* For greedy ? operator. */
233    struct sljit_label *zerohotpath;    struct sljit_label *zero_matchingpath;
234    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
235    union {    union {
236      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
237      jump_list *condfailed;      jump_list *condfailed;
238      assert_fallback *assert;      assert_backtrack *assert;
239      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. -1 if not needed. */
240      int framesize;      int framesize;
241    } u;    } u;
242    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
243    int localptr;    int private_data_ptr;
244  } bracket_fallback;  } bracket_backtrack;
245    
246  typedef struct bracketpos_fallback {  typedef struct bracketpos_backtrack {
247    fallback_common common;    backtrack_common common;
248    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
249    int localptr;    int private_data_ptr;
250    /* Reverting stack is needed. */    /* Reverting stack is needed. */
251    int framesize;    int framesize;
252    /* Allocated stack size. */    /* Allocated stack size. */
253    int stacksize;    int stacksize;
254  } bracketpos_fallback;  } bracketpos_backtrack;
255    
256  typedef struct braminzero_fallback {  typedef struct braminzero_backtrack {
257    fallback_common common;    backtrack_common common;
258    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
259  } braminzero_fallback;  } braminzero_backtrack;
260    
261  typedef struct iterator_fallback {  typedef struct iterator_backtrack {
262    fallback_common common;    backtrack_common common;
263    /* Next iteration. */    /* Next iteration. */
264    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
265  } iterator_fallback;  } iterator_backtrack;
266    
267  typedef struct recurse_entry {  typedef struct recurse_entry {
268    struct recurse_entry *next;    struct recurse_entry *next;
# Line 263  typedef struct recurse_entry { Line 274  typedef struct recurse_entry {
274    int start;    int start;
275  } recurse_entry;  } recurse_entry;
276    
277  typedef struct recurse_fallback {  typedef struct recurse_backtrack {
278    fallback_common common;    backtrack_common common;
279  } recurse_fallback;    BOOL inlined_pattern;
280    } recurse_backtrack;
281    
282    #define MAX_RANGE_SIZE 6
283    
284  typedef struct compiler_common {  typedef struct compiler_common {
285    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
286    pcre_uchar *start;    pcre_uchar *start;
287    int localsize;  
288    int *localptrs;    /* Maps private data offset to each opcode. */
289    const pcre_uint8 *fcc;    int *private_data_ptrs;
290    sljit_w lcc;    /* Tells whether the capturing bracket is optimized. */
291      pcre_uint8 *optimized_cbracket;
292      /* Starting offset of private data for capturing brackets. */
293    int cbraptr;    int cbraptr;
294      /* OVector starting point. Must be divisible by 2. */
295      int ovector_start;
296      /* Last known position of the requested byte. */
297      int req_char_ptr;
298      /* Head of the last recursion. */
299      int recursive_head_ptr;
300      /* First inspected character for partial matching. */
301      int start_used_ptr;
302      /* Starting pointer for partial soft matches. */
303      int hit_start;
304      /* End pointer of the first line. */
305      int first_line_end;
306      /* Points to the marked string. */
307      int mark_ptr;
308      /* Points to the last matched capture block index. */
309      int capture_last_ptr;
310    
311      /* Flipped and lower case tables. */
312      const pcre_uint8 *fcc;
313      sljit_sw lcc;
314      /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
315    int mode;    int mode;
316      /* Newline control. */
317    int nltype;    int nltype;
318    int newline;    int newline;
319    int bsr_nltype;    int bsr_nltype;
320      /* Dollar endonly. */
321    int endonly;    int endonly;
322    sljit_w ctypes;    BOOL has_set_som;
323      /* Tables. */
324      sljit_sw ctypes;
325      int digits[2 + MAX_RANGE_SIZE];
326      /* Named capturing brackets. */
327    sljit_uw name_table;    sljit_uw name_table;
328    sljit_w name_count;    sljit_sw name_count;
329    sljit_w name_entry_size;    sljit_sw name_entry_size;
330    
331      /* Labels and jump lists. */
332    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
333    struct sljit_label *acceptlabel;    struct sljit_label *quit_label;
334      struct sljit_label *forced_quit_label;
335      struct sljit_label *accept_label;
336    stub_list *stubs;    stub_list *stubs;
337    recurse_entry *entries;    recurse_entry *entries;
338    recurse_entry *currententry;    recurse_entry *currententry;
339    jump_list *partialmatch;    jump_list *partialmatch;
340      jump_list *quit;
341      jump_list *forced_quit;
342    jump_list *accept;    jump_list *accept;
343    jump_list *calllimit;    jump_list *calllimit;
344    jump_list *stackalloc;    jump_list *stackalloc;
# Line 306  typedef struct compiler_common { Line 355  typedef struct compiler_common {
355  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
356    BOOL use_ucp;    BOOL use_ucp;
357  #endif  #endif
358    #ifndef COMPILE_PCRE32
359    jump_list *utfreadchar;    jump_list *utfreadchar;
360    #endif
361  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
362    jump_list *utfreadtype8;    jump_list *utfreadtype8;
363  #endif  #endif
# Line 324  typedef struct compare_context { Line 375  typedef struct compare_context {
375  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
376    int ucharptr;    int ucharptr;
377    union {    union {
378      sljit_i asint;      sljit_si asint;
379      sljit_uh asushort;      sljit_uh asushort;
380  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
381      sljit_ub asbyte;      sljit_ub asbyte;
382      sljit_ub asuchars[4];      sljit_ub asuchars[4];
383  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
384      sljit_uh asuchars[2];      sljit_uh asuchars[2];
385  #endif  #elif defined COMPILE_PCRE32
386        sljit_ui asuchars[1];
387  #endif  #endif
388    } c;    } c;
389    union {    union {
390      sljit_i asint;      sljit_si asint;
391      sljit_uh asushort;      sljit_uh asushort;
392  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
393      sljit_ub asbyte;      sljit_ub asbyte;
394      sljit_ub asuchars[4];      sljit_ub asuchars[4];
395  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
396      sljit_uh asuchars[2];      sljit_uh asuchars[2];
397  #endif  #elif defined COMPILE_PCRE32
398        sljit_ui asuchars[1];
399  #endif  #endif
400    } oc;    } oc;
401  #endif  #endif
402  } compare_context;  } compare_context;
403    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1  
 };  
   
404  /* Undefine sljit macros. */  /* Undefine sljit macros. */
405  #undef CMP  #undef CMP
406    
407  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
408  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
409    
410  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
411  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
412  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
413  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
414  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
415  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
416  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
417  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
418  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
419  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
420    
421  /* Locals layout. */  /* Local space layout. */
422  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
423  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
424  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
425  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
426  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
427  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
 /* Head of the last recursion. */  
 #define RECURSIVE_HEAD   (4 * sizeof(sljit_w))  
428  /* Max limit of recursions. */  /* Max limit of recursions. */
429  #define CALL_LIMIT       (5 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
 /* Last known position of the requested byte.  
 Same as START_USED_PTR. (Partial matching and req_char are exclusive) */  
 #define REQ_CHAR_PTR     (6 * sizeof(sljit_w))  
 /* First inspected character for partial matching.  
 Same as REQ_CHAR_PTR. (Partial matching and req_char are exclusive) */  
 #define START_USED_PTR   (6 * sizeof(sljit_w))  
 /* Starting pointer for partial soft matches. */  
 #define HIT_START        (8 * sizeof(sljit_w))  
 /* End pointer of the first line. */  
 #define FIRSTLINE_END    (9 * sizeof(sljit_w))  
430  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
431  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
432  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
433  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. */
434  #define OVECTOR_START    (10 * sizeof(sljit_w))  #define OVECTOR_START    (common->ovector_start)
435  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
436  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_sw))
437  #define PRIV_DATA(cc)    (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
438    
439  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
440  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
441  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
442  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
443  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
444  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
445    #elif defined COMPILE_PCRE32
446    #define MOV_UCHAR  SLJIT_MOV_UI
447    #define MOVU_UCHAR SLJIT_MOVU_UI
448  #else  #else
449  #error Unsupported compiling mode  #error Unsupported compiling mode
450  #endif  #endif
 #endif  
451    
452  /* Shortcuts. */  /* Shortcuts. */
453  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 429  the start pointers when the end of the c Line 464  the start pointers when the end of the c
464    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
465  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
466    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
467    #define SET_LABEL(jump, label) \
468      sljit_set_label((jump), (label))
469  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
470    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
471  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
472    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))
473  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
474    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
475    #define GET_LOCAL_BASE(dst, dstw, offset) \
476      sljit_get_local_base(compiler, (dst), (dstw), (offset))
477    
478  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
479  {  {
# Line 447  return cc; Line 486  return cc;
486    
487  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
488   next_opcode   next_opcode
489   get_localspace   get_private_data_length
490   set_localptrs   set_private_data_ptrs
491   get_framesize   get_framesize
492   init_frame   init_frame
493   get_localsize   get_private_data_length_for_copy
494   copy_locals   copy_private_data
495   compile_hotpath   compile_matchingpath
496   compile_fallbackpath   compile_backtrackingpath
497  */  */
498    
499  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
# Line 475  switch(*cc) Line 514  switch(*cc)
514    case OP_WORDCHAR:    case OP_WORDCHAR:
515    case OP_ANY:    case OP_ANY:
516    case OP_ALLANY:    case OP_ALLANY:
517      case OP_NOTPROP:
518      case OP_PROP:
519    case OP_ANYNL:    case OP_ANYNL:
520    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
521    case OP_HSPACE:    case OP_HSPACE:
# Line 487  switch(*cc) Line 528  switch(*cc)
528    case OP_CIRCM:    case OP_CIRCM:
529    case OP_DOLL:    case OP_DOLL:
530    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:  
531    case OP_CRSTAR:    case OP_CRSTAR:
532    case OP_CRMINSTAR:    case OP_CRMINSTAR:
533    case OP_CRPLUS:    case OP_CRPLUS:
534    case OP_CRMINPLUS:    case OP_CRMINPLUS:
535    case OP_CRQUERY:    case OP_CRQUERY:
536    case OP_CRMINQUERY:    case OP_CRMINQUERY:
537      case OP_CRRANGE:
538      case OP_CRMINRANGE:
539      case OP_CLASS:
540      case OP_NCLASS:
541      case OP_REF:
542      case OP_REFI:
543      case OP_RECURSE:
544      case OP_CALLOUT:
545      case OP_ALT:
546      case OP_KET:
547      case OP_KETRMAX:
548      case OP_KETRMIN:
549      case OP_KETRPOS:
550      case OP_REVERSE:
551      case OP_ASSERT:
552      case OP_ASSERT_NOT:
553      case OP_ASSERTBACK:
554      case OP_ASSERTBACK_NOT:
555      case OP_ONCE:
556      case OP_ONCE_NC:
557      case OP_BRA:
558      case OP_BRAPOS:
559      case OP_CBRA:
560      case OP_CBRAPOS:
561      case OP_COND:
562      case OP_SBRA:
563      case OP_SBRAPOS:
564      case OP_SCBRA:
565      case OP_SCBRAPOS:
566      case OP_SCOND:
567      case OP_CREF:
568      case OP_NCREF:
569      case OP_RREF:
570      case OP_NRREF:
571    case OP_DEF:    case OP_DEF:
572    case OP_BRAZERO:    case OP_BRAZERO:
573    case OP_BRAMINZERO:    case OP_BRAMINZERO:
574    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
575      case OP_COMMIT:
576    case OP_FAIL:    case OP_FAIL:
577    case OP_ACCEPT:    case OP_ACCEPT:
578    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
579      case OP_CLOSE:
580    case OP_SKIPZERO:    case OP_SKIPZERO:
581    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
582    
583    case OP_CHAR:    case OP_CHAR:
584    case OP_CHARI:    case OP_CHARI:
# Line 528  switch(*cc) Line 590  switch(*cc)
590    case OP_MINPLUS:    case OP_MINPLUS:
591    case OP_QUERY:    case OP_QUERY:
592    case OP_MINQUERY:    case OP_MINQUERY:
593      case OP_UPTO:
594      case OP_MINUPTO:
595      case OP_EXACT:
596    case OP_POSSTAR:    case OP_POSSTAR:
597    case OP_POSPLUS:    case OP_POSPLUS:
598    case OP_POSQUERY:    case OP_POSQUERY:
599      case OP_POSUPTO:
600    case OP_STARI:    case OP_STARI:
601    case OP_MINSTARI:    case OP_MINSTARI:
602    case OP_PLUSI:    case OP_PLUSI:
603    case OP_MINPLUSI:    case OP_MINPLUSI:
604    case OP_QUERYI:    case OP_QUERYI:
605    case OP_MINQUERYI:    case OP_MINQUERYI:
606      case OP_UPTOI:
607      case OP_MINUPTOI:
608      case OP_EXACTI:
609    case OP_POSSTARI:    case OP_POSSTARI:
610    case OP_POSPLUSI:    case OP_POSPLUSI:
611    case OP_POSQUERYI:    case OP_POSQUERYI:
612      case OP_POSUPTOI:
613    case OP_NOTSTAR:    case OP_NOTSTAR:
614    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
615    case OP_NOTPLUS:    case OP_NOTPLUS:
616    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
617    case OP_NOTQUERY:    case OP_NOTQUERY:
618    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
619      case OP_NOTUPTO:
620      case OP_NOTMINUPTO:
621      case OP_NOTEXACT:
622    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
623    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
624    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
625      case OP_NOTPOSUPTO:
626    case OP_NOTSTARI:    case OP_NOTSTARI:
627    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
628    case OP_NOTPLUSI:    case OP_NOTPLUSI:
629    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
630    case OP_NOTQUERYI:    case OP_NOTQUERYI:
631    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:  
632    case OP_NOTUPTOI:    case OP_NOTUPTOI:
633    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
634    case OP_NOTEXACTI:    case OP_NOTEXACTI:
635      case OP_NOTPOSSTARI:
636      case OP_NOTPOSPLUSI:
637      case OP_NOTPOSQUERYI:
638    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
639    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
640  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
641    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
642  #endif  #endif
643    return cc;    return cc;
644    
645    case OP_NOTPROP:    /* Special cases. */
646    case OP_PROP:    case OP_TYPESTAR:
647    return cc + 1 + 2;    case OP_TYPEMINSTAR:
648      case OP_TYPEPLUS:
649      case OP_TYPEMINPLUS:
650      case OP_TYPEQUERY:
651      case OP_TYPEMINQUERY:
652    case OP_TYPEUPTO:    case OP_TYPEUPTO:
653    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
654    case OP_TYPEEXACT:    case OP_TYPEEXACT:
655      case OP_TYPEPOSSTAR:
656      case OP_TYPEPOSPLUS:
657      case OP_TYPEPOSQUERY:
658    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
659    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_NCREF:  
   case OP_RREF:  
   case OP_NRREF:  
   case OP_CLOSE:  
   cc += 1 + IMM2_SIZE;  
   return cc;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   return cc + 1 + 2 * IMM2_SIZE;  
660    
661    case OP_CLASS:    case OP_ANYBYTE:
662    case OP_NCLASS:  #ifdef SUPPORT_UTF
663    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
664    #endif
665      return cc + 1;
666    
667  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
668    case OP_XCLASS:    case OP_XCLASS:
669    return cc + GET(cc, 1);    return cc + GET(cc, 1);
670  #endif  #endif
671    
672    case OP_RECURSE:    case OP_MARK:
673    case OP_ASSERT:    return cc + 1 + 2 + cc[1];
   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;  
674    
675    default:    default:
676    return NULL;    return NULL;
677    }    }
678  }  }
679    
680  static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
681        case OP_MINSTAR: \
682        case OP_MINPLUS: \
683        case OP_QUERY: \
684        case OP_MINQUERY: \
685        case OP_MINSTARI: \
686        case OP_MINPLUSI: \
687        case OP_QUERYI: \
688        case OP_MINQUERYI: \
689        case OP_NOTMINSTAR: \
690        case OP_NOTMINPLUS: \
691        case OP_NOTQUERY: \
692        case OP_NOTMINQUERY: \
693        case OP_NOTMINSTARI: \
694        case OP_NOTMINPLUSI: \
695        case OP_NOTQUERYI: \
696        case OP_NOTMINQUERYI:
697    
698    #define CASE_ITERATOR_PRIVATE_DATA_2A \
699        case OP_STAR: \
700        case OP_PLUS: \
701        case OP_STARI: \
702        case OP_PLUSI: \
703        case OP_NOTSTAR: \
704        case OP_NOTPLUS: \
705        case OP_NOTSTARI: \
706        case OP_NOTPLUSI:
707    
708    #define CASE_ITERATOR_PRIVATE_DATA_2B \
709        case OP_UPTO: \
710        case OP_MINUPTO: \
711        case OP_UPTOI: \
712        case OP_MINUPTOI: \
713        case OP_NOTUPTO: \
714        case OP_NOTMINUPTO: \
715        case OP_NOTUPTOI: \
716        case OP_NOTMINUPTOI:
717    
718    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
719        case OP_TYPEMINSTAR: \
720        case OP_TYPEMINPLUS: \
721        case OP_TYPEQUERY: \
722        case OP_TYPEMINQUERY:
723    
724    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
725        case OP_TYPESTAR: \
726        case OP_TYPEPLUS:
727    
728    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
729        case OP_TYPEUPTO: \
730        case OP_TYPEMINUPTO:
731    
732    static int get_class_iterator_size(pcre_uchar *cc)
733  {  {
734  int localspace = 0;  switch(*cc)
735      {
736      case OP_CRSTAR:
737      case OP_CRPLUS:
738      return 2;
739    
740      case OP_CRMINSTAR:
741      case OP_CRMINPLUS:
742      case OP_CRQUERY:
743      case OP_CRMINQUERY:
744      return 1;
745    
746      case OP_CRRANGE:
747      case OP_CRMINRANGE:
748      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
749        return 0;
750      return 2;
751    
752      default:
753      return 0;
754      }
755    }
756    
757    static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
758    {
759    int private_data_length = 0;
760  pcre_uchar *alternative;  pcre_uchar *alternative;
761    pcre_uchar *name;
762    pcre_uchar *end = NULL;
763    int space, size, i;
764    pcre_uint32 bracketlen;
765    
766  /* 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. */
767  while (cc < ccend)  while (cc < ccend)
768    {    {
769      space = 0;
770      size = 0;
771      bracketlen = 0;
772    switch(*cc)    switch(*cc)
773      {      {
774        case OP_SET_SOM:
775        common->has_set_som = TRUE;
776        cc += 1;
777        break;
778    
779        case OP_REF:
780        case OP_REFI:
781        common->optimized_cbracket[GET2(cc, 1)] = 0;
782        cc += 1 + IMM2_SIZE;
783        break;
784    
785      case OP_ASSERT:      case OP_ASSERT:
786      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
787      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 667  while (cc < ccend) Line 791  while (cc < ccend)
791      case OP_BRAPOS:      case OP_BRAPOS:
792      case OP_SBRA:      case OP_SBRA:
793      case OP_SBRAPOS:      case OP_SBRAPOS:
794      case OP_SCOND:      private_data_length += sizeof(sljit_sw);
795      localspace += sizeof(sljit_w);      bracketlen = 1 + LINK_SIZE;
     cc += 1 + LINK_SIZE;  
796      break;      break;
797    
798      case OP_CBRAPOS:      case OP_CBRAPOS:
799      case OP_SCBRAPOS:      case OP_SCBRAPOS:
800      localspace += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
801      cc += 1 + LINK_SIZE + IMM2_SIZE;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
802        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
803      break;      break;
804    
805      case OP_COND:      case OP_COND:
806      /* Might be a hidden SCOND. */      case OP_SCOND:
807      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
808      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
809        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
810          return -1;
811    
812        if (*cc == OP_COND)
813          {
814          /* Might be a hidden SCOND. */
815          alternative = cc + GET(cc, 1);
816          if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
817            private_data_length += sizeof(sljit_sw);
818          }
819        else
820          private_data_length += sizeof(sljit_sw);
821        bracketlen = 1 + LINK_SIZE;
822        break;
823    
824        case OP_CREF:
825        i = GET2(cc, 1);
826        common->optimized_cbracket[i] = 0;
827        cc += 1 + IMM2_SIZE;
828        break;
829    
830        case OP_NCREF:
831        bracketlen = GET2(cc, 1);
832        name = (pcre_uchar *)common->name_table;
833        alternative = name;
834        for (i = 0; i < common->name_count; i++)
835          {
836          if (GET2(name, 0) == bracketlen) break;
837          name += common->name_entry_size;
838          }
839        SLJIT_ASSERT(i != common->name_count);
840    
841        for (i = 0; i < common->name_count; i++)
842          {
843          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
844            common->optimized_cbracket[GET2(alternative, 0)] = 0;
845          alternative += common->name_entry_size;
846          }
847        bracketlen = 0;
848        cc += 1 + IMM2_SIZE;
849        break;
850    
851        case OP_BRA:
852        bracketlen = 1 + LINK_SIZE;
853        break;
854    
855        case OP_CBRA:
856        case OP_SCBRA:
857        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
858        break;
859    
860        CASE_ITERATOR_PRIVATE_DATA_1
861        space = 1;
862        size = -2;
863        break;
864    
865        CASE_ITERATOR_PRIVATE_DATA_2A
866        space = 2;
867        size = -2;
868        break;
869    
870        CASE_ITERATOR_PRIVATE_DATA_2B
871        space = 2;
872        size = -(2 + IMM2_SIZE);
873        break;
874    
875        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
876        space = 1;
877        size = 1;
878        break;
879    
880        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
881        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
882          space = 2;
883        size = 1;
884        break;
885    
886        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
887        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
888          space = 2;
889        size = 1 + IMM2_SIZE;
890        break;
891    
892        case OP_CLASS:
893        case OP_NCLASS:
894        size += 1 + 32 / sizeof(pcre_uchar);
895        space = get_class_iterator_size(cc + size);
896        break;
897    
898    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
899        case OP_XCLASS:
900        size = GET(cc, 1);
901        space = get_class_iterator_size(cc + size);
902        break;
903    #endif
904    
905        case OP_RECURSE:
906        /* Set its value only once. */
907        if (common->recursive_head_ptr == 0)
908          {
909          common->recursive_head_ptr = common->ovector_start;
910          common->ovector_start += sizeof(sljit_sw);
911          }
912      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
913      break;      break;
914    
915      default:      case OP_CALLOUT:
916      cc = next_opcode(common, cc);      if (common->capture_last_ptr == 0)
917      if (cc == NULL)        {
918        return -1;        common->capture_last_ptr = common->ovector_start;
919      break;        common->ovector_start += sizeof(sljit_sw);
920          }
921        cc += 2 + 2 * LINK_SIZE;
922        break;
923    
924        case OP_MARK:
925        if (common->mark_ptr == 0)
926          {
927          common->mark_ptr = common->ovector_start;
928          common->ovector_start += sizeof(sljit_sw);
929          }
930        cc += 1 + 2 + cc[1];
931        break;
932    
933        default:
934        cc = next_opcode(common, cc);
935        if (cc == NULL)
936          return -1;
937        break;
938        }
939    
940      if (space > 0 && cc >= end)
941        private_data_length += sizeof(sljit_sw) * space;
942    
943      if (size != 0)
944        {
945        if (size < 0)
946          {
947          cc += -size;
948    #ifdef SUPPORT_UTF
949          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
950    #endif
951          }
952        else
953          cc += size;
954        }
955    
956      if (bracketlen != 0)
957        {
958        if (cc >= end)
959          {
960          end = bracketend(cc);
961          if (end[-1 - LINK_SIZE] == OP_KET)
962            end = NULL;
963          }
964        cc += bracketlen;
965      }      }
966    }    }
967  return localspace;  return private_data_length;
968  }  }
969    
970  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)
971  {  {
972  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
973  pcre_uchar *alternative;  pcre_uchar *alternative;
974    pcre_uchar *end = NULL;
975    int space, size, bracketlen;
976    
977  while (cc < ccend)  while (cc < ccend)
978    {    {
979      space = 0;
980      size = 0;
981      bracketlen = 0;
982    switch(*cc)    switch(*cc)
983      {      {
984      case OP_ASSERT:      case OP_ASSERT:
# Line 714  while (cc < ccend) Line 991  while (cc < ccend)
991      case OP_SBRA:      case OP_SBRA:
992      case OP_SBRAPOS:      case OP_SBRAPOS:
993      case OP_SCOND:      case OP_SCOND:
994      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
995      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
996      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
997      break;      break;
998    
999      case OP_CBRAPOS:      case OP_CBRAPOS:
1000      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1001      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1002      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1003      cc += 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1004      break;      break;
1005    
1006      case OP_COND:      case OP_COND:
# Line 731  while (cc < ccend) Line 1008  while (cc < ccend)
1008      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1009      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1010        {        {
1011        common->localptrs[cc - common->start] = localptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1012        localptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1013        }        }
1014      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1015        break;
1016    
1017        case OP_BRA:
1018        bracketlen = 1 + LINK_SIZE;
1019        break;
1020    
1021        case OP_CBRA:
1022        case OP_SCBRA:
1023        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1024        break;
1025    
1026        CASE_ITERATOR_PRIVATE_DATA_1
1027        space = 1;
1028        size = -2;
1029        break;
1030    
1031        CASE_ITERATOR_PRIVATE_DATA_2A
1032        space = 2;
1033        size = -2;
1034        break;
1035    
1036        CASE_ITERATOR_PRIVATE_DATA_2B
1037        space = 2;
1038        size = -(2 + IMM2_SIZE);
1039        break;
1040    
1041        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1042        space = 1;
1043        size = 1;
1044        break;
1045    
1046        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1047        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1048          space = 2;
1049        size = 1;
1050        break;
1051    
1052        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1053        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1054          space = 2;
1055        size = 1 + IMM2_SIZE;
1056        break;
1057    
1058        case OP_CLASS:
1059        case OP_NCLASS:
1060        size += 1 + 32 / sizeof(pcre_uchar);
1061        space = get_class_iterator_size(cc + size);
1062        break;
1063    
1064    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1065        case OP_XCLASS:
1066        size = GET(cc, 1);
1067        space = get_class_iterator_size(cc + size);
1068      break;      break;
1069    #endif
1070    
1071      default:      default:
1072      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1073      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1074      break;      break;
1075      }      }
1076    
1077      if (space > 0 && cc >= end)
1078        {
1079        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1080        private_data_ptr += sizeof(sljit_sw) * space;
1081        }
1082    
1083      if (size != 0)
1084        {
1085        if (size < 0)
1086          {
1087          cc += -size;
1088    #ifdef SUPPORT_UTF
1089          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1090    #endif
1091          }
1092        else
1093          cc += size;
1094        }
1095    
1096      if (bracketlen > 0)
1097        {
1098        if (cc >= end)
1099          {
1100          end = bracketend(cc);
1101          if (end[-1 - LINK_SIZE] == OP_KET)
1102            end = NULL;
1103          }
1104        cc += bracketlen;
1105        }
1106    }    }
1107  }  }
1108    
1109  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1110  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)
1111  {  {
1112  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1113  int length = 0;  int length = 0;
1114  BOOL possessive = FALSE;  int possessive = 0;
1115  BOOL setsom_found = FALSE;  BOOL stack_restore = FALSE;
1116    BOOL setsom_found = recursive;
1117    BOOL setmark_found = recursive;
1118    /* The last capture is a local variable even for recursions. */
1119    BOOL capture_last_found = FALSE;
1120    
1121  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1122    {    {
1123    length = 3;    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1124    possessive = TRUE;    /* This is correct regardless of common->capture_last_ptr. */
1125      capture_last_found = TRUE;
1126    }    }
1127    
1128  cc = next_opcode(common, cc);  cc = next_opcode(common, cc);
# Line 765  while (cc < ccend) Line 1131  while (cc < ccend)
1131    switch(*cc)    switch(*cc)
1132      {      {
1133      case OP_SET_SOM:      case OP_SET_SOM:
1134      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1135        stack_restore = TRUE;
1136      if (!setsom_found)      if (!setsom_found)
1137        {        {
1138        length += 2;        length += 2;
1139        setsom_found = TRUE;        setsom_found = TRUE;
1140        }        }
1141      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      cc += 1;
1142        break;
1143    
1144        case OP_MARK:
1145        SLJIT_ASSERT(common->mark_ptr != 0);
1146        stack_restore = TRUE;
1147        if (!setmark_found)
1148          {
1149          length += 2;
1150          setmark_found = TRUE;
1151          }
1152        cc += 1 + 2 + cc[1];
1153        break;
1154    
1155        case OP_RECURSE:
1156        stack_restore = TRUE;
1157        if (common->has_set_som && !setsom_found)
1158          {
1159          length += 2;
1160          setsom_found = TRUE;
1161          }
1162        if (common->mark_ptr != 0 && !setmark_found)
1163          {
1164          length += 2;
1165          setmark_found = TRUE;
1166          }
1167        if (common->capture_last_ptr != 0 && !capture_last_found)
1168          {
1169          length += 2;
1170          capture_last_found = TRUE;
1171          }
1172        cc += 1 + LINK_SIZE;
1173      break;      break;
1174    
1175      case OP_CBRA:      case OP_CBRA:
1176      case OP_CBRAPOS:      case OP_CBRAPOS:
1177      case OP_SCBRA:      case OP_SCBRA:
1178      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1179        stack_restore = TRUE;
1180        if (common->capture_last_ptr != 0 && !capture_last_found)
1181          {
1182          length += 2;
1183          capture_last_found = TRUE;
1184          }
1185      length += 3;      length += 3;
1186      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1187      break;      break;
1188    
1189      default:      default:
1190        stack_restore = TRUE;
1191        /* Fall through. */
1192    
1193        case OP_NOT_WORD_BOUNDARY:
1194        case OP_WORD_BOUNDARY:
1195        case OP_NOT_DIGIT:
1196        case OP_DIGIT:
1197        case OP_NOT_WHITESPACE:
1198        case OP_WHITESPACE:
1199        case OP_NOT_WORDCHAR:
1200        case OP_WORDCHAR:
1201        case OP_ANY:
1202        case OP_ALLANY:
1203        case OP_ANYBYTE:
1204        case OP_NOTPROP:
1205        case OP_PROP:
1206        case OP_ANYNL:
1207        case OP_NOT_HSPACE:
1208        case OP_HSPACE:
1209        case OP_NOT_VSPACE:
1210        case OP_VSPACE:
1211        case OP_EXTUNI:
1212        case OP_EODN:
1213        case OP_EOD:
1214        case OP_CIRC:
1215        case OP_CIRCM:
1216        case OP_DOLL:
1217        case OP_DOLLM:
1218        case OP_CHAR:
1219        case OP_CHARI:
1220        case OP_NOT:
1221        case OP_NOTI:
1222    
1223        case OP_EXACT:
1224        case OP_POSSTAR:
1225        case OP_POSPLUS:
1226        case OP_POSQUERY:
1227        case OP_POSUPTO:
1228    
1229        case OP_EXACTI:
1230        case OP_POSSTARI:
1231        case OP_POSPLUSI:
1232        case OP_POSQUERYI:
1233        case OP_POSUPTOI:
1234    
1235        case OP_NOTEXACT:
1236        case OP_NOTPOSSTAR:
1237        case OP_NOTPOSPLUS:
1238        case OP_NOTPOSQUERY:
1239        case OP_NOTPOSUPTO:
1240    
1241        case OP_NOTEXACTI:
1242        case OP_NOTPOSSTARI:
1243        case OP_NOTPOSPLUSI:
1244        case OP_NOTPOSQUERYI:
1245        case OP_NOTPOSUPTOI:
1246    
1247        case OP_TYPEEXACT:
1248        case OP_TYPEPOSSTAR:
1249        case OP_TYPEPOSPLUS:
1250        case OP_TYPEPOSQUERY:
1251        case OP_TYPEPOSUPTO:
1252    
1253        case OP_CLASS:
1254        case OP_NCLASS:
1255        case OP_XCLASS:
1256    
1257      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1258      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1259      break;      break;
1260      }      }
1261    
1262  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1263  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1264    return -1;    return stack_restore ? no_frame : no_stack;
1265    
1266  if (length > 0)  if (length > 0)
1267    return length + 1;    return length + 1;
1268  return -1;  return stack_restore ? no_frame : no_stack;
1269  }  }
1270    
1271  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)
1272  {  {
1273  DEFINE_COMPILER;  DEFINE_COMPILER;
1274  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1275  BOOL setsom_found = FALSE;  BOOL setsom_found = recursive;
1276    BOOL setmark_found = recursive;
1277    /* The last capture is a local variable even for recursions. */
1278    BOOL capture_last_found = FALSE;
1279  int offset;  int offset;
1280    
1281  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 816  while (cc < ccend) Line 1290  while (cc < ccend)
1290    switch(*cc)    switch(*cc)
1291      {      {
1292      case OP_SET_SOM:      case OP_SET_SOM:
1293      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1294      if (!setsom_found)      if (!setsom_found)
1295        {        {
1296        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1297        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1298        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1299          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1300          stackpos += (int)sizeof(sljit_sw);
1301          setsom_found = TRUE;
1302          }
1303        cc += 1;
1304        break;
1305    
1306        case OP_MARK:
1307        SLJIT_ASSERT(common->mark_ptr != 0);
1308        if (!setmark_found)
1309          {
1310          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1311          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1312          stackpos += (int)sizeof(sljit_sw);
1313          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1314          stackpos += (int)sizeof(sljit_sw);
1315          setmark_found = TRUE;
1316          }
1317        cc += 1 + 2 + cc[1];
1318        break;
1319    
1320        case OP_RECURSE:
1321        if (common->has_set_som && !setsom_found)
1322          {
1323          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1324          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1325          stackpos += (int)sizeof(sljit_sw);
1326        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1327        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1328        setsom_found = TRUE;        setsom_found = TRUE;
1329        }        }
1330      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      if (common->mark_ptr != 0 && !setmark_found)
1331          {
1332          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1333          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1334          stackpos += (int)sizeof(sljit_sw);
1335          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1336          stackpos += (int)sizeof(sljit_sw);
1337          setmark_found = TRUE;
1338          }
1339        if (common->capture_last_ptr != 0 && !capture_last_found)
1340          {
1341          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1342          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1343          stackpos += (int)sizeof(sljit_sw);
1344          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1345          stackpos += (int)sizeof(sljit_sw);
1346          capture_last_found = TRUE;
1347          }
1348        cc += 1 + LINK_SIZE;
1349      break;      break;
1350    
1351      case OP_CBRA:      case OP_CBRA:
1352      case OP_CBRAPOS:      case OP_CBRAPOS:
1353      case OP_SCBRA:      case OP_SCBRA:
1354      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1355        if (common->capture_last_ptr != 0 && !capture_last_found)
1356          {
1357          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1358          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1359          stackpos += (int)sizeof(sljit_sw);
1360          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1361          stackpos += (int)sizeof(sljit_sw);
1362          capture_last_found = TRUE;
1363          }
1364      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1365      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1366      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1367      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1368      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));
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      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1372      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1373    
1374      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1375      break;      break;
# Line 852  while (cc < ccend) Line 1380  while (cc < ccend)
1380      break;      break;
1381      }      }
1382    
1383  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1384  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1385  }  }
1386    
1387  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)
1388  {  {
1389  int localsize = 2;  int private_data_length = 2;
1390    int size;
1391  pcre_uchar *alternative;  pcre_uchar *alternative;
1392  /* Calculate the sum of the local variables. */  /* Calculate the sum of the private machine words. */
1393  while (cc < ccend)  while (cc < ccend)
1394    {    {
1395      size = 0;
1396    switch(*cc)    switch(*cc)
1397      {      {
1398      case OP_ASSERT:      case OP_ASSERT:
# Line 875  while (cc < ccend) Line 1405  while (cc < ccend)
1405      case OP_SBRA:      case OP_SBRA:
1406      case OP_SBRAPOS:      case OP_SBRAPOS:
1407      case OP_SCOND:      case OP_SCOND:
1408      localsize++;      private_data_length++;
1409      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1410      break;      break;
1411    
1412      case OP_CBRA:      case OP_CBRA:
1413      case OP_SCBRA:      case OP_SCBRA:
1414      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1415          private_data_length++;
1416      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1417      break;      break;
1418    
1419      case OP_CBRAPOS:      case OP_CBRAPOS:
1420      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1421      localsize += 2;      private_data_length += 2;
1422      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1423      break;      break;
1424    
# Line 895  while (cc < ccend) Line 1426  while (cc < ccend)
1426      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1427      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1428      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1429        localsize++;        private_data_length++;
1430      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1431      break;      break;
1432    
1433        CASE_ITERATOR_PRIVATE_DATA_1
1434        if (PRIVATE_DATA(cc))
1435          private_data_length++;
1436        cc += 2;
1437    #ifdef SUPPORT_UTF
1438        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1439    #endif
1440        break;
1441    
1442        CASE_ITERATOR_PRIVATE_DATA_2A
1443        if (PRIVATE_DATA(cc))
1444          private_data_length += 2;
1445        cc += 2;
1446    #ifdef SUPPORT_UTF
1447        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1448    #endif
1449        break;
1450    
1451        CASE_ITERATOR_PRIVATE_DATA_2B
1452        if (PRIVATE_DATA(cc))
1453          private_data_length += 2;
1454        cc += 2 + IMM2_SIZE;
1455    #ifdef SUPPORT_UTF
1456        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1457    #endif
1458        break;
1459    
1460        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1461        if (PRIVATE_DATA(cc))
1462          private_data_length++;
1463        cc += 1;
1464        break;
1465    
1466        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1467        if (PRIVATE_DATA(cc))
1468          private_data_length += 2;
1469        cc += 1;
1470        break;
1471    
1472        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1473        if (PRIVATE_DATA(cc))
1474          private_data_length += 2;
1475        cc += 1 + IMM2_SIZE;
1476        break;
1477    
1478        case OP_CLASS:
1479        case OP_NCLASS:
1480    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1481        case OP_XCLASS:
1482        size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1483    #else
1484        size = 1 + 32 / (int)sizeof(pcre_uchar);
1485    #endif
1486        if (PRIVATE_DATA(cc))
1487          private_data_length += get_class_iterator_size(cc + size);
1488        cc += size;
1489        break;
1490    
1491      default:      default:
1492      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1493      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 906  while (cc < ccend) Line 1495  while (cc < ccend)
1495      }      }
1496    }    }
1497  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1498  return localsize;  return private_data_length;
1499  }  }
1500    
1501  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,
1502    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop)
1503  {  {
1504  DEFINE_COMPILER;  DEFINE_COMPILER;
1505  int srcw[2];  int srcw[2];
1506  int count;  int count, size;
1507  BOOL tmp1next = TRUE;  BOOL tmp1next = TRUE;
1508  BOOL tmp1empty = TRUE;  BOOL tmp1empty = TRUE;
1509  BOOL tmp2empty = TRUE;  BOOL tmp2empty = TRUE;
# Line 931  stacktop = STACK(stacktop - 1); Line 1520  stacktop = STACK(stacktop - 1);
1520    
1521  if (!save)  if (!save)
1522    {    {
1523    stackptr += sizeof(sljit_w);    stackptr += sizeof(sljit_sw);
1524    if (stackptr < stacktop)    if (stackptr < stacktop)
1525      {      {
1526      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1527      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1528      tmp1empty = FALSE;      tmp1empty = FALSE;
1529      }      }
1530    if (stackptr < stacktop)    if (stackptr < stacktop)
1531      {      {
1532      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1533      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1534      tmp2empty = FALSE;      tmp2empty = FALSE;
1535      }      }
1536    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
# Line 953  while (status != end) Line 1542  while (status != end)
1542    switch(status)    switch(status)
1543      {      {
1544      case start:      case start:
1545      SLJIT_ASSERT(save);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1546      count = 1;      count = 1;
1547      srcw[0] = RECURSIVE_HEAD;      srcw[0] = common->recursive_head_ptr;
1548      status = loop;      status = loop;
1549      break;      break;
1550    
# Line 979  while (status != end) Line 1568  while (status != end)
1568        case OP_SBRAPOS:        case OP_SBRAPOS:
1569        case OP_SCOND:        case OP_SCOND:
1570        count = 1;        count = 1;
1571        srcw[0] = PRIV_DATA(cc);        srcw[0] = PRIVATE_DATA(cc);
1572        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1573        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1574        break;        break;
1575    
1576        case OP_CBRA:        case OP_CBRA:
1577        case OP_SCBRA:        case OP_SCBRA:
1578        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1579        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1580            count = 1;
1581            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1582            }
1583        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1584        break;        break;
1585    
1586        case OP_CBRAPOS:        case OP_CBRAPOS:
1587        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1588        count = 2;        count = 2;
1589          srcw[0] = PRIVATE_DATA(cc);
1590        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1591        srcw[0] = PRIV_DATA(cc);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
       SLJIT_ASSERT(srcw[0] != 0);  
1592        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1593        break;        break;
1594    
# Line 1006  while (status != end) Line 1598  while (status != end)
1598        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1599          {          {
1600          count = 1;          count = 1;
1601          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1602          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1603          }          }
1604        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1605        break;        break;
1606    
1607          CASE_ITERATOR_PRIVATE_DATA_1
1608          if (PRIVATE_DATA(cc))
1609            {
1610            count = 1;
1611            srcw[0] = PRIVATE_DATA(cc);
1612            }
1613          cc += 2;
1614    #ifdef SUPPORT_UTF
1615          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1616    #endif
1617          break;
1618    
1619          CASE_ITERATOR_PRIVATE_DATA_2A
1620          if (PRIVATE_DATA(cc))
1621            {
1622            count = 2;
1623            srcw[0] = PRIVATE_DATA(cc);
1624            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1625            }
1626          cc += 2;
1627    #ifdef SUPPORT_UTF
1628          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1629    #endif
1630          break;
1631    
1632          CASE_ITERATOR_PRIVATE_DATA_2B
1633          if (PRIVATE_DATA(cc))
1634            {
1635            count = 2;
1636            srcw[0] = PRIVATE_DATA(cc);
1637            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1638            }
1639          cc += 2 + IMM2_SIZE;
1640    #ifdef SUPPORT_UTF
1641          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1642    #endif
1643          break;
1644    
1645          CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1646          if (PRIVATE_DATA(cc))
1647            {
1648            count = 1;
1649            srcw[0] = PRIVATE_DATA(cc);
1650            }
1651          cc += 1;
1652          break;
1653    
1654          CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1655          if (PRIVATE_DATA(cc))
1656            {
1657            count = 2;
1658            srcw[0] = PRIVATE_DATA(cc);
1659            srcw[1] = srcw[0] + sizeof(sljit_sw);
1660            }
1661          cc += 1;
1662          break;
1663    
1664          CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1665          if (PRIVATE_DATA(cc))
1666            {
1667            count = 2;
1668            srcw[0] = PRIVATE_DATA(cc);
1669            srcw[1] = srcw[0] + sizeof(sljit_sw);
1670            }
1671          cc += 1 + IMM2_SIZE;
1672          break;
1673    
1674          case OP_CLASS:
1675          case OP_NCLASS:
1676    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1677          case OP_XCLASS:
1678          size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1679    #else
1680          size = 1 + 32 / (int)sizeof(pcre_uchar);
1681    #endif
1682          if (PRIVATE_DATA(cc))
1683            switch(get_class_iterator_size(cc + size))
1684              {
1685              case 1:
1686              count = 1;
1687              srcw[0] = PRIVATE_DATA(cc);
1688              break;
1689    
1690              case 2:
1691              count = 2;
1692              srcw[0] = PRIVATE_DATA(cc);
1693              srcw[1] = srcw[0] + sizeof(sljit_sw);
1694              break;
1695    
1696              default:
1697              SLJIT_ASSERT_STOP();
1698              break;
1699              }
1700          cc += size;
1701          break;
1702    
1703        default:        default:
1704        cc = next_opcode(common, cc);        cc = next_opcode(common, cc);
1705        SLJIT_ASSERT(cc != NULL);        SLJIT_ASSERT(cc != NULL);
# Line 1034  while (status != end) Line 1722  while (status != end)
1722          if (!tmp1empty)          if (!tmp1empty)
1723            {            {
1724            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1725            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1726            }            }
1727          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1728          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1045  while (status != end) Line 1733  while (status != end)
1733          if (!tmp2empty)          if (!tmp2empty)
1734            {            {
1735            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1736            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1737            }            }
1738          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1739          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1062  while (status != end) Line 1750  while (status != end)
1750          if (!tmp1empty)          if (!tmp1empty)
1751            {            {
1752            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1753            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1754            }            }
1755          tmp1next = FALSE;          tmp1next = FALSE;
1756          }          }
# Line 1074  while (status != end) Line 1762  while (status != end)
1762          if (!tmp2empty)          if (!tmp2empty)
1763            {            {
1764            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1765            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1766            }            }
1767          tmp1next = TRUE;          tmp1next = TRUE;
1768          }          }
# Line 1089  if (save) Line 1777  if (save)
1777      if (!tmp1empty)      if (!tmp1empty)
1778        {        {
1779        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1780        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1781        }        }
1782      if (!tmp2empty)      if (!tmp2empty)
1783        {        {
1784        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1785        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1786        }        }
1787      }      }
1788    else    else
# Line 1102  if (save) Line 1790  if (save)
1790      if (!tmp2empty)      if (!tmp2empty)
1791        {        {
1792        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1793        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1794        }        }
1795      if (!tmp1empty)      if (!tmp1empty)
1796        {        {
1797        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1798        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1799        }        }
1800      }      }
1801    }    }
1802  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1803  }  }
1804    
1805  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  #undef CASE_ITERATOR_PRIVATE_DATA_1
1806    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1807    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1808    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1809    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1810    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1811    
1812    static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1813  {  {
1814  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1815  }  }
# Line 1124  static SLJIT_INLINE void set_jumps(jump_ Line 1819  static SLJIT_INLINE void set_jumps(jump_
1819  while (list)  while (list)
1820    {    {
1821    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1822    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1823    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1824    list = list->next;    list = list->next;
1825    }    }
1826  }  }
# Line 1141  if (list_item) Line 1836  if (list_item)
1836    }    }
1837  }  }
1838    
1839  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)
1840  {  {
1841  DEFINE_COMPILER;  DEFINE_COMPILER;
1842  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1843    
1844  if (list_item)  if (list_item)
1845    {    {
   list_item->type = type;  
   list_item->data = data;  
1846    list_item->start = start;    list_item->start = start;
1847    list_item->leave = LABEL();    list_item->quit = LABEL();
1848    list_item->next = common->stubs;    list_item->next = common->stubs;
1849    common->stubs = list_item;    common->stubs = list_item;
1850    }    }
# Line 1165  stub_list* list_item = common->stubs; Line 1858  stub_list* list_item = common->stubs;
1858  while (list_item)  while (list_item)
1859    {    {
1860    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
1861    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
1862      {    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);  
1863    list_item = list_item->next;    list_item = list_item->next;
1864    }    }
1865  common->stubs = NULL;  common->stubs = NULL;
# Line 1190  static SLJIT_INLINE void allocate_stack( Line 1878  static SLJIT_INLINE void allocate_stack(
1878  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
1879  DEFINE_COMPILER;  DEFINE_COMPILER;
1880    
1881  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));
1882  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
1883  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
1884  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1198  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 1886  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
1886  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
1887  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
1888  #endif  #endif
1889  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));
1890  }  }
1891    
1892  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
1893  {  {
1894  DEFINE_COMPILER;  DEFINE_COMPILER;
1895  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));
1896  }  }
1897    
1898  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1214  struct sljit_label *loop; Line 1902  struct sljit_label *loop;
1902  int i;  int i;
1903  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
1904  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
1905  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));
1906  if (length < 8)  if (length < 8)
1907    {    {
1908    for (i = 0; i < length; i++)    for (i = 0; i < length; i++)
1909      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_TEMPORARY_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
1910    }    }
1911  else  else
1912    {    {
1913    OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START - sizeof(sljit_sw));
1914    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length);
1915    loop = LABEL();    loop = LABEL();
1916    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
1917    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
1918    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
1919    }    }
1920  }  }
# Line 1235  static SLJIT_INLINE void copy_ovector(co Line 1923  static SLJIT_INLINE void copy_ovector(co
1923  {  {
1924  DEFINE_COMPILER;  DEFINE_COMPILER;
1925  struct sljit_label *loop;  struct sljit_label *loop;
1926  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
1927    
1928  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
1929  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));
1930  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);
1931    
1932  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
1933  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  if (common->mark_ptr != 0)
1934  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1935  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offset_count));
1936  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START);  if (common->mark_ptr != 0)
1937      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);
1938    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
1939    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
1940    GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
1941  /* Unlikely, but possible */  /* Unlikely, but possible */
1942  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);
1943  loop = LABEL();  loop = LABEL();
1944  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);
1945  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));
1946  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
1947  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1948  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);
1949  #endif  #endif
1950  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);
1951  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);
1952  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
1953  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
1954    
1955  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
1956  if (topbracket > 1)  if (topbracket > 1)
1957    {    {
1958    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));
1959    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
1960    
1961    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
1962    loop = LABEL();    loop = LABEL();
1963    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)));
1964    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);
1965    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);
1966    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
1967    }    }
1968  else  else
1969    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
1970  }  }
1971    
1972  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)
1973  {  {
1974  DEFINE_COMPILER;  DEFINE_COMPILER;
1975    struct sljit_jump *jump;
1976    
1977  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);
1978    SLJIT_ASSERT(common->start_used_ptr != 0 && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
1979    
1980  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
1981  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
1982  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));
1983  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);
1984    
1985  /* Store match begin and end. */  /* Store match begin and end. */
1986  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));
1987  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));
1988  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? START_USED_PTR : HIT_START);  
1989    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
1990    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr + sizeof(sljit_sw), SLJIT_SAVED_REG1, 0);
1991    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1992    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
1993    #endif
1994    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
1995    JUMPHERE(jump);
1996    
1997    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);
1998  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);
1999  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2000  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);
2001  #endif  #endif
2002  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);
2003    
2004  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);
2005  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2006  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);
2007  #endif  #endif
2008  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);
2009    
2010  JUMPTO(SLJIT_JUMP, leave);  JUMPTO(SLJIT_JUMP, quit);
2011  }  }
2012    
2013  static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)  static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)
# Line 1315  struct sljit_jump *jump; Line 2018  struct sljit_jump *jump;
2018    
2019  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2020    {    {
2021    /* The value of -1 must be kept for START_USED_PTR! */    /* The value of -1 must be kept for start_used_ptr! */
2022    OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), START_USED_PTR, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, 1);
2023    /* Jumps if START_USED_PTR < STR_PTR, or START_USED_PTR == -1. Although overwriting    /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting
2024    is not necessary if START_USED_PTR == STR_PTR, it does not hurt as well. */    is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */
2025    jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_PTR, 0);    jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_PTR, 0);
2026    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), START_USED_PTR, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2027    JUMPHERE(jump);    JUMPHERE(jump);
2028    }    }
2029  else if (common->mode == JIT_PARTIAL_HARD_COMPILE)  else if (common->mode == JIT_PARTIAL_HARD_COMPILE)
2030    {    {
2031    jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), START_USED_PTR, STR_PTR, 0);    jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2032    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), START_USED_PTR, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2033    JUMPHERE(jump);    JUMPHERE(jump);
2034    }    }
2035  }  }
# Line 1415  if (c <= 127 && bit == 0x20) Line 2118  if (c <= 127 && bit == 0x20)
2118    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2119    
2120  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2121  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2122    return 0;    return 0;
2123    
2124  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2125    
2126  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2127  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 1434  if (common->utf && c > 127) Line 2137  if (common->utf && c > 127)
2137  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2138  return (0 << 8) | bit;  return (0 << 8) | bit;
2139    
2140  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2141    
 #ifdef COMPILE_PCRE16  
2142  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2143  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2144    {    {
# Line 1447  if (common->utf && c > 65535) Line 2149  if (common->utf && c > 65535)
2149    }    }
2150  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2151  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2152    
2153  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2154  }  }
2155    
2156  static void check_partial(compiler_common *common)  static void check_partial(compiler_common *common, BOOL force)
2157  {  {
2158    /* Checks whether a partial matching is occured. Does not modify registers. */
2159  DEFINE_COMPILER;  DEFINE_COMPILER;
2160  struct sljit_jump *jump;  struct sljit_jump *jump = NULL;
2161    
2162    SLJIT_ASSERT(!force || common->mode != JIT_COMPILE);
2163    
2164  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2165    return;    return;
2166    
2167  jump = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), START_USED_PTR, STR_PTR, 0);  if (!force)
2168      jump = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2169    else if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2170      jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2171    
2172  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2173    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), HIT_START, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
2174  else  else
2175    {    {
2176    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 1470  else Line 2178  else
2178    else    else
2179      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2180    }    }
2181  JUMPHERE(jump);  
2182    if (jump != NULL)
2183      JUMPHERE(jump);
2184  }  }
2185    
2186  static struct sljit_jump *check_str_end(compiler_common *common)  static struct sljit_jump *check_str_end(compiler_common *common)
# Line 1487  if (common->mode == JIT_COMPILE) Line 2197  if (common->mode == JIT_COMPILE)
2197  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2198  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2199    {    {
2200    nohit = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), START_USED_PTR, STR_PTR, 0);    nohit = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2201    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), HIT_START, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
2202    JUMPHERE(nohit);    JUMPHERE(nohit);
2203    return_value = JUMP(SLJIT_JUMP);    return_value = JUMP(SLJIT_JUMP);
2204    }    }
2205  else  else
2206    {    {
2207    return_value = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), START_USED_PTR, STR_PTR, 0);    return_value = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2208    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2209      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2210    else    else
# Line 1504  JUMPHERE(jump); Line 2214  JUMPHERE(jump);
2214  return return_value;  return return_value;
2215  }  }
2216    
2217  static void fallback_at_str_end(compiler_common *common, jump_list **fallbacks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
2218  {  {
2219  DEFINE_COMPILER;  DEFINE_COMPILER;
2220  struct sljit_jump *jump;  struct sljit_jump *jump;
2221    
2222  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2223    {    {
2224    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));
2225    return;    return;
2226    }    }
2227    
2228  /* Partial matching mode. */  /* Partial matching mode. */
2229  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2230  add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), 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));
2231  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2232    {    {
2233    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), HIT_START, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
2234    add_jump(compiler, fallbacks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2235    }    }
2236  else  else
2237    {    {
# Line 1538  static void read_char(compiler_common *c Line 2248  static void read_char(compiler_common *c
2248  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2249  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2250  DEFINE_COMPILER;  DEFINE_COMPILER;
2251  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2252  struct sljit_jump *jump;  struct sljit_jump *jump;
2253  #endif  #endif
2254    
2255  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2256  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2257  if (common->utf)  if (common->utf)
2258    {    {
2259  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2260    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2261  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2262    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2263  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2264    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2265    JUMPHERE(jump);    JUMPHERE(jump);
2266    }    }
2267  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2268  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));
2269  }  }
2270    
# Line 1565  static void peek_char(compiler_common *c Line 2273  static void peek_char(compiler_common *c
2273  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2274  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2275  DEFINE_COMPILER;  DEFINE_COMPILER;
2276  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2277  struct sljit_jump *jump;  struct sljit_jump *jump;
2278  #endif  #endif
2279    
2280  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2281  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2282  if (common->utf)  if (common->utf)
2283    {    {
2284  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2285    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2286  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2287    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2288  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2289    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2290    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2291    JUMPHERE(jump);    JUMPHERE(jump);
2292    }    }
2293  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2294  }  }
2295    
2296  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2297  {  {
2298  /* 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. */
2299  DEFINE_COMPILER;  DEFINE_COMPILER;
2300  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2301  struct sljit_jump *jump;  struct sljit_jump *jump;
2302  #endif  #endif
2303    
# Line 1600  if (common->utf) Line 2306  if (common->utf)
2306    {    {
2307    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2308    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));
2309  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2310    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2311    it is needed in most cases. */    it is needed in most cases. */
2312    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2313    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2314    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2315    JUMPHERE(jump);    JUMPHERE(jump);
2316  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2317    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2318    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2319    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
# Line 1616  if (common->utf) Line 2321  if (common->utf)
2321    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2322    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2323    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);
2324    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2325    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2326    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2327  #endif  #elif defined COMPILE_PCRE32
2328  #endif /* COMPILE_PCRE8 */    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2329      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2330      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2331      JUMPHERE(jump);
2332    #endif /* COMPILE_PCRE[8|16|32] */
2333    return;    return;
2334    }    }
2335  #endif  #endif /* SUPPORT_UTF */
2336  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2337  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));
2338  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2339  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2340  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2341  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2342  #endif  #endif
2343  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2344  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2345  JUMPHERE(jump);  JUMPHERE(jump);
2346  #endif  #endif
2347  }  }
# Line 1641  static void skip_char_back(compiler_comm Line 2350  static void skip_char_back(compiler_comm
2350  {  {
2351  /* 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. */
2352  DEFINE_COMPILER;  DEFINE_COMPILER;
2353  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2354    #if defined COMPILE_PCRE8
2355  struct sljit_label *label;  struct sljit_label *label;
2356    
2357  if (common->utf)  if (common->utf)
# Line 1653  if (common->utf) Line 2363  if (common->utf)
2363    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2364    return;    return;
2365    }    }
2366  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2367  if (common->utf)  if (common->utf)
2368    {    {
2369    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 1662  if (common->utf) Line 2371  if (common->utf)
2371    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2372    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2373    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);
2374    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2375    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2376    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2377    return;    return;
2378    }    }
2379  #endif  #endif /* COMPILE_PCRE[8|16] */
2380    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2381  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));
2382  }  }
2383    
2384  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)
2385  {  {
2386  /* 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. */
2387  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1679  DEFINE_COMPILER; Line 2389  DEFINE_COMPILER;
2389  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2390    {    {
2391    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2392    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));
2393    }    }
2394  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2395    {    {
2396    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);
2397    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2398    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);
2399    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);
2400    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));
2401    }    }
2402  else  else
2403    {    {
2404    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2405    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));
2406    }    }
2407  }  }
2408    
2409  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2410    
2411  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2412  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2413  {  {
2414  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
# Line 1706  of the character (>= 0xc0). Return char Line 2416  of the character (>= 0xc0). Return char
2416  DEFINE_COMPILER;  DEFINE_COMPILER;
2417  struct sljit_jump *jump;  struct sljit_jump *jump;
2418    
2419  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2420  /* Searching for the first zero. */  /* Searching for the first zero. */
2421  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);
2422  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
# Line 1765  DEFINE_COMPILER; Line 2475  DEFINE_COMPILER;
2475  struct sljit_jump *jump;  struct sljit_jump *jump;
2476  struct sljit_jump *compare;  struct sljit_jump *compare;
2477    
2478  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2479    
2480  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);
2481  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
# Line 1786  sljit_emit_fast_return(compiler, RETURN_ Line 2496  sljit_emit_fast_return(compiler, RETURN_
2496  JUMPHERE(jump);  JUMPHERE(jump);
2497    
2498  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2499  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);
2500  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2501  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2502  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2503  }  }
2504    
2505  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2506    
 #ifdef COMPILE_PCRE16  
2507  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2508  {  {
2509  /* 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 1802  of the character (>= 0xd800). Return cha Line 2511  of the character (>= 0xd800). Return cha
2511  DEFINE_COMPILER;  DEFINE_COMPILER;
2512  struct sljit_jump *jump;  struct sljit_jump *jump;
2513    
2514  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2515  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);
2516  /* Do nothing, only return. */  /* Do nothing, only return. */
2517  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
# Line 1819  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC Line 2528  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2528  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2529  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2530  }  }
 #endif /* COMPILE_PCRE16 */  
2531    
2532  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2533    
2534  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2535    
# Line 1839  DEFINE_COMPILER; Line 2547  DEFINE_COMPILER;
2547    
2548  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);
2549    
2550  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2551  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2552  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));
2553  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2554  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2555  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2556  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2557  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2558  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));
2559  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2560  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2561  }  }
# Line 1861  struct sljit_label *newlinelabel = NULL; Line 2569  struct sljit_label *newlinelabel = NULL;
2569  struct sljit_jump *start;  struct sljit_jump *start;
2570  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2571  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2572  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2573  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2574  #endif  #endif
2575  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 1875  if (!(hascrorlf || firstline) && (common Line 2583  if (!(hascrorlf || firstline) && (common
2583  if (firstline)  if (firstline)
2584    {    {
2585    /* Search for the end of the first line. */    /* Search for the end of the first line. */
2586    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2587    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
2588    
2589    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2590      {      {
# Line 1887  if (firstline) Line 2595  if (firstline)
2595      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2596      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);
2597      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);
2598      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));      JUMPHERE(end);
2599        OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2600      }      }
2601    else    else
2602      {      {
2603      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2604      mainloop = LABEL();      mainloop = LABEL();
2605      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
2606      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2607      read_char(common);      read_char(common);
2608      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
2609      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2610      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);      JUMPHERE(end);
2611        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2612      set_jumps(newline, LABEL());      set_jumps(newline, LABEL());
2613      }      }
2614    
2615    JUMPHERE(end);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
   OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
2616    }    }
2617    
2618  start = JUMP(SLJIT_JUMP);  start = JUMP(SLJIT_JUMP);
# Line 1915  if (newlinecheck) Line 2624  if (newlinecheck)
2624    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2625    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2626    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);
2627    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2628  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2629    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2630  #endif  #endif
2631    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2632    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 1938  if (newlinecheck) Line 2647  if (newlinecheck)
2647    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);
2648    
2649  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));
2650  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2651    #if defined COMPILE_PCRE8
2652  if (common->utf)  if (common->utf)
2653    {    {
2654    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2655    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);
2656    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2657    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2658    }    }
2659  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2660  if (common->utf)  if (common->utf)
2661    {    {
2662    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2663    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2664    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);
2665    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2666    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2667    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2668    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2669    }    }
2670  #endif  #endif /* COMPILE_PCRE[8|16] */
2671    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2672  JUMPHERE(start);  JUMPHERE(start);
2673    
2674  if (newlinecheck)  if (newlinecheck)
# Line 1970  if (newlinecheck) Line 2680  if (newlinecheck)
2680  return mainloop;  return mainloop;
2681  }  }
2682    
2683    #define MAX_N_CHARS 3
2684    
2685    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2686    {
2687    DEFINE_COMPILER;
2688    struct sljit_label *start;
2689    struct sljit_jump *quit;
2690    pcre_uint32 chars[MAX_N_CHARS * 2];
2691    pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2692    int location = 0;
2693    pcre_int32 len, c, bit, caseless;
2694    int must_stop;
2695    
2696    /* We do not support alternatives now. */
2697    if (*(common->start + GET(common->start, 1)) == OP_ALT)
2698      return FALSE;
2699    
2700    while (TRUE)
2701      {
2702      caseless = 0;
2703      must_stop = 1;
2704      switch(*cc)
2705        {
2706        case OP_CHAR:
2707        must_stop = 0;
2708        cc++;
2709        break;
2710    
2711        case OP_CHARI:
2712        caseless = 1;
2713        must_stop = 0;
2714        cc++;
2715        break;
2716    
2717        case OP_SOD:
2718        case OP_SOM:
2719        case OP_SET_SOM:
2720        case OP_NOT_WORD_BOUNDARY:
2721        case OP_WORD_BOUNDARY:
2722        case OP_EODN:
2723        case OP_EOD:
2724        case OP_CIRC:
2725        case OP_CIRCM:
2726        case OP_DOLL:
2727        case OP_DOLLM:
2728        /* Zero width assertions. */
2729        cc++;
2730        continue;
2731    
2732        case OP_PLUS:
2733        case OP_MINPLUS:
2734        case OP_POSPLUS:
2735        cc++;
2736        break;
2737    
2738        case OP_EXACT:
2739        cc += 1 + IMM2_SIZE;
2740        break;
2741    
2742        case OP_PLUSI:
2743        case OP_MINPLUSI:
2744        case OP_POSPLUSI:
2745        caseless = 1;
2746        cc++;
2747        break;
2748    
2749        case OP_EXACTI:
2750        caseless = 1;
2751        cc += 1 + IMM2_SIZE;
2752        break;
2753    
2754        default:
2755        must_stop = 2;
2756        break;
2757        }
2758    
2759      if (must_stop == 2)
2760          break;
2761    
2762      len = 1;
2763    #ifdef SUPPORT_UTF
2764      if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
2765    #endif
2766    
2767      if (caseless && char_has_othercase(common, cc))
2768        {
2769        caseless = char_get_othercase_bit(common, cc);
2770        if (caseless == 0)
2771          return FALSE;
2772    #ifdef COMPILE_PCRE8
2773        caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
2774    #else
2775        if ((caseless & 0x100) != 0)
2776          caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
2777        else
2778          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
2779    #endif
2780        }
2781      else
2782        caseless = 0;
2783    
2784      while (len > 0 && location < MAX_N_CHARS * 2)
2785        {
2786        c = *cc;
2787        bit = 0;
2788        if (len == (caseless & 0xff))
2789          {
2790          bit = caseless >> 8;
2791          c |= bit;
2792          }
2793    
2794        chars[location] = c;
2795        chars[location + 1] = bit;
2796    
2797        len--;
2798        location += 2;
2799        cc++;
2800        }
2801    
2802      if (location >= MAX_N_CHARS * 2 || must_stop != 0)
2803        break;
2804      }
2805    
2806    /* At least two characters are required. */
2807    if (location < 2 * 2)
2808        return FALSE;
2809    
2810    if (firstline)
2811      {
2812      SLJIT_ASSERT(common->first_line_end != 0);
2813      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2814      OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2815      }
2816    else
2817      OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2818    
2819    start = LABEL();
2820    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2821    
2822    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2823    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2824    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2825    if (chars[1] != 0)
2826      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
2827    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
2828    if (location > 2 * 2)
2829      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2830    if (chars[3] != 0)
2831      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
2832    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
2833    if (location > 2 * 2)
2834      {
2835      if (chars[5] != 0)
2836        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
2837      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);
2838      }
2839    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2840    
2841    JUMPHERE(quit);
2842    
2843    if (firstline)
2844      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2845    else
2846      OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2847    return TRUE;
2848    }
2849    
2850    #undef MAX_N_CHARS
2851    
2852  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)
2853  {  {
2854  DEFINE_COMPILER;  DEFINE_COMPILER;
2855  struct sljit_label *start;  struct sljit_label *start;
2856  struct sljit_jump *leave;  struct sljit_jump *quit;
2857  struct sljit_jump *found;  struct sljit_jump *found;
2858  pcre_uchar oc, bit;  pcre_uchar oc, bit;
2859    
2860  if (firstline)  if (firstline)
2861    {    {
2862    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2863    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2864      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
2865    }    }
2866    
2867  start = LABEL();  start = LABEL();
2868  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2869  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2870    
2871  oc = first_char;  oc = first_char;
# Line 2002  if (first_char == oc) Line 2882  if (first_char == oc)
2882  else  else
2883    {    {
2884    bit = first_char ^ oc;    bit = first_char ^ oc;
2885    if (ispowerof2(bit))    if (is_powerof2(bit))
2886      {      {
2887      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
2888      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 2010  else Line 2890  else
2890    else    else
2891      {      {
2892      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);
2893      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2894      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);
2895      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);
2896      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
2897      }      }
2898    }    }
2899    
2900  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  
2901  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
2902  JUMPHERE(found);  JUMPHERE(found);
2903  JUMPHERE(leave);  JUMPHERE(quit);
2904    
2905  if (firstline)  if (firstline)
2906    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2907  }  }
2908    
2909  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 2051  DEFINE_COMPILER; Line 2912  DEFINE_COMPILER;
2912  struct sljit_label *loop;  struct sljit_label *loop;
2913  struct sljit_jump *lastchar;  struct sljit_jump *lastchar;
2914  struct sljit_jump *firstchar;  struct sljit_jump *firstchar;
2915  struct sljit_jump *leave;  struct sljit_jump *quit;
2916  struct sljit_jump *foundcr = NULL;  struct sljit_jump *foundcr = NULL;
2917  struct sljit_jump *notfoundnl;  struct sljit_jump *notfoundnl;
2918  jump_list *newline = NULL;  jump_list *newline = NULL;
2919    
2920  if (firstline)  if (firstline)
2921    {    {
2922    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2923    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2924      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
2925    }    }
2926    
2927  if (common->nltype == NLTYPE_FIXED && common->newline > 255)  if (common->nltype == NLTYPE_FIXED && common->newline > 255)
# Line 2072  if (common->nltype == NLTYPE_FIXED && co Line 2934  if (common->nltype == NLTYPE_FIXED && co
2934    
2935    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
2936    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);
2937    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
2938  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2939    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
2940  #endif  #endif
2941    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2942    
2943    loop = LABEL();    loop = LABEL();
2944    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));
2945    leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2946    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
2947    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
2948    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);
2949    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);
2950    
2951    JUMPHERE(leave);    JUMPHERE(quit);
2952    JUMPHERE(firstchar);    JUMPHERE(firstchar);
2953    JUMPHERE(lastchar);    JUMPHERE(lastchar);
2954    
# Line 2110  set_jumps(newline, loop); Line 2972  set_jumps(newline, loop);
2972    
2973  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
2974    {    {
2975    leave = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
2976    JUMPHERE(foundcr);    JUMPHERE(foundcr);
2977    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2978    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2979    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);
2980    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2981  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2982    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2983  #endif  #endif
2984    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2985    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
2986    JUMPHERE(leave);    JUMPHERE(quit);
2987    }    }
2988  JUMPHERE(lastchar);  JUMPHERE(lastchar);
2989  JUMPHERE(firstchar);  JUMPHERE(firstchar);
2990    
2991  if (firstline)  if (firstline)
2992    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2993  }  }
2994    
2995    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
2996    
2997  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)
2998  {  {
2999  DEFINE_COMPILER;  DEFINE_COMPILER;
3000  struct sljit_label *start;  struct sljit_label *start;
3001  struct sljit_jump *leave;  struct sljit_jump *quit;
3002  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3003    jump_list *matches = NULL;
3004    pcre_uint8 inverted_start_bits[32];
3005    int i;
3006  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3007  struct sljit_jump *jump;  struct sljit_jump *jump;
3008  #endif  #endif
3009    
3010    for (i = 0; i < 32; ++i)
3011      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3012    
3013  if (firstline)  if (firstline)
3014    {    {
3015    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3016    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
3017      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3018    }    }
3019    
3020  start = LABEL();  start = LABEL();
3021  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3022  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3023  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3024  if (common->utf)  if (common->utf)
3025    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3026  #endif  #endif
3027    
3028    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3029      {
3030  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3031  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3032  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3033  JUMPHERE(jump);    JUMPHERE(jump);
3034  #endif  #endif
3035  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3036  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3037  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3038  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3039  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);
3040  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3041      }
3042    
3043  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3044  if (common->utf)  if (common->utf)
3045    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3046  #endif  #endif
3047  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));
3048  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3049    #if defined COMPILE_PCRE8
3050  if (common->utf)  if (common->utf)
3051    {    {
3052    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3053    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);
3054    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3055    }    }
3056  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3057  if (common->utf)  if (common->utf)
3058    {    {
3059    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3060    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3061    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);
3062    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3063    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3064    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3065    }    }
3066  #endif  #endif /* COMPILE_PCRE[8|16] */
3067    #endif /* SUPPORT_UTF */
3068  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3069  JUMPHERE(found);  if (found != NULL)
3070  JUMPHERE(leave);    JUMPHERE(found);
3071    if (matches != NULL)
3072      set_jumps(matches, LABEL());
3073    JUMPHERE(quit);
3074    
3075  if (firstline)  if (firstline)
3076    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
3077  }  }
3078    
3079  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 2206  struct sljit_jump *alreadyfound; Line 3085  struct sljit_jump *alreadyfound;
3085  struct sljit_jump *found;  struct sljit_jump *found;
3086  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3087  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3088  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3089    
3090  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_CHAR_PTR);  SLJIT_ASSERT(common->req_char_ptr != 0);
3091    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
3092  OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, REQ_BYTE_MAX);  OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, REQ_BYTE_MAX);
3093  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);
3094  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);
# Line 2236  if (req_char == oc) Line 3116  if (req_char == oc)
3116  else  else
3117    {    {
3118    bit = req_char ^ oc;    bit = req_char ^ oc;
3119    if (ispowerof2(bit))    if (is_powerof2(bit))
3120      {      {
3121      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3122      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 2253  JUMPTO(SLJIT_JUMP, loop); Line 3133  JUMPTO(SLJIT_JUMP, loop);
3133  JUMPHERE(found);  JUMPHERE(found);
3134  if (foundoc)  if (foundoc)
3135    JUMPHERE(foundoc);    JUMPHERE(foundoc);
3136  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_CHAR_PTR, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr, TMP1, 0);
3137  JUMPHERE(alreadyfound);  JUMPHERE(alreadyfound);
3138  JUMPHERE(toolong);  JUMPHERE(toolong);
3139  return notfound;  return notfound;
# Line 2265  DEFINE_COMPILER; Line 3145  DEFINE_COMPILER;
3145  struct sljit_jump *jump;  struct sljit_jump *jump;
3146  struct sljit_label *mainloop;  struct sljit_label *mainloop;
3147    
3148  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3149  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);
3150    GET_LOCAL_BASE(TMP3, 0, 0);
3151    
3152  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3153  mainloop = LABEL();  mainloop = LABEL();
3154  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3155  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);
3156  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_LOCALS_REG, 0);  jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3157  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
3158  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);
3159  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));
3160    OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
3161    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
3162  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3163    
3164  JUMPHERE(jump);  JUMPHERE(jump);
3165  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3166  /* End of dropping frames. */  /* End of dropping frames. */
3167  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3168    
3169  JUMPHERE(jump);  JUMPHERE(jump);
3170  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3171  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3172  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3173  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);  
 /* Unknown command. */  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
3174  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3175  }  }
3176    
# Line 2307  struct sljit_jump *jump; Line 3184  struct sljit_jump *jump;
3184    
3185  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
3186    
3187  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);
3188  /* Get type of the previous char, and put it to LOCALS1. */  /* Get type of the previous char, and put it to LOCALS1. */
3189  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
3190  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 2326  if (common->use_ucp) Line 3203  if (common->use_ucp)
3203    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3204    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3205    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);
3206    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3207    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);
3208    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);
3209    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3210    JUMPHERE(jump);    JUMPHERE(jump);
3211    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3212    }    }
# Line 2370  if (common->use_ucp) Line 3247  if (common->use_ucp)
3247    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3248    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3249    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);
3250    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3251    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);
3252    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);
3253    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3254      JUMPHERE(jump);
3255      }
3256    else
3257    #endif
3258      {
3259    #ifndef COMPILE_PCRE8
3260      /* TMP2 may be destroyed by peek_char. */
3261      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3262      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3263    #elif defined SUPPORT_UTF
3264      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3265      jump = NULL;
3266      if (common->utf)
3267        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3268    #endif
3269      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);
3270      OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);
3271      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
3272    #ifndef COMPILE_PCRE8
3273    JUMPHERE(jump);    JUMPHERE(jump);
3274    #elif defined SUPPORT_UTF
3275      if (jump != NULL)
3276        JUMPHERE(jump);
3277    #endif /* COMPILE_PCRE8 */
3278      }
3279    JUMPHERE(skipread);
3280    
3281    OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3282    sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3283    }
3284    
3285    /*
3286      range format:
3287    
3288      ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).
3289      ranges[1] = first bit (0 or 1)
3290      ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)
3291    */
3292    
3293    static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3294    {
3295    DEFINE_COMPILER;
3296    struct sljit_jump *jump;
3297    
3298    if (ranges[0] < 0)
3299      return FALSE;
3300    
3301    switch(ranges[0])
3302      {
3303      case 1:
3304      if (readch)
3305        read_char(common);
3306      add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3307      return TRUE;
3308    
3309      case 2:
3310      if (readch)
3311        read_char(common);
3312      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3313      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3314      return TRUE;
3315    
3316      case 4:
3317      if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])
3318        {
3319        if (readch)
3320          read_char(common);
3321        if (ranges[1] != 0)
3322          {
3323          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3324          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3325          }
3326        else
3327          {
3328          jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);
3329          add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3330          JUMPHERE(jump);
3331          }
3332        return TRUE;
3333        }
3334      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))
3335        {
3336        if (readch)
3337          read_char(common);
3338        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3339        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3340        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3341        return TRUE;
3342        }
3343      return FALSE;
3344    
3345      default:
3346      return FALSE;
3347      }
3348    }
3349    
3350    static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)
3351    {
3352    int i, bit, length;
3353    const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;
3354    
3355    bit = ctypes[0] & flag;
3356    ranges[0] = -1;
3357    ranges[1] = bit != 0 ? 1 : 0;
3358    length = 0;
3359    
3360    for (i = 1; i < 256; i++)
3361      if ((ctypes[i] & flag) != bit)
3362        {
3363        if (length >= MAX_RANGE_SIZE)
3364          return;
3365        ranges[2 + length] = i;
3366        length++;
3367        bit ^= flag;
3368        }
3369    
3370    if (bit != 0)
3371      {
3372      if (length >= MAX_RANGE_SIZE)
3373        return;
3374      ranges[2 + length] = 256;
3375      length++;
3376      }
3377    ranges[0] = length;
3378    }
3379    
3380    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)
3381    {
3382    int ranges[2 + MAX_RANGE_SIZE];
3383    pcre_uint8 bit, cbit, all;
3384    int i, byte, length = 0;
3385    
3386    bit = bits[0] & 0x1;
3387    ranges[1] = bit;
3388    /* Can be 0 or 255. */
3389    all = -bit;
3390    
3391    for (i = 0; i < 256; )
3392      {
3393      byte = i >> 3;
3394      if ((i & 0x7) == 0 && bits[byte] == all)
3395        i += 8;
3396      else
3397        {
3398        cbit = (bits[byte] >> (i & 0x7)) & 0x1;
3399        if (cbit != bit)
3400          {
3401          if (length >= MAX_RANGE_SIZE)
3402            return FALSE;
3403          ranges[2 + length] = i;
3404          length++;
3405          bit = cbit;
3406          all = -cbit;
3407          }
3408        i++;
3409        }
3410    }    }
3411  else  
3412  #endif  if (((bit == 0) && nclass) || ((bit == 1) && !nclass))
3413    {    {
3414  #ifndef COMPILE_PCRE8    if (length >= MAX_RANGE_SIZE)
3415    /* TMP2 may be destroyed by peek_char. */      return FALSE;
3416    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);    ranges[2 + length] = 256;
3417    jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);    length++;
 #elif defined SUPPORT_UTF  
   OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  
   jump = NULL;  
   if (common->utf)  
     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
 #endif  
   OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);  
   OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);  
   OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);  
 #ifndef COMPILE_PCRE8  
   JUMPHERE(jump);  
 #elif defined SUPPORT_UTF  
   if (jump != NULL)  
     JUMPHERE(jump);  
 #endif /* COMPILE_PCRE8 */  
3418    }    }
3419  JUMPHERE(skipread);  ranges[0] = length;
3420    
3421  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  return check_ranges(common, ranges, backtracks, FALSE);
 sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
3422  }  }
3423    
3424  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
# Line 2410  static void check_anynewline(compiler_co Line 3426  static void check_anynewline(compiler_co
3426  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3427  DEFINE_COMPILER;  DEFINE_COMPILER;
3428    
3429  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3430    
3431  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3432  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);
3433  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3434  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);
3435  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3436  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3437  if (common->utf)  if (common->utf)
3438    {    {
3439  #endif  #endif
3440    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3441    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3442    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);
3443  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3444    }    }
3445  #endif  #endif
3446  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3447  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);
3448  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3449  }  }
3450    
# Line 2437  static void check_hspace(compiler_common Line 3453  static void check_hspace(compiler_common
3453  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3454  DEFINE_COMPILER;  DEFINE_COMPILER;
3455    
3456  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3457    
3458  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);
3459  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3460  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);
3461  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3462  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);
3463  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3464  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3465  if (common->utf)  if (common->utf)
3466    {    {
3467  #endif  #endif
3468    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3469    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);
3470    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3471    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);
3472    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3473    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3474    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);
3475    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3476    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);
3477    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3478    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);
3479    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3480    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);
3481  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3482    }    }
3483  #endif  #endif
3484  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3485  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);
3486    
3487  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3488  }  }
# Line 2476  static void check_vspace(compiler_common Line 3492  static void check_vspace(compiler_common
3492  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3493  DEFINE_COMPILER;  DEFINE_COMPILER;
3494    
3495  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3496    
3497  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3498  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);
3499  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3500  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);
3501  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3502  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3503  if (common->utf)  if (common->utf)
3504    {    {
3505  #endif  #endif
3506    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);
3507    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3508    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);
3509  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3510    }    }
3511  #endif  #endif
3512  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3513  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);
3514    
3515  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3516  }  }
# Line 2508  DEFINE_COMPILER; Line 3524  DEFINE_COMPILER;
3524  struct sljit_jump *jump;  struct sljit_jump *jump;
3525  struct sljit_label *label;  struct sljit_label *label;
3526    
3527  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3528  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3529  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);
3530  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);
# Line 2537  DEFINE_COMPILER; Line 3553  DEFINE_COMPILER;
3553  struct sljit_jump *jump;  struct sljit_jump *jump;
3554  struct sljit_label *label;  struct sljit_label *label;
3555    
3556  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3557  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3558    
3559  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);
# Line 2580  sljit_emit_fast_return(compiler, RETURN_ Line 3596  sljit_emit_fast_return(compiler, RETURN_
3596    
3597  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3598    
3599  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)
3600  {  {
3601  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3602  int c1, c2;  pcre_uint32 c1, c2;
3603  const pcre_uchar *src2 = args->ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3604  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
3605    const ucd_record *ur;
3606    const pcre_uint32 *pp;
3607    
3608  while (src1 < end1)  while (src1 < end1)
3609    {    {
# Line 2593  while (src1 < end1) Line 3611  while (src1 < end1)
3611      return (pcre_uchar*)1;      return (pcre_uchar*)1;
3612    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3613    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3614    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return NULL;    ur = GET_UCD(c2);
3615      if (c1 != c2 && c1 != c2 + ur->other_case)
3616        {
3617        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3618        for (;;)
3619          {
3620          if (c1 < *pp) return NULL;
3621          if (c1 == *pp++) break;
3622          }
3623        }
3624    }    }
3625  return src2;  return src2;
3626  }  }
# Line 2601  return src2; Line 3628  return src2;
3628  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
3629    
3630  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,
3631      compare_context* context, jump_list **fallbacks)      compare_context* context, jump_list **backtracks)
3632  {  {
3633  DEFINE_COMPILER;  DEFINE_COMPILER;
3634  unsigned int othercasebit = 0;  unsigned int othercasebit = 0;
# Line 2615  if (caseless && char_has_othercase(commo Line 3642  if (caseless && char_has_othercase(commo
3642    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3643    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3644    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3645  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3646    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3647    othercasebit &= 0xff;    othercasebit &= 0xff;
3648  #else  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3649  #ifdef COMPILE_PCRE16    /* Note that this code only handles characters in the BMP. If there
3650      ever are characters outside the BMP whose othercase differs in only one
3651      bit from itself (there currently are none), this code will need to be
3652      revised for COMPILE_PCRE32. */
3653    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3654    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3655      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
3656    else    else
3657      othercasebit &= 0xff;      othercasebit &= 0xff;
3658  #endif  #endif /* COMPILE_PCRE[8|16|32] */
 #endif  
3659    }    }
3660    
3661  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3662    {    {
3663  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3664  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3665    if (context->length >= 4)    if (context->length >= 4)
3666      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 2640  if (context->sourcereg == -1) Line 3669  if (context->sourcereg == -1)
3669    else    else
3670  #endif  #endif
3671      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3672  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
3673  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3674    if (context->length >= 4)    if (context->length >= 4)
3675      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3676    else    else
3677  #endif  #endif
3678      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3679  #endif  #elif defined COMPILE_PCRE32
3680  #endif /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3681    #endif /* COMPILE_PCRE[8|16|32] */
3682    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3683    }    }
3684    
# Line 2663  do Line 3692  do
3692  #endif  #endif
3693    
3694    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3695  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3696    
3697    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3698    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 2678  do Line 3707  do
3707      }      }
3708    context->ucharptr++;    context->ucharptr++;
3709    
3710  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3711    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))
3712  #else  #else
3713    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
# Line 2686  do Line 3715  do
3715      {      {
3716      if (context->length >= 4)      if (context->length >= 4)
3717        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  
3718      else if (context->length >= 2)      else if (context->length >= 2)
3719        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);
3720    #if defined COMPILE_PCRE8
3721      else if (context->length >= 1)      else if (context->length >= 1)
3722        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);
3723  #else  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3724      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3725    
3726      switch(context->ucharptr)      switch(context->ucharptr)
# Line 2702  do Line 3728  do
3728        case 4 / sizeof(pcre_uchar):        case 4 / sizeof(pcre_uchar):
3729        if (context->oc.asint != 0)        if (context->oc.asint != 0)
3730          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);
3731        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));
3732        break;        break;
3733    
3734        case 2 / sizeof(pcre_uchar):        case 2 / sizeof(pcre_uchar):
3735        if (context->oc.asushort != 0)        if (context->oc.asushort != 0)
3736          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);
3737        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));
3738        break;        break;
3739    
3740  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3741        case 1:        case 1:
3742        if (context->oc.asbyte != 0)        if (context->oc.asbyte != 0)
3743          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);
3744        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));
3745        break;        break;
3746  #endif  #endif
3747    
# Line 2728  do Line 3754  do
3754    
3755  #else  #else
3756    
3757    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3758  #ifdef COMPILE_PCRE8    if (context->length >= 1)
3759    if (context->length > 0)      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3760      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  
3761    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3762    
3763    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
3764      {      {
3765      OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, othercasebit);      OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, othercasebit);
3766      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));
3767      }      }
3768    else    else
3769      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));
3770    
3771  #endif  #endif
3772    
# Line 2780  return cc; Line 3802  return cc;
3802      } \      } \
3803    charoffset = (value);    charoffset = (value);
3804    
3805  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)
3806  {  {
3807  DEFINE_COMPILER;  DEFINE_COMPILER;
3808  jump_list *found = NULL;  jump_list *found = NULL;
3809  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : fallbacks;  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;
3810  unsigned int c;  pcre_int32 c, charoffset;
3811  int compares;  const pcre_uint32 *other_cases;
3812  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
3813  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
3814    int compares, invertcmp, numberofcmps;
3815  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3816  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
3817  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
3818  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
3819  unsigned int typeoffset;  pcre_int32 typeoffset;
3820  #endif  #endif
 int invertcmp, numberofcmps;  
 unsigned int charoffset;  
3821    
3822  /* Although SUPPORT_UTF must be defined, we are not necessary in utf mode. */  /* Although SUPPORT_UTF must be defined, we are
3823  fallback_at_str_end(common, fallbacks);     not necessary in utf mode even in 8 bit mode. */
3824    detect_partial_match(common, backtracks);
3825  read_char(common);  read_char(common);
3826    
3827  if ((*cc++ & XCL_MAP) != 0)  if ((*cc++ & XCL_MAP) != 0)
# Line 2812  if ((*cc++ & XCL_MAP) != 0) Line 3834  if ((*cc++ & XCL_MAP) != 0)
3834      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3835  #endif  #endif
3836    
3837    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, list))
3838    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      {
3839    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3840    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3841    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);
3842    add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3843        OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
3844        add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
3845        }
3846    
3847  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3848    JUMPHERE(jump);    JUMPHERE(jump);
# Line 2890  while (*cc != XCL_END) Line 3915  while (*cc != XCL_END)
3915        needschar = TRUE;        needschar = TRUE;
3916        break;        break;
3917    
3918          case PT_CLIST:
3919          case PT_UCNC:
3920          needschar = TRUE;
3921          break;
3922    
3923        default:        default:
3924        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
3925        break;        break;
# Line 2926  if (needstype || needsscript) Line 3956  if (needstype || needsscript)
3956      {      {
3957      if (scriptreg == TMP1)      if (scriptreg == TMP1)
3958        {        {
3959        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));
3960        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
3961        }        }
3962      else      else
3963        {        {
3964        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
3965        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));
3966        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
3967        }        }
3968      }      }
# Line 2950  typeoffset = 0; Line 3980  typeoffset = 0;
3980  while (*cc != XCL_END)  while (*cc != XCL_END)
3981    {    {
3982    compares--;    compares--;
3983    invertcmp = (compares == 0 && list != fallbacks);    invertcmp = (compares == 0 && list != backtracks);
3984    jump = NULL;    jump = NULL;
3985    
3986    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
# Line 2968  while (*cc != XCL_END) Line 3998  while (*cc != XCL_END)
3998      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
3999        {        {
4000        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);
4001        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);
4002        numberofcmps++;        numberofcmps++;
4003        }        }
4004      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4005        {        {
4006        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);
4007        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);
4008        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4009        numberofcmps = 0;        numberofcmps = 0;
4010        }        }
# Line 3007  while (*cc != XCL_END) Line 4037  while (*cc != XCL_END)
4037      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4038        {        {
4039        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);
4040        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);
4041        numberofcmps++;        numberofcmps++;
4042        }        }
4043      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4044        {        {
4045        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);
4046        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);
4047        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4048        numberofcmps = 0;        numberofcmps = 0;
4049        }        }
# Line 3032  while (*cc != XCL_END) Line 4062  while (*cc != XCL_END)
4062      switch(*cc)      switch(*cc)
4063        {        {
4064        case PT_ANY:        case PT_ANY:
4065        if (list != fallbacks)        if (list != backtracks)
4066          {          {
4067          if ((cc[-1] == XCL_NOTPROP && compares > 0) || (cc[-1] == XCL_PROP && compares == 0))          if ((cc[-1] == XCL_NOTPROP && compares > 0) || (cc[-1] == XCL_PROP && compares == 0))
4068            continue;            continue;
# Line 3044  while (*cc != XCL_END) Line 4074  while (*cc != XCL_END)
4074    
4075        case PT_LAMP:        case PT_LAMP:
4076        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - typeoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - typeoffset);
4077        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4078        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ll - typeoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ll - typeoffset);
4079        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4080        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lt - typeoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lt - typeoffset);
4081        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);
4082        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4083        break;        break;
4084    
# Line 3075  while (*cc != XCL_END) Line 4105  while (*cc != XCL_END)
4105          }          }