/[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 792 by ph10, Wed Dec 7 16:44:48 2011 UTC revision 1246 by zherczeg, Sun Feb 10 08:44:53 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-2012 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-2012
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) (pcre_malloc)(size)  #define SLJIT_MALLOC(size) (PUBL(malloc))(size)
56  #define SLJIT_FREE(ptr) (pcre_free)(ptr)  #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 62  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. */  /* Allocate memory for the regex stack on the real machine stack.
69  #define LOCAL_SPACE_SIZE 32768  Fast, but limited size. */
70    #define MACHINE_STACK_SIZE 32768
71    
72    /* Growth rate for stack allocated by the OS. Should be the multiply
73    of page size. */
74  #define STACK_GROWTH_RATE 8192  #define STACK_GROWTH_RATE 8192
75    
76  /* Enable to check that the allocation could destroy temporaries. */  /* Enable to check that the allocation could destroy temporaries. */
# Line 82  The code generator follows the recursive Line 85  The code generator follows the recursive
85  expressions. The basic blocks of regular expressions are condition checkers  expressions. The basic blocks of regular expressions are condition checkers
86  whose execute different commands depending on the result of the condition check.  whose execute different commands depending on the result of the condition check.
87  The relationship between the operators can be horizontal (concatenation) and  The relationship between the operators can be horizontal (concatenation) and
88  vertical (sub-expression) (See struct fallback_common for more details).  vertical (sub-expression) (See struct backtrack_common for more details).
89    
90    'ab' - 'a' and 'b' regexps are concatenated    'ab' - 'a' and 'b' regexps are concatenated
91    'a+' - 'a' is the sub-expression of the '+' operator    'a+' - 'a' is the sub-expression of the '+' operator
92    
93  The condition checkers are boolean (true/false) checkers. Machine code is generated  The condition checkers are boolean (true/false) checkers. Machine code is generated
94  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.
95  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
96  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
97  branches on the hot path.  branches on the matching path.
98    
99   Greedy star operator (*) :   Greedy star operator (*) :
100     Hot path: match happens.     Matching path: match happens.
101     Fallback path: match failed.     Backtrack path: match failed.
102   Non-greedy star operator (*?) :   Non-greedy star operator (*?) :
103     Hot path: no need to perform a match.     Matching path: no need to perform a match.
104     Fallback path: match is required.     Backtrack path: match is required.
105    
106  The following example shows how the code generated for a capturing bracket  The following example shows how the code generated for a capturing bracket
107  with two alternatives. Let A, B, C, D are arbirary regular expressions, and  with two alternatives. Let A, B, C, D are arbirary regular expressions, and
# Line 108  we have the following regular expression Line 111  we have the following regular expression
111    
112  The generated code will be the following:  The generated code will be the following:
113    
114   A hot path   A matching path
115   '(' hot path (pushing arguments to the stack)   '(' matching path (pushing arguments to the stack)
116   B hot path   B matching path
117   ')' hot path (pushing arguments to the stack)   ')' matching path (pushing arguments to the stack)
118   D hot path   D matching path
119   return with successful match   return with successful match
120    
121   D fallback path   D backtrack path
122   ')' 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")
123   B fallback path   B backtrack path
124   C expected path   C expected path
125   jump to D hot path   jump to D matching path
126   C fallback path   C backtrack path
127   A fallback path   A backtrack path
128    
129   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
130   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
131   to the current fallback code path. The fallback code path must check   to the current backtrack code path. The backtrack path must check
132   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
133   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
134   frame and continue the execution on the fallback code paths.   frame and continue the execution on the backtrack code paths.
135  */  */
136    
137  /*  /*
138  Saved stack frames:  Saved stack frames:
139    
140  Atomic blocks and asserts require reloading the values of local variables  Atomic blocks and asserts require reloading the values of private data
141  when the fallback mechanism performed. Because of OP_RECURSE, the locals  when the backtrack mechanism performed. Because of OP_RECURSE, the data
142  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
143  mechanism.  mechanism.
144    
145  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:
146  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]
147    
148  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.
149  */  */
150    
151  typedef struct jit_arguments {  typedef struct jit_arguments {
152    /* Pointers first. */    /* Pointers first. */
153    struct sljit_stack *stack;    struct sljit_stack *stack;
154    PCRE_SPTR str;    const pcre_uchar *str;
155    PCRE_SPTR begin;    const pcre_uchar *begin;
156    PCRE_SPTR end;    const pcre_uchar *end;
157    int *offsets;    int *offsets;
158    uschar *ptr;    pcre_uchar *uchar_ptr;
159      pcre_uchar *mark_ptr;
160      void *callout_data;
161    /* Everything else after. */    /* Everything else after. */
162    int offsetcount;    int offset_count;
163    int calllimit;    int call_limit;
164    uschar notbol;    pcre_uint8 notbol;
165    uschar noteol;    pcre_uint8 noteol;
166    uschar notempty;    pcre_uint8 notempty;
167    uschar notempty_atstart;    pcre_uint8 notempty_atstart;
168  } jit_arguments;  } jit_arguments;
169    
170  typedef struct executable_function {  typedef struct executable_functions {
171    void *executable_func;    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
172    pcre_jit_callback callback;    PUBL(jit_callback) callback;
173    void *userdata;    void *userdata;
174    sljit_uw executable_size;    pcre_uint32 top_bracket;
175  } executable_function;    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
176    } executable_functions;
177    
178  typedef struct jump_list {  typedef struct jump_list {
179    struct sljit_jump *jump;    struct sljit_jump *jump;
# Line 180  typedef struct stub_list { Line 186  typedef struct stub_list {
186    enum stub_types type;    enum stub_types type;
187    int data;    int data;
188    struct sljit_jump *start;    struct sljit_jump *start;
189    struct sljit_label *leave;    struct sljit_label *quit;
190    struct stub_list *next;    struct stub_list *next;
191  } stub_list;  } stub_list;
192    
193  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
194    
195  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
196  code generator. It is allocated by compile_hotpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
197  the aguments for compile_fallbackpath. Must be the first member  the aguments for compile_backtrackingpath. Must be the first member
198  of its descendants. */  of its descendants. */
199  typedef struct fallback_common {  typedef struct backtrack_common {
200    /* Concatenation stack. */    /* Concatenation stack. */
201    struct fallback_common *prev;    struct backtrack_common *prev;
202    jump_list *nextfallbacks;    jump_list *nextbacktracks;
203    /* Internal stack (for component operators). */    /* Internal stack (for component operators). */
204    struct fallback_common *top;    struct backtrack_common *top;
205    jump_list *topfallbacks;    jump_list *topbacktracks;
206    /* Opcode pointer. */    /* Opcode pointer. */
207    uschar *cc;    pcre_uchar *cc;
208  } fallback_common;  } backtrack_common;
209    
210  typedef struct assert_fallback {  typedef struct assert_backtrack {
211    fallback_common common;    backtrack_common common;
212    jump_list *condfailed;    jump_list *condfailed;
213    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 (-1) if a frame is not needed. */
214    int framesize;    int framesize;
215    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
216    int localptr;    int private_data_ptr;
217    /* For iterators. */    /* For iterators. */
218    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
219  } assert_fallback;  } assert_backtrack;
220    
221  typedef struct bracket_fallback {  typedef struct bracket_backtrack {
222    fallback_common common;    backtrack_common common;
223    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
224    struct sljit_label *althotpath;    struct sljit_label *alternative_matchingpath;
225    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
226    struct sljit_label *recursivehotpath;    struct sljit_label *recursive_matchingpath;
227    /* For greedy ? operator. */    /* For greedy ? operator. */
228    struct sljit_label *zerohotpath;    struct sljit_label *zero_matchingpath;
229    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
230    union {    union {
231      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
232      jump_list *condfailed;      jump_list *condfailed;
233      assert_fallback *assert;      assert_backtrack *assert;
234      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. -1 if not needed. */
235      int framesize;      int framesize;
236    } u;    } u;
237    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
238    int localptr;    int private_data_ptr;
239  } bracket_fallback;  } bracket_backtrack;
240    
241  typedef struct bracketpos_fallback {  typedef struct bracketpos_backtrack {
242    fallback_common common;    backtrack_common common;
243    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
244    int localptr;    int private_data_ptr;
245    /* Reverting stack is needed. */    /* Reverting stack is needed. */
246    int framesize;    int framesize;
247    /* Allocated stack size. */    /* Allocated stack size. */
248    int stacksize;    int stacksize;
249  } bracketpos_fallback;  } bracketpos_backtrack;
250    
251  typedef struct braminzero_fallback {  typedef struct braminzero_backtrack {
252    fallback_common common;    backtrack_common common;
253    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
254  } braminzero_fallback;  } braminzero_backtrack;
255    
256  typedef struct iterator_fallback {  typedef struct iterator_backtrack {
257    fallback_common common;    backtrack_common common;
258    /* Next iteration. */    /* Next iteration. */
259    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
260  } iterator_fallback;  } iterator_backtrack;
261    
262  typedef struct recurse_entry {  typedef struct recurse_entry {
263    struct recurse_entry *next;    struct recurse_entry *next;
# Line 263  typedef struct recurse_entry { Line 269  typedef struct recurse_entry {
269    int start;    int start;
270  } recurse_entry;  } recurse_entry;
271    
272  typedef struct recurse_fallback {  typedef struct recurse_backtrack {
273    fallback_common common;    backtrack_common common;
274  } recurse_fallback;  } recurse_backtrack;
275    
276    #define MAX_RANGE_SIZE 6
277    
278  typedef struct compiler_common {  typedef struct compiler_common {
279    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
280    uschar *start;    pcre_uchar *start;
281    int localsize;  
282    int *localptrs;    /* Maps private data offset to each opcode. */
283    const uschar *fcc;    int *private_data_ptrs;
284    sljit_w lcc;    /* Tells whether the capturing bracket is optimized. */
285      pcre_uint8 *optimized_cbracket;
286      /* Starting offset of private data for capturing brackets. */
287    int cbraptr;    int cbraptr;
288      /* OVector starting point. Must be divisible by 2. */
289      int ovector_start;
290      /* Last known position of the requested byte. */
291      int req_char_ptr;
292      /* Head of the last recursion. */
293      int recursive_head_ptr;
294      /* First inspected character for partial matching. */
295      int start_used_ptr;
296      /* Starting pointer for partial soft matches. */
297      int hit_start;
298      /* End pointer of the first line. */
299      int first_line_end;
300      /* Points to the marked string. */
301      int mark_ptr;
302      /* Points to the last matched capture block index. */
303      int capture_last_ptr;
304    
305      /* Flipped and lower case tables. */
306      const pcre_uint8 *fcc;
307      sljit_sw lcc;
308      /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
309      int mode;
310      /* Newline control. */
311    int nltype;    int nltype;
312    int newline;    int newline;
313    int bsr_nltype;    int bsr_nltype;
314      /* Dollar endonly. */
315    int endonly;    int endonly;
316    sljit_w ctypes;    BOOL has_set_som;
317      /* Tables. */
318      sljit_sw ctypes;
319      int digits[2 + MAX_RANGE_SIZE];
320      /* Named capturing brackets. */
321    sljit_uw name_table;    sljit_uw name_table;
322    sljit_w name_count;    sljit_sw name_count;
323    sljit_w name_entry_size;    sljit_sw name_entry_size;
324    struct sljit_label *acceptlabel;  
325      /* Labels and jump lists. */
326      struct sljit_label *partialmatchlabel;
327      struct sljit_label *quit_label;
328      struct sljit_label *forced_quit_label;
329      struct sljit_label *accept_label;
330    stub_list *stubs;    stub_list *stubs;
331    recurse_entry *entries;    recurse_entry *entries;
332    recurse_entry *currententry;    recurse_entry *currententry;
333      jump_list *partialmatch;
334      jump_list *quit;
335      jump_list *forced_quit;
336    jump_list *accept;    jump_list *accept;
337    jump_list *calllimit;    jump_list *calllimit;
338    jump_list *stackalloc;    jump_list *stackalloc;
# Line 298  typedef struct compiler_common { Line 344  typedef struct compiler_common {
344    jump_list *casefulcmp;    jump_list *casefulcmp;
345    jump_list *caselesscmp;    jump_list *caselesscmp;
346    BOOL jscript_compat;    BOOL jscript_compat;
347  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
348    BOOL utf8;    BOOL utf;
349  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
350    BOOL useucp;    BOOL use_ucp;
351    #endif
352    #ifndef COMPILE_PCRE32
353      jump_list *utfreadchar;
354  #endif  #endif
355    jump_list *utf8readchar;  #ifdef COMPILE_PCRE8
356    jump_list *utf8readtype8;    jump_list *utfreadtype8;
357  #endif  #endif
358    #endif /* SUPPORT_UTF */
359  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
360    jump_list *getucd;    jump_list *getucd;
361  #endif  #endif
# Line 317  typedef struct compare_context { Line 367  typedef struct compare_context {
367    int length;    int length;
368    int sourcereg;    int sourcereg;
369  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
370    int byteptr;    int ucharptr;
371    union {    union {
372      int asint;      sljit_si asint;
373      short asshort;      sljit_uh asushort;
374    #if defined COMPILE_PCRE8
375      sljit_ub asbyte;      sljit_ub asbyte;
376      sljit_ub asbytes[4];      sljit_ub asuchars[4];
377    #elif defined COMPILE_PCRE16
378        sljit_uh asuchars[2];
379    #elif defined COMPILE_PCRE32
380        sljit_ui asuchars[1];
381    #endif
382    } c;    } c;
383    union {    union {
384      int asint;      sljit_si asint;
385      short asshort;      sljit_uh asushort;
386    #if defined COMPILE_PCRE8
387      sljit_ub asbyte;      sljit_ub asbyte;
388      sljit_ub asbytes[4];      sljit_ub asuchars[4];
389    #elif defined COMPILE_PCRE16
390        sljit_uh asuchars[2];
391    #elif defined COMPILE_PCRE32
392        sljit_ui asuchars[1];
393    #endif
394    } oc;    } oc;
395  #endif  #endif
396  } compare_context;  } compare_context;
397    
398  enum {  /* Undefine sljit macros. */
399    frame_end = 0,  #undef CMP
   frame_setstrbegin = -1  
 };  
400    
401  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
402  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
403    
404  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
405  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
406  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
407  #define STR_PTR       SLJIT_GENERAL_REG1  #define STR_PTR       SLJIT_SAVED_REG1
408  #define STR_END       SLJIT_GENERAL_REG2  #define STR_END       SLJIT_SAVED_REG2
409  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
410  #define STACK_LIMIT   SLJIT_GENERAL_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
411  #define ARGUMENTS     SLJIT_GENERAL_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
412  #define CALL_COUNT    SLJIT_GENERAL_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
413  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
414    
415  /* Locals layout. */  /* Local space layout. */
416  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
417  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
418  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
419  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
420  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
421  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
 /* Head of the last recursion. */  
 #define RECURSIVE_HEAD   (4 * sizeof(sljit_w))  
422  /* Max limit of recursions. */  /* Max limit of recursions. */
423  #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))  
424  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
425  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
426  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
427  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. */
428  #define OVECTOR_START    (8 * sizeof(sljit_w))  #define OVECTOR_START    (common->ovector_start)
429  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
430  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_sw))
431  #define PRIV(cc)         (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
432    
433    #if defined COMPILE_PCRE8
434    #define MOV_UCHAR  SLJIT_MOV_UB
435    #define MOVU_UCHAR SLJIT_MOVU_UB
436    #elif defined COMPILE_PCRE16
437    #define MOV_UCHAR  SLJIT_MOV_UH
438    #define MOVU_UCHAR SLJIT_MOVU_UH
439    #elif defined COMPILE_PCRE32
440    #define MOV_UCHAR  SLJIT_MOV_UI
441    #define MOVU_UCHAR SLJIT_MOVU_UI
442    #else
443    #error Unsupported compiling mode
444    #endif
445    
446  /* Shortcuts. */  /* Shortcuts. */
447  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 391  the start pointers when the end of the c Line 458  the start pointers when the end of the c
458    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
459  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
460    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
461    #define SET_LABEL(jump, label) \
462      sljit_set_label((jump), (label))
463  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
464    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
465  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
466    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))
467  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
468    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
469    #define GET_LOCAL_BASE(dst, dstw, offset) \
470      sljit_get_local_base(compiler, (dst), (dstw), (offset))
471    
472  static uschar* bracketend(uschar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
473  {  {
474  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));
475  do cc += GET(cc, 1); while (*cc == OP_ALT);  do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 409  return cc; Line 480  return cc;
480    
481  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
482   next_opcode   next_opcode
483   get_localspace   get_private_data_length
484   set_localptrs   set_private_data_ptrs
485   get_framesize   get_framesize
486   init_frame   init_frame
487   get_localsize   get_private_data_length_for_copy
488   copy_locals   copy_private_data
489   compile_hotpath   compile_matchingpath
490   compile_fallbackpath   compile_backtrackingpath
491  */  */
492    
493  static uschar *next_opcode(compiler_common *common, uschar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
494  {  {
495  SLJIT_UNUSED_ARG(common);  SLJIT_UNUSED_ARG(common);
496  switch(*cc)  switch(*cc)
# Line 468  switch(*cc) Line 539  switch(*cc)
539    case OP_BRAZERO:    case OP_BRAZERO:
540    case OP_BRAMINZERO:    case OP_BRAMINZERO:
541    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
542      case OP_COMMIT:
543    case OP_FAIL:    case OP_FAIL:
544    case OP_ACCEPT:    case OP_ACCEPT:
545    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
# Line 475  switch(*cc) Line 547  switch(*cc)
547    return cc + 1;    return cc + 1;
548    
549    case OP_ANYBYTE:    case OP_ANYBYTE:
550  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
551    if (common->utf8) return NULL;    if (common->utf) return NULL;
552  #endif  #endif
553    return cc + 1;    return cc + 1;
554    
# Line 484  switch(*cc) Line 556  switch(*cc)
556    case OP_CHARI:    case OP_CHARI:
557    case OP_NOT:    case OP_NOT:
558    case OP_NOTI:    case OP_NOTI:
   
559    case OP_STAR:    case OP_STAR:
560    case OP_MINSTAR:    case OP_MINSTAR:
561    case OP_PLUS:    case OP_PLUS:
# Line 522  switch(*cc) Line 593  switch(*cc)
593    case OP_NOTPOSPLUSI:    case OP_NOTPOSPLUSI:
594    case OP_NOTPOSQUERYI:    case OP_NOTPOSQUERYI:
595    cc += 2;    cc += 2;
596  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
597    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]);
598  #endif  #endif
599    return cc;    return cc;
600    
# Line 543  switch(*cc) Line 614  switch(*cc)
614    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
615    case OP_NOTEXACTI:    case OP_NOTEXACTI:
616    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
617    cc += 4;    cc += 2 + IMM2_SIZE;
618  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
619    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]);
620  #endif  #endif
621    return cc;    return cc;
622    
623    case OP_NOTPROP:    case OP_NOTPROP:
624    case OP_PROP:    case OP_PROP:
625      return cc + 1 + 2;
626    
627    case OP_TYPEUPTO:    case OP_TYPEUPTO:
628    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
629    case OP_TYPEEXACT:    case OP_TYPEEXACT:
# Line 562  switch(*cc) Line 635  switch(*cc)
635    case OP_RREF:    case OP_RREF:
636    case OP_NRREF:    case OP_NRREF:
637    case OP_CLOSE:    case OP_CLOSE:
638    cc += 3;    cc += 1 + IMM2_SIZE;
639    return cc;    return cc;
640    
641    case OP_CRRANGE:    case OP_CRRANGE:
642    case OP_CRMINRANGE:    case OP_CRMINRANGE:
643    return cc + 5;    return cc + 1 + 2 * IMM2_SIZE;
644    
645    case OP_CLASS:    case OP_CLASS:
646    case OP_NCLASS:    case OP_NCLASS:
647    return cc + 33;    return cc + 1 + 32 / sizeof(pcre_uchar);
648    
649  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
650    case OP_XCLASS:    case OP_XCLASS:
651    return cc + GET(cc, 1);    return cc + GET(cc, 1);
652  #endif  #endif
# Line 603  switch(*cc) Line 676  switch(*cc)
676    case OP_CBRAPOS:    case OP_CBRAPOS:
677    case OP_SCBRA:    case OP_SCBRA:
678    case OP_SCBRAPOS:    case OP_SCBRAPOS:
679    return cc + 1 + LINK_SIZE + 2;    return cc + 1 + LINK_SIZE + IMM2_SIZE;
680    
681      case OP_MARK:
682      return cc + 1 + 2 + cc[1];
683    
684      case OP_CALLOUT:
685      return cc + 2 + 2 * LINK_SIZE;
686    
687    default:    default:
688    return NULL;    return NULL;
689    }    }
690  }  }
691    
692  static int get_localspace(compiler_common *common, uschar *cc, uschar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
693        case OP_MINSTAR: \
694        case OP_MINPLUS: \
695        case OP_QUERY: \
696        case OP_MINQUERY: \
697        case OP_MINSTARI: \
698        case OP_MINPLUSI: \
699        case OP_QUERYI: \
700        case OP_MINQUERYI: \
701        case OP_NOTMINSTAR: \
702        case OP_NOTMINPLUS: \
703        case OP_NOTQUERY: \
704        case OP_NOTMINQUERY: \
705        case OP_NOTMINSTARI: \
706        case OP_NOTMINPLUSI: \
707        case OP_NOTQUERYI: \
708        case OP_NOTMINQUERYI:
709    
710    #define CASE_ITERATOR_PRIVATE_DATA_2A \
711        case OP_STAR: \
712        case OP_PLUS: \
713        case OP_STARI: \
714        case OP_PLUSI: \
715        case OP_NOTSTAR: \
716        case OP_NOTPLUS: \
717        case OP_NOTSTARI: \
718        case OP_NOTPLUSI:
719    
720    #define CASE_ITERATOR_PRIVATE_DATA_2B \
721        case OP_UPTO: \
722        case OP_MINUPTO: \
723        case OP_UPTOI: \
724        case OP_MINUPTOI: \
725        case OP_NOTUPTO: \
726        case OP_NOTMINUPTO: \
727        case OP_NOTUPTOI: \
728        case OP_NOTMINUPTOI:
729    
730    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
731        case OP_TYPEMINSTAR: \
732        case OP_TYPEMINPLUS: \
733        case OP_TYPEQUERY: \
734        case OP_TYPEMINQUERY:
735    
736    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
737        case OP_TYPESTAR: \
738        case OP_TYPEPLUS:
739    
740    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
741        case OP_TYPEUPTO: \
742        case OP_TYPEMINUPTO:
743    
744    static int get_class_iterator_size(pcre_uchar *cc)
745    {
746    switch(*cc)
747      {
748      case OP_CRSTAR:
749      case OP_CRPLUS:
750      return 2;
751    
752      case OP_CRMINSTAR:
753      case OP_CRMINPLUS:
754      case OP_CRQUERY:
755      case OP_CRMINQUERY:
756      return 1;
757    
758      case OP_CRRANGE:
759      case OP_CRMINRANGE:
760      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
761        return 0;
762      return 2;
763    
764      default:
765      return 0;
766      }
767    }
768    
769    static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
770  {  {
771  int localspace = 0;  int private_data_length = 0;
772  uschar *alternative;  pcre_uchar *alternative;
773    pcre_uchar *name;
774    pcre_uchar *end = NULL;
775    int space, size, i;
776    pcre_uint32 bracketlen;
777    
778  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
779  while (cc < ccend)  while (cc < ccend)
780    {    {
781      space = 0;
782      size = 0;
783      bracketlen = 0;
784    switch(*cc)    switch(*cc)
785      {      {
786        case OP_SET_SOM:
787        common->has_set_som = TRUE;
788        cc += 1;
789        break;
790    
791        case OP_REF:
792        case OP_REFI:
793        common->optimized_cbracket[GET2(cc, 1)] = 0;
794        cc += 1 + IMM2_SIZE;
795        break;
796    
797      case OP_ASSERT:      case OP_ASSERT:
798      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
799      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 628  while (cc < ccend) Line 803  while (cc < ccend)
803      case OP_BRAPOS:      case OP_BRAPOS:
804      case OP_SBRA:      case OP_SBRA:
805      case OP_SBRAPOS:      case OP_SBRAPOS:
806      case OP_SCOND:      private_data_length += sizeof(sljit_sw);
807      localspace += sizeof(sljit_w);      bracketlen = 1 + LINK_SIZE;
     cc += 1 + LINK_SIZE;  
808      break;      break;
809    
810      case OP_CBRAPOS:      case OP_CBRAPOS:
811      case OP_SCBRAPOS:      case OP_SCBRAPOS:
812      localspace += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
813      cc += 1 + LINK_SIZE + 2;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
814        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
815      break;      break;
816    
817      case OP_COND:      case OP_COND:
818      /* Might be a hidden SCOND. */      case OP_SCOND:
819      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
820      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
821        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
822          return -1;
823    
824        if (*cc == OP_COND)
825          {
826          /* Might be a hidden SCOND. */
827          alternative = cc + GET(cc, 1);
828          if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
829            private_data_length += sizeof(sljit_sw);
830          }
831        else
832          private_data_length += sizeof(sljit_sw);
833        bracketlen = 1 + LINK_SIZE;
834        break;
835    
836        case OP_CREF:
837        i = GET2(cc, 1);
838        common->optimized_cbracket[i] = 0;
839        cc += 1 + IMM2_SIZE;
840        break;
841    
842        case OP_NCREF:
843        bracketlen = GET2(cc, 1);
844        name = (pcre_uchar *)common->name_table;
845        alternative = name;
846        for (i = 0; i < common->name_count; i++)
847          {
848          if (GET2(name, 0) == bracketlen) break;
849          name += common->name_entry_size;
850          }
851        SLJIT_ASSERT(i != common->name_count);
852    
853        for (i = 0; i < common->name_count; i++)
854          {
855          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
856            common->optimized_cbracket[GET2(alternative, 0)] = 0;
857          alternative += common->name_entry_size;
858          }
859        bracketlen = 0;
860        cc += 1 + IMM2_SIZE;
861        break;
862    
863        case OP_BRA:
864        bracketlen = 1 + LINK_SIZE;
865        break;
866    
867        case OP_CBRA:
868        case OP_SCBRA:
869        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
870        break;
871    
872        CASE_ITERATOR_PRIVATE_DATA_1
873        space = 1;
874        size = -2;
875        break;
876    
877        CASE_ITERATOR_PRIVATE_DATA_2A
878        space = 2;
879        size = -2;
880        break;
881    
882        CASE_ITERATOR_PRIVATE_DATA_2B
883        space = 2;
884        size = -(2 + IMM2_SIZE);
885        break;
886    
887        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
888        space = 1;
889        size = 1;
890        break;
891    
892        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
893        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
894          space = 2;
895        size = 1;
896        break;
897    
898        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
899        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
900          space = 2;
901        size = 1 + IMM2_SIZE;
902        break;
903    
904        case OP_CLASS:
905        case OP_NCLASS:
906        size += 1 + 32 / sizeof(pcre_uchar);
907        space = get_class_iterator_size(cc + size);
908        break;
909    
910    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
911        case OP_XCLASS:
912        size = GET(cc, 1);
913        space = get_class_iterator_size(cc + size);
914        break;
915    #endif
916    
917        case OP_RECURSE:
918        /* Set its value only once. */
919        if (common->recursive_head_ptr == 0)
920          {
921          common->recursive_head_ptr = common->ovector_start;
922          common->ovector_start += sizeof(sljit_sw);
923          }
924      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
925      break;      break;
926    
927        case OP_CALLOUT:
928        if (common->capture_last_ptr == 0)
929          {
930          common->capture_last_ptr = common->ovector_start;
931          common->ovector_start += sizeof(sljit_sw);
932          }
933        cc += 2 + 2 * LINK_SIZE;
934        break;
935    
936        case OP_MARK:
937        if (common->mark_ptr == 0)
938          {
939          common->mark_ptr = common->ovector_start;
940          common->ovector_start += sizeof(sljit_sw);
941          }
942        cc += 1 + 2 + cc[1];
943        break;
944    
945      default:      default:
946      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
947      if (cc == NULL)      if (cc == NULL)
948        return -1;        return -1;
949      break;      break;
950      }      }
951    
952      if (space > 0 && cc >= end)
953        private_data_length += sizeof(sljit_sw) * space;
954    
955      if (size != 0)
956        {
957        if (size < 0)
958          {
959          cc += -size;
960    #ifdef SUPPORT_UTF
961          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
962    #endif
963          }
964        else
965          cc += size;
966        }
967    
968      if (bracketlen != 0)
969        {
970        if (cc >= end)
971          {
972          end = bracketend(cc);
973          if (end[-1 - LINK_SIZE] == OP_KET)
974            end = NULL;
975          }
976        cc += bracketlen;
977        }
978    }    }
979  return localspace;  return private_data_length;
980  }  }
981    
982  static void set_localptrs(compiler_common *common, int localptr, uschar *ccend)  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)
983  {  {
984  uschar *cc = common->start;  pcre_uchar *cc = common->start;
985  uschar *alternative;  pcre_uchar *alternative;
986    pcre_uchar *end = NULL;
987    int space, size, bracketlen;
988    
989  while (cc < ccend)  while (cc < ccend)
990    {    {
991      space = 0;
992      size = 0;
993      bracketlen = 0;
994    switch(*cc)    switch(*cc)
995      {      {
996      case OP_ASSERT:      case OP_ASSERT:
# Line 675  while (cc < ccend) Line 1003  while (cc < ccend)
1003      case OP_SBRA:      case OP_SBRA:
1004      case OP_SBRAPOS:      case OP_SBRAPOS:
1005      case OP_SCOND:      case OP_SCOND:
1006      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1007      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1008      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1009      break;      break;
1010    
1011      case OP_CBRAPOS:      case OP_CBRAPOS:
1012      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1013      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1014      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1015      cc += 1 + LINK_SIZE + 2;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1016      break;      break;
1017    
1018      case OP_COND:      case OP_COND:
# Line 692  while (cc < ccend) Line 1020  while (cc < ccend)
1020      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1021      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1022        {        {
1023        common->localptrs[cc - common->start] = localptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1024        localptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1025        }        }
1026      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1027        break;
1028    
1029        case OP_BRA:
1030        bracketlen = 1 + LINK_SIZE;
1031        break;
1032    
1033        case OP_CBRA:
1034        case OP_SCBRA:
1035        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1036        break;
1037    
1038        CASE_ITERATOR_PRIVATE_DATA_1
1039        space = 1;
1040        size = -2;
1041        break;
1042    
1043        CASE_ITERATOR_PRIVATE_DATA_2A
1044        space = 2;
1045        size = -2;
1046        break;
1047    
1048        CASE_ITERATOR_PRIVATE_DATA_2B
1049        space = 2;
1050        size = -(2 + IMM2_SIZE);
1051        break;
1052    
1053        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1054        space = 1;
1055        size = 1;
1056        break;
1057    
1058        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1059        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1060          space = 2;
1061        size = 1;
1062        break;
1063    
1064        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1065        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1066          space = 2;
1067        size = 1 + IMM2_SIZE;
1068        break;
1069    
1070        case OP_CLASS:
1071        case OP_NCLASS:
1072        size += 1 + 32 / sizeof(pcre_uchar);
1073        space = get_class_iterator_size(cc + size);
1074        break;
1075    
1076    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1077        case OP_XCLASS:
1078        size = GET(cc, 1);
1079        space = get_class_iterator_size(cc + size);
1080      break;      break;
1081    #endif
1082    
1083      default:      default:
1084      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1085      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1086      break;      break;
1087      }      }
1088    
1089      if (space > 0 && cc >= end)
1090        {
1091        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1092        private_data_ptr += sizeof(sljit_sw) * space;
1093        }
1094    
1095      if (size != 0)
1096        {
1097        if (size < 0)
1098          {
1099          cc += -size;
1100    #ifdef SUPPORT_UTF
1101          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1102    #endif
1103          }
1104        else
1105          cc += size;
1106        }
1107    
1108      if (bracketlen > 0)
1109        {
1110        if (cc >= end)
1111          {
1112          end = bracketend(cc);
1113          if (end[-1 - LINK_SIZE] == OP_KET)
1114            end = NULL;
1115          }
1116        cc += bracketlen;
1117        }
1118    }    }
1119  }  }
1120    
1121  /* Returns with -1 if no need for frame. */  /* Returns with -1 if no need for frame. */
1122  static int get_framesize(compiler_common *common, uschar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)
1123  {  {
1124  uschar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc);
1125  int length = 0;  int length = 0;
1126  BOOL possessive = FALSE;  int possessive = 0;
1127  BOOL setsom_found = FALSE;  BOOL setsom_found = recursive;
1128    BOOL setmark_found = recursive;
1129    BOOL capture_last_found = recursive;
1130    
1131  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1132    {    {
1133    length = 3;    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1134    possessive = TRUE;    /* This is correct regardless of common->capture_last_ptr. */
1135      capture_last_found = TRUE;
1136    }    }
1137    
1138  cc = next_opcode(common, cc);  cc = next_opcode(common, cc);
# Line 726  while (cc < ccend) Line 1141  while (cc < ccend)
1141    switch(*cc)    switch(*cc)
1142      {      {
1143      case OP_SET_SOM:      case OP_SET_SOM:
1144      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1145      if (!setsom_found)      if (!setsom_found)
1146        {        {
1147        length += 2;        length += 2;
1148        setsom_found = TRUE;        setsom_found = TRUE;
1149        }        }
1150      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      cc += 1;
1151        break;
1152    
1153        case OP_MARK:
1154        SLJIT_ASSERT(common->mark_ptr != 0);
1155        if (!setmark_found)
1156          {
1157          length += 2;
1158          setmark_found = TRUE;
1159          }
1160        cc += 1 + 2 + cc[1];
1161        break;
1162    
1163        case OP_RECURSE:
1164        if (common->has_set_som && !setsom_found)
1165          {
1166          length += 2;
1167          setsom_found = TRUE;
1168          }
1169        if (common->mark_ptr != 0 && !setmark_found)
1170          {
1171          length += 2;
1172          setmark_found = TRUE;
1173          }
1174        if (common->capture_last_ptr != 0 && !capture_last_found)
1175          {
1176          length += 2;
1177          capture_last_found = TRUE;
1178          }
1179        cc += 1 + LINK_SIZE;
1180      break;      break;
1181    
1182      case OP_CBRA:      case OP_CBRA:
1183      case OP_CBRAPOS:      case OP_CBRAPOS:
1184      case OP_SCBRA:      case OP_SCBRA:
1185      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1186        if (common->capture_last_ptr != 0 && !capture_last_found)
1187          {
1188          length += 2;
1189          capture_last_found = TRUE;
1190          }
1191      length += 3;      length += 3;
1192      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1193      break;      break;
1194    
1195      default:      default:
# Line 750  while (cc < ccend) Line 1199  while (cc < ccend)
1199      }      }
1200    
1201  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1202  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1203    return -1;    return -1;
1204    
1205  if (length > 0)  if (length > 0)
# Line 758  if (length > 0) Line 1207  if (length > 0)
1207  return -1;  return -1;
1208  }  }
1209    
1210  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)
1211  {  {
1212  DEFINE_COMPILER;  DEFINE_COMPILER;
1213  uschar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc);
1214  BOOL setsom_found = FALSE;  BOOL setsom_found = recursive;
1215    BOOL setmark_found = recursive;
1216    BOOL capture_last_found = recursive;
1217  int offset;  int offset;
1218    
1219  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
1220    SLJIT_UNUSED_ARG(stacktop);
1221  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1222    
1223  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
# Line 776  while (cc < ccend) Line 1228  while (cc < ccend)
1228    switch(*cc)    switch(*cc)
1229      {      {
1230      case OP_SET_SOM:      case OP_SET_SOM:
1231      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1232      if (!setsom_found)      if (!setsom_found)
1233        {        {
1234        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1235        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1236        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1237          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1238          stackpos += (int)sizeof(sljit_sw);
1239          setsom_found = TRUE;
1240          }
1241        cc += 1;
1242        break;
1243    
1244        case OP_MARK:
1245        SLJIT_ASSERT(common->mark_ptr != 0);
1246        if (!setmark_found)
1247          {
1248          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1249          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1250          stackpos += (int)sizeof(sljit_sw);
1251          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1252          stackpos += (int)sizeof(sljit_sw);
1253          setmark_found = TRUE;
1254          }
1255        cc += 1 + 2 + cc[1];
1256        break;
1257    
1258        case OP_RECURSE:
1259        if (common->has_set_som && !setsom_found)
1260          {
1261          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1262          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1263          stackpos += (int)sizeof(sljit_sw);
1264        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1265        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1266        setsom_found = TRUE;        setsom_found = TRUE;
1267        }        }
1268      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      if (common->mark_ptr != 0 && !setmark_found)
1269          {
1270          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1271          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1272          stackpos += (int)sizeof(sljit_sw);
1273          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1274          stackpos += (int)sizeof(sljit_sw);
1275          setmark_found = TRUE;
1276          }
1277        if (common->capture_last_ptr != 0 && !capture_last_found)
1278          {
1279          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1280          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1281          stackpos += (int)sizeof(sljit_sw);
1282          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1283          stackpos += (int)sizeof(sljit_sw);
1284          capture_last_found = TRUE;
1285          }
1286        cc += 1 + LINK_SIZE;
1287      break;      break;
1288    
1289      case OP_CBRA:      case OP_CBRA:
1290      case OP_CBRAPOS:      case OP_CBRAPOS:
1291      case OP_SCBRA:      case OP_SCBRA:
1292      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1293        if (common->capture_last_ptr != 0 && !capture_last_found)
1294          {
1295          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1296          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1297          stackpos += (int)sizeof(sljit_sw);
1298          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1299          stackpos += (int)sizeof(sljit_sw);
1300          capture_last_found = TRUE;
1301          }
1302      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1303      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1304      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1305      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1306      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));
1307      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1308      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1309      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1310      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1311    
1312      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1313      break;      break;
1314    
1315      default:      default:
# Line 812  while (cc < ccend) Line 1318  while (cc < ccend)
1318      break;      break;
1319      }      }
1320    
1321  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1322  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1323  }  }
1324    
1325  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)
1326  {  {
1327  int localsize = 2;  int private_data_length = 2;
1328  uschar *alternative;  int size;
1329  /* Calculate the sum of the local variables. */  pcre_uchar *alternative;
1330    /* Calculate the sum of the private machine words. */
1331  while (cc < ccend)  while (cc < ccend)
1332    {    {
1333      size = 0;
1334    switch(*cc)    switch(*cc)
1335      {      {
1336      case OP_ASSERT:      case OP_ASSERT:
# Line 835  while (cc < ccend) Line 1343  while (cc < ccend)
1343      case OP_SBRA:      case OP_SBRA:
1344      case OP_SBRAPOS:      case OP_SBRAPOS:
1345      case OP_SCOND:      case OP_SCOND:
1346      localsize++;      private_data_length++;
1347      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1348      break;      break;
1349    
1350      case OP_CBRA:      case OP_CBRA:
1351      case OP_SCBRA:      case OP_SCBRA:
1352      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1353      cc += 1 + LINK_SIZE + 2;        private_data_length++;
1354        cc += 1 + LINK_SIZE + IMM2_SIZE;
1355      break;      break;
1356    
1357      case OP_CBRAPOS:      case OP_CBRAPOS:
1358      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1359      localsize += 2;      private_data_length += 2;
1360      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1361      break;      break;
1362    
1363      case OP_COND:      case OP_COND:
1364      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1365      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1366      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1367        localsize++;        private_data_length++;
1368      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1369      break;      break;
1370    
1371        CASE_ITERATOR_PRIVATE_DATA_1
1372        if (PRIVATE_DATA(cc))
1373          private_data_length++;
1374        cc += 2;
1375    #ifdef SUPPORT_UTF
1376        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1377    #endif
1378        break;
1379    
1380        CASE_ITERATOR_PRIVATE_DATA_2A
1381        if (PRIVATE_DATA(cc))
1382          private_data_length += 2;
1383        cc += 2;
1384    #ifdef SUPPORT_UTF
1385        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1386    #endif
1387        break;
1388    
1389        CASE_ITERATOR_PRIVATE_DATA_2B
1390        if (PRIVATE_DATA(cc))
1391          private_data_length += 2;
1392        cc += 2 + IMM2_SIZE;
1393    #ifdef SUPPORT_UTF
1394        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1395    #endif
1396        break;
1397    
1398        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1399        if (PRIVATE_DATA(cc))
1400          private_data_length++;
1401        cc += 1;
1402        break;
1403    
1404        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1405        if (PRIVATE_DATA(cc))
1406          private_data_length += 2;
1407        cc += 1;
1408        break;
1409    
1410        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1411        if (PRIVATE_DATA(cc))
1412          private_data_length += 2;
1413        cc += 1 + IMM2_SIZE;
1414        break;
1415    
1416        case OP_CLASS:
1417        case OP_NCLASS:
1418    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1419        case OP_XCLASS:
1420        size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1421    #else
1422        size = 1 + 32 / (int)sizeof(pcre_uchar);
1423    #endif
1424        if (PRIVATE_DATA(cc))
1425          private_data_length += get_class_iterator_size(cc + size);
1426        cc += size;
1427        break;
1428    
1429      default:      default:
1430      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1431      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 866  while (cc < ccend) Line 1433  while (cc < ccend)
1433      }      }
1434    }    }
1435  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1436  return localsize;  return private_data_length;
1437  }  }
1438    
1439  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,
1440    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop)
1441  {  {
1442  DEFINE_COMPILER;  DEFINE_COMPILER;
1443  int srcw[2];  int srcw[2];
1444  int count;  int count, size;
1445  BOOL tmp1next = TRUE;  BOOL tmp1next = TRUE;
1446  BOOL tmp1empty = TRUE;  BOOL tmp1empty = TRUE;
1447  BOOL tmp2empty = TRUE;  BOOL tmp2empty = TRUE;
1448  uschar *alternative;  pcre_uchar *alternative;
1449  enum {  enum {
1450    start,    start,
1451    loop,    loop,
# Line 891  stacktop = STACK(stacktop - 1); Line 1458  stacktop = STACK(stacktop - 1);
1458    
1459  if (!save)  if (!save)
1460    {    {
1461    stackptr += sizeof(sljit_w);    stackptr += sizeof(sljit_sw);
1462    if (stackptr < stacktop)    if (stackptr < stacktop)
1463      {      {
1464      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1465      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1466      tmp1empty = FALSE;      tmp1empty = FALSE;
1467      }      }
1468    if (stackptr < stacktop)    if (stackptr < stacktop)
1469      {      {
1470      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1471      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1472      tmp2empty = FALSE;      tmp2empty = FALSE;
1473      }      }
1474    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
# Line 913  while (status != end) Line 1480  while (status != end)
1480    switch(status)    switch(status)
1481      {      {
1482      case start:      case start:
1483      SLJIT_ASSERT(save);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1484      count = 1;      count = 1;
1485      srcw[0] = RECURSIVE_HEAD;      srcw[0] = common->recursive_head_ptr;
1486      status = loop;      status = loop;
1487      break;      break;
1488    
# Line 939  while (status != end) Line 1506  while (status != end)
1506        case OP_SBRAPOS:        case OP_SBRAPOS:
1507        case OP_SCOND:        case OP_SCOND:
1508        count = 1;        count = 1;
1509        srcw[0] = PRIV(cc);        srcw[0] = PRIVATE_DATA(cc);
1510        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1511        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1512        break;        break;
1513    
1514        case OP_CBRA:        case OP_CBRA:
1515        case OP_SCBRA:        case OP_SCBRA:
1516        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1517        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1518        cc += 1 + LINK_SIZE + 2;          count = 1;
1519            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1520            }
1521          cc += 1 + LINK_SIZE + IMM2_SIZE;
1522        break;        break;
1523    
1524        case OP_CBRAPOS:        case OP_CBRAPOS:
1525        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1526        count = 2;        count = 2;
1527          srcw[0] = PRIVATE_DATA(cc);
1528        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1529        srcw[0] = PRIV(cc);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
1530        SLJIT_ASSERT(srcw[0] != 0);        cc += 1 + LINK_SIZE + IMM2_SIZE;
       cc += 1 + LINK_SIZE + 2;  
1531        break;        break;
1532    
1533        case OP_COND:        case OP_COND:
# Line 966  while (status != end) Line 1536  while (status != end)
1536        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1537          {          {
1538          count = 1;          count = 1;
1539          srcw[0] = PRIV(cc);          srcw[0] = PRIVATE_DATA(cc);
1540          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1541          }          }
1542        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1543        break;        break;
1544    
1545          CASE_ITERATOR_PRIVATE_DATA_1
1546          if (PRIVATE_DATA(cc))
1547            {
1548            count = 1;
1549            srcw[0] = PRIVATE_DATA(cc);
1550            }
1551          cc += 2;
1552    #ifdef SUPPORT_UTF
1553          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1554    #endif
1555          break;
1556    
1557          CASE_ITERATOR_PRIVATE_DATA_2A
1558          if (PRIVATE_DATA(cc))
1559            {
1560            count = 2;
1561            srcw[0] = PRIVATE_DATA(cc);
1562            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1563            }
1564          cc += 2;
1565    #ifdef SUPPORT_UTF
1566          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1567    #endif
1568          break;
1569    
1570          CASE_ITERATOR_PRIVATE_DATA_2B
1571          if (PRIVATE_DATA(cc))
1572            {
1573            count = 2;
1574            srcw[0] = PRIVATE_DATA(cc);
1575            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1576            }
1577          cc += 2 + IMM2_SIZE;
1578    #ifdef SUPPORT_UTF
1579          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1580    #endif
1581          break;
1582    
1583          CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1584          if (PRIVATE_DATA(cc))
1585            {
1586            count = 1;
1587            srcw[0] = PRIVATE_DATA(cc);
1588            }
1589          cc += 1;
1590          break;
1591    
1592          CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1593          if (PRIVATE_DATA(cc))
1594            {
1595            count = 2;
1596            srcw[0] = PRIVATE_DATA(cc);
1597            srcw[1] = srcw[0] + sizeof(sljit_sw);
1598            }
1599          cc += 1;
1600          break;
1601    
1602          CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1603          if (PRIVATE_DATA(cc))
1604            {
1605            count = 2;
1606            srcw[0] = PRIVATE_DATA(cc);
1607            srcw[1] = srcw[0] + sizeof(sljit_sw);
1608            }
1609          cc += 1 + IMM2_SIZE;
1610          break;
1611    
1612          case OP_CLASS:
1613          case OP_NCLASS:
1614    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1615          case OP_XCLASS:
1616          size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1617    #else
1618          size = 1 + 32 / (int)sizeof(pcre_uchar);
1619    #endif
1620          if (PRIVATE_DATA(cc))
1621            switch(get_class_iterator_size(cc + size))
1622              {
1623              case 1:
1624              count = 1;
1625              srcw[0] = PRIVATE_DATA(cc);
1626              break;
1627    
1628              case 2:
1629              count = 2;
1630              srcw[0] = PRIVATE_DATA(cc);
1631              srcw[1] = srcw[0] + sizeof(sljit_sw);
1632              break;
1633    
1634              default:
1635              SLJIT_ASSERT_STOP();
1636              break;
1637              }
1638          cc += size;
1639          break;
1640    
1641        default:        default:
1642        cc = next_opcode(common, cc);        cc = next_opcode(common, cc);
1643        SLJIT_ASSERT(cc != NULL);        SLJIT_ASSERT(cc != NULL);
# Line 994  while (status != end) Line 1660  while (status != end)
1660          if (!tmp1empty)          if (!tmp1empty)
1661            {            {
1662            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1663            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1664            }            }
1665          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1666          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1005  while (status != end) Line 1671  while (status != end)
1671          if (!tmp2empty)          if (!tmp2empty)
1672            {            {
1673            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1674            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1675            }            }
1676          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1677          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1022  while (status != end) Line 1688  while (status != end)
1688          if (!tmp1empty)          if (!tmp1empty)
1689            {            {
1690            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1691            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1692            }            }
1693          tmp1next = FALSE;          tmp1next = FALSE;
1694          }          }
# Line 1034  while (status != end) Line 1700  while (status != end)
1700          if (!tmp2empty)          if (!tmp2empty)
1701            {            {
1702            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1703            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1704            }            }
1705          tmp1next = TRUE;          tmp1next = TRUE;
1706          }          }
# Line 1049  if (save) Line 1715  if (save)
1715      if (!tmp1empty)      if (!tmp1empty)
1716        {        {
1717        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1718        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1719        }        }
1720      if (!tmp2empty)      if (!tmp2empty)
1721        {        {
1722        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1723        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1724        }        }
1725      }      }
1726    else    else
# Line 1062  if (save) Line 1728  if (save)
1728      if (!tmp2empty)      if (!tmp2empty)
1729        {        {
1730        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1731        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1732        }        }
1733      if (!tmp1empty)      if (!tmp1empty)
1734        {        {
1735        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1736        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1737        }        }
1738      }      }
1739    }    }
1740  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1741  }  }
1742    
1743  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  #undef CASE_ITERATOR_PRIVATE_DATA_1
1744    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1745    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1746    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1747    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1748    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1749    
1750    static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1751  {  {
1752  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1753  }  }
# Line 1084  static SLJIT_INLINE void set_jumps(jump_ Line 1757  static SLJIT_INLINE void set_jumps(jump_
1757  while (list)  while (list)
1758    {    {
1759    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1760    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1761    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1762    list = list->next;    list = list->next;
1763    }    }
1764  }  }
# Line 1111  if (list_item) Line 1784  if (list_item)
1784    list_item->type = type;    list_item->type = type;
1785    list_item->data = data;    list_item->data = data;
1786    list_item->start = start;    list_item->start = start;
1787    list_item->leave = LABEL();    list_item->quit = LABEL();
1788    list_item->next = common->stubs;    list_item->next = common->stubs;
1789    common->stubs = list_item;    common->stubs = list_item;
1790    }    }
# Line 1131  while (list_item) Line 1804  while (list_item)
1804      add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));      add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
1805      break;      break;
1806      }      }
1807    JUMPTO(SLJIT_JUMP, list_item->leave);    JUMPTO(SLJIT_JUMP, list_item->quit);
1808    list_item = list_item->next;    list_item = list_item->next;
1809    }    }
1810  common->stubs = NULL;  common->stubs = NULL;
# Line 1150  static SLJIT_INLINE void allocate_stack( Line 1823  static SLJIT_INLINE void allocate_stack(
1823  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
1824  DEFINE_COMPILER;  DEFINE_COMPILER;
1825    
1826  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));
1827  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
1828  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
1829  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1164  add_stub(common, stack_alloc, 0, CMP(SLJ Line 1837  add_stub(common, stack_alloc, 0, CMP(SLJ
1837  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
1838  {  {
1839  DEFINE_COMPILER;  DEFINE_COMPILER;
1840  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));
1841  }  }
1842    
1843  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1174  struct sljit_label *loop; Line 1847  struct sljit_label *loop;
1847  int i;  int i;
1848  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
1849  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
1850  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));
1851  if (length < 8)  if (length < 8)
1852    {    {
1853    for (i = 0; i < length; i++)    for (i = 0; i < length; i++)
1854      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);
1855    }    }
1856  else  else
1857    {    {
1858    OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START - sizeof(sljit_sw));
1859    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length);
1860    loop = LABEL();    loop = LABEL();
1861    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);
1862    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);
1863    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
1864    }    }
1865  }  }
# Line 1195  static SLJIT_INLINE void copy_ovector(co Line 1868  static SLJIT_INLINE void copy_ovector(co
1868  {  {
1869  DEFINE_COMPILER;  DEFINE_COMPILER;
1870  struct sljit_label *loop;  struct sljit_label *loop;
1871  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
1872    
1873  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
1874  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));
1875  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);
1876    
1877  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
1878  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  if (common->mark_ptr != 0)
1879  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);
1880  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));
1881  OP2(SLJIT_ADD, SLJIT_GENERAL_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START);  if (common->mark_ptr != 0)
1882      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);
1883    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
1884    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
1885    GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
1886  /* Unlikely, but possible */  /* Unlikely, but possible */
1887  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);
1888  loop = LABEL();  loop = LABEL();
1889  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);
1890  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));
1891  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
1892  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_GENERAL_REG2, 0);  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1893  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);
1894    #endif
1895    OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
1896    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
1897  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
1898  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
1899    
1900  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
1901  if (topbracket > 1)  if (topbracket > 1)
1902    {    {
1903    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));
1904    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
1905    
1906    /* OVECTOR(0) is never equal to SLJIT_GENERAL_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
1907    loop = LABEL();    loop = LABEL();
1908    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)));
1909    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);
1910    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);
1911    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
1912    }    }
1913  else  else
1914    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
1915  }  }
1916    
1917  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)
1918    {
1919    DEFINE_COMPILER;
1920    
1921    SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
1922    SLJIT_ASSERT(common->start_used_ptr != 0 && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
1923    
1924    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
1925    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
1926    OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offset_count));
1927    CMPTO(SLJIT_C_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
1928    
1929    /* Store match begin and end. */
1930    OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));
1931    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
1932    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);
1933    OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);
1934    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1935    OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
1936    #endif
1937    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);
1938    
1939    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);
1940    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1941    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
1942    #endif
1943    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0);
1944    
1945    JUMPTO(SLJIT_JUMP, quit);
1946    }
1947    
1948    static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)
1949    {
1950    /* May destroy TMP1. */
1951    DEFINE_COMPILER;
1952    struct sljit_jump *jump;
1953    
1954    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
1955      {
1956      /* The value of -1 must be kept for start_used_ptr! */
1957      OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, 1);
1958      /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting
1959      is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */
1960      jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_PTR, 0);
1961      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
1962      JUMPHERE(jump);
1963      }
1964    else if (common->mode == JIT_PARTIAL_HARD_COMPILE)
1965      {
1966      jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
1967      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
1968      JUMPHERE(jump);
1969      }
1970    }
1971    
1972    static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar* cc)
1973  {  {
1974  /* Detects if the character has an othercase. */  /* Detects if the character has an othercase. */
1975  unsigned int c;  unsigned int c;
1976    
1977  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
1978  if (common->utf8)  if (common->utf)
1979    {    {
1980    GETCHAR(c, cc);    GETCHAR(c, cc);
1981    if (c > 127)    if (c > 127)
# Line 1251  if (common->utf8) Line 1986  if (common->utf8)
1986      return FALSE;      return FALSE;
1987  #endif  #endif
1988      }      }
1989    #ifndef COMPILE_PCRE8
1990      return common->fcc[c] != c;
1991    #endif
1992    }    }
1993  else  else
1994  #endif  #endif
1995    c = *cc;    c = *cc;
1996  return common->fcc[c] != c;  return MAX_255(c) ? common->fcc[c] != c : FALSE;
1997  }  }
1998    
1999  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)
2000  {  {
2001  /* Returns with the othercase. */  /* Returns with the othercase. */
2002  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2003  if (common->utf8 && c > 127)  if (common->utf && c > 127)
2004    {    {
2005  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2006    return UCD_OTHERCASE(c);    return UCD_OTHERCASE(c);
# Line 1271  if (common->utf8 && c > 127) Line 2009  if (common->utf8 && c > 127)
2009  #endif  #endif
2010    }    }
2011  #endif  #endif
2012  return common->fcc[c];  return TABLE_GET(c, common->fcc, c);
2013  }  }
2014    
2015  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)
2016  {  {
2017  /* Detects if the character and its othercase has only 1 bit difference. */  /* Detects if the character and its othercase has only 1 bit difference. */
2018  unsigned int c, oc, bit;  unsigned int c, oc, bit;
2019  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2020  int n;  int n;
2021  #endif  #endif
2022    
2023  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2024  if (common->utf8)  if (common->utf)
2025    {    {
2026    GETCHAR(c, cc);    GETCHAR(c, cc);
2027    if (c <= 127)    if (c <= 127)
# Line 1300  if (common->utf8) Line 2038  if (common->utf8)
2038  else  else
2039    {    {
2040    c = *cc;    c = *cc;
2041    oc = common->fcc[c];    oc = TABLE_GET(c, common->fcc, c);
2042    }    }
2043  #else  #else
2044  c = *cc;  c = *cc;
2045  oc = common->fcc[c];  oc = TABLE_GET(c, common->fcc, c);
2046  #endif  #endif
2047    
2048  SLJIT_ASSERT(c != oc);  SLJIT_ASSERT(c != oc);
# Line 1315  if (c <= 127 && bit == 0x20) Line 2053  if (c <= 127 && bit == 0x20)
2053    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2054    
2055  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2056  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2057    return 0;    return 0;
2058    
2059  #ifdef SUPPORT_UTF8  #if defined COMPILE_PCRE8
2060  if (common->utf8 && c > 127)  
2061    #ifdef SUPPORT_UTF
2062    if (common->utf && c > 127)
2063    {    {
2064    n = _pcre_utf8_table4[*cc & 0x3f];    n = GET_EXTRALEN(*cc);
2065    while ((bit & 0x3f) == 0)    while ((bit & 0x3f) == 0)
2066      {      {
2067      n--;      n--;
# Line 1329  if (common->utf8 && c > 127) Line 2069  if (common->utf8 && c > 127)
2069      }      }
2070    return (n << 8) | bit;    return (n << 8) | bit;
2071    }    }
2072  #endif  #endif /* SUPPORT_UTF */
2073  return (0 << 8) | bit;  return (0 << 8) | bit;
2074    
2075    #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2076    
2077    #ifdef SUPPORT_UTF
2078    if (common->utf && c > 65535)
2079      {
2080      if (bit >= (1 << 10))
2081        bit >>= 10;
2082      else
2083        return (bit < 256) ? ((2 << 8) | bit) : ((3 << 8) | (bit >> 8));
2084      }
2085    #endif /* SUPPORT_UTF */
2086    return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
2087    
2088    #endif /* COMPILE_PCRE[8|16|32] */
2089  }  }
2090    
2091  static SLJIT_INLINE void check_input_end(compiler_common *common, jump_list **fallbacks)  static void check_partial(compiler_common *common, BOOL force)
2092  {  {
2093    /* Checks whether a partial matching is occured. Does not modify registers. */
2094  DEFINE_COMPILER;  DEFINE_COMPILER;
2095  add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));  struct sljit_jump *jump = NULL;
2096    
2097    SLJIT_ASSERT(!force || common->mode != JIT_COMPILE);
2098    
2099    if (common->mode == JIT_COMPILE)
2100      return;
2101    
2102    if (!force)
2103      jump = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2104    else if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2105      jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2106    
2107    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2108      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
2109    else
2110      {
2111      if (common->partialmatchlabel != NULL)
2112        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2113      else
2114        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2115      }
2116    
2117    if (jump != NULL)
2118      JUMPHERE(jump);
2119    }
2120    
2121    static struct sljit_jump *check_str_end(compiler_common *common)
2122    {
2123    /* Does not affect registers. Usually used in a tight spot. */
2124    DEFINE_COMPILER;
2125    struct sljit_jump *jump;
2126    struct sljit_jump *nohit;
2127    struct sljit_jump *return_value;
2128    
2129    if (common->mode == JIT_COMPILE)
2130      return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2131    
2132    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2133    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2134      {
2135      nohit = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2136      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
2137      JUMPHERE(nohit);
2138      return_value = JUMP(SLJIT_JUMP);
2139      }
2140    else
2141      {
2142      return_value = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2143      if (common->partialmatchlabel != NULL)
2144        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2145      else
2146        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2147      }
2148    JUMPHERE(jump);
2149    return return_value;
2150    }
2151    
2152    static void detect_partial_match(compiler_common *common, jump_list **backtracks)
2153    {
2154    DEFINE_COMPILER;
2155    struct sljit_jump *jump;
2156    
2157    if (common->mode == JIT_COMPILE)
2158      {
2159      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2160      return;
2161      }
2162    
2163    /* Partial matching mode. */
2164    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2165    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2166    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2167      {
2168      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
2169      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2170      }
2171    else
2172      {
2173      if (common->partialmatchlabel != NULL)
2174        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2175      else
2176        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2177      }
2178    JUMPHERE(jump);
2179  }  }
2180    
2181  static void read_char(compiler_common *common)  static void read_char(compiler_common *common)
# Line 1344  static void read_char(compiler_common *c Line 2183  static void read_char(compiler_common *c
2183  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2184  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2185  DEFINE_COMPILER;  DEFINE_COMPILER;
2186  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2187  struct sljit_jump *jump;  struct sljit_jump *jump;
2188  #endif  #endif
2189    
2190  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2191  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2192  if (common->utf8)  if (common->utf)
2193    {    {
2194    #if defined COMPILE_PCRE8
2195    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2196    add_jump(compiler, &common->utf8readchar, JUMP(SLJIT_FAST_CALL));  #elif defined COMPILE_PCRE16
2197      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2198    #endif /* COMPILE_PCRE[8|16] */
2199      add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2200    JUMPHERE(jump);    JUMPHERE(jump);
2201    }    }
2202  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2203  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));
2204  }  }
2205    
2206  static void peek_char(compiler_common *common)  static void peek_char(compiler_common *common)
# Line 1365  static void peek_char(compiler_common *c Line 2208  static void peek_char(compiler_common *c
2208  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2209  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2210  DEFINE_COMPILER;  DEFINE_COMPILER;
2211  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2212  struct sljit_jump *jump;  struct sljit_jump *jump;
2213  #endif  #endif
2214    
2215  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2216  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2217  if (common->utf8)  if (common->utf)
2218    {    {
2219    #if defined COMPILE_PCRE8
2220    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2221    add_jump(compiler, &common->utf8readchar, JUMP(SLJIT_FAST_CALL));  #elif defined COMPILE_PCRE16
2222      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2223    #endif /* COMPILE_PCRE[8|16] */
2224      add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2225    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2226    JUMPHERE(jump);    JUMPHERE(jump);
2227    }    }
2228  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2229  }  }
2230    
2231  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2232  {  {
2233  /* 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. */
2234  DEFINE_COMPILER;  DEFINE_COMPILER;
2235  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2236  struct sljit_jump *jump;  struct sljit_jump *jump;
2237  #endif  #endif
2238    
2239  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2240  if (common->utf8)  if (common->utf)
2241    {    {
2242    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2243    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));
2244    #if defined COMPILE_PCRE8
2245    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2246    it is a clever early read in most cases. */    it is needed in most cases. */
2247    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2248    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2249    add_jump(compiler, &common->utf8readtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2250      JUMPHERE(jump);
2251    #elif defined COMPILE_PCRE16
2252      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2253      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2254      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2255    JUMPHERE(jump);    JUMPHERE(jump);
2256      /* Skip low surrogate if necessary. */
2257      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2258      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2259      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2260      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2261      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2262    #elif defined COMPILE_PCRE32
2263      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2264      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2265      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2266      JUMPHERE(jump);
2267    #endif /* COMPILE_PCRE[8|16|32] */
2268    return;    return;
2269    }    }
2270    #endif /* SUPPORT_UTF */
2271    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2272    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2273    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2274    /* The ctypes array contains only 256 values. */
2275    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2276    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2277    #endif
2278    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2279    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2280    JUMPHERE(jump);
2281  #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);  
2282  }  }
2283    
2284  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
2285  {  {
2286  /* 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. */
2287  DEFINE_COMPILER;  DEFINE_COMPILER;
2288  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2289    #if defined COMPILE_PCRE8
2290  struct sljit_label *label;  struct sljit_label *label;
2291    
2292  if (common->utf8)  if (common->utf)
2293    {    {
2294    label = LABEL();    label = LABEL();
2295    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
2296    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));
2297    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);
2298    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2299    return;    return;
2300    }    }
2301  #endif  #elif defined COMPILE_PCRE16
2302  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  if (common->utf)
2303      {
2304      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
2305      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2306      /* Skip low surrogate if necessary. */
2307      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2308      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);
2309      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2310      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2311      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2312      return;
2313      }
2314    #endif /* COMPILE_PCRE[8|16] */
2315    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2316    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2317  }  }
2318    
2319  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)
2320  {  {
2321  /* 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. */
2322  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1436  DEFINE_COMPILER; Line 2324  DEFINE_COMPILER;
2324  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2325    {    {
2326    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2327    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));
2328    }    }
2329  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2330    {    {
2331    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);
2332    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2333    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);
2334    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);
2335    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));
2336    }    }
2337  else  else
2338    {    {
2339    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline <= 255);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2340    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));
2341    }    }
2342  }  }
2343    
2344  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2345  static void do_utf8readchar(compiler_common *common)  
2346    #if defined COMPILE_PCRE8
2347    static void do_utfreadchar(compiler_common *common)
2348  {  {
2349  /* Fast decoding an utf8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2350  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. */
2351  DEFINE_COMPILER;  DEFINE_COMPILER;
2352  struct sljit_jump *jump;  struct sljit_jump *jump;
2353    
2354  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2355  /* Searching for the first zero. */  /* Searching for the first zero. */
2356  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);
2357  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2358  /* 2 byte sequence */  /* Two byte sequence. */
2359  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2360  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));
2361  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);
2362  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2363  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2364  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2365  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
2366  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2367  JUMPHERE(jump);  JUMPHERE(jump);
2368    
2369  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);
2370  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2371  /* 3 byte sequence */  /* Three byte sequence. */
2372  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2373  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);
2374  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);
2375  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2376  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2377  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2378  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 2);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2379  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));
2380  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2381  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2382  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 2);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2383  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2384  JUMPHERE(jump);  JUMPHERE(jump);
2385    
2386  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x08);  /* Four byte sequence. */
2387  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);  
2388  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);
2389  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);
2390  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2391  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);
2392  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2393  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);  
2394  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2395  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2396  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2397  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 4);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));
2398  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));
2399  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2400  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2401  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 4);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
2402  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2403  }  }
2404    
2405  static void do_utf8readtype8(compiler_common *common)  static void do_utfreadtype8(compiler_common *common)
2406  {  {
2407  /* Fast decoding an utf8 character type. TMP2 contains the first byte  /* Fast decoding a UTF-8 character type. TMP2 contains the first byte
2408  of the character (>= 0xc0) and TMP1 is destroyed. Return value in TMP1. */  of the character (>= 0xc0). Return value in TMP1. */
2409  DEFINE_COMPILER;  DEFINE_COMPILER;
2410  struct sljit_jump *jump;  struct sljit_jump *jump;
2411  struct sljit_jump *compare;  struct sljit_jump *compare;
2412    
2413  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2414    
2415  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);
2416  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2417  /* 2 byte sequence */  /* Two byte sequence. */
2418  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2419  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));
2420  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2421  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2422  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
# Line 1566  sljit_emit_fast_return(compiler, RETURN_ Line 2431  sljit_emit_fast_return(compiler, RETURN_
2431  JUMPHERE(jump);  JUMPHERE(jump);
2432    
2433  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2434  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);
2435  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2436  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2437  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2438  }  }
2439    
2440  #endif  #elif defined COMPILE_PCRE16
2441    
2442    static void do_utfreadchar(compiler_common *common)
2443    {
2444    /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char
2445    of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */
2446    DEFINE_COMPILER;
2447    struct sljit_jump *jump;
2448    
2449    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2450    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);
2451    /* Do nothing, only return. */
2452    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2453    
2454    JUMPHERE(jump);
2455    /* Combine two 16 bit characters. */
2456    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2457    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2458    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2459    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);
2460    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff);
2461    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2462    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
2463    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2464    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2465    }
2466    
2467    #endif /* COMPILE_PCRE[8|16] */
2468    
2469    #endif /* SUPPORT_UTF */
2470    
2471  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2472    
# Line 1588  DEFINE_COMPILER; Line 2482  DEFINE_COMPILER;
2482    
2483  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);
2484    
2485  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2486  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2487  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));
2488  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2489  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2490  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2491  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)_pcre_ucd_stage2);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2492  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2493  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));
2494  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2495  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2496  }  }
# Line 1610  struct sljit_label *newlinelabel = NULL; Line 2504  struct sljit_label *newlinelabel = NULL;
2504  struct sljit_jump *start;  struct sljit_jump *start;
2505  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2506  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2507  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2508  struct sljit_jump *singlebyte;  struct sljit_jump *singlechar;
2509  #endif  #endif
2510  jump_list *newline = NULL;  jump_list *newline = NULL;
2511  BOOL newlinecheck = FALSE;  BOOL newlinecheck = FALSE;
2512  BOOL readbyte = FALSE;  BOOL readuchar = FALSE;
2513    
2514  if (!(hascrorlf || firstline) && (common->nltype == NLTYPE_ANY ||  if (!(hascrorlf || firstline) && (common->nltype == NLTYPE_ANY ||
2515      common->nltype == NLTYPE_ANYCRLF || common->newline > 255))      common->nltype == NLTYPE_ANYCRLF || common->newline > 255))
# Line 1624  if (!(hascrorlf || firstline) && (common Line 2518  if (!(hascrorlf || firstline) && (common
2518  if (firstline)  if (firstline)
2519    {    {
2520    /* Search for the end of the first line. */    /* Search for the end of the first line. */
2521    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2522    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
2523    
2524    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2525      {      {
2526      mainloop = LABEL();      mainloop = LABEL();
2527      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));
2528      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2529      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -1);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
2530      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2531      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);
2532      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);
2533      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0, SLJIT_IMM, 1);      JUMPHERE(end);
2534        OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2535      }      }
2536    else    else
2537      {      {
2538      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2539      mainloop = LABEL();      mainloop = LABEL();
2540      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
2541      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2542      read_char(common);      read_char(common);
2543      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
2544      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2545      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);      JUMPHERE(end);
2546        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2547      set_jumps(newline, LABEL());      set_jumps(newline, LABEL());
2548      }      }
2549    
2550    JUMPHERE(end);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
   OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
2551    }    }
2552    
2553  start = JUMP(SLJIT_JUMP);  start = JUMP(SLJIT_JUMP);
# Line 1660  start = JUMP(SLJIT_JUMP); Line 2555  start = JUMP(SLJIT_JUMP);
2555  if (newlinecheck)  if (newlinecheck)
2556    {    {
2557    newlinelabel = LABEL();    newlinelabel = LABEL();
2558    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));
2559    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2560    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2561    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);
2562    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2563    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2564      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2565    #endif
2566    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2567    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
2568    }    }
# Line 1672  if (newlinecheck) Line 2570  if (newlinecheck)
2570  mainloop = LABEL();  mainloop = LABEL();
2571    
2572  /* Increasing the STR_PTR here requires one less jump in the most common case. */  /* Increasing the STR_PTR here requires one less jump in the most common case. */
2573  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2574  if (common->utf8) readbyte = TRUE;  if (common->utf) readuchar = TRUE;
2575  #endif  #endif
2576  if (newlinecheck) readbyte = TRUE;  if (newlinecheck) readuchar = TRUE;
2577    
2578  if (readbyte)  if (readuchar)
2579    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2580    
2581  if (newlinecheck)  if (newlinecheck)
2582    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);
2583    
2584  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));
2585  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2586  if (common->utf8)  #if defined COMPILE_PCRE8
2587    if (common->utf)
2588    {    {
2589    singlebyte = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2590    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);
2591    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2592    JUMPHERE(singlebyte);    JUMPHERE(singlechar);
2593    }    }
2594  #endif  #elif defined COMPILE_PCRE16
2595    if (common->utf)
2596      {
2597      singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2598      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2599      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2600      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2601      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2602      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2603      JUMPHERE(singlechar);
2604      }
2605    #endif /* COMPILE_PCRE[8|16] */
2606    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2607  JUMPHERE(start);  JUMPHERE(start);
2608    
2609  if (newlinecheck)  if (newlinecheck)
# Line 1704  if (newlinecheck) Line 2615  if (newlinecheck)
2615  return mainloop;  return mainloop;
2616  }  }
2617    
2618  static SLJIT_INLINE void fast_forward_first_byte(compiler_common *common, pcre_uint16 firstbyte, BOOL firstline)  #define MAX_N_CHARS 3
2619    
2620    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2621  {  {
2622  DEFINE_COMPILER;  DEFINE_COMPILER;
2623  struct sljit_label *start;  struct sljit_label *start;
2624  struct sljit_jump *leave;  struct sljit_jump *quit;
2625    pcre_uint32 chars[MAX_N_CHARS * 2];
2626    pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2627    int location = 0;
2628    pcre_int32 len, c, bit, caseless;
2629    int must_stop;
2630    
2631    /* We do not support alternatives now. */
2632    if (*(common->start + GET(common->start, 1)) == OP_ALT)
2633      return FALSE;
2634    
2635    while (TRUE)
2636      {
2637      caseless = 0;
2638      must_stop = 1;
2639      switch(*cc)
2640        {
2641        case OP_CHAR:
2642        must_stop = 0;
2643        cc++;
2644        break;
2645    
2646        case OP_CHARI:
2647        caseless = 1;
2648        must_stop = 0;
2649        cc++;
2650        break;
2651    
2652        case OP_SOD:
2653        case OP_SOM:
2654        case OP_SET_SOM:
2655        case OP_NOT_WORD_BOUNDARY:
2656        case OP_WORD_BOUNDARY:
2657        case OP_EODN:
2658        case OP_EOD:
2659        case OP_CIRC:
2660        case OP_CIRCM:
2661        case OP_DOLL:
2662        case OP_DOLLM:
2663        /* Zero width assertions. */
2664        cc++;
2665        continue;
2666    
2667        case OP_PLUS:
2668        case OP_MINPLUS:
2669        case OP_POSPLUS:
2670        cc++;
2671        break;
2672    
2673        case OP_EXACT:
2674        cc += 1 + IMM2_SIZE;
2675        break;
2676    
2677        case OP_PLUSI:
2678        case OP_MINPLUSI:
2679        case OP_POSPLUSI:
2680        caseless = 1;
2681        cc++;
2682        break;
2683    
2684        case OP_EXACTI:
2685        caseless = 1;
2686        cc += 1 + IMM2_SIZE;
2687        break;
2688    
2689        default:
2690        must_stop = 2;
2691        break;
2692        }
2693    
2694      if (must_stop == 2)
2695          break;
2696    
2697      len = 1;
2698    #ifdef SUPPORT_UTF
2699      if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
2700    #endif
2701    
2702      if (caseless && char_has_othercase(common, cc))
2703        {
2704        caseless = char_get_othercase_bit(common, cc);
2705        if (caseless == 0)
2706          return FALSE;
2707    #ifdef COMPILE_PCRE8
2708        caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
2709    #else
2710        if ((caseless & 0x100) != 0)
2711          caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
2712        else
2713          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
2714    #endif
2715        }
2716      else
2717        caseless = 0;
2718    
2719      while (len > 0 && location < MAX_N_CHARS * 2)
2720        {
2721        c = *cc;
2722        bit = 0;
2723        if (len == (caseless & 0xff))
2724          {
2725          bit = caseless >> 8;
2726          c |= bit;
2727          }
2728    
2729        chars[location] = c;
2730        chars[location + 1] = bit;
2731    
2732        len--;
2733        location += 2;
2734        cc++;
2735        }
2736    
2737      if (location >= MAX_N_CHARS * 2 || must_stop != 0)
2738        break;
2739      }
2740    
2741    /* At least two characters are required. */
2742    if (location < 2 * 2)
2743        return FALSE;
2744    
2745    if (firstline)
2746      {
2747      SLJIT_ASSERT(common->first_line_end != 0);
2748      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2749      OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2750      }
2751    else
2752      OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2753    
2754    start = LABEL();
2755    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2756    
2757    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2758    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2759    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2760    if (chars[1] != 0)
2761      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
2762    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
2763    if (location > 2 * 2)
2764      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2765    if (chars[3] != 0)
2766      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
2767    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
2768    if (location > 2 * 2)
2769      {
2770      if (chars[5] != 0)
2771        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
2772      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);
2773      }
2774    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2775    
2776    JUMPHERE(quit);
2777    
2778    if (firstline)
2779      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2780    else
2781      OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2782    return TRUE;
2783    }
2784    
2785    #undef MAX_N_CHARS
2786    
2787    static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
2788    {
2789    DEFINE_COMPILER;
2790    struct sljit_label *start;
2791    struct sljit_jump *quit;
2792  struct sljit_jump *found;  struct sljit_jump *found;
2793  pcre_uint16 oc, bit;  pcre_uchar oc, bit;
2794    
2795  if (firstline)  if (firstline)
2796    {    {
2797    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2798    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2799      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
2800    }    }
2801    
2802  start = LABEL();  start = LABEL();
2803  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2804  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2805    
2806  if ((firstbyte & REQ_CASELESS) == 0)  oc = first_char;
2807    found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, firstbyte & 0xff);  if (caseless)
2808      {
2809      oc = TABLE_GET(first_char, common->fcc, first_char);
2810    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
2811      if (first_char > 127 && common->utf)
2812        oc = UCD_OTHERCASE(first_char);
2813    #endif
2814      }
2815    if (first_char == oc)
2816      found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, first_char);
2817  else  else
2818    {    {
2819    firstbyte &= 0xff;    bit = first_char ^ oc;
2820    oc = common->fcc[firstbyte];    if (is_powerof2(bit))
   bit = firstbyte ^ oc;  
   if (ispowerof2(bit))  
2821      {      {
2822      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
2823      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, firstbyte | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
2824      }      }
2825    else    else
2826      {      {
2827      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);
2828      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2829      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);
2830      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);
2831      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
2832      }      }
2833    }    }
2834    
2835  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  
2836  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
2837  JUMPHERE(found);  JUMPHERE(found);
2838  JUMPHERE(leave);  JUMPHERE(quit);
2839    
2840  if (firstline)  if (firstline)
2841    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2842  }  }
2843    
2844  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 1767  DEFINE_COMPILER; Line 2847  DEFINE_COMPILER;
2847  struct sljit_label *loop;  struct sljit_label *loop;
2848  struct sljit_jump *lastchar;  struct sljit_jump *lastchar;
2849  struct sljit_jump *firstchar;  struct sljit_jump *firstchar;
2850  struct sljit_jump *leave;  struct sljit_jump *quit;
2851  struct sljit_jump *foundcr = NULL;  struct sljit_jump *foundcr = NULL;
2852  struct sljit_jump *notfoundnl;  struct sljit_jump *notfoundnl;
2853  jump_list *newline = NULL;  jump_list *newline = NULL;
2854    
2855  if (firstline)  if (firstline)
2856    {    {
2857    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2858    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2859      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
2860    }    }
2861    
2862  if (common->nltype == NLTYPE_FIXED && common->newline > 255)  if (common->nltype == NLTYPE_FIXED && common->newline > 255)
# Line 1786  if (common->nltype == NLTYPE_FIXED && co Line 2867  if (common->nltype == NLTYPE_FIXED && co
2867    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));
2868    firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);    firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);
2869    
2870    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2);    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
2871    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);
2872    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
2873    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2874      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
2875    #endif
2876    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2877    
2878    loop = LABEL();    loop = LABEL();
2879    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));
2880    leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2881    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -2);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
2882    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), -1);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
2883    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);
2884    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);
2885    
2886    JUMPHERE(leave);    JUMPHERE(quit);
2887    JUMPHERE(firstchar);    JUMPHERE(firstchar);
2888    JUMPHERE(lastchar);    JUMPHERE(lastchar);
2889    
# Line 1823  set_jumps(newline, loop); Line 2907  set_jumps(newline, loop);
2907    
2908  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
2909    {    {
2910    leave = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
2911    JUMPHERE(foundcr);    JUMPHERE(foundcr);
2912    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2913    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2914    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);
2915    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2916    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2917      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2918    #endif
2919    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2920    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
2921    JUMPHERE(leave);    JUMPHERE(quit);
2922    }    }
2923  JUMPHERE(lastchar);  JUMPHERE(lastchar);
2924  JUMPHERE(firstchar);  JUMPHERE(firstchar);
2925    
2926  if (firstline)  if (firstline)
2927    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2928  }  }
2929    
2930    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
2931    
2932  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)
2933  {  {
2934  DEFINE_COMPILER;  DEFINE_COMPILER;
2935  struct sljit_label *start;  struct sljit_label *start;
2936  struct sljit_jump *leave;  struct sljit_jump *quit;
2937  struct sljit_jump *found;  struct sljit_jump *found = NULL;
2938    jump_list *matches = NULL;
2939    pcre_uint8 inverted_start_bits[32];
2940    int i;
2941    #ifndef COMPILE_PCRE8
2942    struct sljit_jump *jump;
2943    #endif
2944    
2945    for (i = 0; i < 32; ++i)
2946      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
2947    
2948  if (firstline)  if (firstline)
2949    {    {
2950    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2951    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
2952      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
2953    }    }
2954    
2955  start = LABEL();  start = LABEL();
2956  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2957  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2958  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2959  if (common->utf8)  if (common->utf)
2960    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
2961  #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);  
2962    
2963  #ifdef SUPPORT_UTF8  if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
2964  if (common->utf8)    {
2965    #ifndef COMPILE_PCRE8
2966      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
2967      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
2968      JUMPHERE(jump);
2969    #endif
2970      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
2971      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
2972      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
2973      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
2974      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
2975      found = JUMP(SLJIT_C_NOT_ZERO);
2976      }
2977    
2978    #ifdef SUPPORT_UTF
2979    if (common->utf)
2980    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
2981  #endif  #endif
2982  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));
2983  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2984  if (common->utf8)  #if defined COMPILE_PCRE8
2985    if (common->utf)
2986    {    {
2987    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
2988    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);
2989    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2990    }    }
2991  #endif  #elif defined COMPILE_PCRE16
2992    if (common->utf)
2993      {
2994      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
2995      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2996      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2997      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2998      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2999      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3000      }
3001    #endif /* COMPILE_PCRE[8|16] */
3002    #endif /* SUPPORT_UTF */
3003  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3004  JUMPHERE(found);  if (found != NULL)
3005  JUMPHERE(leave);    JUMPHERE(found);
3006    if (matches != NULL)
3007      set_jumps(matches, LABEL());
3008    JUMPHERE(quit);
3009    
3010  if (firstline)  if (firstline)
3011    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
3012  }  }
3013    
3014  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)
3015  {  {
3016  DEFINE_COMPILER;  DEFINE_COMPILER;
3017  struct sljit_label *loop;  struct sljit_label *loop;
# Line 1897  struct sljit_jump *alreadyfound; Line 3020  struct sljit_jump *alreadyfound;
3020  struct sljit_jump *found;  struct sljit_jump *found;
3021  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3022  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3023  pcre_uint16 oc, bit;  pcre_uint32 oc, bit;
3024    
3025  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_BYTE_PTR);  SLJIT_ASSERT(common->req_char_ptr != 0);
3026    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
3027  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);
3028  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);
3029  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);
3030    
3031  if (has_firstbyte)  if (has_firstchar)
3032    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3033  else  else
3034    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);
3035    
3036  loop = LABEL();  loop = LABEL();
3037  notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);  notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);
3038    
3039  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3040  if ((reqbyte & REQ_CASELESS) == 0)  oc = req_char;
3041    found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte & 0xff);  if (caseless)
3042      {
3043      oc = TABLE_GET(req_char, common->fcc, req_char);
3044    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
3045      if (req_char > 127 && common->utf)
3046        oc = UCD_OTHERCASE(req_char);
3047    #endif
3048      }
3049    if (req_char == oc)
3050      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
3051  else  else
3052    {    {
3053    reqbyte &= 0xff;    bit = req_char ^ oc;
3054    oc = common->fcc[reqbyte];    if (is_powerof2(bit))
   bit = reqbyte ^ oc;  
   if (ispowerof2(bit))  
3055      {      {
3056      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3057      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
3058      }      }
3059    else    else
3060      {      {
3061      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
3062      foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);      foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);
3063      }      }
3064    }    }
3065  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
3066  JUMPTO(SLJIT_JUMP, loop);  JUMPTO(SLJIT_JUMP, loop);
3067    
3068  JUMPHERE(found);  JUMPHERE(found);
3069  if (foundoc)  if (foundoc)
3070    JUMPHERE(foundoc);    JUMPHERE(foundoc);
3071  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);
3072  JUMPHERE(alreadyfound);  JUMPHERE(alreadyfound);
3073  JUMPHERE(toolong);  JUMPHERE(toolong);
3074  return notfound;  return notfound;
# Line 1949  DEFINE_COMPILER; Line 3080  DEFINE_COMPILER;
3080  struct sljit_jump *jump;  struct sljit_jump *jump;
3081  struct sljit_label *mainloop;  struct sljit_label *mainloop;
3082    
3083  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3084  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);
3085    GET_LOCAL_BASE(TMP3, 0, 0);
3086    
3087  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3088  mainloop = LABEL();  mainloop = LABEL();
3089  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3090  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);
3091  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_LOCALS_REG, 0);  jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3092  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
3093  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);
3094  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));
3095    OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
3096    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
3097  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3098    
3099  JUMPHERE(jump);  JUMPHERE(jump);
3100  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3101  /* End of dropping frames. */  /* End of dropping frames. */
3102  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3103    
3104  JUMPHERE(jump);  JUMPHERE(jump);
3105  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3106  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3107  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3108  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));  
3109  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3110  }  }
3111    
3112  static void check_wordboundary(compiler_common *common)  static void check_wordboundary(compiler_common *common)
3113  {  {
3114  DEFINE_COMPILER;  DEFINE_COMPILER;
3115  struct sljit_jump *beginend;  struct sljit_jump *skipread;
3116  #ifdef SUPPORT_UTF8  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3117  struct sljit_jump *jump;  struct sljit_jump *jump;
3118  #endif  #endif
3119    
3120  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
3121    
3122  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);
3123  /* Get type of the previous char, and put it to LOCALS1. */  /* Get type of the previous char, and put it to LOCALS1. */
3124  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
3125  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));
3126  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);
3127  beginend = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);  skipread = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3128  skip_char_back(common);  skip_char_back(common);
3129    check_start_used_ptr(common);
3130  read_char(common);  read_char(common);
3131    
3132  /* Testing char type. */  /* Testing char type. */
3133  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3134  if (common->useucp)  if (common->use_ucp)
3135    {    {
3136    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
3137    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
3138    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3139    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3140    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);
3141    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3142    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);
3143    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);
3144    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3145    JUMPHERE(jump);    JUMPHERE(jump);
3146    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3147    }    }
3148  else  else
3149  #endif  #endif
3150    {    {
3151  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3152      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3153    #elif defined SUPPORT_UTF
3154    /* Here LOCALS1 has already been zeroed. */    /* Here LOCALS1 has already been zeroed. */
3155    jump = NULL;    jump = NULL;
3156    if (common->utf8)    if (common->utf)
3157      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3158  #endif  #endif /* COMPILE_PCRE8 */
3159    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);
3160    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);
3161    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3162    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
3163  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3164      JUMPHERE(jump);
3165    #elif defined SUPPORT_UTF
3166    if (jump != NULL)    if (jump != NULL)
3167      JUMPHERE(jump);      JUMPHERE(jump);
3168  #endif  #endif /* COMPILE_PCRE8 */
3169    }    }
3170  JUMPHERE(beginend);  JUMPHERE(skipread);
3171    
3172  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3173  beginend = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  skipread = check_str_end(common);
3174  peek_char(common);  peek_char(common);
3175    
3176  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
3177  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3178  if (common->useucp)  if (common->use_ucp)
3179    {    {
3180    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
3181    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
3182    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3183    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3184    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);
3185    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3186    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);
3187    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);
3188    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3189    JUMPHERE(jump);    JUMPHERE(jump);
3190    }    }
3191  else  else
3192  #endif  #endif
3193    {    {
3194  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3195      /* TMP2 may be destroyed by peek_char. */
3196      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3197      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3198    #elif defined SUPPORT_UTF
3199    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3200    jump = NULL;    jump = NULL;
3201    if (common->utf8)    if (common->utf)
3202      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3203  #endif  #endif
3204    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);
3205    OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);    OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);
3206    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
3207  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3208      JUMPHERE(jump);
3209    #elif defined SUPPORT_UTF
3210    if (jump != NULL)    if (jump != NULL)
3211      JUMPHERE(jump);      JUMPHERE(jump);
3212  #endif  #endif /* COMPILE_PCRE8 */
3213      }
3214    JUMPHERE(skipread);
3215    
3216    OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3217    sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3218    }
3219    
3220    /*
3221      range format:
3222    
3223      ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).
3224      ranges[1] = first bit (0 or 1)
3225      ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)
3226    */
3227    
3228    static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3229    {
3230    DEFINE_COMPILER;
3231    struct sljit_jump *jump;
3232    
3233    if (ranges[0] < 0)
3234      return FALSE;
3235    
3236    switch(ranges[0])
3237      {
3238      case 1:
3239      if (readch)
3240        read_char(common);
3241      add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3242      return TRUE;
3243    
3244      case 2:
3245      if (readch)
3246        read_char(common);
3247      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3248      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3249      return TRUE;
3250    
3251      case 4:
3252      if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])
3253        {
3254        if (readch)
3255          read_char(common);
3256        if (ranges[1] != 0)
3257          {
3258          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3259          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3260          }
3261        else
3262          {
3263          jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);
3264          add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3265          JUMPHERE(jump);
3266          }
3267        return TRUE;
3268        }
3269      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))
3270        {
3271        if (readch)
3272          read_char(common);
3273        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3274        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3275        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3276        return TRUE;
3277        }
3278      return FALSE;
3279    
3280      default:
3281      return FALSE;
3282      }
3283    }
3284    
3285    static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)
3286    {
3287    int i, bit, length;
3288    const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;
3289    
3290    bit = ctypes[0] & flag;
3291    ranges[0] = -1;
3292    ranges[1] = bit != 0 ? 1 : 0;
3293    length = 0;
3294    
3295    for (i = 1; i < 256; i++)
3296      if ((ctypes[i] & flag) != bit)
3297        {
3298        if (length >= MAX_RANGE_SIZE)
3299          return;
3300        ranges[2 + length] = i;
3301        length++;
3302        bit ^= flag;
3303        }
3304    
3305    if (bit != 0)
3306      {
3307      if (length >= MAX_RANGE_SIZE)
3308        return;
3309      ranges[2 + length] = 256;
3310      length++;
3311      }
3312    ranges[0] = length;
3313    }
3314    
3315    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)
3316    {
3317    int ranges[2 + MAX_RANGE_SIZE];
3318    pcre_uint8 bit, cbit, all;
3319    int i, byte, length = 0;
3320    
3321    bit = bits[0] & 0x1;
3322    ranges[1] = bit;
3323    /* Can be 0 or 255. */
3324    all = -bit;
3325    
3326    for (i = 0; i < 256; )
3327      {
3328      byte = i >> 3;
3329      if ((i & 0x7) == 0 && bits[byte] == all)
3330        i += 8;
3331      else
3332        {
3333        cbit = (bits[byte] >> (i & 0x7)) & 0x1;
3334        if (cbit != bit)
3335          {
3336          if (length >= MAX_RANGE_SIZE)
3337            return FALSE;
3338          ranges[2 + length] = i;
3339          length++;
3340          bit = cbit;
3341          all = -cbit;
3342          }
3343        i++;
3344        }
3345    }    }
 JUMPHERE(beginend);  
3346    
3347  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  if (((bit == 0) && nclass) || ((bit == 1) && !nclass))
3348  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    {
3349      if (length >= MAX_RANGE_SIZE)
3350        return FALSE;
3351      ranges[2 + length] = 256;
3352      length++;
3353      }
3354    ranges[0] = length;
3355    
3356    return check_ranges(common, ranges, backtracks, FALSE);
3357  }  }
3358    
3359  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
# Line 2083  static void check_anynewline(compiler_co Line 3361  static void check_anynewline(compiler_co
3361  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3362  DEFINE_COMPILER;  DEFINE_COMPILER;
3363    
3364  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3365    
3366  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3367  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
3368  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3369  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
3370  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3371  if (common->utf8)  #ifdef COMPILE_PCRE8
3372    if (common->utf)
3373    {    {
3374    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  #endif
3375      OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3376    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3377    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
3378    #ifdef COMPILE_PCRE8
3379    }    }
3380  #endif  #endif
3381  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3382    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3383  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3384  }  }
3385    
# Line 2106  static void check_hspace(compiler_common Line 3388  static void check_hspace(compiler_common
3388  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3389  DEFINE_COMPILER;  DEFINE_COMPILER;
3390    
3391  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3392    
3393  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);
3394  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3395  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
3396  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3397  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);
3398  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3399  if (common->utf8)  #ifdef COMPILE_PCRE8
3400    if (common->utf)
3401    {    {
3402    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  #endif
3403      OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3404    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);
3405    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3406    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);
3407    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3408    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3409    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);
3410    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3411    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);
3412    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3413    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);
3414    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3415    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);
3416    #ifdef COMPILE_PCRE8
3417    }    }
3418  #endif  #endif
3419  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3420    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3421    
3422  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3423  }  }
# Line 2141  static void check_vspace(compiler_common Line 3427  static void check_vspace(compiler_common
3427  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3428  DEFINE_COMPILER;  DEFINE_COMPILER;
3429    
3430  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3431    
3432  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3433  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
3434  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3435  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
3436  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3437  if (common->utf8)  #ifdef COMPILE_PCRE8
3438    if (common->utf)
3439    {    {
3440    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  #endif
3441      OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3442    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3443    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
3444    #ifdef COMPILE_PCRE8
3445    }    }
3446  #endif  #endif
3447  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3448    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3449    
3450  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3451  }  }
# Line 2169  DEFINE_COMPILER; Line 3459  DEFINE_COMPILER;
3459  struct sljit_jump *jump;  struct sljit_jump *jump;
3460  struct sljit_label *label;  struct sljit_label *label;
3461    
3462  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3463  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3464  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);
3465  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);
3466  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
3467  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3468    
3469  label = LABEL();  label = LABEL();
3470  OP1(SLJIT_MOVU_UB, CHAR1, 0, SLJIT_MEM1(TMP1), 1);  OP1(MOVU_UCHAR, CHAR1, 0, SLJIT_MEM1(TMP1), IN_UCHARS(1));
3471  OP1(SLJIT_MOVU_UB, CHAR2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOVU_UCHAR, CHAR2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3472  jump = CMP(SLJIT_C_NOT_EQUAL, CHAR1, 0, CHAR2, 0);  jump = CMP(SLJIT_C_NOT_EQUAL, CHAR1, 0, CHAR2, 0);
3473  OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
3474  JUMPTO(SLJIT_C_NOT_ZERO, label);  JUMPTO(SLJIT_C_NOT_ZERO, label);
3475    
3476  JUMPHERE(jump);  JUMPHERE(jump);
3477  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));
3478  OP1(SLJIT_MOV, CHAR1, 0, TMP3, 0);  OP1(SLJIT_MOV, CHAR1, 0, TMP3, 0);
3479  OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3480  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
# Line 2198  DEFINE_COMPILER; Line 3488  DEFINE_COMPILER;
3488  struct sljit_jump *jump;  struct sljit_jump *jump;
3489  struct sljit_label *label;  struct sljit_label *label;
3490    
3491  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3492  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3493    
3494  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);
3495  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR1, 0);
3496  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, CHAR2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, CHAR2, 0);
3497  OP1(SLJIT_MOV, LCC_TABLE, 0, SLJIT_IMM, common->lcc);  OP1(SLJIT_MOV, LCC_TABLE, 0, SLJIT_IMM, common->lcc);
3498  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
3499  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3500    
3501  label = LABEL();  label = LABEL();
3502  OP1(SLJIT_MOVU_UB, CHAR1, 0, SLJIT_MEM1(TMP1), 1);  OP1(MOVU_UCHAR, CHAR1, 0, SLJIT_MEM1(TMP1), IN_UCHARS(1));
3503  OP1(SLJIT_MOVU_UB, CHAR2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOVU_UCHAR, CHAR2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3504    #ifndef COMPILE_PCRE8
3505    jump = CMP(SLJIT_C_GREATER, CHAR1, 0, SLJIT_IMM, 255);
3506    #endif
3507  OP1(SLJIT_MOV_UB, CHAR1, 0, SLJIT_MEM2(LCC_TABLE, CHAR1), 0);  OP1(SLJIT_MOV_UB, CHAR1, 0, SLJIT_MEM2(LCC_TABLE, CHAR1), 0);
3508    #ifndef COMPILE_PCRE8
3509    JUMPHERE(jump);
3510    jump = CMP(SLJIT_C_GREATER, CHAR2, 0, SLJIT_IMM, 255);
3511    #endif
3512  OP1(SLJIT_MOV_UB, CHAR2, 0, SLJIT_MEM2(LCC_TABLE, CHAR2), 0);  OP1(SLJIT_MOV_UB, CHAR2, 0, SLJIT_MEM2(LCC_TABLE, CHAR2), 0);
3513    #ifndef COMPILE_PCRE8
3514    JUMPHERE(jump);
3515    #endif
3516  jump = CMP(SLJIT_C_NOT_EQUAL, CHAR1, 0, CHAR2, 0);  jump = CMP(SLJIT_C_NOT_EQUAL, CHAR1, 0, CHAR2, 0);
3517  OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
3518  JUMPTO(SLJIT_C_NOT_ZERO, label);  JUMPTO(SLJIT_C_NOT_ZERO, label);
3519    
3520  JUMPHERE(jump);  JUMPHERE(jump);
3521  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));
3522  OP1(SLJIT_MOV, LCC_TABLE, 0, TMP3, 0);  OP1(SLJIT_MOV, LCC_TABLE, 0, TMP3, 0);
3523  OP1(SLJIT_MOV, CHAR1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  OP1(SLJIT_MOV, CHAR1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3524  OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
# Line 2229  sljit_emit_fast_return(compiler, RETURN_ Line 3529  sljit_emit_fast_return(compiler, RETURN_
3529  #undef CHAR1  #undef CHAR1
3530  #undef CHAR2  #undef CHAR2
3531    
3532  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && defined SUPPORT_UCP
 #ifdef SUPPORT_UCP  
3533    
3534  static uschar * SLJIT_CALL do_utf8caselesscmp(uschar *src1, jit_arguments *args, uschar *end1)  static const pcre_uchar * SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)
3535  {  {
3536  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3537  int c1, c2;  pcre_uint32 c1, c2;
3538  uschar *src2 = args->ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3539  uschar *end2 = (uschar*)args->end;  const pcre_uchar *end2 = args->end;
3540    const ucd_record *ur;
3541    const pcre_uint32 *pp;
3542    
3543  while (src1 < end1)  while (src1 < end1)
3544    {    {
3545    if (src2 >= end2)    if (src2 >= end2)
3546      return 0;      return (pcre_uchar*)1;
3547    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3548    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3549    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return 0;    ur = GET_UCD(c2);
3550      if (c1 != c2 && c1 != c2 + ur->other_case)
3551        {
3552        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3553        for (;;)
3554          {
3555          if (c1 < *pp) return NULL;
3556          if (c1 == *pp++) break;
3557          }
3558        }
3559    }    }
3560  return src2;  return src2;
3561  }  }
3562    
3563  #endif  #endif /* SUPPORT_UTF && SUPPORT_UCP */
 #endif  
3564    
3565  static uschar *byte_sequence_compare(compiler_common *common, BOOL caseless, uschar *cc,  static pcre_uchar *byte_sequence_compare(compiler_common *common, BOOL caseless, pcre_uchar *cc,
3566      compare_context* context, jump_list **fallbacks)      compare_context* context, jump_list **backtracks)
3567  {  {
3568  DEFINE_COMPILER;  DEFINE_COMPILER;
3569  unsigned int othercasebit = 0;  unsigned int othercasebit = 0;
3570  uschar *othercasebyte = NULL;  pcre_uchar *othercasechar = NULL;
3571  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3572  int utf8length;  int utflength;
3573  #endif  #endif
3574    
3575  if (caseless && char_has_othercase(common, cc))  if (caseless && char_has_othercase(common, cc))
# Line 2268  if (caseless && char_has_othercase(commo Line 3577  if (caseless && char_has_othercase(commo
3577    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3578    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3579    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3580    othercasebyte = cc + (othercasebit >> 8);  #if defined COMPILE_PCRE8
3581      othercasechar = cc + (othercasebit >> 8);
3582    othercasebit &= 0xff;    othercasebit &= 0xff;
3583    #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3584      /* Note that this code only handles characters in the BMP. If there
3585      ever are characters outside the BMP whose othercase differs in only one
3586      bit from itself (there currently are none), this code will need to be
3587      revised for COMPILE_PCRE32. */
3588      othercasechar = cc + (othercasebit >> 9);
3589      if ((othercasebit & 0x100) != 0)
3590        othercasebit = (othercasebit & 0xff) << 8;
3591      else
3592        othercasebit &= 0xff;
3593    #endif /* COMPILE_PCRE[8|16|32] */
3594    }    }
3595    
3596  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3597    {    {
3598    #if defined COMPILE_PCRE8
3599  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3600    if (context->length >= 4)    if (context->length >= 4)
3601      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3602    else if (context->length >= 2)    else if (context->length >= 2)
3603      OP1(SLJIT_MOV_SH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3604    else    else
3605  #endif  #endif
3606      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3607    #elif defined COMPILE_PCRE16
3608    #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3609      if (context->length >= 4)
3610        OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3611      else
3612    #endif
3613        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3614    #elif defined COMPILE_PCRE32
3615      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3616    #endif /* COMPILE_PCRE[8|16|32] */
3617    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3618    }    }
3619    
3620  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3621  utf8length = 1;  utflength = 1;
3622  if (common->utf8 && *cc >= 0xc0)  if (common->utf && HAS_EXTRALEN(*cc))
3623    utf8length += _pcre_utf8_table4[*cc & 0x3f];    utflength += GET_EXTRALEN(*cc);
3624    
3625  do  do
3626    {    {
3627  #endif  #endif
3628    
3629    context->length--;    context->length -= IN_UCHARS(1);
3630  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3631    
3632    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3633    if (othercasebit != 0 && othercasebyte == cc)    if (othercasebit != 0 && othercasechar == cc)
3634      {      {
3635      context->c.asbytes[context->byteptr] = *cc | othercasebit;      context->c.asuchars[context->ucharptr] = *cc | othercasebit;
3636      context->oc.asbytes[context->byteptr] = othercasebit;      context->oc.asuchars[context->ucharptr] = othercasebit;
3637      }      }
3638    else    else
3639      {      {
3640      context->c.asbytes[context->byteptr] = *cc;      context->c.asuchars[context->ucharptr] = *cc;
3641      context->oc.asbytes[context->byteptr] = 0;      context->oc.asuchars[context->ucharptr] = 0;
3642      }      }
3643    context->byteptr++;    context->ucharptr++;
3644    
3645    if (context->byteptr >= 4 || context->length == 0 || (context->byteptr == 2 && context->length == 1))  #if defined COMPILE_PCRE8
3646      if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))
3647    #else
3648      if (context->ucharptr >= 2 || context->length == 0)
3649    #endif
3650      {      {
3651      if (context->length >= 4)      if (context->length >= 4)
3652        OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3653      else if (context->length >= 2)      else if (context->length >= 2)
3654        OP1(SLJIT_MOV_SH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3655    #if defined COMPILE_PCRE8
3656      else if (context->length >= 1)      else if (context->length >= 1)
3657        OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3658    #endif /* COMPILE_PCRE8 */
3659      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3660    
3661      switch(context->byteptr)      switch(context->ucharptr)
3662        {        {
3663        case 4:        case 4 / sizeof(pcre_uchar):
3664        if (context->oc.asint != 0)        if (context->oc.asint != 0)
3665          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asint);          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asint);
3666        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asint | context->oc.asint));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asint | context->oc.asint));
3667        break;        break;
3668    
3669        case 2:        case 2 / sizeof(pcre_uchar):
3670        if (context->oc.asshort != 0)        if (context->oc.asushort != 0)
3671          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asshort);          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);
3672        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asshort | context->oc.asshort));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asushort | context->oc.asushort));
3673        break;        break;
3674    
3675    #ifdef COMPILE_PCRE8
3676        case 1:        case 1:
3677        if (context->oc.asbyte != 0)        if (context->oc.asbyte != 0)
3678          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asbyte);          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asbyte);
3679        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asbyte | context->oc.asbyte));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asbyte | context->oc.asbyte));
3680        break;        break;
3681    #endif
3682    
3683        default:        default:
3684        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
3685        break;        break;
3686        }        }