/[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 741 by zherczeg, Mon Oct 31 09:31:46 2011 UTC revision 1275 by zherczeg, Sun Mar 10 05:32:10 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2008 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-2011                        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
53  system files. */  system files. */
54    
55    #define SLJIT_MALLOC(size) (PUBL(malloc))(size)
56    #define SLJIT_FREE(ptr) (PUBL(free))(ptr)
57  #define SLJIT_CONFIG_AUTO 1  #define SLJIT_CONFIG_AUTO 1
58  #define SLJIT_CONFIG_STATIC 1  #define SLJIT_CONFIG_STATIC 1
59  #define SLJIT_VERBOSE 0  #define SLJIT_VERBOSE 0
# Line 60  system files. */ Line 62  system files. */
62  #include "sljit/sljitLir.c"  #include "sljit/sljitLir.c"
63    
64  #if defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED  #if defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED
65  #error "Unsupported architecture"  #error Unsupported architecture
66  #endif  #endif
67    
68  /* Allocate memory on the stack. Fast, but limited size. */  /* Defines for debugging purposes. */
 #define LOCAL_SPACE_SIZE 32768  
69    
70    /* 1 - Use unoptimized capturing brackets.
71       2 - Enable capture_last_ptr (includes option 1). */
72    /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */
73    
74    /* 1 - Always have a control head. */
75    /* #define DEBUG_FORCE_CONTROL_HEAD 1 */
76    
77    /* Allocate memory for the regex stack on the real machine stack.
78    Fast, but limited size. */
79    #define MACHINE_STACK_SIZE 32768
80    
81    /* Growth rate for stack allocated by the OS. Should be the multiply
82    of page size. */
83  #define STACK_GROWTH_RATE 8192  #define STACK_GROWTH_RATE 8192
84    
85  /* Enable to check that the allocation could destroy temporaries. */  /* Enable to check that the allocation could destroy temporaries. */
# Line 80  The code generator follows the recursive Line 94  The code generator follows the recursive
94  expressions. The basic blocks of regular expressions are condition checkers  expressions. The basic blocks of regular expressions are condition checkers
95  whose execute different commands depending on the result of the condition check.  whose execute different commands depending on the result of the condition check.
96  The relationship between the operators can be horizontal (concatenation) and  The relationship between the operators can be horizontal (concatenation) and
97  vertical (sub-expression) (See struct fallback_common for more details).  vertical (sub-expression) (See struct backtrack_common for more details).
98    
99    'ab' - 'a' and 'b' regexps are concatenated    'ab' - 'a' and 'b' regexps are concatenated
100    'a+' - 'a' is the sub-expression of the '+' operator    'a+' - 'a' is the sub-expression of the '+' operator
101    
102  The condition checkers are boolean (true/false) checkers. Machine code is generated  The condition checkers are boolean (true/false) checkers. Machine code is generated
103  for the checker itself and for the actions depending on the result of the checker.  for the checker itself and for the actions depending on the result of the checker.
104  The 'true' case is called as the hot path (expected path), and the other is called as  The 'true' case is called as the matching path (expected path), and the other is called as
105  the 'fallback' path. Branch instructions are expesive for all CPUs, so we avoid taken  the 'backtrack' path. Branch instructions are expesive for all CPUs, so we avoid taken
106  branches on the hot path.  branches on the matching path.
107    
108   Greedy star operator (*) :   Greedy star operator (*) :
109     Hot path: match happens.     Matching path: match happens.
110     Fallback path: match failed.     Backtrack path: match failed.
111   Non-greedy star operator (*?) :   Non-greedy star operator (*?) :
112     Hot path: no need to perform a match.     Matching path: no need to perform a match.
113     Fallback path: match is required.     Backtrack path: match is required.
114    
115  The following example shows how the code generated for a capturing bracket  The following example shows how the code generated for a capturing bracket
116  with two alternatives. Let A, B, C, D are arbirary regular expressions, and  with two alternatives. Let A, B, C, D are arbirary regular expressions, and
# Line 106  we have the following regular expression Line 120  we have the following regular expression
120    
121  The generated code will be the following:  The generated code will be the following:
122    
123   A hot path   A matching path
124   '(' hot path (pushing arguments to the stack)   '(' matching path (pushing arguments to the stack)
125   B hot path   B matching path
126   ')' hot path (pushing arguments to the stack)   ')' matching path (pushing arguments to the stack)
127   D hot path   D matching path
128   return with successful match   return with successful match
129    
130   D fallback path   D backtrack path
131   ')' fallback path (If we arrived from "C" jump to the fallback of "C")   ')' backtrack path (If we arrived from "C" jump to the backtrack of "C")
132   B fallback path   B backtrack path
133   C expected path   C expected path
134   jump to D hot path   jump to D matching path
135   C fallback path   C backtrack path
136   A fallback path   A backtrack path
137    
138   Notice, that the order of fallback code paths are the opposite of the fast   Notice, that the order of backtrack code paths are the opposite of the fast
139   code paths. In this way the topmost value on the stack is always belong   code paths. In this way the topmost value on the stack is always belong
140   to the current fallback code path. The fallback code path must check   to the current backtrack code path. The backtrack path must check
141   whether there is a next alternative. If so, it needs to jump back to   whether there is a next alternative. If so, it needs to jump back to
142   the hot path eventually. Otherwise it needs to clear out its own stack   the matching path eventually. Otherwise it needs to clear out its own stack
143   frame and continue the execution on the fallback code paths.   frame and continue the execution on the backtrack code paths.
144  */  */
145    
146  /*  /*
147  Saved stack frames:  Saved stack frames:
148    
149  Atomic blocks and asserts require reloading the values of local variables  Atomic blocks and asserts require reloading the values of private data
150  when the fallback mechanism performed. Because of OP_RECURSE, the locals  when the backtrack mechanism performed. Because of OP_RECURSE, the data
151  are not necessarly known in compile time, thus we need a dynamic restore  are not necessarly known in compile time, thus we need a dynamic restore
152  mechanism.  mechanism.
153    
154  The stack frames are stored in a chain list, and have the following format:  The stack frames are stored in a chain list, and have the following format:
155  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]
156    
157  Thus we can restore the locals to a particular point in the stack.  Thus we can restore the private data to a particular point in the stack.
158  */  */
159    
160  typedef struct jit_arguments {  typedef struct jit_arguments {
161    /* Pointers first. */    /* Pointers first. */
162    struct sljit_stack *stack;    struct sljit_stack *stack;
163    PCRE_SPTR str;    const pcre_uchar *str;
164    PCRE_SPTR begin;    const pcre_uchar *begin;
165    PCRE_SPTR end;    const pcre_uchar *end;
166    int *offsets;    int *offsets;
167    uschar *ptr;    pcre_uchar *uchar_ptr;
168      pcre_uchar *mark_ptr;
169      void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171    int offsetcount;    int real_offset_count;
172    int calllimit;    int offset_count;
173    uschar notbol;    int call_limit;
174    uschar noteol;    pcre_uint8 notbol;
175    uschar notempty;    pcre_uint8 noteol;
176    uschar notempty_atstart;    pcre_uint8 notempty;
177      pcre_uint8 notempty_atstart;
178  } jit_arguments;  } jit_arguments;
179    
180  typedef struct executable_function {  typedef struct executable_functions {
181    void *executable_func;    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182    pcre_jit_callback callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184  } executable_function;    pcre_uint32 top_bracket;
185      sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
186    } executable_functions;
187    
188  typedef struct jump_list {  typedef struct jump_list {
189    struct sljit_jump *jump;    struct sljit_jump *jump;
190    struct jump_list *next;    struct jump_list *next;
191  } jump_list;  } jump_list;
192    
 enum stub_types { stack_alloc };  
   
193  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
194    struct sljit_jump *start;    struct sljit_jump *start;
195    struct sljit_label *leave;    struct sljit_label *quit;
196    struct stub_list *next;    struct stub_list *next;
197  } stub_list;  } stub_list;
198    
199    enum frame_types {
200      no_frame = -1,
201      no_stack = -2
202    };
203    
204    enum control_types {
205      type_commit = 0,
206      type_prune = 1,
207      type_skip = 2
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
213  code generator. It is allocated by compile_hotpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_fallbackpath. Must be the first member  the aguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct fallback_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
218    struct fallback_common *prev;    struct backtrack_common *prev;
219    jump_list *nextfallbacks;    jump_list *nextbacktracks;
220    /* Internal stack (for component operators). */    /* Internal stack (for component operators). */
221    struct fallback_common *top;    struct backtrack_common *top;
222    jump_list *topfallbacks;    jump_list *topbacktracks;
223    /* Opcode pointer. */    /* Opcode pointer. */
224    uschar *cc;    pcre_uchar *cc;
225  } fallback_common;  } backtrack_common;
226    
227  typedef struct assert_fallback {  typedef struct assert_backtrack {
228    fallback_common common;    backtrack_common common;
229    jump_list *condfailed;    jump_list *condfailed;
230    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 (-1) if a frame is not needed. */
231    int framesize;    int framesize;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int localptr;    int private_data_ptr;
234    /* For iterators. */    /* For iterators. */
235    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
236  } assert_fallback;  } assert_backtrack;
237    
238  typedef struct bracket_fallback {  typedef struct bracket_backtrack {
239    fallback_common common;    backtrack_common common;
240    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
241    struct sljit_label *althotpath;    struct sljit_label *alternative_matchingpath;
242    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
243    struct sljit_label *recursivehotpath;    struct sljit_label *recursive_matchingpath;
244    /* For greedy ? operator. */    /* For greedy ? operator. */
245    struct sljit_label *zerohotpath;    struct sljit_label *zero_matchingpath;
246    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
247    union {    union {
248      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
249      jump_list *condfailed;      jump_list *condfailed;
250      assert_fallback *assert;      assert_backtrack *assert;
251      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. -1 if not needed. */
252      int framesize;      int framesize;
253    } u;    } u;
254    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
255    int localptr;    int private_data_ptr;
256  } bracket_fallback;  } bracket_backtrack;
257    
258  typedef struct bracketpos_fallback {  typedef struct bracketpos_backtrack {
259    fallback_common common;    backtrack_common common;
260    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
261    int localptr;    int private_data_ptr;
262    /* Reverting stack is needed. */    /* Reverting stack is needed. */
263    int framesize;    int framesize;
264    /* Allocated stack size. */    /* Allocated stack size. */
265    int stacksize;    int stacksize;
266  } bracketpos_fallback;  } bracketpos_backtrack;
267    
268  typedef struct braminzero_fallback {  typedef struct braminzero_backtrack {
269    fallback_common common;    backtrack_common common;
270    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
271  } braminzero_fallback;  } braminzero_backtrack;
272    
273  typedef struct iterator_fallback {  typedef struct iterator_backtrack {
274    fallback_common common;    backtrack_common common;
275    /* Next iteration. */    /* Next iteration. */
276    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
277  } iterator_fallback;  } iterator_backtrack;
278    
279  typedef struct recurse_entry {  typedef struct recurse_entry {
280    struct recurse_entry *next;    struct recurse_entry *next;
# Line 260  typedef struct recurse_entry { Line 286  typedef struct recurse_entry {
286    int start;    int start;
287  } recurse_entry;  } recurse_entry;
288    
289  typedef struct recurse_fallback {  typedef struct recurse_backtrack {
290    fallback_common common;    backtrack_common common;
291  } recurse_fallback;    BOOL inlined_pattern;
292    } recurse_backtrack;
293    
294    #define MAX_RANGE_SIZE 6
295    
296  typedef struct compiler_common {  typedef struct compiler_common {
297      /* The sljit ceneric compiler. */
298    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
299    uschar *start;    /* First byte code. */
300    int localsize;    pcre_uchar *start;
301    int *localptrs;    /* Maps private data offset to each opcode. */
302    const uschar *fcc;    int *private_data_ptrs;
303    sljit_w lcc;    /* Tells whether the capturing bracket is optimized. */
304    int cbraptr;    pcre_uint8 *optimized_cbracket;
305      /* Starting offset of private data for capturing brackets. */
306      int cbra_ptr;
307      /* Output vector starting point. Must be divisible by 2. */
308      int ovector_start;
309      /* Last known position of the requested byte. */
310      int req_char_ptr;
311      /* Head of the last recursion. */
312      int recursive_head_ptr;
313      /* First inspected character for partial matching. */
314      int start_used_ptr;
315      /* Starting pointer for partial soft matches. */
316      int hit_start;
317      /* End pointer of the first line. */
318      int first_line_end;
319      /* Points to the marked string. */
320      int mark_ptr;
321      /* Recursive control verb management chain. */
322      int control_head_ptr;
323      /* Points to the last matched capture block index. */
324      int capture_last_ptr;
325      /* Points to the starting position of the current match. */
326      int start_ptr;
327    
328      /* Flipped and lower case tables. */
329      const pcre_uint8 *fcc;
330      sljit_sw lcc;
331      /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
332      int mode;
333      /* \K is in the pattern. */
334      BOOL has_set_som;
335      /* Needs to know the start position anytime. */
336      BOOL needs_start_ptr;
337      /* Currently in recurse or assert. */
338      BOOL local_exit;
339      /* Newline control. */
340    int nltype;    int nltype;
341    int newline;    int newline;
342    int bsr_nltype;    int bsr_nltype;
343      /* Dollar endonly. */
344    int endonly;    int endonly;
345    sljit_w ctypes;    /* Tables. */
346      sljit_sw ctypes;
347      int digits[2 + MAX_RANGE_SIZE];
348      /* Named capturing brackets. */
349    sljit_uw name_table;    sljit_uw name_table;
350    sljit_w name_count;    sljit_sw name_count;
351    sljit_w name_entry_size;    sljit_sw name_entry_size;
352    struct sljit_label *acceptlabel;  
353      /* Labels and jump lists. */
354      struct sljit_label *partialmatchlabel;
355      struct sljit_label *quit_label;
356      struct sljit_label *forced_quit_label;
357      struct sljit_label *accept_label;
358    stub_list *stubs;    stub_list *stubs;
359    recurse_entry *entries;    recurse_entry *entries;
360    recurse_entry *currententry;    recurse_entry *currententry;
361      jump_list *partialmatch;
362      jump_list *quit;
363      jump_list *forced_quit;
364    jump_list *accept;    jump_list *accept;
365    jump_list *calllimit;    jump_list *calllimit;
366    jump_list *stackalloc;    jump_list *stackalloc;
# Line 294  typedef struct compiler_common { Line 371  typedef struct compiler_common {
371    jump_list *vspace;    jump_list *vspace;
372    jump_list *casefulcmp;    jump_list *casefulcmp;
373    jump_list *caselesscmp;    jump_list *caselesscmp;
374      jump_list *reset_match;
375    BOOL jscript_compat;    BOOL jscript_compat;
376  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
377    BOOL utf8;    BOOL utf;
378  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
379    BOOL useucp;    BOOL use_ucp;
380  #endif  #endif
381    jump_list *utf8readchar;  #ifndef COMPILE_PCRE32
382    jump_list *utf8readtype8;    jump_list *utfreadchar;
383  #endif  #endif
384    #ifdef COMPILE_PCRE8
385      jump_list *utfreadtype8;
386    #endif
387    #endif /* SUPPORT_UTF */
388  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
389    jump_list *getucd;    jump_list *getucd;
390  #endif  #endif
# Line 314  typedef struct compare_context { Line 396  typedef struct compare_context {
396    int length;    int length;
397    int sourcereg;    int sourcereg;
398  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
399    int byteptr;    int ucharptr;
400    union {    union {
401      int asint;      sljit_si asint;
402      short asshort;      sljit_uh asushort;
403    #if defined COMPILE_PCRE8
404      sljit_ub asbyte;      sljit_ub asbyte;
405      sljit_ub asbytes[4];      sljit_ub asuchars[4];
406    #elif defined COMPILE_PCRE16
407        sljit_uh asuchars[2];
408    #elif defined COMPILE_PCRE32
409        sljit_ui asuchars[1];
410    #endif
411    } c;    } c;
412    union {    union {
413      int asint;      sljit_si asint;
414      short asshort;      sljit_uh asushort;
415    #if defined COMPILE_PCRE8
416      sljit_ub asbyte;      sljit_ub asbyte;
417      sljit_ub asbytes[4];      sljit_ub asuchars[4];
418    #elif defined COMPILE_PCRE16
419        sljit_uh asuchars[2];
420    #elif defined COMPILE_PCRE32
421        sljit_ui asuchars[1];
422    #endif
423    } oc;    } oc;
424  #endif  #endif
425  } compare_context;  } compare_context;
426    
427  enum {  /* Undefine sljit macros. */
428    frame_end = 0,  #undef CMP
   frame_setstrbegin = -1  
 };  
429    
430  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
431  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
432    
433  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
434  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
435  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
436  #define STR_PTR       SLJIT_GENERAL_REG1  #define STR_PTR       SLJIT_SAVED_REG1
437  #define STR_END       SLJIT_GENERAL_REG2  #define STR_END       SLJIT_SAVED_REG2
438  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
439  #define STACK_LIMIT   SLJIT_GENERAL_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
440  #define ARGUMENTS     SLJIT_GENERAL_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
441  #define CALL_COUNT    SLJIT_GENERAL_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
442  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
443    
444  /* Locals layout. */  /* Local space layout. */
445  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
446  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
447  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
448  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
449  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
450  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
 /* Head of the last recursion. */  
 #define RECURSIVE_HEAD   (4 * sizeof(sljit_w))  
451  /* Max limit of recursions. */  /* Max limit of recursions. */
452  #define CALL_LIMIT       (5 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
 /* Last known position of the requested byte. */  
 #define REQ_BYTE_PTR     (6 * sizeof(sljit_w))  
 /* End pointer of the first line. */  
 #define FIRSTLINE_END    (7 * sizeof(sljit_w))  
453  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
454  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
455  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
456  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
457  #define OVECTOR_START    (8 * sizeof(sljit_w))  #define OVECTOR_START    (common->ovector_start)
458  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
459  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))
460  #define PRIV(cc)         (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
461    
462    #if defined COMPILE_PCRE8
463    #define MOV_UCHAR  SLJIT_MOV_UB
464    #define MOVU_UCHAR SLJIT_MOVU_UB
465    #elif defined COMPILE_PCRE16
466    #define MOV_UCHAR  SLJIT_MOV_UH
467    #define MOVU_UCHAR SLJIT_MOVU_UH
468    #elif defined COMPILE_PCRE32
469    #define MOV_UCHAR  SLJIT_MOV_UI
470    #define MOVU_UCHAR SLJIT_MOVU_UI
471    #else
472    #error Unsupported compiling mode
473    #endif
474    
475  /* Shortcuts. */  /* Shortcuts. */
476  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 388  the start pointers when the end of the c Line 487  the start pointers when the end of the c
487    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
488  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
489    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
490    #define SET_LABEL(jump, label) \
491      sljit_set_label((jump), (label))
492  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
493    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
494  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
495    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))
496  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
497    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
498    #define GET_LOCAL_BASE(dst, dstw, offset) \
499      sljit_get_local_base(compiler, (dst), (dstw), (offset))
500    
501  static uschar* bracketend(uschar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
502  {  {
503  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
504  do cc += GET(cc, 1); while (*cc == OP_ALT);  do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 406  return cc; Line 509  return cc;
509    
510  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
511   next_opcode   next_opcode
512   get_localspace   get_private_data_length
513   set_localptrs   set_private_data_ptrs
514   get_framesize   get_framesize
515   init_frame   init_frame
516   get_localsize   get_private_data_length_for_copy
517   copy_locals   copy_private_data
518   compile_hotpath   compile_matchingpath
519   compile_fallbackpath   compile_backtrackingpath
520  */  */
521    
522  static uschar *next_opcode(compiler_common *common, uschar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
523  {  {
524  SLJIT_UNUSED_ARG(common);  SLJIT_UNUSED_ARG(common);
525  switch(*cc)  switch(*cc)
# Line 434  switch(*cc) Line 537  switch(*cc)
537    case OP_WORDCHAR:    case OP_WORDCHAR:
538    case OP_ANY:    case OP_ANY:
539    case OP_ALLANY:    case OP_ALLANY:
540      case OP_NOTPROP:
541      case OP_PROP:
542    case OP_ANYNL:    case OP_ANYNL:
543    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
544    case OP_HSPACE:    case OP_HSPACE:
# Line 446  switch(*cc) Line 551  switch(*cc)
551    case OP_CIRCM:    case OP_CIRCM:
552    case OP_DOLL:    case OP_DOLL:
553    case OP_DOLLM:    case OP_DOLLM:
   case OP_TYPESTAR:  
   case OP_TYPEMINSTAR:  
   case OP_TYPEPLUS:  
   case OP_TYPEMINPLUS:  
   case OP_TYPEQUERY:  
   case OP_TYPEMINQUERY:  
   case OP_TYPEPOSSTAR:  
   case OP_TYPEPOSPLUS:  
   case OP_TYPEPOSQUERY:  
554    case OP_CRSTAR:    case OP_CRSTAR:
555    case OP_CRMINSTAR:    case OP_CRMINSTAR:
556    case OP_CRPLUS:    case OP_CRPLUS:
557    case OP_CRMINPLUS:    case OP_CRMINPLUS:
558    case OP_CRQUERY:    case OP_CRQUERY:
559    case OP_CRMINQUERY:    case OP_CRMINQUERY:
560      case OP_CRRANGE:
561      case OP_CRMINRANGE:
562      case OP_CLASS:
563      case OP_NCLASS:
564      case OP_REF:
565      case OP_REFI:
566      case OP_RECURSE:
567      case OP_CALLOUT:
568      case OP_ALT:
569      case OP_KET:
570      case OP_KETRMAX:
571      case OP_KETRMIN:
572      case OP_KETRPOS:
573      case OP_REVERSE:
574      case OP_ASSERT:
575      case OP_ASSERT_NOT:
576      case OP_ASSERTBACK:
577      case OP_ASSERTBACK_NOT:
578      case OP_ONCE:
579      case OP_ONCE_NC:
580      case OP_BRA:
581      case OP_BRAPOS:
582      case OP_CBRA:
583      case OP_CBRAPOS:
584      case OP_COND:
585      case OP_SBRA:
586      case OP_SBRAPOS:
587      case OP_SCBRA:
588      case OP_SCBRAPOS:
589      case OP_SCOND:
590      case OP_CREF:
591      case OP_NCREF:
592      case OP_RREF:
593      case OP_NRREF:
594    case OP_DEF:    case OP_DEF:
595    case OP_BRAZERO:    case OP_BRAZERO:
596    case OP_BRAMINZERO:    case OP_BRAMINZERO:
597    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
598      case OP_PRUNE:
599      case OP_SKIP:
600      case OP_COMMIT:
601    case OP_FAIL:    case OP_FAIL:
602    case OP_ACCEPT:    case OP_ACCEPT:
603    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
604      case OP_CLOSE:
605    case OP_SKIPZERO:    case OP_SKIPZERO:
606    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF8  
   if (common->utf8) return NULL;  
 #endif  
   return cc + 1;  
607    
608    case OP_CHAR:    case OP_CHAR:
609    case OP_CHARI:    case OP_CHARI:
610    case OP_NOT:    case OP_NOT:
611    case OP_NOTI:    case OP_NOTI:
   
612    case OP_STAR:    case OP_STAR:
613    case OP_MINSTAR:    case OP_MINSTAR:
614    case OP_PLUS:    case OP_PLUS:
615    case OP_MINPLUS:    case OP_MINPLUS:
616    case OP_QUERY:    case OP_QUERY:
617    case OP_MINQUERY:    case OP_MINQUERY:
618      case OP_UPTO:
619      case OP_MINUPTO:
620      case OP_EXACT:
621    case OP_POSSTAR:    case OP_POSSTAR:
622    case OP_POSPLUS:    case OP_POSPLUS:
623    case OP_POSQUERY:    case OP_POSQUERY:
624      case OP_POSUPTO:
625    case OP_STARI:    case OP_STARI:
626    case OP_MINSTARI:    case OP_MINSTARI:
627    case OP_PLUSI:    case OP_PLUSI:
628    case OP_MINPLUSI:    case OP_MINPLUSI:
629    case OP_QUERYI:    case OP_QUERYI:
630    case OP_MINQUERYI:    case OP_MINQUERYI:
631      case OP_UPTOI:
632      case OP_MINUPTOI:
633      case OP_EXACTI:
634    case OP_POSSTARI:    case OP_POSSTARI:
635    case OP_POSPLUSI:    case OP_POSPLUSI:
636    case OP_POSQUERYI:    case OP_POSQUERYI:
637      case OP_POSUPTOI:
638    case OP_NOTSTAR:    case OP_NOTSTAR:
639    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
640    case OP_NOTPLUS:    case OP_NOTPLUS:
641    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
642    case OP_NOTQUERY:    case OP_NOTQUERY:
643    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
644      case OP_NOTUPTO:
645      case OP_NOTMINUPTO:
646      case OP_NOTEXACT:
647    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
648    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
649    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
650      case OP_NOTPOSUPTO:
651    case OP_NOTSTARI:    case OP_NOTSTARI:
652    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
653    case OP_NOTPLUSI:    case OP_NOTPLUSI:
654    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
655    case OP_NOTQUERYI:    case OP_NOTQUERYI:
656    case OP_NOTMINQUERYI:    case OP_NOTMINQUERYI:
   case OP_NOTPOSSTARI:  
   case OP_NOTPOSPLUSI:  
   case OP_NOTPOSQUERYI:  
   cc += 2;  
 #ifdef SUPPORT_UTF8  
   if (common->utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];  
 #endif  
   return cc;  
   
   case OP_UPTO:  
   case OP_MINUPTO:  
   case OP_EXACT:  
   case OP_POSUPTO:  
   case OP_UPTOI:  
   case OP_MINUPTOI:  
   case OP_EXACTI:  
   case OP_POSUPTOI:  
   case OP_NOTUPTO:  
   case OP_NOTMINUPTO:  
   case OP_NOTEXACT:  
   case OP_NOTPOSUPTO:  
657    case OP_NOTUPTOI:    case OP_NOTUPTOI:
658    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
659    case OP_NOTEXACTI:    case OP_NOTEXACTI:
660      case OP_NOTPOSSTARI:
661      case OP_NOTPOSPLUSI:
662      case OP_NOTPOSQUERYI:
663    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
664    cc += 4;    cc += PRIV(OP_lengths)[*cc];
665  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
666    if (common->utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
667  #endif  #endif
668    return cc;    return cc;
669    
670    case OP_NOTPROP:    /* Special cases. */
671    case OP_PROP:    case OP_TYPESTAR:
672      case OP_TYPEMINSTAR:
673      case OP_TYPEPLUS:
674      case OP_TYPEMINPLUS:
675      case OP_TYPEQUERY:
676      case OP_TYPEMINQUERY:
677    case OP_TYPEUPTO:    case OP_TYPEUPTO:
678    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
679    case OP_TYPEEXACT:    case OP_TYPEEXACT:
680      case OP_TYPEPOSSTAR:
681      case OP_TYPEPOSPLUS:
682      case OP_TYPEPOSQUERY:
683    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
684    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_NCREF:  
   case OP_RREF:  
   case OP_NRREF:  
   case OP_CLOSE:  
   cc += 3;  
   return cc;  
685    
686    case OP_CRRANGE:    case OP_ANYBYTE:
687    case OP_CRMINRANGE:  #ifdef SUPPORT_UTF
688    return cc + 5;    if (common->utf) return NULL;
689    #endif
690    case OP_CLASS:    return cc + 1;
   case OP_NCLASS:  
   return cc + 33;  
691    
692  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
693    case OP_XCLASS:    case OP_XCLASS:
694    return cc + GET(cc, 1);    return cc + GET(cc, 1);
695  #endif  #endif
696    
697    case OP_RECURSE:    case OP_MARK:
698    case OP_ASSERT:    case OP_PRUNE_ARG:
699    case OP_ASSERT_NOT:    return cc + 1 + 2 + cc[1];
   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 + 2;  
700    
701    default:    default:
702    return NULL;    return NULL;
703    }    }
704  }  }
705    
706  static int get_localspace(compiler_common *common, uschar *cc, uschar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
707        case OP_MINSTAR: \
708        case OP_MINPLUS: \
709        case OP_QUERY: \
710        case OP_MINQUERY: \
711        case OP_MINSTARI: \
712        case OP_MINPLUSI: \
713        case OP_QUERYI: \
714        case OP_MINQUERYI: \
715        case OP_NOTMINSTAR: \
716        case OP_NOTMINPLUS: \
717        case OP_NOTQUERY: \
718        case OP_NOTMINQUERY: \
719        case OP_NOTMINSTARI: \
720        case OP_NOTMINPLUSI: \
721        case OP_NOTQUERYI: \
722        case OP_NOTMINQUERYI:
723    
724    #define CASE_ITERATOR_PRIVATE_DATA_2A \
725        case OP_STAR: \
726        case OP_PLUS: \
727        case OP_STARI: \
728        case OP_PLUSI: \
729        case OP_NOTSTAR: \
730        case OP_NOTPLUS: \
731        case OP_NOTSTARI: \
732        case OP_NOTPLUSI:
733    
734    #define CASE_ITERATOR_PRIVATE_DATA_2B \
735        case OP_UPTO: \
736        case OP_MINUPTO: \
737        case OP_UPTOI: \
738        case OP_MINUPTOI: \
739        case OP_NOTUPTO: \
740        case OP_NOTMINUPTO: \
741        case OP_NOTUPTOI: \
742        case OP_NOTMINUPTOI:
743    
744    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
745        case OP_TYPEMINSTAR: \
746        case OP_TYPEMINPLUS: \
747        case OP_TYPEQUERY: \
748        case OP_TYPEMINQUERY:
749    
750    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
751        case OP_TYPESTAR: \
752        case OP_TYPEPLUS:
753    
754    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
755        case OP_TYPEUPTO: \
756        case OP_TYPEMINUPTO:
757    
758    static int get_class_iterator_size(pcre_uchar *cc)
759  {  {
760  int localspace = 0;  switch(*cc)
 uschar *alternative;  
 /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  
 while (cc < ccend)  
761    {    {
762    switch(*cc)    case OP_CRSTAR:
763      {    case OP_CRPLUS:
764      case OP_ASSERT:    return 2;
     case OP_ASSERT_NOT:  
     case OP_ASSERTBACK:  
     case OP_ASSERTBACK_NOT:  
     case OP_ONCE:  
     case OP_ONCE_NC:  
     case OP_BRAPOS:  
     case OP_SBRA:  
     case OP_SBRAPOS:  
     case OP_SCOND:  
     localspace += sizeof(sljit_w);  
     cc += 1 + LINK_SIZE;  
     break;  
765    
766      case OP_CBRAPOS:    case OP_CRMINSTAR:
767      case OP_SCBRAPOS:    case OP_CRMINPLUS:
768      localspace += sizeof(sljit_w);    case OP_CRQUERY:
769      cc += 1 + LINK_SIZE + 2;    case OP_CRMINQUERY:
770      break;    return 1;
771    
772      case OP_COND:    case OP_CRRANGE:
773      /* Might be a hidden SCOND. */    case OP_CRMINRANGE:
774      alternative = cc + GET(cc, 1);    if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
775      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      return 0;
776        localspace += sizeof(sljit_w);    return 2;
     cc += 1 + LINK_SIZE;  
     break;  
777    
778      default:    default:
779      cc = next_opcode(common, cc);    return 0;
     if (cc == NULL)  
       return -1;  
     break;  
     }  
780    }    }
 return localspace;  
781  }  }
782    
783  static void set_localptrs(compiler_common *common, int localptr, uschar *ccend)  static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
784  {  {
785  uschar *cc = common->start;  int private_data_length = 0;
786  uschar *alternative;  pcre_uchar *alternative;
787    pcre_uchar *name;
788    pcre_uchar *end = NULL;
789    int space, size, i;
790    pcre_uint32 bracketlen;
791    
792    /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
793  while (cc < ccend)  while (cc < ccend)
794    {    {
795      space = 0;
796      size = 0;
797      bracketlen = 0;
798    switch(*cc)    switch(*cc)
799      {      {
800        case OP_SET_SOM:
801        common->has_set_som = TRUE;
802        cc += 1;
803        break;
804    
805        case OP_REF:
806        case OP_REFI:
807        common->optimized_cbracket[GET2(cc, 1)] = 0;
808        cc += 1 + IMM2_SIZE;
809        break;
810    
811      case OP_ASSERT:      case OP_ASSERT:
812      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
813      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 671  while (cc < ccend) Line 817  while (cc < ccend)
817      case OP_BRAPOS:      case OP_BRAPOS:
818      case OP_SBRA:      case OP_SBRA:
819      case OP_SBRAPOS:      case OP_SBRAPOS:
820      case OP_SCOND:      private_data_length += sizeof(sljit_sw);
821      common->localptrs[cc - common->start] = localptr;      bracketlen = 1 + LINK_SIZE;
     localptr += sizeof(sljit_w);  
     cc += 1 + LINK_SIZE;  
822      break;      break;
823    
824      case OP_CBRAPOS:      case OP_CBRAPOS:
825      case OP_SCBRAPOS:      case OP_SCBRAPOS:
826      common->localptrs[cc - common->start] = localptr;      private_data_length += sizeof(sljit_sw);
827      localptr += sizeof(sljit_w);      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
828      cc += 1 + LINK_SIZE + 2;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
829      break;      break;
830    
831      case OP_COND:      case OP_COND:
832      /* Might be a hidden SCOND. */      case OP_SCOND:
833      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
834      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
835        if (cc[1 + LINK_SIZE] == OP_CALLOUT)
836          return -1;
837    
838        if (*cc == OP_COND)
839        {        {
840        common->localptrs[cc - common->start] = localptr;        /* Might be a hidden SCOND. */
841        localptr += sizeof(sljit_w);        alternative = cc + GET(cc, 1);
842          if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
843            private_data_length += sizeof(sljit_sw);
844        }        }
845      cc += 1 + LINK_SIZE;      else
846          private_data_length += sizeof(sljit_sw);
847        bracketlen = 1 + LINK_SIZE;
848      break;      break;
849    
850      default:      case OP_CREF:
851      cc = next_opcode(common, cc);      i = GET2(cc, 1);
852      SLJIT_ASSERT(cc != NULL);      common->optimized_cbracket[i] = 0;
853        cc += 1 + IMM2_SIZE;
854      break;      break;
     }  
   }  
 }  
855    
856  /* Returns with -1 if no need for frame. */      case OP_NCREF:
857  static int get_framesize(compiler_common *common, uschar *cc, BOOL recursive)      bracketlen = GET2(cc, 1);
858  {      name = (pcre_uchar *)common->name_table;
859  uschar *ccend = bracketend(cc);      alternative = name;
860  int length = 0;      for (i = 0; i < common->name_count; i++)
861  BOOL possessive = FALSE;        {
862  BOOL setsom_found = FALSE;        if (GET2(name, 0) == bracketlen) break;
863          name += common->name_entry_size;
864  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))        }
865    {      SLJIT_ASSERT(i != common->name_count);
   length = 3;  
   possessive = TRUE;  
   }  
866    
867  cc = next_opcode(common, cc);      for (i = 0; i < common->name_count; i++)
 SLJIT_ASSERT(cc != NULL);  
 while (cc < ccend)  
   switch(*cc)  
     {  
     case OP_SET_SOM:  
     case OP_RECURSE:  
     if (!setsom_found)  
868        {        {
869        length += 2;        if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
870        setsom_found = TRUE;          common->optimized_cbracket[GET2(alternative, 0)] = 0;
871          alternative += common->name_entry_size;
872        }        }
873      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      bracketlen = 0;
874        cc += 1 + IMM2_SIZE;
875      break;      break;
876    
877      case OP_CBRA:      case OP_BRA:
878      case OP_CBRAPOS:      bracketlen = 1 + LINK_SIZE;
879        break;
880    
881        case OP_CBRA:
882        case OP_SCBRA:
883        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
884        break;
885    
886        CASE_ITERATOR_PRIVATE_DATA_1
887        space = 1;
888        size = -2;
889        break;
890    
891        CASE_ITERATOR_PRIVATE_DATA_2A
892        space = 2;
893        size = -2;
894        break;
895    
896        CASE_ITERATOR_PRIVATE_DATA_2B
897        space = 2;
898        size = -(2 + IMM2_SIZE);
899        break;
900    
901        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
902        space = 1;
903        size = 1;
904        break;
905    
906        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
907        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
908          space = 2;
909        size = 1;
910        break;
911    
912        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
913        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
914          space = 2;
915        size = 1 + IMM2_SIZE;
916        break;
917    
918        case OP_CLASS:
919        case OP_NCLASS:
920        size += 1 + 32 / sizeof(pcre_uchar);
921        space = get_class_iterator_size(cc + size);
922        break;
923    
924    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
925        case OP_XCLASS:
926        size = GET(cc, 1);
927        space = get_class_iterator_size(cc + size);
928        break;
929    #endif
930    
931        case OP_RECURSE:
932        /* Set its value only once. */
933        if (common->recursive_head_ptr == 0)
934          {
935          common->recursive_head_ptr = common->ovector_start;
936          common->ovector_start += sizeof(sljit_sw);
937          }
938        cc += 1 + LINK_SIZE;
939        break;
940    
941        case OP_CALLOUT:
942        if (common->capture_last_ptr == 0)
943          {
944          common->capture_last_ptr = common->ovector_start;
945          common->ovector_start += sizeof(sljit_sw);
946          }
947        cc += 2 + 2 * LINK_SIZE;
948        break;
949    
950        case OP_PRUNE_ARG:
951        common->needs_start_ptr = TRUE;
952        common->control_head_ptr = 1;
953        /* Fall through. */
954    
955        case OP_MARK:
956        if (common->mark_ptr == 0)
957          {
958          common->mark_ptr = common->ovector_start;
959          common->ovector_start += sizeof(sljit_sw);
960          }
961        cc += 1 + 2 + cc[1];
962        break;
963    
964        case OP_PRUNE:
965        case OP_SKIP:
966        common->needs_start_ptr = TRUE;
967        /* Fall through. */
968    
969        case OP_COMMIT:
970        common->control_head_ptr = 1;
971        cc += 1;
972        break;
973    
974        default:
975        cc = next_opcode(common, cc);
976        if (cc == NULL)
977          return -1;
978        break;
979        }
980    
981      if (space > 0 && cc >= end)
982        private_data_length += sizeof(sljit_sw) * space;
983    
984      if (size != 0)
985        {
986        if (size < 0)
987          {
988          cc += -size;
989    #ifdef SUPPORT_UTF
990          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
991    #endif
992          }
993        else
994          cc += size;
995        }
996    
997      if (bracketlen != 0)
998        {
999        if (cc >= end)
1000          {
1001          end = bracketend(cc);
1002          if (end[-1 - LINK_SIZE] == OP_KET)
1003            end = NULL;
1004          }
1005        cc += bracketlen;
1006        }
1007      }
1008    return private_data_length;
1009    }
1010    
1011    static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)
1012    {
1013    pcre_uchar *cc = common->start;
1014    pcre_uchar *alternative;
1015    pcre_uchar *end = NULL;
1016    int space, size, bracketlen;
1017    
1018    while (cc < ccend)
1019      {
1020      space = 0;
1021      size = 0;
1022      bracketlen = 0;
1023      switch(*cc)
1024        {
1025        case OP_ASSERT:
1026        case OP_ASSERT_NOT:
1027        case OP_ASSERTBACK:
1028        case OP_ASSERTBACK_NOT:
1029        case OP_ONCE:
1030        case OP_ONCE_NC:
1031        case OP_BRAPOS:
1032        case OP_SBRA:
1033        case OP_SBRAPOS:
1034        case OP_SCOND:
1035        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1036        private_data_ptr += sizeof(sljit_sw);
1037        bracketlen = 1 + LINK_SIZE;
1038        break;
1039    
1040        case OP_CBRAPOS:
1041        case OP_SCBRAPOS:
1042        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1043        private_data_ptr += sizeof(sljit_sw);
1044        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1045        break;
1046    
1047        case OP_COND:
1048        /* Might be a hidden SCOND. */
1049        alternative = cc + GET(cc, 1);
1050        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1051          {
1052          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1053          private_data_ptr += sizeof(sljit_sw);
1054          }
1055        bracketlen = 1 + LINK_SIZE;
1056        break;
1057    
1058        case OP_BRA:
1059        bracketlen = 1 + LINK_SIZE;
1060        break;
1061    
1062        case OP_CBRA:
1063        case OP_SCBRA:
1064        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1065        break;
1066    
1067        CASE_ITERATOR_PRIVATE_DATA_1
1068        space = 1;
1069        size = -2;
1070        break;
1071    
1072        CASE_ITERATOR_PRIVATE_DATA_2A
1073        space = 2;
1074        size = -2;
1075        break;
1076    
1077        CASE_ITERATOR_PRIVATE_DATA_2B
1078        space = 2;
1079        size = -(2 + IMM2_SIZE);
1080        break;
1081    
1082        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1083        space = 1;
1084        size = 1;
1085        break;
1086    
1087        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1088        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1089          space = 2;
1090        size = 1;
1091        break;
1092    
1093        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1094        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1095          space = 2;
1096        size = 1 + IMM2_SIZE;
1097        break;
1098    
1099        case OP_CLASS:
1100        case OP_NCLASS:
1101        size += 1 + 32 / sizeof(pcre_uchar);
1102        space = get_class_iterator_size(cc + size);
1103        break;
1104    
1105    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1106        case OP_XCLASS:
1107        size = GET(cc, 1);
1108        space = get_class_iterator_size(cc + size);
1109        break;
1110    #endif
1111    
1112        default:
1113        cc = next_opcode(common, cc);
1114        SLJIT_ASSERT(cc != NULL);
1115        break;
1116        }
1117    
1118      if (space > 0 && cc >= end)
1119        {
1120        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1121        private_data_ptr += sizeof(sljit_sw) * space;
1122        }
1123    
1124      if (size != 0)
1125        {
1126        if (size < 0)
1127          {
1128          cc += -size;
1129    #ifdef SUPPORT_UTF
1130          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1131    #endif
1132          }
1133        else
1134          cc += size;
1135        }
1136    
1137      if (bracketlen > 0)
1138        {
1139        if (cc >= end)
1140          {
1141          end = bracketend(cc);
1142          if (end[-1 - LINK_SIZE] == OP_KET)
1143            end = NULL;
1144          }
1145        cc += bracketlen;
1146        }
1147      }
1148    }
1149    
1150    /* Returns with a frame_types (always < 0) if no need for frame. */
1151    static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)
1152    {
1153    pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1154    int length = 0;
1155    int possessive = 0;
1156    BOOL stack_restore = FALSE;
1157    BOOL setsom_found = recursive;
1158    BOOL setmark_found = recursive;
1159    /* The last capture is a local variable even for recursions. */
1160    BOOL capture_last_found = FALSE;
1161    
1162    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1163      {
1164      possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1165      /* This is correct regardless of common->capture_last_ptr. */
1166      capture_last_found = TRUE;
1167      }
1168    
1169    cc = next_opcode(common, cc);
1170    SLJIT_ASSERT(cc != NULL);
1171    while (cc < ccend)
1172      switch(*cc)
1173        {
1174        case OP_SET_SOM:
1175        SLJIT_ASSERT(common->has_set_som);
1176        stack_restore = TRUE;
1177        if (!setsom_found)
1178          {
1179          length += 2;
1180          setsom_found = TRUE;
1181          }
1182        cc += 1;
1183        break;
1184    
1185        case OP_MARK:
1186        case OP_PRUNE_ARG:
1187        SLJIT_ASSERT(common->mark_ptr != 0);
1188        stack_restore = TRUE;
1189        if (!setmark_found)
1190          {
1191          length += 2;
1192          setmark_found = TRUE;
1193          }
1194        cc += 1 + 2 + cc[1];
1195        break;
1196    
1197        case OP_RECURSE:
1198        stack_restore = TRUE;
1199        if (common->has_set_som && !setsom_found)
1200          {
1201          length += 2;
1202          setsom_found = TRUE;
1203          }
1204        if (common->mark_ptr != 0 && !setmark_found)
1205          {
1206          length += 2;
1207          setmark_found = TRUE;
1208          }
1209        if (common->capture_last_ptr != 0 && !capture_last_found)
1210          {
1211          length += 2;
1212          capture_last_found = TRUE;
1213          }
1214        cc += 1 + LINK_SIZE;
1215        break;
1216    
1217        case OP_CBRA:
1218        case OP_CBRAPOS:
1219      case OP_SCBRA:      case OP_SCBRA:
1220      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1221        stack_restore = TRUE;
1222        if (common->capture_last_ptr != 0 && !capture_last_found)
1223          {
1224          length += 2;
1225          capture_last_found = TRUE;
1226          }
1227      length += 3;      length += 3;
1228      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1229      break;      break;
1230    
1231      default:      default:
1232        stack_restore = TRUE;
1233        /* Fall through. */
1234    
1235        case OP_NOT_WORD_BOUNDARY:
1236        case OP_WORD_BOUNDARY:
1237        case OP_NOT_DIGIT:
1238        case OP_DIGIT:
1239        case OP_NOT_WHITESPACE:
1240        case OP_WHITESPACE:
1241        case OP_NOT_WORDCHAR:
1242        case OP_WORDCHAR:
1243        case OP_ANY:
1244        case OP_ALLANY:
1245        case OP_ANYBYTE:
1246        case OP_NOTPROP:
1247        case OP_PROP:
1248        case OP_ANYNL:
1249        case OP_NOT_HSPACE:
1250        case OP_HSPACE:
1251        case OP_NOT_VSPACE:
1252        case OP_VSPACE:
1253        case OP_EXTUNI:
1254        case OP_EODN:
1255        case OP_EOD:
1256        case OP_CIRC:
1257        case OP_CIRCM:
1258        case OP_DOLL:
1259        case OP_DOLLM:
1260        case OP_CHAR:
1261        case OP_CHARI:
1262        case OP_NOT:
1263        case OP_NOTI:
1264    
1265        case OP_EXACT:
1266        case OP_POSSTAR:
1267        case OP_POSPLUS:
1268        case OP_POSQUERY:
1269        case OP_POSUPTO:
1270    
1271        case OP_EXACTI:
1272        case OP_POSSTARI:
1273        case OP_POSPLUSI:
1274        case OP_POSQUERYI:
1275        case OP_POSUPTOI:
1276    
1277        case OP_NOTEXACT:
1278        case OP_NOTPOSSTAR:
1279        case OP_NOTPOSPLUS:
1280        case OP_NOTPOSQUERY:
1281        case OP_NOTPOSUPTO:
1282    
1283        case OP_NOTEXACTI:
1284        case OP_NOTPOSSTARI:
1285        case OP_NOTPOSPLUSI:
1286        case OP_NOTPOSQUERYI:
1287        case OP_NOTPOSUPTOI:
1288    
1289        case OP_TYPEEXACT:
1290        case OP_TYPEPOSSTAR:
1291        case OP_TYPEPOSPLUS:
1292        case OP_TYPEPOSQUERY:
1293        case OP_TYPEPOSUPTO:
1294    
1295        case OP_CLASS:
1296        case OP_NCLASS:
1297        case OP_XCLASS:
1298    
1299      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1300      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1301      break;      break;
1302      }      }
1303    
1304  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1305  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1306    return -1;    return stack_restore ? no_frame : no_stack;
1307    
1308  if (length > 0)  if (length > 0)
1309    return length + 1;    return length + 1;
1310  return -1;  return stack_restore ? no_frame : no_stack;
1311  }  }
1312    
1313  static void init_frame(compiler_common *common, uschar *cc, int stackpos, int stacktop, BOOL recursive)  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)
1314  {  {
1315  DEFINE_COMPILER;  DEFINE_COMPILER;
1316  uschar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1317  BOOL setsom_found = FALSE;  BOOL setsom_found = recursive;
1318    BOOL setmark_found = recursive;
1319    /* The last capture is a local variable even for recursions. */
1320    BOOL capture_last_found = FALSE;
1321  int offset;  int offset;
1322    
1323  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
1324    SLJIT_UNUSED_ARG(stacktop);
1325  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1326    
1327  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
# Line 773  while (cc < ccend) Line 1332  while (cc < ccend)
1332    switch(*cc)    switch(*cc)
1333      {      {
1334      case OP_SET_SOM:      case OP_SET_SOM:
1335      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1336      if (!setsom_found)      if (!setsom_found)
1337        {        {
1338        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1339        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1340        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1341          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1342          stackpos += (int)sizeof(sljit_sw);
1343          setsom_found = TRUE;
1344          }
1345        cc += 1;
1346        break;
1347    
1348        case OP_MARK:
1349        case OP_PRUNE_ARG:
1350        SLJIT_ASSERT(common->mark_ptr != 0);
1351        if (!setmark_found)
1352          {
1353          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1354          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1355          stackpos += (int)sizeof(sljit_sw);
1356          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1357          stackpos += (int)sizeof(sljit_sw);
1358          setmark_found = TRUE;
1359          }
1360        cc += 1 + 2 + cc[1];
1361        break;
1362    
1363        case OP_RECURSE:
1364        if (common->has_set_som && !setsom_found)
1365          {
1366          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1367          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1368          stackpos += (int)sizeof(sljit_sw);
1369        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1370        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1371        setsom_found = TRUE;        setsom_found = TRUE;
1372        }        }
1373      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      if (common->mark_ptr != 0 && !setmark_found)
1374          {
1375          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1376          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1377          stackpos += (int)sizeof(sljit_sw);
1378          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1379          stackpos += (int)sizeof(sljit_sw);
1380          setmark_found = TRUE;
1381          }
1382        if (common->capture_last_ptr != 0 && !capture_last_found)
1383          {
1384          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1385          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1386          stackpos += (int)sizeof(sljit_sw);
1387          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1388          stackpos += (int)sizeof(sljit_sw);
1389          capture_last_found = TRUE;
1390          }
1391        cc += 1 + LINK_SIZE;
1392      break;      break;
1393    
1394      case OP_CBRA:      case OP_CBRA:
1395      case OP_CBRAPOS:      case OP_CBRAPOS:
1396      case OP_SCBRA:      case OP_SCBRA:
1397      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1398        if (common->capture_last_ptr != 0 && !capture_last_found)
1399          {
1400          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1401          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1402          stackpos += (int)sizeof(sljit_sw);
1403          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1404          stackpos += (int)sizeof(sljit_sw);
1405          capture_last_found = TRUE;
1406          }
1407      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1408      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1409      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1410      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1411      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
1412      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1413      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1414      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1415      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1416    
1417      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1418      break;      break;
1419    
1420      default:      default:
# Line 809  while (cc < ccend) Line 1423  while (cc < ccend)
1423      break;      break;
1424      }      }
1425    
1426  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1427  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1428  }  }
1429    
1430  static SLJIT_INLINE int get_localsize(compiler_common *common, uschar *cc, uschar *ccend)  static SLJIT_INLINE int get_private_data_length_for_copy(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
1431  {  {
1432  int localsize = 2;  int private_data_length = common->control_head_ptr ? 3 : 2;
1433  uschar *alternative;  int size;
1434  /* Calculate the sum of the local variables. */  pcre_uchar *alternative;
1435    /* Calculate the sum of the private machine words. */
1436  while (cc < ccend)  while (cc < ccend)
1437    {    {
1438      size = 0;
1439    switch(*cc)    switch(*cc)
1440      {      {
1441      case OP_ASSERT:      case OP_ASSERT:
# Line 832  while (cc < ccend) Line 1448  while (cc < ccend)
1448      case OP_SBRA:      case OP_SBRA:
1449      case OP_SBRAPOS:      case OP_SBRAPOS:
1450      case OP_SCOND:      case OP_SCOND:
1451      localsize++;      private_data_length++;
1452      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1453      break;      break;
1454    
1455      case OP_CBRA:      case OP_CBRA:
1456      case OP_SCBRA:      case OP_SCBRA:
1457      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1458      cc += 1 + LINK_SIZE + 2;        private_data_length++;
1459        cc += 1 + LINK_SIZE + IMM2_SIZE;
1460      break;      break;
1461    
1462      case OP_CBRAPOS:      case OP_CBRAPOS:
1463      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1464      localsize += 2;      private_data_length += 2;
1465      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1466      break;      break;
1467    
1468      case OP_COND:      case OP_COND:
1469      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1470      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1471      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1472        localsize++;        private_data_length++;
1473      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1474      break;      break;
1475    
1476        CASE_ITERATOR_PRIVATE_DATA_1
1477        if (PRIVATE_DATA(cc))
1478          private_data_length++;
1479        cc += 2;
1480    #ifdef SUPPORT_UTF
1481        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1482    #endif
1483        break;
1484    
1485        CASE_ITERATOR_PRIVATE_DATA_2A
1486        if (PRIVATE_DATA(cc))
1487          private_data_length += 2;
1488        cc += 2;
1489    #ifdef SUPPORT_UTF
1490        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1491    #endif
1492        break;
1493    
1494        CASE_ITERATOR_PRIVATE_DATA_2B
1495        if (PRIVATE_DATA(cc))
1496          private_data_length += 2;
1497        cc += 2 + IMM2_SIZE;
1498    #ifdef SUPPORT_UTF
1499        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1500    #endif
1501        break;
1502    
1503        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1504        if (PRIVATE_DATA(cc))
1505          private_data_length++;
1506        cc += 1;
1507        break;
1508    
1509        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1510        if (PRIVATE_DATA(cc))
1511          private_data_length += 2;
1512        cc += 1;
1513        break;
1514    
1515        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1516        if (PRIVATE_DATA(cc))
1517          private_data_length += 2;
1518        cc += 1 + IMM2_SIZE;
1519        break;
1520    
1521        case OP_CLASS:
1522        case OP_NCLASS:
1523    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1524        case OP_XCLASS:
1525        size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1526    #else
1527        size = 1 + 32 / (int)sizeof(pcre_uchar);
1528    #endif
1529        if (PRIVATE_DATA(cc))
1530          private_data_length += get_class_iterator_size(cc + size);
1531        cc += size;
1532        break;
1533    
1534      default:      default:
1535      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1536      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 863  while (cc < ccend) Line 1538  while (cc < ccend)
1538      }      }
1539    }    }
1540  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1541  return localsize;  return private_data_length;
1542  }  }
1543    
1544  static void copy_locals(compiler_common *common, uschar *cc, uschar *ccend,  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,
1545    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop)
1546  {  {
1547  DEFINE_COMPILER;  DEFINE_COMPILER;
1548  int srcw[2];  int srcw[2];
1549  int count;  int count, size;
1550  BOOL tmp1next = TRUE;  BOOL tmp1next = TRUE;
1551  BOOL tmp1empty = TRUE;  BOOL tmp1empty = TRUE;
1552  BOOL tmp2empty = TRUE;  BOOL tmp2empty = TRUE;
1553  uschar *alternative;  pcre_uchar *alternative;
1554  enum {  enum {
1555    start,    start,
1556    loop,    loop,
# Line 888  stacktop = STACK(stacktop - 1); Line 1563  stacktop = STACK(stacktop - 1);
1563    
1564  if (!save)  if (!save)
1565    {    {
1566    stackptr += sizeof(sljit_w);    stackptr += (common->control_head_ptr ? 2 : 1) * sizeof(sljit_sw);
1567    if (stackptr < stacktop)    if (stackptr < stacktop)
1568      {      {
1569      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1570      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1571      tmp1empty = FALSE;      tmp1empty = FALSE;
1572      }      }
1573    if (stackptr < stacktop)    if (stackptr < stacktop)
1574      {      {
1575      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1576      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1577      tmp2empty = FALSE;      tmp2empty = FALSE;
1578      }      }
1579    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1580    }    }
1581    
1582  while (status != end)  do
1583    {    {
1584    count = 0;    count = 0;
1585    switch(status)    switch(status)
1586      {      {
1587      case start:      case start:
1588      SLJIT_ASSERT(save);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1589      count = 1;      count = 1;
1590      srcw[0] = RECURSIVE_HEAD;      srcw[0] = common->recursive_head_ptr;
1591        if (common->control_head_ptr != 0)
1592          {
1593          count = 2;
1594          srcw[1] = common->control_head_ptr;
1595          }
1596      status = loop;      status = loop;
1597      break;      break;
1598    
# Line 936  while (status != end) Line 1616  while (status != end)
1616        case OP_SBRAPOS:        case OP_SBRAPOS:
1617        case OP_SCOND:        case OP_SCOND:
1618        count = 1;        count = 1;
1619        srcw[0] = PRIV(cc);        srcw[0] = PRIVATE_DATA(cc);
1620        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1621        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1622        break;        break;
1623    
1624        case OP_CBRA:        case OP_CBRA:
1625        case OP_SCBRA:        case OP_SCBRA:
1626        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1627        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1628        cc += 1 + LINK_SIZE + 2;          count = 1;
1629            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1630            }
1631          cc += 1 + LINK_SIZE + IMM2_SIZE;
1632        break;        break;
1633    
1634        case OP_CBRAPOS:        case OP_CBRAPOS:
1635        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1636        count = 2;        count = 2;
1637          srcw[0] = PRIVATE_DATA(cc);
1638        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1639        srcw[0] = PRIV(cc);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
1640        SLJIT_ASSERT(srcw[0] != 0);        cc += 1 + LINK_SIZE + IMM2_SIZE;
       cc += 1 + LINK_SIZE + 2;  
1641        break;        break;
1642    
1643        case OP_COND:        case OP_COND:
# Line 963  while (status != end) Line 1646  while (status != end)
1646        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1647          {          {
1648          count = 1;          count = 1;
1649          srcw[0] = PRIV(cc);          srcw[0] = PRIVATE_DATA(cc);
1650          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1651          }          }
1652        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1653        break;        break;
1654    
1655          CASE_ITERATOR_PRIVATE_DATA_1
1656          if (PRIVATE_DATA(cc))
1657            {
1658            count = 1;
1659            srcw[0] = PRIVATE_DATA(cc);
1660            }
1661          cc += 2;
1662    #ifdef SUPPORT_UTF
1663          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1664    #endif
1665          break;
1666    
1667          CASE_ITERATOR_PRIVATE_DATA_2A
1668          if (PRIVATE_DATA(cc))
1669            {
1670            count = 2;
1671            srcw[0] = PRIVATE_DATA(cc);
1672            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1673            }
1674          cc += 2;
1675    #ifdef SUPPORT_UTF
1676          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1677    #endif
1678          break;
1679    
1680          CASE_ITERATOR_PRIVATE_DATA_2B
1681          if (PRIVATE_DATA(cc))
1682            {
1683            count = 2;
1684            srcw[0] = PRIVATE_DATA(cc);
1685            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1686            }
1687          cc += 2 + IMM2_SIZE;
1688    #ifdef SUPPORT_UTF
1689          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1690    #endif
1691          break;
1692    
1693          CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1694          if (PRIVATE_DATA(cc))
1695            {
1696            count = 1;
1697            srcw[0] = PRIVATE_DATA(cc);
1698            }
1699          cc += 1;
1700          break;
1701    
1702          CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1703          if (PRIVATE_DATA(cc))
1704            {
1705            count = 2;
1706            srcw[0] = PRIVATE_DATA(cc);
1707            srcw[1] = srcw[0] + sizeof(sljit_sw);
1708            }
1709          cc += 1;
1710          break;
1711    
1712          CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1713          if (PRIVATE_DATA(cc))
1714            {
1715            count = 2;
1716            srcw[0] = PRIVATE_DATA(cc);
1717            srcw[1] = srcw[0] + sizeof(sljit_sw);
1718            }
1719          cc += 1 + IMM2_SIZE;
1720          break;
1721    
1722          case OP_CLASS:
1723          case OP_NCLASS:
1724    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1725          case OP_XCLASS:
1726          size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1727    #else
1728          size = 1 + 32 / (int)sizeof(pcre_uchar);
1729    #endif
1730          if (PRIVATE_DATA(cc))
1731            switch(get_class_iterator_size(cc + size))
1732              {
1733              case 1:
1734              count = 1;
1735              srcw[0] = PRIVATE_DATA(cc);
1736              break;
1737    
1738              case 2:
1739              count = 2;
1740              srcw[0] = PRIVATE_DATA(cc);
1741              srcw[1] = srcw[0] + sizeof(sljit_sw);
1742              break;
1743    
1744              default:
1745              SLJIT_ASSERT_STOP();
1746              break;
1747              }
1748          cc += size;
1749          break;
1750    
1751        default:        default:
1752        cc = next_opcode(common, cc);        cc = next_opcode(common, cc);
1753        SLJIT_ASSERT(cc != NULL);        SLJIT_ASSERT(cc != NULL);
# Line 991  while (status != end) Line 1770  while (status != end)
1770          if (!tmp1empty)          if (!tmp1empty)
1771            {            {
1772            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1773            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1774            }            }
1775          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1776          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1002  while (status != end) Line 1781  while (status != end)
1781          if (!tmp2empty)          if (!tmp2empty)
1782            {            {
1783            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1784            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1785            }            }
1786          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1787          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1019  while (status != end) Line 1798  while (status != end)
1798          if (!tmp1empty)          if (!tmp1empty)
1799            {            {
1800            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1801            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1802            }            }
1803          tmp1next = FALSE;          tmp1next = FALSE;
1804          }          }
# Line 1031  while (status != end) Line 1810  while (status != end)
1810          if (!tmp2empty)          if (!tmp2empty)
1811            {            {
1812            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1813            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1814            }            }
1815          tmp1next = TRUE;          tmp1next = TRUE;
1816          }          }
1817        }        }
1818      }      }
1819    }    }
1820    while (status != end);
1821    
1822  if (save)  if (save)
1823    {    {
# Line 1046  if (save) Line 1826  if (save)
1826      if (!tmp1empty)      if (!tmp1empty)
1827        {        {
1828        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1829        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1830        }        }
1831      if (!tmp2empty)      if (!tmp2empty)
1832        {        {
1833        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1834        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1835        }        }
1836      }      }
1837    else    else
# Line 1059  if (save) Line 1839  if (save)
1839      if (!tmp2empty)      if (!tmp2empty)
1840        {        {
1841        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1842        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1843        }        }
1844      if (!tmp1empty)      if (!tmp1empty)
1845        {        {
1846        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1847        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1848        }        }
1849      }      }
1850    }    }
1851  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1852  }  }
1853    
1854  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  #undef CASE_ITERATOR_PRIVATE_DATA_1
1855    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1856    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1857    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1858    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1859    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1860    
1861    static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1862  {  {
1863  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1864  }  }
# Line 1081  static SLJIT_INLINE void set_jumps(jump_ Line 1868  static SLJIT_INLINE void set_jumps(jump_
1868  while (list)  while (list)
1869    {    {
1870    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1871    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1872    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1873    list = list->next;    list = list->next;
1874    }    }
1875  }  }
# Line 1098  if (list_item) Line 1885  if (list_item)
1885    }    }
1886  }  }
1887    
1888  static void add_stub(compiler_common *common, enum stub_types type, int data, struct sljit_jump *start)  static void add_stub(compiler_common *common, struct sljit_jump *start)
1889  {  {
1890  DEFINE_COMPILER;  DEFINE_COMPILER;
1891  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1892    
1893  if (list_item)  if (list_item)
1894    {    {
   list_item->type = type;  
   list_item->data = data;  
1895    list_item->start = start;    list_item->start = start;
1896    list_item->leave = LABEL();    list_item->quit = LABEL();
1897    list_item->next = common->stubs;    list_item->next = common->stubs;
1898    common->stubs = list_item;    common->stubs = list_item;
1899    }    }
# Line 1122  stub_list* list_item = common->stubs; Line 1907  stub_list* list_item = common->stubs;
1907  while (list_item)  while (list_item)
1908    {    {
1909    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
1910    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
1911      {    JUMPTO(SLJIT_JUMP, list_item->quit);
     case stack_alloc:  
     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));  
     break;  
     }  
   JUMPTO(SLJIT_JUMP, list_item->leave);  
1912    list_item = list_item->next;    list_item = list_item->next;
1913    }    }
1914  common->stubs = NULL;  common->stubs = NULL;
# Line 1147  static SLJIT_INLINE void allocate_stack( Line 1927  static SLJIT_INLINE void allocate_stack(
1927  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
1928  DEFINE_COMPILER;  DEFINE_COMPILER;
1929    
1930  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
1931  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
1932  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
1933  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1155  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 1935  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
1935  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
1936  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
1937  #endif  #endif
1938  add_stub(common, stack_alloc, 0, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));  add_stub(common, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));
1939  }  }
1940    
1941  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
1942  {  {
1943  DEFINE_COMPILER;  DEFINE_COMPILER;
1944  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
1945  }  }
1946    
1947  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1169  static SLJIT_INLINE void reset_ovector(c Line 1949  static SLJIT_INLINE void reset_ovector(c
1949  DEFINE_COMPILER;  DEFINE_COMPILER;
1950  struct sljit_label *loop;  struct sljit_label *loop;
1951  int i;  int i;
1952    
1953  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
1954    SLJIT_ASSERT(length > 1);
1955  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
1956  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_GENERAL_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, 1);  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
1957  if (length < 8)  if (length < 8)
1958    {    {
1959    for (i = 0; i < length; i++)    for (i = 1; i < length; i++)
1960      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);
1961    }    }
1962  else  else
1963    {    {
1964    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);
1965    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
1966    loop = LABEL();    loop = LABEL();
1967    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);
1968    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);
1969    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
1970      }
1971    }
1972    
1973    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
1974    {
1975    DEFINE_COMPILER;
1976    struct sljit_label *loop;
1977    int i;
1978    
1979    SLJIT_ASSERT(length > 1);
1980    /* OVECTOR(1) contains the "string begin - 1" constant. */
1981    if (length > 2)
1982      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
1983    if (length < 8)
1984      {
1985      for (i = 2; i < length; i++)
1986        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
1987      }
1988    else
1989      {
1990      GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
1991      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
1992      loop = LABEL();
1993      OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
1994      OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
1995      JUMPTO(SLJIT_C_NOT_ZERO, loop);
1996      }
1997    
1998    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
1999    if (common->mark_ptr != 0)
2000      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2001    SLJIT_ASSERT(common->control_head_ptr != 0);
2002    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2003    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2004    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2005    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2006    }
2007    
2008    static sljit_sw do_check_control_chain(sljit_sw *current)
2009    {
2010    sljit_sw return_value = 0;
2011    
2012    SLJIT_ASSERT(current != NULL);
2013    do
2014      {
2015      switch (current[-2])
2016        {
2017        case type_commit:
2018        /* Commit overwrites all. */
2019        return -1;
2020    
2021        case type_prune:
2022        break;
2023    
2024        case type_skip:
2025        /* Overwrites prune, but not other skips. */
2026        if (return_value == 0)
2027          return_value = current[-3];
2028        break;
2029    
2030        default:
2031        SLJIT_ASSERT_STOP();
2032        break;
2033        }
2034      current = (sljit_sw*)current[-1];
2035    }    }
2036    while (current != NULL);
2037    return return_value;
2038  }  }
2039    
2040  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2041  {  {
2042  DEFINE_COMPILER;  DEFINE_COMPILER;
2043  struct sljit_label *loop;  struct sljit_label *loop;
2044  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2045    
2046  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2047  OP1(SLJIT_MOV, SLJIT_GENERAL_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2048  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);
2049    
2050  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2051  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  if (common->mark_ptr != 0)
2052  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);
2053  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));
2054  OP2(SLJIT_ADD, SLJIT_GENERAL_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START);  if (common->mark_ptr != 0)
2055      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);
2056    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
2057    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
2058    GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2059  /* Unlikely, but possible */  /* Unlikely, but possible */
2060  earlyexit = CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0);  early_quit = CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
2061  loop = LABEL();  loop = LABEL();
2062  OP2(SLJIT_SUB, SLJIT_GENERAL_REG2, 0, SLJIT_MEM1(SLJIT_GENERAL_REG1), 0, SLJIT_TEMPORARY_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
2063  OP2(SLJIT_ADD, SLJIT_GENERAL_REG1, 0, SLJIT_GENERAL_REG1, 0, SLJIT_IMM, sizeof(sljit_w));  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
2064  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2065  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_GENERAL_REG2, 0);  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2066  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2067    #endif
2068    OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
2069    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2070  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2071  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2072    
2073  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2074  if (topbracket > 1)  if (topbracket > 1)
2075    {    {
2076    OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START + topbracket * 2 * sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
2077    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2078    
2079    /* OVECTOR(0) is never equal to SLJIT_GENERAL_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2080    loop = LABEL();    loop = LABEL();
2081    OP1(SLJIT_MOVU, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), -(2 * (sljit_w)sizeof(sljit_w)));    OP1(SLJIT_MOVU, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -(2 * (sljit_sw)sizeof(sljit_sw)));
2082    OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2083    CMPTO(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG3, 0, SLJIT_GENERAL_REG3, 0, loop);    CMPTO(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG3, 0, loop);
2084    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2085    }    }
2086  else  else
2087    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
2088  }  }
2089    
2090  static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, uschar* cc)  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2091    {
2092    DEFINE_COMPILER;
2093    struct sljit_jump *jump;
2094    
2095    SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
2096    SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0
2097      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2098    
2099    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2100    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2101    OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
2102    CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2103    
2104    /* Store match begin and end. */
2105    OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));
2106    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
2107    
2108    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2109    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);
2110    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2111    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2112    #endif
2113    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2114    JUMPHERE(jump);
2115    
2116    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);
2117    OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);
2118    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2119    OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2120    #endif
2121    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);
2122    
2123    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);
2124    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2125    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2126    #endif
2127    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0);
2128    
2129    JUMPTO(SLJIT_JUMP, quit);
2130    }
2131    
2132    static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)
2133    {
2134    /* May destroy TMP1. */
2135    DEFINE_COMPILER;
2136    struct sljit_jump *jump;
2137    
2138    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2139      {
2140      /* The value of -1 must be kept for start_used_ptr! */
2141      OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, 1);
2142      /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting
2143      is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */
2144      jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_PTR, 0);
2145      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2146      JUMPHERE(jump);
2147      }
2148    else if (common->mode == JIT_PARTIAL_HARD_COMPILE)
2149      {
2150      jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2151      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2152      JUMPHERE(jump);
2153      }
2154    }
2155    
2156    static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar* cc)
2157  {  {
2158  /* Detects if the character has an othercase. */  /* Detects if the character has an othercase. */
2159  unsigned int c;  unsigned int c;
2160    
2161  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2162  if (common->utf8)  if (common->utf)
2163    {    {
2164    GETCHAR(c, cc);    GETCHAR(c, cc);
2165    if (c > 127)    if (c > 127)
# Line 1248  if (common->utf8) Line 2170  if (common->utf8)
2170      return FALSE;      return FALSE;
2171  #endif  #endif
2172      }      }
2173    #ifndef COMPILE_PCRE8
2174      return common->fcc[c] != c;
2175    #endif
2176    }    }
2177  else  else
2178  #endif  #endif
2179    c = *cc;    c = *cc;
2180  return common->fcc[c] != c;  return MAX_255(c) ? common->fcc[c] != c : FALSE;
2181  }  }
2182    
2183  static SLJIT_INLINE unsigned int char_othercase(compiler_common *common, unsigned int c)  static SLJIT_INLINE unsigned int char_othercase(compiler_common *common, unsigned int c)
2184  {  {
2185  /* Returns with the othercase. */  /* Returns with the othercase. */
2186  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2187  if (common->utf8 && c > 127)  if (common->utf && c > 127)
2188    {    {
2189  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2190    return UCD_OTHERCASE(c);    return UCD_OTHERCASE(c);
# Line 1268  if (common->utf8 && c > 127) Line 2193  if (common->utf8 && c > 127)
2193  #endif  #endif
2194    }    }
2195  #endif  #endif
2196  return common->fcc[c];  return TABLE_GET(c, common->fcc, c);
2197  }  }
2198    
2199  static unsigned int char_get_othercase_bit(compiler_common *common, uschar* cc)  static unsigned int char_get_othercase_bit(compiler_common *common, pcre_uchar* cc)
2200  {  {
2201  /* Detects if the character and its othercase has only 1 bit difference. */  /* Detects if the character and its othercase has only 1 bit difference. */
2202  unsigned int c, oc, bit;  unsigned int c, oc, bit;
2203  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2204  int n;  int n;
2205  #endif  #endif
2206    
2207  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2208  if (common->utf8)  if (common->utf)
2209    {    {
2210    GETCHAR(c, cc);    GETCHAR(c, cc);
2211    if (c <= 127)    if (c <= 127)
# Line 1297  if (common->utf8) Line 2222  if (common->utf8)
2222  else  else
2223    {    {
2224    c = *cc;    c = *cc;
2225    oc = common->fcc[c];    oc = TABLE_GET(c, common->fcc, c);
2226    }    }
2227  #else  #else
2228  c = *cc;  c = *cc;
2229  oc = common->fcc[c];  oc = TABLE_GET(c, common->fcc, c);
2230  #endif  #endif
2231    
2232  SLJIT_ASSERT(c != oc);  SLJIT_ASSERT(c != oc);
# Line 1312  if (c <= 127 && bit == 0x20) Line 2237  if (c <= 127 && bit == 0x20)
2237    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2238    
2239  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2240  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2241    return 0;    return 0;
2242    
2243  #ifdef SUPPORT_UTF8  #if defined COMPILE_PCRE8
2244  if (common->utf8 && c > 127)  
2245    #ifdef SUPPORT_UTF
2246    if (common->utf && c > 127)
2247    {    {
2248    n = _pcre_utf8_table4[*cc & 0x3f];    n = GET_EXTRALEN(*cc);
2249    while ((bit & 0x3f) == 0)    while ((bit & 0x3f) == 0)
2250      {      {
2251      n--;      n--;
# Line 1326  if (common->utf8 && c > 127) Line 2253  if (common->utf8 && c > 127)
2253      }      }
2254    return (n << 8) | bit;    return (n << 8) | bit;
2255    }    }
2256  #endif  #endif /* SUPPORT_UTF */
2257  return (0 << 8) | bit;  return (0 << 8) | bit;
2258    
2259    #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2260    
2261    #ifdef SUPPORT_UTF
2262    if (common->utf && c > 65535)
2263      {
2264      if (bit >= (1 << 10))
2265        bit >>= 10;
2266      else
2267        return (bit < 256) ? ((2 << 8) | bit) : ((3 << 8) | (bit >> 8));
2268      }
2269    #endif /* SUPPORT_UTF */
2270    return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
2271    
2272    #endif /* COMPILE_PCRE[8|16|32] */
2273    }
2274    
2275    static void check_partial(compiler_common *common, BOOL force)
2276    {
2277    /* Checks whether a partial matching is occured. Does not modify registers. */
2278    DEFINE_COMPILER;
2279    struct sljit_jump *jump = NULL;
2280    
2281    SLJIT_ASSERT(!force || common->mode != JIT_COMPILE);
2282    
2283    if (common->mode == JIT_COMPILE)
2284      return;
2285    
2286    if (!force)
2287      jump = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2288    else if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2289      jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2290    
2291    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2292      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2293    else
2294      {
2295      if (common->partialmatchlabel != NULL)
2296        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2297      else
2298        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2299      }
2300    
2301    if (jump != NULL)
2302      JUMPHERE(jump);
2303    }
2304    
2305    static void check_str_end(compiler_common *common, jump_list **end_reached)
2306    {
2307    /* Does not affect registers. Usually used in a tight spot. */
2308    DEFINE_COMPILER;
2309    struct sljit_jump *jump;
2310    
2311    if (common->mode == JIT_COMPILE)
2312      {
2313      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2314      return;
2315      }
2316    
2317    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2318    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2319      {
2320      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2321      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2322      add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
2323      }
2324    else
2325      {
2326      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2327      if (common->partialmatchlabel != NULL)
2328        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2329      else
2330        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2331      }
2332    JUMPHERE(jump);
2333  }  }
2334    
2335  static SLJIT_INLINE void check_input_end(compiler_common *common, jump_list **fallbacks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
2336  {  {
2337  DEFINE_COMPILER;  DEFINE_COMPILER;
2338  add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));  struct sljit_jump *jump;
2339    
2340    if (common->mode == JIT_COMPILE)
2341      {
2342      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2343      return;
2344      }
2345    
2346    /* Partial matching mode. */
2347    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2348    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2349    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2350      {
2351      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2352      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2353      }
2354    else
2355      {
2356      if (common->partialmatchlabel != NULL)
2357        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2358      else
2359        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2360      }
2361    JUMPHERE(jump);
2362  }  }
2363    
2364  static void read_char(compiler_common *common)  static void read_char(compiler_common *common)
# Line 1341  static void read_char(compiler_common *c Line 2366  static void read_char(compiler_common *c
2366  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2367  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2368  DEFINE_COMPILER;  DEFINE_COMPILER;
2369  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2370  struct sljit_jump *jump;  struct sljit_jump *jump;
2371  #endif  #endif
2372    
2373  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2374  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2375  if (common->utf8)  if (common->utf)
2376    {    {
2377    #if defined COMPILE_PCRE8
2378    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2379    add_jump(compiler, &common->utf8readchar, JUMP(SLJIT_FAST_CALL));  #elif defined COMPILE_PCRE16
2380      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2381    #endif /* COMPILE_PCRE[8|16] */
2382      add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2383    JUMPHERE(jump);    JUMPHERE(jump);
2384    }    }
2385  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2386  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2387  }  }
2388    
2389  static void peek_char(compiler_common *common)  static void peek_char(compiler_common *common)
# Line 1362  static void peek_char(compiler_common *c Line 2391  static void peek_char(compiler_common *c
2391  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2392  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2393  DEFINE_COMPILER;  DEFINE_COMPILER;
2394  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2395  struct sljit_jump *jump;  struct sljit_jump *jump;
2396  #endif  #endif
2397    
2398  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2399  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2400  if (common->utf8)  if (common->utf)
2401    {    {
2402    #if defined COMPILE_PCRE8
2403    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2404    add_jump(compiler, &common->utf8readchar, JUMP(SLJIT_FAST_CALL));  #elif defined COMPILE_PCRE16
2405      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2406    #endif /* COMPILE_PCRE[8|16] */
2407      add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2408    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2409    JUMPHERE(jump);    JUMPHERE(jump);
2410    }    }
2411  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2412  }  }
2413    
2414  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2415  {  {
2416  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */
2417  DEFINE_COMPILER;  DEFINE_COMPILER;
2418  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2419  struct sljit_jump *jump;  struct sljit_jump *jump;
2420  #endif  #endif
2421    
2422  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2423  if (common->utf8)  if (common->utf)
2424    {    {
2425    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2426    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2427    #if defined COMPILE_PCRE8
2428    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2429    it is a clever early read in most cases. */    it is needed in most cases. */
2430    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2431    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2432    add_jump(compiler, &common->utf8readtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2433      JUMPHERE(jump);
2434    #elif defined COMPILE_PCRE16
2435      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2436      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2437      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2438    JUMPHERE(jump);    JUMPHERE(jump);
2439      /* Skip low surrogate if necessary. */
2440      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2441      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2442      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2443      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2444      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2445    #elif defined COMPILE_PCRE32
2446      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2447      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2448      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2449      JUMPHERE(jump);
2450    #endif /* COMPILE_PCRE[8|16|32] */
2451    return;    return;
2452    }    }
2453    #endif /* SUPPORT_UTF */
2454    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2455    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2456    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2457    /* The ctypes array contains only 256 values. */
2458    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2459    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2460    #endif
2461    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2462    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2463    JUMPHERE(jump);
2464  #endif  #endif
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);  
2465  }  }
2466    
2467  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
2468  {  {
2469  /* Goes one character back. Only affects STR_PTR. Does not check begin. */  /* Goes one character back. Affects STR_PTR and TMP1. Does not check begin. */
2470  DEFINE_COMPILER;  DEFINE_COMPILER;
2471  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2472    #if defined COMPILE_PCRE8
2473  struct sljit_label *label;  struct sljit_label *label;
2474    
2475  if (common->utf8)  if (common->utf)
2476    {    {
2477    label = LABEL();    label = LABEL();
2478    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
2479    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2480    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);
2481    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2482    return;    return;
2483    }    }
2484  #endif  #elif defined COMPILE_PCRE16
2485  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  if (common->utf)
2486      {
2487      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
2488      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2489      /* Skip low surrogate if necessary. */
2490      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2491      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);
2492      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2493      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2494      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2495      return;
2496      }
2497    #endif /* COMPILE_PCRE[8|16] */
2498    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2499    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2500  }  }
2501    
2502  static void check_newlinechar(compiler_common *common, int nltype, jump_list **fallbacks, BOOL jumpiftrue)  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpiftrue)
2503  {  {
2504  /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */  /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */
2505  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1433  DEFINE_COMPILER; Line 2507  DEFINE_COMPILER;
2507  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2508    {    {
2509    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2510    add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2511    }    }
2512  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2513    {    {
2514    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);
2515    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2516    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);
2517    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
2518    add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2519    }    }
2520  else  else
2521    {    {
2522    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline <= 255);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2523    add_jump(compiler, fallbacks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));    add_jump(compiler, backtracks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
2524    }    }
2525  }  }
2526    
2527  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2528  static void do_utf8readchar(compiler_common *common)  
2529    #if defined COMPILE_PCRE8
2530    static void do_utfreadchar(compiler_common *common)
2531  {  {
2532  /* Fast decoding an utf8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2533  of the character (>= 0xc0). Return char value in TMP1, length - 1 in TMP2. */  of the character (>= 0xc0). Return char value in TMP1, length - 1 in TMP2. */
2534  DEFINE_COMPILER;  DEFINE_COMPILER;
2535  struct sljit_jump *jump;  struct sljit_jump *jump;
2536    
2537  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2538  /* Searching for the first zero. */  /* Searching for the first zero. */
2539  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
2540  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2541  /* 2 byte sequence */  /* Two byte sequence. */
2542  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2543  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2544  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);
2545  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2546  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2547  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2548  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
2549  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2550  JUMPHERE(jump);  JUMPHERE(jump);
2551    
2552  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);
2553  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2554  /* 3 byte sequence */  /* Three byte sequence. */
2555  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2556  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);
2557  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);
2558  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2559  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2560  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2561  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 2);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2562  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 2);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2563  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2564  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2565  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 2);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2566  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2567  JUMPHERE(jump);  JUMPHERE(jump);
2568    
2569  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x08);  /* Four byte sequence. */
2570  jump = JUMP(SLJIT_C_NOT_ZERO);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
 /* 4 byte sequence */  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  
2571  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);
2572  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);
2573  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2574  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);
2575  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2576  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 2);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 3);  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 3);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 3);  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 JUMPHERE(jump);  
   
 /* 5 byte sequence */  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x03);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 24);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 18);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 2);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 3);  
2577  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2578  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2579  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2580  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 4);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));
2581  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 4);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2582  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2583  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2584  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 4);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
2585  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2586  }  }
2587    
2588  static void do_utf8readtype8(compiler_common *common)  static void do_utfreadtype8(compiler_common *common)
2589  {  {
2590  /* Fast decoding an utf8 character type. TMP2 contains the first byte  /* Fast decoding a UTF-8 character type. TMP2 contains the first byte
2591  of the character (>= 0xc0) and TMP1 is destroyed. Return value in TMP1. */  of the character (>= 0xc0). Return value in TMP1. */
2592  DEFINE_COMPILER;  DEFINE_COMPILER;
2593  struct sljit_jump *jump;  struct sljit_jump *jump;
2594  struct sljit_jump *compare;  struct sljit_jump *compare;
2595    
2596  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2597    
2598  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);
2599  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2600  /* 2 byte sequence */  /* Two byte sequence. */
2601  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2602  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2603  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2604  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2605  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
# Line 1563  sljit_emit_fast_return(compiler, RETURN_ Line 2614  sljit_emit_fast_return(compiler, RETURN_
2614  JUMPHERE(jump);  JUMPHERE(jump);
2615    
2616  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2617  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)_pcre_utf8_char_sizes - 0xc0);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2618  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2619  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2620  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2621  }  }
2622    
2623  #endif  #elif defined COMPILE_PCRE16
2624    
2625    static void do_utfreadchar(compiler_common *common)
2626    {
2627    /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char
2628    of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */
2629    DEFINE_COMPILER;
2630    struct sljit_jump *jump;
2631    
2632    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2633    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);
2634    /* Do nothing, only return. */
2635    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2636    
2637    JUMPHERE(jump);
2638    /* Combine two 16 bit characters. */
2639    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2640    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2641    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2642    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);
2643    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff);
2644    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2645    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
2646    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2647    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2648    }
2649    
2650    #endif /* COMPILE_PCRE[8|16] */
2651    
2652    #endif /* SUPPORT_UTF */
2653    
2654  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2655    
# Line 1585  DEFINE_COMPILER; Line 2665  DEFINE_COMPILER;
2665    
2666  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);
2667    
2668  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2669  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2670  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_w)_pcre_ucd_stage1);  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(ucd_stage1));
2671  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2672  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2673  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2674  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)_pcre_ucd_stage2);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2675  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2676  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)_pcre_ucd_records + SLJIT_OFFSETOF(ucd_record, chartype));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));
2677  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2678  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2679  }  }
# Line 1607  struct sljit_label *newlinelabel = NULL; Line 2687  struct sljit_label *newlinelabel = NULL;
2687  struct sljit_jump *start;  struct sljit_jump *start;
2688  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2689  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2690  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2691  struct sljit_jump *singlebyte;  struct sljit_jump *singlechar;
2692  #endif  #endif
2693  jump_list *newline = NULL;  jump_list *newline = NULL;
2694  BOOL newlinecheck = FALSE;  BOOL newlinecheck = FALSE;
2695  BOOL readbyte = FALSE;  BOOL readuchar = FALSE;
2696    
2697  if (!(hascrorlf || firstline) && (common->nltype == NLTYPE_ANY ||  if (!(hascrorlf || firstline) && (common->nltype == NLTYPE_ANY ||
2698      common->nltype == NLTYPE_ANYCRLF || common->newline > 255))      common->nltype == NLTYPE_ANYCRLF || common->newline > 255))
2699    newlinecheck = TRUE;    newlinecheck = TRUE;
2700    
2701  if (firstline)  if (firstline)
2702    {    {
2703    /* Search for the end of the first line. */    /* Search for the end of the first line. */
2704    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2705    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
2706    
2707      if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2708        {
2709        mainloop = LABEL();
2710        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2711        end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2712        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
2713        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2714        CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);
2715        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);
2716        JUMPHERE(end);
2717        OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2718        }
2719      else
2720        {
2721        end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2722        mainloop = LABEL();
2723        /* Continual stores does not cause data dependency. */
2724        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2725        read_char(common);
2726        check_newlinechar(common, common->nltype, &newline, TRUE);
2727        CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2728        JUMPHERE(end);
2729        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2730        set_jumps(newline, LABEL());
2731        }
2732    
2733      OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
2734      }
2735    
2736    start = JUMP(SLJIT_JUMP);
2737    
2738    if (newlinecheck)
2739      {
2740      newlinelabel = LABEL();
2741      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2742      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2743      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2744      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);
2745      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2746    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2747      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2748    #endif
2749      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2750      nl = JUMP(SLJIT_JUMP);
2751      }
2752    
2753    mainloop = LABEL();
2754    
2755    /* Increasing the STR_PTR here requires one less jump in the most common case. */
2756    #ifdef SUPPORT_UTF
2757    if (common->utf) readuchar = TRUE;
2758    #endif
2759    if (newlinecheck) readuchar = TRUE;
2760    
2761    if (readuchar)
2762      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2763    
2764    if (newlinecheck)
2765      CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);
2766    
2767    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2768    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2769    #if defined COMPILE_PCRE8
2770    if (common->utf)
2771      {
2772      singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2773      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2774      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2775      JUMPHERE(singlechar);
2776      }
2777    #elif defined COMPILE_PCRE16
2778    if (common->utf)
2779      {
2780      singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2781      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2782      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2783      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2784      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2785      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2786      JUMPHERE(singlechar);
2787      }
2788    #endif /* COMPILE_PCRE[8|16] */
2789    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2790    JUMPHERE(start);
2791    
2792    if (newlinecheck)
2793      {
2794      JUMPHERE(end);
2795      JUMPHERE(nl);
2796      }
2797    
2798    return mainloop;
2799    }
2800    
2801    #define MAX_N_CHARS 3
2802    
2803    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2804    {
2805    DEFINE_COMPILER;
2806    struct sljit_label *start;
2807    struct sljit_jump *quit;
2808    pcre_uint32 chars[MAX_N_CHARS * 2];
2809    pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2810    int location = 0;
2811    pcre_int32 len, c, bit, caseless;
2812    int must_stop;
2813    
2814    /* We do not support alternatives now. */
2815    if (*(common->start + GET(common->start, 1)) == OP_ALT)
2816      return FALSE;
2817    
2818    while (TRUE)
2819      {
2820      caseless = 0;
2821      must_stop = 1;
2822      switch(*cc)
2823        {
2824        case OP_CHAR:
2825        must_stop = 0;
2826        cc++;
2827        break;
2828    
2829        case OP_CHARI:
2830        caseless = 1;
2831        must_stop = 0;
2832        cc++;
2833        break;
2834    
2835        case OP_SOD:
2836        case OP_SOM:
2837        case OP_SET_SOM:
2838        case OP_NOT_WORD_BOUNDARY:
2839        case OP_WORD_BOUNDARY:
2840        case OP_EODN:
2841        case OP_EOD:
2842        case OP_CIRC:
2843        case OP_CIRCM:
2844        case OP_DOLL:
2845        case OP_DOLLM:
2846        /* Zero width assertions. */
2847        cc++;
2848        continue;
2849    
2850        case OP_PLUS:
2851        case OP_MINPLUS:
2852        case OP_POSPLUS:
2853        cc++;
2854        break;
2855    
2856        case OP_EXACT:
2857        cc += 1 + IMM2_SIZE;
2858        break;
2859    
2860        case OP_PLUSI:
2861        case OP_MINPLUSI:
2862        case OP_POSPLUSI:
2863        caseless = 1;
2864        cc++;
2865        break;
2866    
2867        case OP_EXACTI:
2868        caseless = 1;
2869        cc += 1 + IMM2_SIZE;
2870        break;
2871    
2872        default:
2873        must_stop = 2;
2874        break;
2875        }
2876    
2877      if (must_stop == 2)
2878          break;
2879    
2880      len = 1;
2881    #ifdef SUPPORT_UTF
2882      if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
2883    #endif
2884    
2885    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (caseless && char_has_othercase(common, cc))
2886      {      {
2887      mainloop = LABEL();      caseless = char_get_othercase_bit(common, cc);
2888      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);      if (caseless == 0)
2889      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);        return FALSE;
2890      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -1);  #ifdef COMPILE_PCRE8
2891      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
2892      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);  #else
2893      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);      if ((caseless & 0x100) != 0)
2894      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0, SLJIT_IMM, 1);        caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
2895        else
2896          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
2897    #endif
2898      }      }
2899    else    else
2900        caseless = 0;
2901    
2902      while (len > 0 && location < MAX_N_CHARS * 2)
2903      {      {
2904      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      c = *cc;
2905      mainloop = LABEL();      bit = 0;
2906      /* Continual stores does not cause data dependency. */      if (len == (caseless & 0xff))
2907      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);        {
2908      read_char(common);        bit = caseless >> 8;
2909      check_newlinechar(common, common->nltype, &newline, TRUE);        c |= bit;
2910      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);        }
2911      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);  
2912      set_jumps(newline, LABEL());      chars[location] = c;
2913        chars[location + 1] = bit;
2914    
2915        len--;
2916        location += 2;
2917        cc++;
2918      }      }
2919    
2920    JUMPHERE(end);    if (location >= MAX_N_CHARS * 2 || must_stop != 0)
2921    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);      break;
2922    }    }
2923    
2924  start = JUMP(SLJIT_JUMP);  /* At least two characters are required. */
2925    if (location < 2 * 2)
2926        return FALSE;
2927    
2928  if (newlinecheck)  if (firstline)
2929    {    {
2930    newlinelabel = LABEL();    SLJIT_ASSERT(common->first_line_end != 0);
2931    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2932    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);  
   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   nl = JUMP(SLJIT_JUMP);  
2933    }    }
2934    else
2935      OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2936    
2937  mainloop = LABEL();  start = LABEL();
2938    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 /* Increasing the STR_PTR here requires one less jump in the most common case. */  
 #ifdef SUPPORT_UTF8  
 if (common->utf8) readbyte = TRUE;  
 #endif  
 if (newlinecheck) readbyte = TRUE;  
   
 if (readbyte)  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
   
 if (newlinecheck)  
   CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);  
2939    
2940  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2941  #ifdef SUPPORT_UTF8  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2942  if (common->utf8)  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2943    {  if (chars[1] != 0)
2944    singlebyte = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
2945    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)_pcre_utf8_char_sizes - 0xc0);  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
2946    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  if (location > 2 * 2)
2947    JUMPHERE(singlebyte);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2948    if (chars[3] != 0)
2949      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
2950    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
2951    if (location > 2 * 2)
2952      {
2953      if (chars[5] != 0)
2954        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
2955      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);
2956    }    }
2957  #endif  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 JUMPHERE(start);  
2958    
2959  if (newlinecheck)  JUMPHERE(quit);
   {  
   JUMPHERE(end);  
   JUMPHERE(nl);  
   }  
2960    
2961  return mainloop;  if (firstline)
2962      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2963    else
2964      OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2965    return TRUE;
2966  }  }
2967    
2968  static SLJIT_INLINE void fast_forward_first_byte(compiler_common *common, pcre_uint16 firstbyte, BOOL firstline)  #undef MAX_N_CHARS
2969    
2970    static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
2971  {  {
2972  DEFINE_COMPILER;  DEFINE_COMPILER;
2973  struct sljit_label *start;  struct sljit_label *start;
2974  struct sljit_jump *leave;  struct sljit_jump *quit;
2975  struct sljit_jump *found;  struct sljit_jump *found;
2976  pcre_uint16 oc, bit;  pcre_uchar oc, bit;
2977    
2978  if (firstline)  if (firstline)
2979    {    {
2980    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2981    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2982      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
2983    }    }
2984    
2985  start = LABEL();  start = LABEL();
2986  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2987  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2988    
2989  if ((firstbyte & REQ_CASELESS) == 0)  oc = first_char;
2990    found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, firstbyte & 0xff);  if (caseless)
2991      {
2992      oc = TABLE_GET(first_char, common->fcc, first_char);
2993    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
2994      if (first_char > 127 && common->utf)
2995        oc = UCD_OTHERCASE(first_char);
2996    #endif
2997      }
2998    if (first_char == oc)
2999      found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, first_char);
3000  else  else
3001    {    {
3002    firstbyte &= 0xff;    bit = first_char ^ oc;
3003    oc = common->fcc[firstbyte];    if (is_powerof2(bit))
   bit = firstbyte ^ oc;  
   if (ispowerof2(bit))  
3004      {      {
3005      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3006      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, firstbyte | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
3007      }      }
3008    else    else
3009      {      {
3010      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, firstbyte);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char);
3011      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3012      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);
3013      COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3014      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3015      }      }
3016    }    }
3017    
3018  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 #ifdef SUPPORT_UTF8  
 if (common->utf8)  
   {  
   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)_pcre_utf8_char_sizes - 0xc0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 #endif  
3019  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3020  JUMPHERE(found);  JUMPHERE(found);
3021  JUMPHERE(leave);  JUMPHERE(quit);
3022    
3023  if (firstline)  if (firstline)
3024    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3025  }  }
3026    
3027  static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline)  static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline)
# Line 1764  DEFINE_COMPILER; Line 3030  DEFINE_COMPILER;
3030  struct sljit_label *loop;  struct sljit_label *loop;
3031  struct sljit_jump *lastchar;  struct sljit_jump *lastchar;
3032  struct sljit_jump *firstchar;  struct sljit_jump *firstchar;
3033  struct sljit_jump *leave;  struct sljit_jump *quit;
3034  struct sljit_jump *foundcr = NULL;  struct sljit_jump *foundcr = NULL;
3035  struct sljit_jump *notfoundnl;  struct sljit_jump *notfoundnl;
3036  jump_list *newline = NULL;  jump_list *newline = NULL;
3037    
3038  if (firstline)  if (firstline)
3039    {    {
3040    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3041    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3042      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3043    }    }
3044    
3045  if (common->nltype == NLTYPE_FIXED && common->newline > 255)  if (common->nltype == NLTYPE_FIXED && common->newline > 255)
# Line 1783  if (common->nltype == NLTYPE_FIXED && co Line 3050  if (common->nltype == NLTYPE_FIXED && co
3050    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));
3051    firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);    firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);
3052    
3053    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2);    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3054    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, TMP1, 0);
3055    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3056    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3057      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3058    #endif
3059    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3060    
3061    loop = LABEL();    loop = LABEL();
3062    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3063    leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3064    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -2);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
3065    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), -1);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
3066    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);
3067    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);
3068    
3069    JUMPHERE(leave);    JUMPHERE(quit);
3070    JUMPHERE(firstchar);    JUMPHERE(firstchar);
3071    JUMPHERE(lastchar);    JUMPHERE(lastchar);
3072    
# Line 1820  set_jumps(newline, loop); Line 3090  set_jumps(newline, loop);
3090    
3091  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3092    {    {
3093    leave = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
3094    JUMPHERE(foundcr);    JUMPHERE(foundcr);
3095    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3096    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3097    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);
3098    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3099    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3100      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3101    #endif
3102    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3103    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
3104    JUMPHERE(leave);    JUMPHERE(quit);
3105    }    }
3106  JUMPHERE(lastchar);  JUMPHERE(lastchar);
3107  JUMPHERE(firstchar);  JUMPHERE(firstchar);
3108    
3109  if (firstline)  if (firstline)
3110    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3111  }  }
3112    
3113    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3114    
3115  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)
3116  {  {
3117  DEFINE_COMPILER;  DEFINE_COMPILER;
3118  struct sljit_label *start;  struct sljit_label *start;
3119  struct sljit_jump *leave;  struct sljit_jump *quit;
3120  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3121    jump_list *matches = NULL;
3122    pcre_uint8 inverted_start_bits[32];
3123    int i;
3124    #ifndef COMPILE_PCRE8
3125    struct sljit_jump *jump;
3126    #endif
3127    
3128    for (i = 0; i < 32; ++i)
3129      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3130    
3131  if (firstline)  if (firstline)
3132    {    {
3133    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3134    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
3135      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3136    }    }
3137    
3138  start = LABEL();  start = LABEL();
3139  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3140  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3141  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3142  if (common->utf8)  if (common->utf)
3143    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3144  #endif  #endif
 OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);  
 OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);  
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);  
 OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);  
 OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);  
 found = JUMP(SLJIT_C_NOT_ZERO);  
3145    
3146  #ifdef SUPPORT_UTF8  if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3147  if (common->utf8)    {
3148    #ifndef COMPILE_PCRE8
3149      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3150      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3151      JUMPHERE(jump);
3152    #endif
3153      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3154      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3155      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3156      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3157      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
3158      found = JUMP(SLJIT_C_NOT_ZERO);
3159      }
3160    
3161    #ifdef SUPPORT_UTF
3162    if (common->utf)
3163    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3164  #endif  #endif
3165  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3166  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3167  if (common->utf8)  #if defined COMPILE_PCRE8
3168    if (common->utf)
3169    {    {
3170    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3171    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)_pcre_utf8_char_sizes - 0xc0);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
3172    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3173    }    }
3174  #endif  #elif defined COMPILE_PCRE16
3175    if (common->utf)
3176      {
3177      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3178      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3179      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
3180      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3181      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3182      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3183      }
3184    #endif /* COMPILE_PCRE[8|16] */
3185    #endif /* SUPPORT_UTF */
3186  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3187  JUMPHERE(found);  if (found != NULL)
3188  JUMPHERE(leave);    JUMPHERE(found);
3189    if (matches != NULL)
3190      set_jumps(matches, LABEL());
3191    JUMPHERE(quit);
3192    
3193  if (firstline)  if (firstline)
3194    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
3195  }  }
3196    
3197  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uint16 reqbyte, BOOL has_firstbyte)  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar req_char, BOOL caseless, BOOL has_firstchar)
3198  {  {
3199  DEFINE_COMPILER;  DEFINE_COMPILER;
3200  struct sljit_label *loop;  struct sljit_label *loop;
# Line 1894  struct sljit_jump *alreadyfound; Line 3203  struct sljit_jump *alreadyfound;
3203  struct sljit_jump *found;  struct sljit_jump *found;
3204  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3205  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3206  pcre_uint16 oc, bit;  pcre_uint32 oc, bit;
3207    
3208  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_BYTE_PTR);  SLJIT_ASSERT(common->req_char_ptr != 0);
3209    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
3210  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);
3211  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);
3212  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);
3213    
3214  if (has_firstbyte)  if (has_firstchar)
3215    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3216  else  else
3217    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);
3218    
3219  loop = LABEL();  loop = LABEL();
3220  notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);  notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);
3221    
3222  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3223  if ((reqbyte & REQ_CASELESS) == 0)  oc = req_char;
3224    found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte & 0xff);  if (caseless)
3225      {
3226      oc = TABLE_GET(req_char, common->fcc, req_char);
3227    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
3228      if (req_char > 127 && common->utf)
3229        oc = UCD_OTHERCASE(req_char);
3230    #endif
3231      }
3232    if (req_char == oc)
3233      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
3234  else  else
3235    {    {
3236    reqbyte &= 0xff;    bit = req_char ^ oc;
3237    oc = common->fcc[reqbyte];    if (is_powerof2(bit))
   bit = reqbyte ^ oc;  
   if (ispowerof2(bit))  
3238      {      {
3239      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3240      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
3241      }      }
3242    else    else
3243      {      {
3244      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
3245      foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);      foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);
3246      }      }
3247    }    }
3248  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
3249  JUMPTO(SLJIT_JUMP, loop);  JUMPTO(SLJIT_JUMP, loop);
3250    
3251  JUMPHERE(found);  JUMPHERE(found);
3252  if (foundoc)  if (foundoc)
3253    JUMPHERE(foundoc);    JUMPHERE(foundoc);
3254  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_BYTE_PTR, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr, TMP1, 0);
3255  JUMPHERE(alreadyfound);  JUMPHERE(alreadyfound);
3256  JUMPHERE(toolong);  JUMPHERE(toolong);
3257  return notfound;  return notfound;
# Line 1946  DEFINE_COMPILER; Line 3263  DEFINE_COMPILER;
3263  struct sljit_jump *jump;  struct sljit_jump *jump;
3264  struct sljit_label *mainloop;  struct sljit_label *mainloop;
3265    
3266  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3267  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);
3268    GET_LOCAL_BASE(TMP3, 0, 0);
3269    
3270  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3271  mainloop = LABEL();  mainloop = LABEL();
3272  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3273  jump = CMP(SLJIT_C_SIG_LESS_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0);
3274  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_LOCALS_REG, 0);  jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3275  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
3276  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3277  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3278    OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
3279    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
3280  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3281    
3282  JUMPHERE(jump);  JUMPHERE(jump);
3283  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3284  /* End of dropping frames. */  /* End of dropping frames. */
3285  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3286    
3287  JUMPHERE(jump);  JUMPHERE(jump);
3288  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3289  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3290  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3291  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), TMP2, 0);  
 JUMPTO(SLJIT_JUMP, mainloop);  
   
 JUMPHERE(jump);  
 /* Unknown command. */  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
3292  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3293  }  }
3294    
3295  static void check_wordboundary(compiler_common *common)  static void check_wordboundary(compiler_common *common)
3296  {  {
3297  DEFINE_COMPILER;  DEFINE_COMPILER;
3298  struct sljit_jump *beginend;  struct sljit_jump *skipread;
3299  #ifdef SUPPORT_UTF8  jump_list *skipread_list = NULL;
3300    #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3301  struct sljit_jump *jump;  struct sljit_jump *jump;
3302  #endif  #endif
3303    
3304  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
3305    
3306  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3307  /* Get type of the previous char, and put it to LOCALS1. */  /* Get type of the previous char, and put it to LOCALS1. */
3308  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
3309  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
3310  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);
3311  beginend = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);  skipread = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3312  skip_char_back(common);  skip_char_back(common);
3313    check_start_used_ptr(common);
3314  read_char(common);  read_char(common);
3315    
3316  /* Testing char type. */  /* Testing char type. */
3317  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3318  if (common->useucp)  if (common->use_ucp)
3319    {    {
3320    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
3321    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
3322    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3323    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3324    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
3325    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3326    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);
3327    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
3328    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3329    JUMPHERE(jump);    JUMPHERE(jump);
3330    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3331    }    }
3332  else  else
3333  #endif  #endif
3334    {    {
3335  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3336      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3337    #elif defined SUPPORT_UTF
3338    /* Here LOCALS1 has already been zeroed. */    /* Here LOCALS1 has already been zeroed. */
3339    jump = NULL;    jump = NULL;
3340    if (common->utf8)    if (common->utf)
3341      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3342  #endif  #endif /* COMPILE_PCRE8 */
3343    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);
3344    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);
3345    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3346    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
3347  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3348      JUMPHERE(jump);
3349    #elif defined SUPPORT_UTF
3350    if (jump != NULL)    if (jump != NULL)
3351      JUMPHERE(jump);      JUMPHERE(jump);
3352  #endif  #endif /* COMPILE_PCRE8 */
3353    }    }
3354  JUMPHERE(beginend);  JUMPHERE(skipread);
3355    
3356  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3357  beginend = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  check_str_end(common, &skipread_list);
3358  peek_char(common);  peek_char(common);
3359    
3360  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
3361  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3362  if (common->useucp)  if (common->use_ucp)
3363    {    {
3364    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
3365    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
3366    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3367    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3368    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
3369    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3370    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);
3371    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
3372    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3373    JUMPHERE(jump);    JUMPHERE(jump);
3374    }    }
3375  else  else
3376  #endif  #endif
3377    {    {
3378  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3379      /* TMP2 may be destroyed by peek_char. */
3380      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3381      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3382    #elif defined SUPPORT_UTF
3383    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3384    jump = NULL;    jump = NULL;
3385    if (common->utf8)    if (common->utf)
3386      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3387  #endif  #endif
3388    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);
3389    OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);    OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);
3390    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
3391  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3392      JUMPHERE(jump);
3393    #elif defined SUPPORT_UTF
3394    if (jump != NULL)    if (jump != NULL)
3395      JUMPHERE(jump);      JUMPHERE(jump);
3396  #endif  #endif /* COMPILE_PCRE8 */
3397    }    }
3398  JUMPHERE(beginend);  set_jumps(skipread_list, LABEL());
3399    
3400  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3401  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3402  }  }
3403    
3404    /*
3405      range format:
3406    
3407      ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).
3408      ranges[1] = first bit (0 or 1)
3409      ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)
3410    */
3411    
3412    static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3413    {
3414    DEFINE_COMPILER;
3415    struct sljit_jump *jump;
3416    
3417    if (ranges[0] < 0)
3418      return FALSE;
3419    
3420    switch(ranges[0])
3421      {
3422      case 1:
3423      if (readch)
3424        read_char(common);
3425      add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3426      return TRUE;
3427    
3428      case 2:
3429      if (readch)
3430        read_char(common);
3431      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3432      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3433      return TRUE;
3434    
3435      case 4:
3436      if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])
3437        {
3438        if (readch)
3439          read_char(common);
3440        if (ranges[1] != 0)
3441          {
3442          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3443          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3444          }
3445        else
3446          {
3447          jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);
3448          add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3449          JUMPHERE(jump);
3450          }
3451        return TRUE;
3452        }
3453      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))
3454        {
3455        if (readch)
3456          read_char(common);
3457        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3458        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3459        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3460        return TRUE;
3461        }
3462      return FALSE;
3463    
3464      default:
3465      return FALSE;
3466      }
3467    }
3468    
3469    static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)
3470    {
3471    int i, bit, length;
3472    const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;
3473    
3474    bit = ctypes[0] & flag;
3475    ranges[0] = -1;
3476    ranges[1] = bit != 0 ? 1 : 0;
3477    length = 0;
3478    
3479    for (i = 1; i < 256; i++)
3480      if ((ctypes[i] & flag) != bit)
3481        {
3482        if (length >= MAX_RANGE_SIZE)
3483          return;
3484        ranges[2 + length] = i;
3485        length++;
3486        bit ^= flag;
3487        }
3488    
3489    if (bit != 0)
3490      {
3491      if (length >= MAX_RANGE_SIZE)
3492        return;
3493      ranges[2 + length] = 256;