/[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 726 by zherczeg, Sun Oct 9 18:53:25 2011 UTC revision 1245 by zherczeg, Sat Feb 9 11:30:51 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-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) (PUBL(malloc))(size)
56    #define SLJIT_FREE(ptr) (PUBL(free))(ptr)
57  #define SLJIT_CONFIG_AUTO 1  #define SLJIT_CONFIG_AUTO 1
58    #define SLJIT_CONFIG_STATIC 1
59  #define SLJIT_VERBOSE 0  #define SLJIT_VERBOSE 0
60  #define SLJIT_DEBUG 0  #define SLJIT_DEBUG 0
61    
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 79  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 105  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  } executable_function;    pcre_uint32 top_bracket;
175      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 176  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 259  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    struct sljit_label *acceptlabel;    /* Tables. */
318      sljit_sw ctypes;
319      int digits[2 + MAX_RANGE_SIZE];
320      /* Named capturing brackets. */
321      sljit_uw name_table;
322      sljit_sw name_count;
323      sljit_sw name_entry_size;
324    
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 291  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  #endif
352    jump_list *utf8readchar;  #ifndef COMPILE_PCRE32
353    jump_list *utf8readtype8;    jump_list *utfreadchar;
354  #endif  #endif
355    #ifdef COMPILE_PCRE8
356      jump_list *utfreadtype8;
357    #endif
358    #endif /* SUPPORT_UTF */
359  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
360    jump_list *getucd;    jump_list *getucd;
361  #endif  #endif
# Line 310  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 {  enum {
399    frame_end = 0,    frame_end = 0,
400    frame_setstrbegin = -1    frame_setstrbegin = -1,
401      frame_setmark = -2
402  };  };
403    
404    /* Undefine sljit macros. */
405    #undef CMP
406    
407  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
408  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
409    
410  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
411  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
412  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
413  #define STR_PTR       SLJIT_GENERAL_REG1  #define STR_PTR       SLJIT_SAVED_REG1
414  #define STR_END       SLJIT_GENERAL_REG2  #define STR_END       SLJIT_SAVED_REG2
415  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
416  #define STACK_LIMIT   SLJIT_GENERAL_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
417  #define ARGUMENTS     SLJIT_GENERAL_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
418  #define CALL_COUNT    SLJIT_GENERAL_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
419  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
420    
421  /* Locals layout. */  /* Local space layout. */
422  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
423  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
424  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
425  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
426  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
427  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
 /* Head of the last recursion. */  
 #define RECURSIVE_HEAD   (4 * sizeof(sljit_w))  
428  /* Max limit of recursions. */  /* Max limit of recursions. */
429  #define CALL_LIMIT       (5 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
 /* Last known position of the requested byte. */  
 #define REQ_BYTE_PTR     (6 * sizeof(sljit_w))  
 /* End pointer of the first line. */  
 #define FIRSTLINE_END    (7 * sizeof(sljit_w))  
430  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
431  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
432  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
433  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
434  #define OVECTOR_START    (8 * sizeof(sljit_w))  #define OVECTOR_START    (common->ovector_start)
435  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
436  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_sw))
437  #define PRIV(cc)         (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
438    
439    #if defined COMPILE_PCRE8
440    #define MOV_UCHAR  SLJIT_MOV_UB
441    #define MOVU_UCHAR SLJIT_MOVU_UB
442    #elif defined COMPILE_PCRE16
443    #define MOV_UCHAR  SLJIT_MOV_UH
444    #define MOVU_UCHAR SLJIT_MOVU_UH
445    #elif defined COMPILE_PCRE32
446    #define MOV_UCHAR  SLJIT_MOV_UI
447    #define MOVU_UCHAR SLJIT_MOVU_UI
448    #else
449    #error Unsupported compiling mode
450    #endif
451    
452  /* Shortcuts. */  /* Shortcuts. */
453  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 388  the start pointers when the end of the c Line 468  the start pointers when the end of the c
468    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
469  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
470    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))
471  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
472    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
473    #define GET_LOCAL_BASE(dst, dstw, offset) \
474      sljit_get_local_base(compiler, (dst), (dstw), (offset))
475    
476  static uschar* bracketend(uschar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
477  {  {
478  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));
479  do cc += GET(cc, 1); while (*cc == OP_ALT);  do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 402  return cc; Line 484  return cc;
484    
485  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
486   next_opcode   next_opcode
487   get_localspace   get_private_data_length
488   set_localptrs   set_private_data_ptrs
489   get_framesize   get_framesize
490   init_frame   init_frame
491   get_localsize   get_private_data_length_for_copy
492   copy_locals   copy_private_data
493   compile_hotpath   compile_matchingpath
494   compile_fallbackpath   compile_backtrackingpath
495  */  */
496    
497  static uschar *next_opcode(compiler_common *common, uschar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
498  {  {
499  SLJIT_UNUSED_ARG(common);  SLJIT_UNUSED_ARG(common);
500  switch(*cc)  switch(*cc)
# Line 461  switch(*cc) Line 543  switch(*cc)
543    case OP_BRAZERO:    case OP_BRAZERO:
544    case OP_BRAMINZERO:    case OP_BRAMINZERO:
545    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
546      case OP_COMMIT:
547    case OP_FAIL:    case OP_FAIL:
548    case OP_ACCEPT:    case OP_ACCEPT:
549    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
550    case OP_SKIPZERO:    case OP_SKIPZERO:
551    return cc + 1;    return cc + 1;
552    
553      case OP_ANYBYTE:
554    #ifdef SUPPORT_UTF
555      if (common->utf) return NULL;
556    #endif
557      return cc + 1;
558    
559    case OP_CHAR:    case OP_CHAR:
560    case OP_CHARI:    case OP_CHARI:
561    case OP_NOT:    case OP_NOT:
562    case OP_NOTI:    case OP_NOTI:
   
563    case OP_STAR:    case OP_STAR:
564    case OP_MINSTAR:    case OP_MINSTAR:
565    case OP_PLUS:    case OP_PLUS:
# Line 509  switch(*cc) Line 597  switch(*cc)
597    case OP_NOTPOSPLUSI:    case OP_NOTPOSPLUSI:
598    case OP_NOTPOSQUERYI:    case OP_NOTPOSQUERYI:
599    cc += 2;    cc += 2;
600  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
601    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]);
602  #endif  #endif
603    return cc;    return cc;
604    
# Line 530  switch(*cc) Line 618  switch(*cc)
618    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
619    case OP_NOTEXACTI:    case OP_NOTEXACTI:
620    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
621    cc += 4;    cc += 2 + IMM2_SIZE;
622  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
623    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]);
624  #endif  #endif
625    return cc;    return cc;
626    
627    case OP_NOTPROP:    case OP_NOTPROP:
628    case OP_PROP:    case OP_PROP:
629      return cc + 1 + 2;
630    
631    case OP_TYPEUPTO:    case OP_TYPEUPTO:
632    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
633    case OP_TYPEEXACT:    case OP_TYPEEXACT:
# Line 545  switch(*cc) Line 635  switch(*cc)
635    case OP_REF:    case OP_REF:
636    case OP_REFI:    case OP_REFI:
637    case OP_CREF:    case OP_CREF:
638      case OP_NCREF:
639      case OP_RREF:
640      case OP_NRREF:
641    case OP_CLOSE:    case OP_CLOSE:
642    cc += 3;    cc += 1 + IMM2_SIZE;
643    return cc;    return cc;
644    
645    case OP_CRRANGE:    case OP_CRRANGE:
646    case OP_CRMINRANGE:    case OP_CRMINRANGE:
647    return cc + 5;    return cc + 1 + 2 * IMM2_SIZE;
648    
649    case OP_CLASS:    case OP_CLASS:
650    case OP_NCLASS:    case OP_NCLASS:
651    return cc + 33;    return cc + 1 + 32 / sizeof(pcre_uchar);
652    
653  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
654    case OP_XCLASS:    case OP_XCLASS:
655    return cc + GET(cc, 1);    return cc + GET(cc, 1);
656  #endif  #endif
# Line 587  switch(*cc) Line 680  switch(*cc)
680    case OP_CBRAPOS:    case OP_CBRAPOS:
681    case OP_SCBRA:    case OP_SCBRA:
682    case OP_SCBRAPOS:    case OP_SCBRAPOS:
683    return cc + 1 + LINK_SIZE + 2;    return cc + 1 + LINK_SIZE + IMM2_SIZE;
684    
685      case OP_MARK:
686      return cc + 1 + 2 + cc[1];
687    
688      case OP_CALLOUT:
689      return cc + 2 + 2 * LINK_SIZE;
690    
691    default:    default:
692    return NULL;    return NULL;
693    }    }
694  }  }
695    
696  static int get_localspace(compiler_common *common, uschar *cc, uschar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
697        case OP_MINSTAR: \
698        case OP_MINPLUS: \
699        case OP_QUERY: \
700        case OP_MINQUERY: \
701        case OP_MINSTARI: \
702        case OP_MINPLUSI: \
703        case OP_QUERYI: \
704        case OP_MINQUERYI: \
705        case OP_NOTMINSTAR: \
706        case OP_NOTMINPLUS: \
707        case OP_NOTQUERY: \
708        case OP_NOTMINQUERY: \
709        case OP_NOTMINSTARI: \
710        case OP_NOTMINPLUSI: \
711        case OP_NOTQUERYI: \
712        case OP_NOTMINQUERYI:
713    
714    #define CASE_ITERATOR_PRIVATE_DATA_2A \
715        case OP_STAR: \
716        case OP_PLUS: \
717        case OP_STARI: \
718        case OP_PLUSI: \
719        case OP_NOTSTAR: \
720        case OP_NOTPLUS: \
721        case OP_NOTSTARI: \
722        case OP_NOTPLUSI:
723    
724    #define CASE_ITERATOR_PRIVATE_DATA_2B \
725        case OP_UPTO: \
726        case OP_MINUPTO: \
727        case OP_UPTOI: \
728        case OP_MINUPTOI: \
729        case OP_NOTUPTO: \
730        case OP_NOTMINUPTO: \
731        case OP_NOTUPTOI: \
732        case OP_NOTMINUPTOI:
733    
734    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
735        case OP_TYPEMINSTAR: \
736        case OP_TYPEMINPLUS: \
737        case OP_TYPEQUERY: \
738        case OP_TYPEMINQUERY:
739    
740    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
741        case OP_TYPESTAR: \
742        case OP_TYPEPLUS:
743    
744    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
745        case OP_TYPEUPTO: \
746        case OP_TYPEMINUPTO:
747    
748    static int get_class_iterator_size(pcre_uchar *cc)
749    {
750    switch(*cc)
751      {
752      case OP_CRSTAR:
753      case OP_CRPLUS:
754      return 2;
755    
756      case OP_CRMINSTAR:
757      case OP_CRMINPLUS:
758      case OP_CRQUERY:
759      case OP_CRMINQUERY:
760      return 1;
761    
762      case OP_CRRANGE:
763      case OP_CRMINRANGE:
764      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
765        return 0;
766      return 2;
767    
768      default:
769      return 0;
770      }
771    }
772    
773    static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
774  {  {
775  int localspace = 0;  int private_data_length = 0;
776  uschar *alternative;  pcre_uchar *alternative;
777    pcre_uchar *name;
778    pcre_uchar *end = NULL;
779    int space, size, i;
780    pcre_uint32 bracketlen;
781    
782  /* 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. */
783  while (cc < ccend)  while (cc < ccend)
784    {    {
785      space = 0;
786      size = 0;
787      bracketlen = 0;
788    switch(*cc)    switch(*cc)
789      {      {
790        case OP_SET_SOM:
791        common->has_set_som = TRUE;
792        cc += 1;
793        break;
794    
795        case OP_REF:
796        case OP_REFI:
797        common->optimized_cbracket[GET2(cc, 1)] = 0;
798        cc += 1 + IMM2_SIZE;
799        break;
800    
801      case OP_ASSERT:      case OP_ASSERT:
802      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
803      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 612  while (cc < ccend) Line 807  while (cc < ccend)
807      case OP_BRAPOS:      case OP_BRAPOS:
808      case OP_SBRA:      case OP_SBRA:
809      case OP_SBRAPOS:      case OP_SBRAPOS:
810      case OP_SCOND:      private_data_length += sizeof(sljit_sw);
811      localspace += sizeof(sljit_w);      bracketlen = 1 + LINK_SIZE;
     cc += 1 + LINK_SIZE;  
812      break;      break;
813    
814      case OP_CBRAPOS:      case OP_CBRAPOS:
815      case OP_SCBRAPOS:      case OP_SCBRAPOS:
816      localspace += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
817      cc += 1 + LINK_SIZE + 2;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
818        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
819      break;      break;
820    
821      case OP_COND:      case OP_COND:
822      /* Might be a hidden SCOND. */      case OP_SCOND:
823      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
824      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
825        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
826          return -1;
827    
828        if (*cc == OP_COND)
829          {
830          /* Might be a hidden SCOND. */
831          alternative = cc + GET(cc, 1);
832          if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
833            private_data_length += sizeof(sljit_sw);
834          }
835        else
836          private_data_length += sizeof(sljit_sw);
837        bracketlen = 1 + LINK_SIZE;
838        break;
839    
840        case OP_CREF:
841        i = GET2(cc, 1);
842        common->optimized_cbracket[i] = 0;
843        cc += 1 + IMM2_SIZE;
844        break;
845    
846        case OP_NCREF:
847        bracketlen = GET2(cc, 1);
848        name = (pcre_uchar *)common->name_table;
849        alternative = name;
850        for (i = 0; i < common->name_count; i++)
851          {
852          if (GET2(name, 0) == bracketlen) break;
853          name += common->name_entry_size;
854          }
855        SLJIT_ASSERT(i != common->name_count);
856    
857        for (i = 0; i < common->name_count; i++)
858          {
859          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
860            common->optimized_cbracket[GET2(alternative, 0)] = 0;
861          alternative += common->name_entry_size;
862          }
863        bracketlen = 0;
864        cc += 1 + IMM2_SIZE;
865        break;
866    
867        case OP_BRA:
868        bracketlen = 1 + LINK_SIZE;
869        break;
870    
871        case OP_CBRA:
872        case OP_SCBRA:
873        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
874        break;
875    
876        CASE_ITERATOR_PRIVATE_DATA_1
877        space = 1;
878        size = -2;
879        break;
880    
881        CASE_ITERATOR_PRIVATE_DATA_2A
882        space = 2;
883        size = -2;
884        break;
885    
886        CASE_ITERATOR_PRIVATE_DATA_2B
887        space = 2;
888        size = -(2 + IMM2_SIZE);
889        break;
890    
891        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
892        space = 1;
893        size = 1;
894        break;
895    
896        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
897        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
898          space = 2;
899        size = 1;
900        break;
901    
902        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
903        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
904          space = 2;
905        size = 1 + IMM2_SIZE;
906        break;
907    
908        case OP_CLASS:
909        case OP_NCLASS:
910        size += 1 + 32 / sizeof(pcre_uchar);
911        space = get_class_iterator_size(cc + size);
912        break;
913    
914    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
915        case OP_XCLASS:
916        size = GET(cc, 1);
917        space = get_class_iterator_size(cc + size);
918        break;
919    #endif
920    
921        case OP_RECURSE:
922        /* Set its value only once. */
923        if (common->recursive_head_ptr == 0)
924          {
925          common->recursive_head_ptr = common->ovector_start;
926          common->ovector_start += sizeof(sljit_sw);
927          }
928      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
929      break;      break;
930    
931        case OP_CALLOUT:
932        if (common->capture_last_ptr == 0)
933          {
934          common->capture_last_ptr = common->ovector_start;
935          common->ovector_start += sizeof(sljit_sw);
936          }
937        cc += 2 + 2 * LINK_SIZE;
938        break;
939    
940        case OP_MARK:
941        if (common->mark_ptr == 0)
942          {
943          common->mark_ptr = common->ovector_start;
944          common->ovector_start += sizeof(sljit_sw);
945          }
946        cc += 1 + 2 + cc[1];
947        break;
948    
949      default:      default:
950      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
951      if (cc == NULL)      if (cc == NULL)
952        return -1;        return -1;
953      break;      break;
954      }      }
955    
956      if (space > 0 && cc >= end)
957        private_data_length += sizeof(sljit_sw) * space;
958    
959      if (size != 0)
960        {
961        if (size < 0)
962          {
963          cc += -size;
964    #ifdef SUPPORT_UTF
965          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
966    #endif
967          }
968        else
969          cc += size;
970        }
971    
972      if (bracketlen != 0)
973        {
974        if (cc >= end)
975          {
976          end = bracketend(cc);
977          if (end[-1 - LINK_SIZE] == OP_KET)
978            end = NULL;
979          }
980        cc += bracketlen;
981        }
982    }    }
983  return localspace;  return private_data_length;
984  }  }
985    
986  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)
987  {  {
988  uschar *cc = common->start;  pcre_uchar *cc = common->start;
989  uschar *alternative;  pcre_uchar *alternative;
990    pcre_uchar *end = NULL;
991    int space, size, bracketlen;
992    
993  while (cc < ccend)  while (cc < ccend)
994    {    {
995      space = 0;
996      size = 0;
997      bracketlen = 0;
998    switch(*cc)    switch(*cc)
999      {      {
1000      case OP_ASSERT:      case OP_ASSERT:
# Line 659  while (cc < ccend) Line 1007  while (cc < ccend)
1007      case OP_SBRA:      case OP_SBRA:
1008      case OP_SBRAPOS:      case OP_SBRAPOS:
1009      case OP_SCOND:      case OP_SCOND:
1010      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1011      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1012      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1013      break;      break;
1014    
1015      case OP_CBRAPOS:      case OP_CBRAPOS:
1016      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1017      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1018      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1019      cc += 1 + LINK_SIZE + 2;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1020      break;      break;
1021    
1022      case OP_COND:      case OP_COND:
# Line 676  while (cc < ccend) Line 1024  while (cc < ccend)
1024      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1025      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1026        {        {
1027        common->localptrs[cc - common->start] = localptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1028        localptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1029        }        }
1030      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1031        break;
1032    
1033        case OP_BRA:
1034        bracketlen = 1 + LINK_SIZE;
1035        break;
1036    
1037        case OP_CBRA:
1038        case OP_SCBRA:
1039        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1040        break;
1041    
1042        CASE_ITERATOR_PRIVATE_DATA_1
1043        space = 1;
1044        size = -2;
1045        break;
1046    
1047        CASE_ITERATOR_PRIVATE_DATA_2A
1048        space = 2;
1049        size = -2;
1050        break;
1051    
1052        CASE_ITERATOR_PRIVATE_DATA_2B
1053        space = 2;
1054        size = -(2 + IMM2_SIZE);
1055        break;
1056    
1057        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1058        space = 1;
1059        size = 1;
1060        break;
1061    
1062        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1063        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1064          space = 2;
1065        size = 1;
1066        break;
1067    
1068        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1069        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1070          space = 2;
1071        size = 1 + IMM2_SIZE;
1072        break;
1073    
1074        case OP_CLASS:
1075        case OP_NCLASS:
1076        size += 1 + 32 / sizeof(pcre_uchar);
1077        space = get_class_iterator_size(cc + size);
1078        break;
1079    
1080    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1081        case OP_XCLASS:
1082        size = GET(cc, 1);
1083        space = get_class_iterator_size(cc + size);
1084      break;      break;
1085    #endif
1086    
1087      default:      default:
1088      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1089      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1090      break;      break;
1091      }      }
1092    
1093      if (space > 0 && cc >= end)
1094        {
1095        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1096        private_data_ptr += sizeof(sljit_sw) * space;
1097        }
1098    
1099      if (size != 0)
1100        {
1101        if (size < 0)
1102          {
1103          cc += -size;
1104    #ifdef SUPPORT_UTF
1105          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1106    #endif
1107          }
1108        else
1109          cc += size;
1110        }
1111    
1112      if (bracketlen > 0)
1113        {
1114        if (cc >= end)
1115          {
1116          end = bracketend(cc);
1117          if (end[-1 - LINK_SIZE] == OP_KET)
1118            end = NULL;
1119          }
1120        cc += bracketlen;
1121        }
1122    }    }
1123  }  }
1124    
1125  /* Returns with -1 if no need for frame. */  /* Returns with -1 if no need for frame. */
1126  static int get_framesize(compiler_common *common, uschar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)
1127  {  {
1128  uschar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc);
1129  int length = 0;  int length = 0;
1130  BOOL possessive = FALSE;  BOOL possessive = FALSE;
1131  BOOL setsom_found = FALSE;  BOOL setsom_found = recursive;
1132    BOOL setmark_found = recursive;
1133    
1134  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1135    {    {
# Line 710  while (cc < ccend) Line 1143  while (cc < ccend)
1143    switch(*cc)    switch(*cc)
1144      {      {
1145      case OP_SET_SOM:      case OP_SET_SOM:
1146      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1147      if (!setsom_found)      if (!setsom_found)
1148        {        {
1149        length += 2;        length += 2;
1150        setsom_found = TRUE;        setsom_found = TRUE;
1151        }        }
1152      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      cc += 1;
1153        break;
1154    
1155        case OP_MARK:
1156        SLJIT_ASSERT(common->mark_ptr != 0);
1157        if (!setmark_found)
1158          {
1159          length += 2;
1160          setmark_found = TRUE;
1161          }
1162        cc += 1 + 2 + cc[1];
1163        break;
1164    
1165        case OP_RECURSE:
1166        if (common->has_set_som && !setsom_found)
1167          {
1168          length += 2;
1169          setsom_found = TRUE;
1170          }
1171        if (common->mark_ptr != 0 && !setmark_found)
1172          {
1173          length += 2;
1174          setmark_found = TRUE;
1175          }
1176        cc += 1 + LINK_SIZE;
1177      break;      break;
1178    
1179      case OP_CBRA:      case OP_CBRA:
# Line 724  while (cc < ccend) Line 1181  while (cc < ccend)
1181      case OP_SCBRA:      case OP_SCBRA:
1182      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1183      length += 3;      length += 3;
1184      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1185      break;      break;
1186    
1187      default:      default:
# Line 742  if (length > 0) Line 1199  if (length > 0)
1199  return -1;  return -1;
1200  }  }
1201    
1202  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)
1203  {  {
1204  DEFINE_COMPILER;  DEFINE_COMPILER;
1205  uschar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc);
1206  BOOL setsom_found = FALSE;  BOOL setsom_found = recursive;
1207    BOOL setmark_found = recursive;
1208  int offset;  int offset;
1209    
1210  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
1211    SLJIT_UNUSED_ARG(stacktop);
1212  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1213    
1214  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
# Line 760  while (cc < ccend) Line 1219  while (cc < ccend)
1219    switch(*cc)    switch(*cc)
1220      {      {
1221      case OP_SET_SOM:      case OP_SET_SOM:
1222      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1223      if (!setsom_found)      if (!setsom_found)
1224        {        {
1225        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1226        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);
1227        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1228          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1229          stackpos += (int)sizeof(sljit_sw);
1230          setsom_found = TRUE;
1231          }
1232        cc += 1;
1233        break;
1234    
1235        case OP_MARK:
1236        SLJIT_ASSERT(common->mark_ptr != 0);
1237        if (!setmark_found)
1238          {
1239          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1240          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark);
1241          stackpos += (int)sizeof(sljit_sw);
1242          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1243          stackpos += (int)sizeof(sljit_sw);
1244          setmark_found = TRUE;
1245          }
1246        cc += 1 + 2 + cc[1];
1247        break;
1248    
1249        case OP_RECURSE:
1250        if (common->has_set_som && !setsom_found)
1251          {
1252          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1253          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);
1254          stackpos += (int)sizeof(sljit_sw);
1255        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1256        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1257        setsom_found = TRUE;        setsom_found = TRUE;
1258        }        }
1259      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      if (common->mark_ptr != 0 && !setmark_found)
1260          {
1261          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1262          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark);
1263          stackpos += (int)sizeof(sljit_sw);
1264          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1265          stackpos += (int)sizeof(sljit_sw);
1266          setmark_found = TRUE;
1267          }
1268        cc += 1 + LINK_SIZE;
1269      break;      break;
1270    
1271      case OP_CBRA:      case OP_CBRA:
# Line 779  while (cc < ccend) Line 1274  while (cc < ccend)
1274      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1275      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1276      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1277      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1278      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1279      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));
1280      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1281      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1282      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1283      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1284    
1285      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1286      break;      break;
1287    
1288      default:      default:
# Line 800  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), st Line 1295  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), st
1295  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1296  }  }
1297    
1298  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)
1299  {  {
1300  int localsize = 2;  int private_data_length = 2;
1301  uschar *alternative;  int size;
1302  /* Calculate the sum of the local variables. */  pcre_uchar *alternative;
1303    /* Calculate the sum of the private machine words. */
1304  while (cc < ccend)  while (cc < ccend)
1305    {    {
1306      size = 0;
1307    switch(*cc)    switch(*cc)
1308      {      {
1309      case OP_ASSERT:      case OP_ASSERT:
# Line 819  while (cc < ccend) Line 1316  while (cc < ccend)
1316      case OP_SBRA:      case OP_SBRA:
1317      case OP_SBRAPOS:      case OP_SBRAPOS:
1318      case OP_SCOND:      case OP_SCOND:
1319      localsize++;      private_data_length++;
1320      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1321      break;      break;
1322    
1323      case OP_CBRA:      case OP_CBRA:
1324      case OP_SCBRA:      case OP_SCBRA:
1325      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1326      cc += 1 + LINK_SIZE + 2;        private_data_length++;
1327        cc += 1 + LINK_SIZE + IMM2_SIZE;
1328      break;      break;
1329    
1330      case OP_CBRAPOS:      case OP_CBRAPOS:
1331      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1332      localsize += 2;      private_data_length += 2;
1333      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1334      break;      break;
1335    
1336      case OP_COND:      case OP_COND:
1337      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1338      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1339      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1340        localsize++;        private_data_length++;
1341      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1342      break;      break;
1343    
1344        CASE_ITERATOR_PRIVATE_DATA_1
1345        if (PRIVATE_DATA(cc))
1346          private_data_length++;
1347        cc += 2;
1348    #ifdef SUPPORT_UTF
1349        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1350    #endif
1351        break;
1352    
1353        CASE_ITERATOR_PRIVATE_DATA_2A
1354        if (PRIVATE_DATA(cc))
1355          private_data_length += 2;
1356        cc += 2;
1357    #ifdef SUPPORT_UTF
1358        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1359    #endif
1360        break;
1361    
1362        CASE_ITERATOR_PRIVATE_DATA_2B
1363        if (PRIVATE_DATA(cc))
1364          private_data_length += 2;
1365        cc += 2 + IMM2_SIZE;
1366    #ifdef SUPPORT_UTF
1367        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1368    #endif
1369        break;
1370    
1371        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1372        if (PRIVATE_DATA(cc))
1373          private_data_length++;
1374        cc += 1;
1375        break;
1376    
1377        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1378        if (PRIVATE_DATA(cc))
1379          private_data_length += 2;
1380        cc += 1;
1381        break;
1382    
1383        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1384        if (PRIVATE_DATA(cc))
1385          private_data_length += 2;
1386        cc += 1 + IMM2_SIZE;
1387        break;
1388    
1389        case OP_CLASS:
1390        case OP_NCLASS:
1391    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1392        case OP_XCLASS:
1393        size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1394    #else
1395        size = 1 + 32 / (int)sizeof(pcre_uchar);
1396    #endif
1397        if (PRIVATE_DATA(cc))
1398          private_data_length += get_class_iterator_size(cc + size);
1399        cc += size;
1400        break;
1401    
1402      default:      default:
1403      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1404      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 850  while (cc < ccend) Line 1406  while (cc < ccend)
1406      }      }
1407    }    }
1408  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1409  return localsize;  return private_data_length;
1410  }  }
1411    
1412  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,
1413    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop)
1414  {  {
1415  DEFINE_COMPILER;  DEFINE_COMPILER;
1416  int srcw[2];  int srcw[2];
1417  int count;  int count, size;
1418  BOOL tmp1next = TRUE;  BOOL tmp1next = TRUE;
1419  BOOL tmp1empty = TRUE;  BOOL tmp1empty = TRUE;
1420  BOOL tmp2empty = TRUE;  BOOL tmp2empty = TRUE;
1421  uschar *alternative;  pcre_uchar *alternative;
1422  enum {  enum {
1423    start,    start,
1424    loop,    loop,
# Line 875  stacktop = STACK(stacktop - 1); Line 1431  stacktop = STACK(stacktop - 1);
1431    
1432  if (!save)  if (!save)
1433    {    {
1434    stackptr += sizeof(sljit_w);    stackptr += sizeof(sljit_sw);
1435    if (stackptr < stacktop)    if (stackptr < stacktop)
1436      {      {
1437      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1438      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1439      tmp1empty = FALSE;      tmp1empty = FALSE;
1440      }      }
1441    if (stackptr < stacktop)    if (stackptr < stacktop)
1442      {      {
1443      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1444      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1445      tmp2empty = FALSE;      tmp2empty = FALSE;
1446      }      }
1447    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
# Line 897  while (status != end) Line 1453  while (status != end)
1453    switch(status)    switch(status)
1454      {      {
1455      case start:      case start:
1456      SLJIT_ASSERT(save);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1457      count = 1;      count = 1;
1458      srcw[0] = RECURSIVE_HEAD;      srcw[0] = common->recursive_head_ptr;
1459      status = loop;      status = loop;
1460      break;      break;
1461    
# Line 923  while (status != end) Line 1479  while (status != end)
1479        case OP_SBRAPOS:        case OP_SBRAPOS:
1480        case OP_SCOND:        case OP_SCOND:
1481        count = 1;        count = 1;
1482        srcw[0] = PRIV(cc);        srcw[0] = PRIVATE_DATA(cc);
1483        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1484        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1485        break;        break;
1486    
1487        case OP_CBRA:        case OP_CBRA:
1488        case OP_SCBRA:        case OP_SCBRA:
1489        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1490        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1491        cc += 1 + LINK_SIZE + 2;          count = 1;
1492            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1493            }
1494          cc += 1 + LINK_SIZE + IMM2_SIZE;
1495        break;        break;
1496    
1497        case OP_CBRAPOS:        case OP_CBRAPOS:
1498        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1499        count = 2;        count = 2;
1500          srcw[0] = PRIVATE_DATA(cc);
1501        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1502        srcw[0] = PRIV(cc);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
1503        SLJIT_ASSERT(srcw[0] != 0);        cc += 1 + LINK_SIZE + IMM2_SIZE;
       cc += 1 + LINK_SIZE + 2;  
1504        break;        break;
1505    
1506        case OP_COND:        case OP_COND:
# Line 950  while (status != end) Line 1509  while (status != end)
1509        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1510          {          {
1511          count = 1;          count = 1;
1512          srcw[0] = PRIV(cc);          srcw[0] = PRIVATE_DATA(cc);
1513          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1514          }          }
1515        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1516        break;        break;
1517    
1518        default:        CASE_ITERATOR_PRIVATE_DATA_1
1519        cc = next_opcode(common, cc);        if (PRIVATE_DATA(cc))
1520        SLJIT_ASSERT(cc != NULL);          {
1521            count = 1;
1522            srcw[0] = PRIVATE_DATA(cc);
1523            }
1524          cc += 2;
1525    #ifdef SUPPORT_UTF
1526          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1527    #endif
1528        break;        break;
1529        }  
1530      break;        CASE_ITERATOR_PRIVATE_DATA_2A
1531          if (PRIVATE_DATA(cc))
1532            {
1533            count = 2;
1534            srcw[0] = PRIVATE_DATA(cc);
1535            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1536            }
1537          cc += 2;
1538    #ifdef SUPPORT_UTF
1539          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1540    #endif
1541          break;
1542    
1543          CASE_ITERATOR_PRIVATE_DATA_2B
1544          if (PRIVATE_DATA(cc))
1545            {
1546            count = 2;
1547            srcw[0] = PRIVATE_DATA(cc);
1548            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1549            }
1550          cc += 2 + IMM2_SIZE;
1551    #ifdef SUPPORT_UTF
1552          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1553    #endif
1554          break;
1555    
1556          CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1557          if (PRIVATE_DATA(cc))
1558            {
1559            count = 1;
1560            srcw[0] = PRIVATE_DATA(cc);
1561            }
1562          cc += 1;
1563          break;
1564    
1565          CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1566          if (PRIVATE_DATA(cc))
1567            {
1568            count = 2;
1569            srcw[0] = PRIVATE_DATA(cc);
1570            srcw[1] = srcw[0] + sizeof(sljit_sw);
1571            }
1572          cc += 1;
1573          break;
1574    
1575          CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1576          if (PRIVATE_DATA(cc))
1577            {
1578            count = 2;
1579            srcw[0] = PRIVATE_DATA(cc);
1580            srcw[1] = srcw[0] + sizeof(sljit_sw);
1581            }
1582          cc += 1 + IMM2_SIZE;
1583          break;
1584    
1585          case OP_CLASS:
1586          case OP_NCLASS:
1587    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1588          case OP_XCLASS:
1589          size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1590    #else
1591          size = 1 + 32 / (int)sizeof(pcre_uchar);
1592    #endif
1593          if (PRIVATE_DATA(cc))
1594            switch(get_class_iterator_size(cc + size))
1595              {
1596              case 1:
1597              count = 1;
1598              srcw[0] = PRIVATE_DATA(cc);
1599              break;
1600    
1601              case 2:
1602              count = 2;
1603              srcw[0] = PRIVATE_DATA(cc);
1604              srcw[1] = srcw[0] + sizeof(sljit_sw);
1605              break;
1606    
1607              default:
1608              SLJIT_ASSERT_STOP();
1609              break;
1610              }
1611          cc += size;
1612          break;
1613    
1614          default:
1615          cc = next_opcode(common, cc);
1616          SLJIT_ASSERT(cc != NULL);
1617          break;
1618          }
1619        break;
1620    
1621      case end:      case end:
1622      SLJIT_ASSERT_STOP();      SLJIT_ASSERT_STOP();
# Line 978  while (status != end) Line 1633  while (status != end)
1633          if (!tmp1empty)          if (!tmp1empty)
1634            {            {
1635            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1636            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1637            }            }
1638          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1639          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 989  while (status != end) Line 1644  while (status != end)
1644          if (!tmp2empty)          if (!tmp2empty)
1645            {            {
1646            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1647            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1648            }            }
1649          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1650          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1006  while (status != end) Line 1661  while (status != end)
1661          if (!tmp1empty)          if (!tmp1empty)
1662            {            {
1663            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1664            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1665            }            }
1666          tmp1next = FALSE;          tmp1next = FALSE;
1667          }          }
# Line 1018  while (status != end) Line 1673  while (status != end)
1673          if (!tmp2empty)          if (!tmp2empty)
1674            {            {
1675            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1676            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1677            }            }
1678          tmp1next = TRUE;          tmp1next = TRUE;
1679          }          }
# Line 1033  if (save) Line 1688  if (save)
1688      if (!tmp1empty)      if (!tmp1empty)
1689        {        {
1690        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1691        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1692        }        }
1693      if (!tmp2empty)      if (!tmp2empty)
1694        {        {
1695        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1696        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1697        }        }
1698      }      }
1699    else    else
# Line 1046  if (save) Line 1701  if (save)
1701      if (!tmp2empty)      if (!tmp2empty)
1702        {        {
1703        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1704        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1705        }        }
1706      if (!tmp1empty)      if (!tmp1empty)
1707        {        {
1708        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1709        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1710        }        }
1711      }      }
1712    }    }
1713  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1714  }  }
1715    
1716  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  #undef CASE_ITERATOR_PRIVATE_DATA_1
1717    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1718    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1719    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1720    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1721    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1722    
1723    static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1724  {  {
1725  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1726  }  }
# Line 1068  static SLJIT_INLINE void set_jumps(jump_ Line 1730  static SLJIT_INLINE void set_jumps(jump_
1730  while (list)  while (list)
1731    {    {
1732    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1733    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1734    sljit_set_label(list->jump, label);    sljit_set_label(list->jump, label);
1735    list = list->next;    list = list->next;
1736    }    }
# Line 1095  if (list_item) Line 1757  if (list_item)
1757    list_item->type = type;    list_item->type = type;
1758    list_item->data = data;    list_item->data = data;
1759    list_item->start = start;    list_item->start = start;
1760    list_item->leave = LABEL();    list_item->quit = LABEL();
1761    list_item->next = common->stubs;    list_item->next = common->stubs;
1762    common->stubs = list_item;    common->stubs = list_item;
1763    }    }
# Line 1115  while (list_item) Line 1777  while (list_item)
1777      add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));      add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
1778      break;      break;
1779      }      }
1780    JUMPTO(SLJIT_JUMP, list_item->leave);    JUMPTO(SLJIT_JUMP, list_item->quit);
1781    list_item = list_item->next;    list_item = list_item->next;
1782    }    }
1783  common->stubs = NULL;  common->stubs = NULL;
# Line 1134  static SLJIT_INLINE void allocate_stack( Line 1796  static SLJIT_INLINE void allocate_stack(
1796  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
1797  DEFINE_COMPILER;  DEFINE_COMPILER;
1798    
1799  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));
1800  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
1801  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
1802  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1148  add_stub(common, stack_alloc, 0, CMP(SLJ Line 1810  add_stub(common, stack_alloc, 0, CMP(SLJ
1810  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
1811  {  {
1812  DEFINE_COMPILER;  DEFINE_COMPILER;
1813  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));
1814  }  }
1815    
1816  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1158  struct sljit_label *loop; Line 1820  struct sljit_label *loop;
1820  int i;  int i;
1821  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
1822  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
1823  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));
1824  if (length < 8)  if (length < 8)
1825    {    {
1826    for (i = 0; i < length; i++)    for (i = 0; i < length; i++)
1827      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);
1828    }    }
1829  else  else
1830    {    {
1831    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));
1832    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length);
1833    loop = LABEL();    loop = LABEL();
1834    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);
1835    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);
1836    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
1837    }    }
1838  }  }
# Line 1179  static SLJIT_INLINE void copy_ovector(co Line 1841  static SLJIT_INLINE void copy_ovector(co
1841  {  {
1842  DEFINE_COMPILER;  DEFINE_COMPILER;
1843  struct sljit_label *loop;  struct sljit_label *loop;
1844  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
1845    
1846  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
1847  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));
1848  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);
1849    
1850  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
1851  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  if (common->mark_ptr != 0)
1852  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);
1853  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));
1854  OP2(SLJIT_ADD, SLJIT_GENERAL_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START);  if (common->mark_ptr != 0)
1855      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);
1856    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
1857    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
1858    GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
1859  /* Unlikely, but possible */  /* Unlikely, but possible */
1860  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);
1861  loop = LABEL();  loop = LABEL();
1862  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);
1863  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));
1864  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
1865  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_GENERAL_REG2, 0);  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1866  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);
1867    #endif
1868    OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
1869    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
1870  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
1871  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
1872    
1873  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
1874  if (topbracket > 1)  if (topbracket > 1)
1875    {    {
1876    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));
1877    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
1878    
1879    /* OVECTOR(0) is never equal to SLJIT_GENERAL_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
1880    loop = LABEL();    loop = LABEL();
1881    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)));
1882    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);
1883    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);
1884    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
1885    }    }
1886  else  else
1887    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
1888  }  }
1889    
1890  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)
1891    {
1892    DEFINE_COMPILER;
1893    
1894    SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
1895    SLJIT_ASSERT(common->start_used_ptr != 0 && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
1896    
1897    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
1898    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
1899    OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offset_count));
1900    CMPTO(SLJIT_C_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
1901    
1902    /* Store match begin and end. */
1903    OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));
1904    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
1905    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);
1906    OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);
1907    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1908    OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
1909    #endif
1910    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);
1911    
1912    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);
1913    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1914    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
1915    #endif
1916    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0);
1917    
1918    JUMPTO(SLJIT_JUMP, quit);
1919    }
1920    
1921    static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)
1922    {
1923    /* May destroy TMP1. */
1924    DEFINE_COMPILER;
1925    struct sljit_jump *jump;
1926    
1927    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
1928      {
1929      /* The value of -1 must be kept for start_used_ptr! */
1930      OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, 1);
1931      /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting
1932      is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */
1933      jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_PTR, 0);
1934      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
1935      JUMPHERE(jump);
1936      }
1937    else if (common->mode == JIT_PARTIAL_HARD_COMPILE)
1938      {
1939      jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
1940      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
1941      JUMPHERE(jump);
1942      }
1943    }
1944    
1945    static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar* cc)
1946  {  {
1947  /* Detects if the character has an othercase. */  /* Detects if the character has an othercase. */
1948  unsigned int c;  unsigned int c;
1949    
1950  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
1951  if (common->utf8)  if (common->utf)
1952    {    {
1953    GETCHAR(c, cc);    GETCHAR(c, cc);
1954    if (c > 127)    if (c > 127)
# Line 1235  if (common->utf8) Line 1959  if (common->utf8)
1959      return FALSE;      return FALSE;
1960  #endif  #endif
1961      }      }
1962    #ifndef COMPILE_PCRE8
1963      return common->fcc[c] != c;
1964    #endif
1965    }    }
1966  else  else
1967  #endif  #endif
1968    c = *cc;    c = *cc;
1969  return common->fcc[c] != c;  return MAX_255(c) ? common->fcc[c] != c : FALSE;
1970  }  }
1971    
1972  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)
1973  {  {
1974  /* Returns with the othercase. */  /* Returns with the othercase. */
1975  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
1976  if (common->utf8 && c > 127)  if (common->utf && c > 127)
1977    {    {
1978  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
1979    return UCD_OTHERCASE(c);    return UCD_OTHERCASE(c);
# Line 1255  if (common->utf8 && c > 127) Line 1982  if (common->utf8 && c > 127)
1982  #endif  #endif
1983    }    }
1984  #endif  #endif
1985  return common->fcc[c];  return TABLE_GET(c, common->fcc, c);
1986  }  }
1987    
1988  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)
1989  {  {
1990  /* Detects if the character and its othercase has only 1 bit difference. */  /* Detects if the character and its othercase has only 1 bit difference. */
1991  unsigned int c, oc, bit;  unsigned int c, oc, bit;
1992  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
1993  int n;  int n;
1994  #endif  #endif
1995    
1996  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
1997  if (common->utf8)  if (common->utf)
1998    {    {
1999    GETCHAR(c, cc);    GETCHAR(c, cc);
2000    if (c <= 127)    if (c <= 127)
# Line 1284  if (common->utf8) Line 2011  if (common->utf8)
2011  else  else
2012    {    {
2013    c = *cc;    c = *cc;
2014    oc = common->fcc[c];    oc = TABLE_GET(c, common->fcc, c);
2015    }    }
2016  #else  #else
2017  c = *cc;  c = *cc;
2018  oc = common->fcc[c];  oc = TABLE_GET(c, common->fcc, c);
2019  #endif  #endif
2020    
2021  SLJIT_ASSERT(c != oc);  SLJIT_ASSERT(c != oc);
# Line 1299  if (c <= 127 && bit == 0x20) Line 2026  if (c <= 127 && bit == 0x20)
2026    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2027    
2028  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2029  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2030    return 0;    return 0;
2031    
2032  #ifdef SUPPORT_UTF8  #if defined COMPILE_PCRE8
2033  if (common->utf8 && c > 127)  
2034    #ifdef SUPPORT_UTF
2035    if (common->utf && c > 127)
2036    {    {
2037    n = _pcre_utf8_table4[*cc & 0x3f];    n = GET_EXTRALEN(*cc);
2038    while ((bit & 0x3f) == 0)    while ((bit & 0x3f) == 0)
2039      {      {
2040      n--;      n--;
# Line 1313  if (common->utf8 && c > 127) Line 2042  if (common->utf8 && c > 127)
2042      }      }
2043    return (n << 8) | bit;    return (n << 8) | bit;
2044    }    }
2045  #endif  #endif /* SUPPORT_UTF */
2046  return (0 << 8) | bit;  return (0 << 8) | bit;
2047    
2048    #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2049    
2050    #ifdef SUPPORT_UTF
2051    if (common->utf && c > 65535)
2052      {
2053      if (bit >= (1 << 10))
2054        bit >>= 10;
2055      else
2056        return (bit < 256) ? ((2 << 8) | bit) : ((3 << 8) | (bit >> 8));
2057      }
2058    #endif /* SUPPORT_UTF */
2059    return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
2060    
2061    #endif /* COMPILE_PCRE[8|16|32] */
2062  }  }
2063    
2064  static SLJIT_INLINE void check_input_end(compiler_common *common, jump_list **fallbacks)  static void check_partial(compiler_common *common, BOOL force)
2065  {  {
2066    /* Checks whether a partial matching is occured. Does not modify registers. */
2067  DEFINE_COMPILER;  DEFINE_COMPILER;
2068  add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));  struct sljit_jump *jump = NULL;
2069    
2070    SLJIT_ASSERT(!force || common->mode != JIT_COMPILE);
2071    
2072    if (common->mode == JIT_COMPILE)
2073      return;
2074    
2075    if (!force)
2076      jump = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2077    else if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2078      jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2079    
2080    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2081      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
2082    else
2083      {
2084      if (common->partialmatchlabel != NULL)
2085        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2086      else
2087        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2088      }
2089    
2090    if (jump != NULL)
2091      JUMPHERE(jump);
2092    }
2093    
2094    static struct sljit_jump *check_str_end(compiler_common *common)
2095    {
2096    /* Does not affect registers. Usually used in a tight spot. */
2097    DEFINE_COMPILER;
2098    struct sljit_jump *jump;
2099    struct sljit_jump *nohit;
2100    struct sljit_jump *return_value;
2101    
2102    if (common->mode == JIT_COMPILE)
2103      return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2104    
2105    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2106    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2107      {
2108      nohit = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2109      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
2110      JUMPHERE(nohit);
2111      return_value = JUMP(SLJIT_JUMP);
2112      }
2113    else
2114      {
2115      return_value = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2116      if (common->partialmatchlabel != NULL)
2117        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2118      else
2119        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2120      }
2121    JUMPHERE(jump);
2122    return return_value;
2123    }
2124    
2125    static void detect_partial_match(compiler_common *common, jump_list **backtracks)
2126    {
2127    DEFINE_COMPILER;
2128    struct sljit_jump *jump;
2129    
2130    if (common->mode == JIT_COMPILE)
2131      {
2132      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2133      return;
2134      }
2135    
2136    /* Partial matching mode. */
2137    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2138    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2139    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2140      {
2141      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
2142      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2143      }
2144    else
2145      {
2146      if (common->partialmatchlabel != NULL)
2147        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2148      else
2149        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2150      }
2151    JUMPHERE(jump);
2152  }  }
2153    
2154  static void read_char(compiler_common *common)  static void read_char(compiler_common *common)
# Line 1328  static void read_char(compiler_common *c Line 2156  static void read_char(compiler_common *c
2156  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2157  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2158  DEFINE_COMPILER;  DEFINE_COMPILER;
2159  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2160  struct sljit_jump *jump;  struct sljit_jump *jump;
2161  #endif  #endif
2162    
2163  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2164  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2165  if (common->utf8)  if (common->utf)
2166    {    {
2167    /* Should not found a value between 128 and 192 here. */  #if defined COMPILE_PCRE8
2168    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 192);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2169    add_jump(compiler, &common->utf8readchar, JUMP(SLJIT_FAST_CALL));  #elif defined COMPILE_PCRE16
2170      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2171    #endif /* COMPILE_PCRE[8|16] */
2172      add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2173    JUMPHERE(jump);    JUMPHERE(jump);
2174    }    }
2175  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2176  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));
2177  }  }
2178    
2179  static void peek_char(compiler_common *common)  static void peek_char(compiler_common *common)
# Line 1350  static void peek_char(compiler_common *c Line 2181  static void peek_char(compiler_common *c
2181  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2182  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2183  DEFINE_COMPILER;  DEFINE_COMPILER;
2184  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2185  struct sljit_jump *jump;  struct sljit_jump *jump;
2186  #endif  #endif
2187    
2188  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2189  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2190  if (common->utf8)  if (common->utf)
2191    {    {
2192    /* Should not found a value between 128 and 192 here. */  #if defined COMPILE_PCRE8
2193    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 192);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2194    add_jump(compiler, &common->utf8readchar, JUMP(SLJIT_FAST_CALL));  #elif defined COMPILE_PCRE16
2195      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2196    #endif /* COMPILE_PCRE[8|16] */
2197      add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2198    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2199    JUMPHERE(jump);    JUMPHERE(jump);
2200    }    }
2201  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2202  }  }
2203    
2204  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2205  {  {
2206  /* 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. */
2207  DEFINE_COMPILER;  DEFINE_COMPILER;
2208  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2209  struct sljit_jump *jump;  struct sljit_jump *jump;
2210  #endif  #endif
2211    
2212  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2213  if (common->utf8)  if (common->utf)
2214    {    {
2215    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2216    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));
2217    #if defined COMPILE_PCRE8
2218    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2219    it is a clever early read in most cases. */    it is needed in most cases. */
2220      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2221      jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2222      add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2223      JUMPHERE(jump);
2224    #elif defined COMPILE_PCRE16
2225      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2226      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2227    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
   /* Should not found a value between 128 and 192 here. */  
   jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 192);  
   add_jump(compiler, &common->utf8readtype8, JUMP(SLJIT_FAST_CALL));  
2228    JUMPHERE(jump);    JUMPHERE(jump);
2229      /* Skip low surrogate if necessary. */
2230      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2231      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2232      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2233      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2234      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2235    #elif defined COMPILE_PCRE32
2236      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2237      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2238      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2239      JUMPHERE(jump);
2240    #endif /* COMPILE_PCRE[8|16|32] */
2241    return;    return;
2242    }    }
2243    #endif /* SUPPORT_UTF */
2244    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2245    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2246    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2247    /* The ctypes array contains only 256 values. */
2248    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2249    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2250    #endif
2251    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2252    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2253    JUMPHERE(jump);
2254  #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);  
2255  }  }
2256    
2257  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
2258  {  {
2259  /* 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. */
2260  DEFINE_COMPILER;  DEFINE_COMPILER;
2261  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2262    #if defined COMPILE_PCRE8
2263  struct sljit_label *label;  struct sljit_label *label;
2264    
2265  if (common->utf8)  if (common->utf)
2266    {    {
2267    label = LABEL();    label = LABEL();
2268    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
2269    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));
2270    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);
2271    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2272    return;    return;
2273    }    }
2274  #endif  #elif defined COMPILE_PCRE16
2275  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  if (common->utf)
2276      {
2277      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
2278      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2279      /* Skip low surrogate if necessary. */
2280      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2281      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);
2282      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2283      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2284      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2285      return;
2286      }
2287    #endif /* COMPILE_PCRE[8|16] */
2288    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2289    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2290  }  }
2291    
2292  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)
2293  {  {
2294  /* 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. */
2295  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1423  DEFINE_COMPILER; Line 2297  DEFINE_COMPILER;
2297  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2298    {    {
2299    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2300    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));
2301    }    }
2302  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2303    {    {
2304    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);
2305    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2306    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);
2307    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);
2308    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));
2309    }    }
2310  else  else
2311    {    {
2312    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline <= 255);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2313    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));
2314    }    }
2315  }  }
2316    
2317  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2318  static void do_utf8readchar(compiler_common *common)  
2319    #if defined COMPILE_PCRE8
2320    static void do_utfreadchar(compiler_common *common)
2321  {  {
2322  /* Fast decoding an utf8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2323  of the character (>= 192). Return char value in TMP1, length - 1 in TMP2. */  of the character (>= 0xc0). Return char value in TMP1, length - 1 in TMP2. */
2324  DEFINE_COMPILER;  DEFINE_COMPILER;
2325  struct sljit_jump *jump;  struct sljit_jump *jump;
2326    
2327  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2328  /* Searching for the first zero. */  /* Searching for the first zero. */
2329  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);
2330  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2331  /* 2 byte sequence */  /* Two byte sequence. */
2332  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2333  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));
2334  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);
2335  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2336  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2337  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2338  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
2339  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2340  JUMPHERE(jump);  JUMPHERE(jump);
2341    
2342  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);
2343  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2344  /* 3 byte sequence */  /* Three byte sequence. */
2345  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2346  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);
2347  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);
2348  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2349  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2350  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2351  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 2);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2352  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));
2353  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2354  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2355  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 2);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2356  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2357  JUMPHERE(jump);  JUMPHERE(jump);
2358    
2359  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x08);  /* Four byte sequence. */
2360  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);  
2361  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);
2362  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);
2363  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2364  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);
2365  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2366  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 2);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2367  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2368  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2369  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2370  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 3);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));
2371  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 3);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2372  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2373  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2374  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 3);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(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);  
 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), 4);  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 4);  
 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, 4);  
2375  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2376  }  }
2377    
2378  static void do_utf8readtype8(compiler_common *common)  static void do_utfreadtype8(compiler_common *common)
2379  {  {
2380  /* Fast decoding an utf8 character type. TMP2 contains the first byte  /* Fast decoding a UTF-8 character type. TMP2 contains the first byte
2381  of the character (>= 192) and TMP1 is destroyed. Return value in TMP1. */  of the character (>= 0xc0). Return value in TMP1. */
2382  DEFINE_COMPILER;  DEFINE_COMPILER;
2383  struct sljit_jump *jump;  struct sljit_jump *jump;
2384  struct sljit_jump *compare;  struct sljit_jump *compare;
2385    
2386  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2387    
2388  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);
2389  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2390  /* 2 byte sequence */  /* Two byte sequence. */
2391  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2392  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));
2393  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2394  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2395  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
# Line 1553  sljit_emit_fast_return(compiler, RETURN_ Line 2404  sljit_emit_fast_return(compiler, RETURN_
2404  JUMPHERE(jump);  JUMPHERE(jump);
2405    
2406  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2407  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)_pcre_utf8_char_sizes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
 OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  
2408  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2409  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2410  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2411  }  }
2412    
2413  #endif  #elif defined COMPILE_PCRE16
2414    
2415    static void do_utfreadchar(compiler_common *common)
2416    {
2417    /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char
2418    of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */
2419    DEFINE_COMPILER;
2420    struct sljit_jump *jump;
2421    
2422    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2423    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);
2424    /* Do nothing, only return. */
2425    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2426    
2427    JUMPHERE(jump);
2428    /* Combine two 16 bit characters. */
2429    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2430    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2431    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2432    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);
2433    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff);
2434    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2435    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
2436    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2437    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2438    }
2439    
2440    #endif /* COMPILE_PCRE[8|16] */
2441    
2442    #endif /* SUPPORT_UTF */
2443    
2444  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2445    
# Line 1576  DEFINE_COMPILER; Line 2455  DEFINE_COMPILER;
2455    
2456  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);
2457    
2458  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2459  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2460  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));
2461  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2462  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2463  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2464  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)_pcre_ucd_stage2);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2465  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2466  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));
2467  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2468  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2469  }  }
# Line 1598  struct sljit_label *newlinelabel = NULL; Line 2477  struct sljit_label *newlinelabel = NULL;
2477  struct sljit_jump *start;  struct sljit_jump *start;
2478  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2479  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2480    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2481    struct sljit_jump *singlechar;
2482    #endif
2483  jump_list *newline = NULL;  jump_list *newline = NULL;
2484  BOOL newlinecheck = FALSE;  BOOL newlinecheck = FALSE;
2485  BOOL readbyte = FALSE;  BOOL readuchar = FALSE;
2486    
2487    if (!(hascrorlf || firstline) && (common->nltype == NLTYPE_ANY ||
2488        common->nltype == NLTYPE_ANYCRLF || common->newline > 255))
2489      newlinecheck = TRUE;
2490    
2491    if (firstline)
2492      {
2493      /* Search for the end of the first line. */
2494      SLJIT_ASSERT(common->first_line_end != 0);
2495      OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
2496    
2497      if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2498        {
2499        mainloop = LABEL();
2500        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2501        end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2502        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
2503        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2504        CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);
2505        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);
2506        JUMPHERE(end);
2507        OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2508        }
2509      else
2510        {
2511        end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2512        mainloop = LABEL();
2513        /* Continual stores does not cause data dependency. */
2514        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2515        read_char(common);
2516        check_newlinechar(common, common->nltype, &newline, TRUE);
2517        CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2518        JUMPHERE(end);
2519        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2520        set_jumps(newline, LABEL());
2521        }
2522    
2523      OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
2524      }
2525    
2526    start = JUMP(SLJIT_JUMP);
2527    
2528    if (newlinecheck)
2529      {
2530      newlinelabel = LABEL();
2531      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2532      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2533      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2534      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);
2535      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2536    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2537      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2538    #endif
2539      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2540      nl = JUMP(SLJIT_JUMP);
2541      }
2542    
2543    mainloop = LABEL();
2544    
2545    /* Increasing the STR_PTR here requires one less jump in the most common case. */
2546    #ifdef SUPPORT_UTF
2547    if (common->utf) readuchar = TRUE;
2548    #endif
2549    if (newlinecheck) readuchar = TRUE;
2550    
2551    if (readuchar)
2552      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2553    
2554    if (newlinecheck)
2555      CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);
2556    
2557    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2558    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2559    #if defined COMPILE_PCRE8
2560    if (common->utf)
2561      {
2562      singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2563      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2564      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2565      JUMPHERE(singlechar);
2566      }
2567    #elif defined COMPILE_PCRE16
2568    if (common->utf)
2569      {
2570      singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2571      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2572      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2573      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2574      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2575      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2576      JUMPHERE(singlechar);
2577      }
2578    #endif /* COMPILE_PCRE[8|16] */
2579    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2580    JUMPHERE(start);
2581    
2582    if (newlinecheck)
2583      {
2584      JUMPHERE(end);
2585      JUMPHERE(nl);
2586      }
2587    
2588    return mainloop;
2589    }
2590    
2591    #define MAX_N_CHARS 3
2592    
2593    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2594    {
2595    DEFINE_COMPILER;
2596    struct sljit_label *start;
2597    struct sljit_jump *quit;
2598    pcre_uint32 chars[MAX_N_CHARS * 2];
2599    pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2600    int location = 0;
2601    pcre_int32 len, c, bit, caseless;
2602    int must_stop;
2603    
2604    /* We do not support alternatives now. */
2605    if (*(common->start + GET(common->start, 1)) == OP_ALT)
2606      return FALSE;
2607    
2608    while (TRUE)
2609      {
2610      caseless = 0;
2611      must_stop = 1;
2612      switch(*cc)
2613        {
2614        case OP_CHAR:
2615        must_stop = 0;
2616        cc++;
2617        break;
2618    
2619        case OP_CHARI:
2620        caseless = 1;
2621        must_stop = 0;
2622        cc++;
2623        break;
2624    
2625        case OP_SOD:
2626        case OP_SOM:
2627        case OP_SET_SOM:
2628        case OP_NOT_WORD_BOUNDARY:
2629        case OP_WORD_BOUNDARY:
2630        case OP_EODN:
2631        case OP_EOD:
2632        case OP_CIRC:
2633        case OP_CIRCM:
2634        case OP_DOLL:
2635        case OP_DOLLM:
2636        /* Zero width assertions. */
2637        cc++;
2638        continue;
2639    
2640        case OP_PLUS:
2641        case OP_MINPLUS:
2642        case OP_POSPLUS:
2643        cc++;
2644        break;
2645    
2646        case OP_EXACT:
2647        cc += 1 + IMM2_SIZE;
2648        break;
2649    
2650        case OP_PLUSI:
2651        case OP_MINPLUSI:
2652        case OP_POSPLUSI:
2653        caseless = 1;
2654        cc++;
2655        break;
2656    
2657        case OP_EXACTI:
2658        caseless = 1;
2659        cc += 1 + IMM2_SIZE;
2660        break;
2661    
2662        default:
2663        must_stop = 2;
2664        break;
2665        }
2666    
2667  if (!(hascrorlf || firstline) && (common->nltype == NLTYPE_ANY ||    if (must_stop == 2)
2668      common->nltype == NLTYPE_ANYCRLF || common->newline > 255))        break;
   newlinecheck = TRUE;  
2669    
2670  if (firstline)    len = 1;
2671    {  #ifdef SUPPORT_UTF
2672    /* Search for the end of the first line. */    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
2673    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);  #endif
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_END, 0);  
2674    
2675    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (caseless && char_has_othercase(common, cc))
2676      {      {
2677      mainloop = LABEL();      caseless = char_get_othercase_bit(common, cc);
2678      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);      if (caseless == 0)
2679      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);        return FALSE;
2680      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -1);  #ifdef COMPILE_PCRE8
2681      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
2682      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);  #else
2683      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);      if ((caseless & 0x100) != 0)
2684      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0, SLJIT_IMM, 1);        caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
2685        else
2686          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
2687    #endif
2688      }      }
2689    else    else
2690        caseless = 0;
2691    
2692      while (len > 0 && location < MAX_N_CHARS * 2)
2693      {      {
2694      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      c = *cc;
2695      mainloop = LABEL();      bit = 0;
2696      /* Continual stores does not cause data dependency. */      if (len == (caseless & 0xff))
2697      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);        {
2698      read_char(common);        bit = caseless >> 8;
2699      check_newlinechar(common, common->nltype, &newline, TRUE);        c |= bit;
2700      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);        }
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);  
     set_jumps(newline, LABEL());  
     }  
2701    
2702    JUMPHERE(end);      chars[location] = c;
2703    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);      chars[location + 1] = bit;
   }  
2704    
2705  start = JUMP(SLJIT_JUMP);      len--;
2706        location += 2;
2707        cc++;
2708        }
2709    
2710  if (newlinecheck)    if (location >= MAX_N_CHARS * 2 || must_stop != 0)
2711    {      break;
   newlinelabel = LABEL();  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  
   end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);  
   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   nl = JUMP(SLJIT_JUMP);  
2712    }    }
2713    
2714  mainloop = LABEL();  /* At least two characters are required. */
2715    if (location < 2 * 2)
2716  /* Increasing the STR_PTR here requires one less jump in the most common case. */      return FALSE;
 #ifdef SUPPORT_UTF8  
 if (common->utf8) readbyte = TRUE;  
 #endif  
 if (newlinecheck) readbyte = TRUE;  
   
 if (readbyte)  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
   
 if (newlinecheck)  
   CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);  
2717    
2718  #ifdef SUPPORT_UTF8  if (firstline)
 if (common->utf8)  
2719    {    {
2720    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)_pcre_utf8_char_sizes);    SLJIT_ASSERT(common->first_line_end != 0);
2721    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2722      OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2723    }    }
2724  else  else
2725    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
 #else  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  
 #endif  
 JUMPHERE(start);  
2726    
2727  if (newlinecheck)  start = LABEL();
2728    {  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2729    JUMPHERE(end);  
2730    JUMPHERE(nl);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2731    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2732    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2733    if (chars[1] != 0)
2734      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
2735    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
2736    if (location > 2 * 2)
2737      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2738    if (chars[3] != 0)
2739      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
2740    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
2741    if (location > 2 * 2)
2742      {
2743      if (chars[5] != 0)
2744        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
2745      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);
2746    }    }
2747    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2748    
2749  return mainloop;  JUMPHERE(quit);
2750    
2751    if (firstline)
2752      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2753    else
2754      OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2755    return TRUE;
2756  }  }
2757    
2758  static SLJIT_INLINE void fast_forward_first_byte(compiler_common *common, pcre_uint16 firstbyte, BOOL firstline)  #undef MAX_N_CHARS
2759    
2760    static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
2761  {  {
2762  DEFINE_COMPILER;  DEFINE_COMPILER;
2763  struct sljit_label *start;  struct sljit_label *start;
2764  struct sljit_jump *leave;  struct sljit_jump *quit;
2765  struct sljit_jump *found;  struct sljit_jump *found;
2766  pcre_uint16 oc, bit;  pcre_uchar oc, bit;
2767    
2768  if (firstline)  if (firstline)
2769    {    {
2770    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2771    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2772      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
2773    }    }
2774    
2775  start = LABEL();  start = LABEL();
2776  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2777  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2778    
2779  if ((firstbyte & REQ_CASELESS) == 0)  oc = first_char;
2780    found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, firstbyte & 0xff);  if (caseless)
2781      {
2782      oc = TABLE_GET(first_char, common->fcc, first_char);
2783    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
2784      if (first_char > 127 && common->utf)
2785        oc = UCD_OTHERCASE(first_char);
2786    #endif
2787      }
2788    if (first_char == oc)
2789      found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, first_char);
2790  else  else
2791    {    {
2792    firstbyte &= 0xff;    bit = first_char ^ oc;
2793    oc = common->fcc[firstbyte];    if (is_powerof2(bit))
   bit = firstbyte ^ oc;  
   if (ispowerof2(bit))  
2794      {      {
2795      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
2796      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, firstbyte | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
2797      }      }
2798    else    else
2799      {      {
2800      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);
2801      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2802      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);
2803      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);
2804      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
2805      }      }
2806    }    }
2807    
2808  #ifdef SUPPORT_UTF8  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 if (common->utf8)  
   {  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)_pcre_utf8_char_sizes);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 else  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  
 #else  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  
 #endif  
2809  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
2810  JUMPHERE(found);  JUMPHERE(found);
2811  JUMPHERE(leave);  JUMPHERE(quit);
2812    
2813  if (firstline)  if (firstline)
2814    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2815  }  }
2816    
2817  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 1755  DEFINE_COMPILER; Line 2820  DEFINE_COMPILER;
2820  struct sljit_label *loop;  struct sljit_label *loop;
2821  struct sljit_jump *lastchar;  struct sljit_jump *lastchar;
2822  struct sljit_jump *firstchar;  struct sljit_jump *firstchar;
2823  struct sljit_jump *leave;  struct sljit_jump *quit;
2824  struct sljit_jump *foundcr = NULL;  struct sljit_jump *foundcr = NULL;
2825  struct sljit_jump *notfoundnl;  struct sljit_jump *notfoundnl;
2826  jump_list *newline = NULL;  jump_list *newline = NULL;
2827    
2828  if (firstline)  if (firstline)
2829    {    {
2830    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2831    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2832      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
2833    }    }
2834    
2835  if (common->nltype == NLTYPE_FIXED && common->newline > 255)  if (common->nltype == NLTYPE_FIXED && common->newline > 255)
# Line 1774  if (common->nltype == NLTYPE_FIXED && co Line 2840  if (common->nltype == NLTYPE_FIXED && co
2840    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));
2841    firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);    firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);
2842    
2843    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2);    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
2844    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);
2845    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
2846    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2847      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
2848    #endif
2849    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2850    
2851    loop = LABEL();    loop = LABEL();
2852    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));
2853    leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2854    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -2);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
2855    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), -1);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
2856    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);
2857    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);
2858    
2859    JUMPHERE(leave);    JUMPHERE(quit);
2860    JUMPHERE(firstchar);    JUMPHERE(firstchar);
2861    JUMPHERE(lastchar);    JUMPHERE(lastchar);
2862    
# Line 1811  set_jumps(newline, loop); Line 2880  set_jumps(newline, loop);
2880    
2881  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
2882    {    {
2883    leave = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
2884    JUMPHERE(foundcr);    JUMPHERE(foundcr);
2885    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2886    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2887    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);
2888    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2889    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2890      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2891    #endif
2892    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2893    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
2894    JUMPHERE(leave);    JUMPHERE(quit);
2895    }    }
2896  JUMPHERE(lastchar);  JUMPHERE(lastchar);
2897  JUMPHERE(firstchar);  JUMPHERE(firstchar);
2898    
2899  if (firstline)  if (firstline)
2900    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2901  }  }
2902    
2903    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
2904    
2905  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)
2906  {  {
2907  DEFINE_COMPILER;  DEFINE_COMPILER;
2908  struct sljit_label *start;  struct sljit_label *start;
2909  struct sljit_jump *leave;  struct sljit_jump *quit;
2910  struct sljit_jump *found;  struct sljit_jump *found = NULL;
2911    jump_list *matches = NULL;
2912    pcre_uint8 inverted_start_bits[32];
2913    int i;
2914    #ifndef COMPILE_PCRE8
2915    struct sljit_jump *jump;
2916    #endif
2917    
2918    for (i = 0; i < 32; ++i)
2919      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
2920    
2921  if (firstline)  if (firstline)
2922    {    {
2923    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2924    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
2925      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
2926    }    }
2927    
2928  start = LABEL();  start = LABEL();
2929  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2930  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2931  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2932  if (common->utf8)  if (common->utf)
2933    OP1(SLJIT_MOV_UB, TMP3, 0, SLJIT_MEM1(TMP1), (sljit_w)_pcre_utf8_char_sizes);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
2934  #endif  #endif
2935  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);  
2936  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);  if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
2937  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    {
2938  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);  #ifndef COMPILE_PCRE8
2939  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
2940  found = JUMP(SLJIT_C_NOT_ZERO);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
2941      JUMPHERE(jump);
2942  #ifdef SUPPORT_UTF8  #endif
2943  if (common->utf8)    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
2944    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP3, 0);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
2945  else    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
2946    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
2947  #else    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
2948  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    found = JUMP(SLJIT_C_NOT_ZERO);
2949      }
2950    
2951    #ifdef SUPPORT_UTF
2952    if (common->utf)
2953      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
2954  #endif  #endif
2955    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2956    #ifdef SUPPORT_UTF
2957    #if defined COMPILE_PCRE8
2958    if (common->utf)
2959      {
2960      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
2961      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2962      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2963      }
2964    #elif defined COMPILE_PCRE16
2965    if (common->utf)
2966      {
2967      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
2968      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2969      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2970      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2971      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2972      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2973      }
2974    #endif /* COMPILE_PCRE[8|16] */
2975    #endif /* SUPPORT_UTF */
2976  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
2977  JUMPHERE(found);  if (found != NULL)
2978  JUMPHERE(leave);    JUMPHERE(found);
2979    if (matches != NULL)
2980      set_jumps(matches, LABEL());
2981    JUMPHERE(quit);
2982    
2983  if (firstline)  if (firstline)
2984    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
2985  }  }
2986    
2987  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)
2988  {  {
2989  DEFINE_COMPILER;  DEFINE_COMPILER;
2990  struct sljit_label *loop;  struct sljit_label *loop;
# Line 1880  struct sljit_jump *alreadyfound; Line 2993  struct sljit_jump *alreadyfound;
2993  struct sljit_jump *found;  struct sljit_jump *found;
2994  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
2995  struct sljit_jump *notfound;  struct sljit_jump *notfound;
2996  pcre_uint16 oc, bit;  pcre_uint32 oc, bit;
2997    
2998  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_BYTE_PTR);  SLJIT_ASSERT(common->req_char_ptr != 0);
2999    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
3000  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);
3001  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);
3002  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);
3003    
3004  if (has_firstbyte)  if (has_firstchar)
3005    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3006  else  else
3007    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);
3008    
3009  loop = LABEL();  loop = LABEL();
3010  notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);  notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);
3011    
3012  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3013  if ((reqbyte & REQ_CASELESS) == 0)  oc = req_char;
3014    found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte & 0xff);  if (caseless)
3015      {
3016      oc = TABLE_GET(req_char, common->fcc, req_char);
3017    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
3018      if (req_char > 127 && common->utf)
3019        oc = UCD_OTHERCASE(req_char);
3020    #endif
3021      }
3022    if (req_char == oc)
3023      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
3024  else  else
3025    {    {
3026    reqbyte &= 0xff;    bit = req_char ^ oc;
3027    oc = common->fcc[reqbyte];    if (is_powerof2(bit))
   bit = reqbyte ^ oc;  
   if (ispowerof2(bit))  
3028      {      {
3029      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3030      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
3031      }      }
3032    else    else
3033      {      {
3034      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
3035      foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);      foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);
3036      }      }
3037    }    }
3038  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
3039  JUMPTO(SLJIT_JUMP, loop);  JUMPTO(SLJIT_JUMP, loop);
3040    
3041  JUMPHERE(found);  JUMPHERE(found);
3042  if (foundoc)  if (foundoc)
3043    JUMPHERE(foundoc);    JUMPHERE(foundoc);
3044  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);
3045  JUMPHERE(alreadyfound);  JUMPHERE(alreadyfound);
3046  JUMPHERE(toolong);  JUMPHERE(toolong);
3047  return notfound;  return notfound;
# Line 1932  DEFINE_COMPILER; Line 3053  DEFINE_COMPILER;
3053  struct sljit_jump *jump;  struct sljit_jump *jump;
3054  struct sljit_label *mainloop;  struct sljit_label *mainloop;
3055    
3056  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3057  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);
3058    GET_LOCAL_BASE(TMP3, 0, 0);
3059    
3060  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3061  mainloop = LABEL();  mainloop = LABEL();
3062  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3063  jump = CMP(SLJIT_C_SIG_LESS_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = CMP(SLJIT_C_SIG_LESS_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);
3064  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_LOCALS_REG, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3065  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3066  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
3067  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
3068  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3069    
3070  JUMPHERE(jump);  JUMPHERE(jump);
# Line 1953  sljit_emit_fast_return(compiler, RETURN_ Line 3075  sljit_emit_fast_return(compiler, RETURN_
3075  JUMPHERE(jump);  JUMPHERE(jump);
3076  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);
3077  /* Set string begin. */  /* Set string begin. */
3078  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3079  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));
3080  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), TMP2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), TMP2, 0);
3081  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3082    
3083  JUMPHERE(jump);  JUMPHERE(jump);
3084    if (common->mark_ptr != 0)
3085      {
3086      jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setmark);
3087      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3088      OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
3089      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);
3090      JUMPTO(SLJIT_JUMP, mainloop);
3091    
3092      JUMPHERE(jump);
3093      }
3094    
3095  /* Unknown command. */  /* Unknown command. */
3096  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));
3097  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3098  }  }
3099    
3100  static void check_wordboundary(compiler_common *common)  static void check_wordboundary(compiler_common *common)
3101  {  {
3102  DEFINE_COMPILER;  DEFINE_COMPILER;
3103  struct sljit_jump *beginend;  struct sljit_jump *skipread;
3104  #ifdef SUPPORT_UTF8  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3105  struct sljit_jump *jump;  struct sljit_jump *jump;
3106  #endif  #endif
3107    
3108  SLJIT_ASSERT(ctype_word == 0x10);  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
3109    
3110  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);
3111  /* Get type of the previous char, and put it to LOCALS1. */  /* Get type of the previous char, and put it to LOCALS1. */
3112  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
3113  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));
3114  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);
3115  beginend = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);  skipread = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3116  skip_char_back(common);  skip_char_back(common);
3117    check_start_used_ptr(common);
3118  read_char(common);  read_char(common);
3119    
3120  /* Testing char type. */  /* Testing char type. */
3121  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3122  if (common->useucp)  if (common->use_ucp)
3123    {    {
3124    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
3125    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
3126    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3127    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3128    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);
3129    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3130    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);
3131    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);
3132    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3133    JUMPHERE(jump);    JUMPHERE(jump);
3134    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3135    }    }
3136  else  else
3137  #endif  #endif
3138    {    {
3139  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3140      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3141    #elif defined SUPPORT_UTF
3142    /* Here LOCALS1 has already been zeroed. */    /* Here LOCALS1 has already been zeroed. */
3143    jump = NULL;    jump = NULL;
3144    if (common->utf8)    if (common->utf)
3145      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3146  #endif  #endif /* COMPILE_PCRE8 */
3147    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);
3148    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);
3149    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3150    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
3151  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3152      JUMPHERE(jump);
3153    #elif defined SUPPORT_UTF
3154    if (jump != NULL)    if (jump != NULL)
3155      JUMPHERE(jump);      JUMPHERE(jump);
3156  #endif  #endif /* COMPILE_PCRE8 */
3157    }    }
3158  JUMPHERE(beginend);  JUMPHERE(skipread);
3159    
3160  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3161  beginend = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  skipread = check_str_end(common);
3162  peek_char(common);  peek_char(common);
3163    
3164  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
3165  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3166  if (common->useucp)  if (common->use_ucp)
3167    {    {
3168    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
3169    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
3170    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3171    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3172    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);
3173    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3174    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);
3175    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);
3176    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3177    JUMPHERE(jump);    JUMPHERE(jump);
3178    }    }
3179  else  else
3180  #endif  #endif
3181    {    {
3182  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3183      /* TMP2 may be destroyed by peek_char. */
3184      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3185      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3186    #elif defined SUPPORT_UTF
3187    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3188    jump = NULL;    jump = NULL;
3189    if (common->utf8)    if (common->utf)
3190      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3191  #endif  #endif
3192    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);
3193    OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);    OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);
3194    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
3195  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3196      JUMPHERE(jump);
3197    #elif defined SUPPORT_UTF
3198    if (jump != NULL)    if (jump != NULL)
3199      JUMPHERE(jump);      JUMPHERE(jump);
3200  #endif  #endif /* COMPILE_PCRE8 */
3201    }    }
3202  JUMPHERE(beginend);  JUMPHERE(skipread);
3203    
3204  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3205  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3206  }  }
3207    
3208    /*
3209      range format:
3210    
3211      ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).
3212      ranges[1] = first bit (0 or 1)
3213      ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)
3214    */
3215    
3216    static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3217    {
3218    DEFINE_COMPILER;
3219    struct sljit_jump *jump;
3220    
3221    if (ranges[0] < 0)
3222      return FALSE;
3223    
3224    switch(ranges[0])
3225      {
3226      case 1:
3227      if (readch)
3228        read_char(common);
3229      add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3230      return TRUE;
3231    
3232      case 2:
3233      if (readch)
3234        read_char(common);
3235      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3236      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3237      return TRUE;
3238    
3239      case 4:
3240      if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])
3241        {
3242        if (readch)
3243          read_char(common);
3244        if (ranges[1] != 0)
3245          {
3246          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3247          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3248          }
3249        else
3250          {
3251          jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);
3252          add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3253          JUMPHERE(jump);
3254          }
3255        return TRUE;
3256        }
3257      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))
3258        {
3259        if (readch)
3260          read_char(common);
3261        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3262        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3263        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3264        return TRUE;
3265        }
3266      return FALSE;
3267    
3268      default:
3269      return FALSE;
3270      }
3271    }
3272    
3273    static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)
3274    {
3275    int i, bit, length;
3276    const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;
3277    
3278    bit = ctypes[0] & flag;
3279    ranges[0] = -1;
3280    ranges[1] = bit != 0 ? 1 : 0;
3281    length = 0;
3282    
3283    for (i = 1; i < 256; i++)
3284      if ((ctypes[i] & flag) != bit)
3285        {
3286        if (length >= MAX_RANGE_SIZE)
3287          return;
3288        ranges[2 + length] = i;
3289        length++;
3290        bit ^= flag;
3291        }
3292    
3293    if (bit != 0)
3294      {
3295      if (length >= MAX_RANGE_SIZE)
3296        return;
3297      ranges[2 + length] = 256;
3298      length++;
3299      }
3300    ranges[0] = length;
3301    }
3302    
3303    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)
3304    {
3305    int ranges[2 + MAX_RANGE_SIZE];
3306    pcre_uint8 bit, cbit, all;
3307    int i, byte, length = 0;
3308    
3309    bit = bits[0] & 0x1;
3310    ranges[1] = bit;
3311    /* Can be 0 or 255. */
3312    all = -bit;
3313    
3314    for (i = 0; i < 256; )
3315      {
3316      byte = i >> 3;
3317      if ((i & 0x7) == 0 && bits[byte] == all)
3318        i += 8;
3319      else
3320        {
3321        cbit = (bits[byte] >> (i & 0x7)) & 0x1;
3322        if (cbit != bit)
3323          {
3324          if (length >= MAX_RANGE_SIZE)
3325            return FALSE;
3326          ranges[2 + length] = i;
3327          length++;
3328          bit = cbit;
3329          all = -cbit;
3330          }
3331        i++;
3332        }
3333      }
3334    
3335    if (((bit == 0) && nclass) || ((bit == 1) && !nclass))
3336      {
3337      if (length >= MAX_RANGE_SIZE)
3338        return FALSE;
3339      ranges[2 + length] = 256;
3340      length++;
3341      }
3342    ranges[0] = length;
3343    
3344    return check_ranges(common, ranges, backtracks, FALSE);
3345    }
3346    
3347  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
3348  {  {
3349  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3350  DEFINE_COMPILER;  DEFINE_COMPILER;
3351    
3352  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3353    
3354  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3355  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);
3356  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3357  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);
3358  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3359  if (common->utf8)  #ifdef COMPILE_PCRE8
3360    if (common->utf)
3361    {    {
3362    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  #endif
3363      OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3364    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3365    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);
3366    #ifdef COMPILE_PCRE8
3367    }    }
3368  #endif  #endif
3369  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3370    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3371  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3372  }  }
3373    
# Line 2089  static void check_hspace(compiler_common Line 3376  static void check_hspace(compiler_common
3376  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3377  DEFINE_COMPILER;  DEFINE_COMPILER;
3378    
3379  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3380    
3381  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);
3382  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3383  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);
3384  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3385  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);
3386  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3387  if (common->utf8)  #ifdef COMPILE_PCRE8
3388    if (common->utf)
3389    {    {
3390    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  #endif
3391      OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3392    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);
3393    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3394    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);
3395    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3396    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3397    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);
3398    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3399    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);
3400    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3401    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);
3402    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3403    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);
3404    #ifdef COMPILE_PCRE8
3405    }    }
3406  #endif  #endif
3407  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3408    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3409    
3410  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3411  }  }
# Line 2124  static void check_vspace(compiler_common Line 3415  static void check_vspace(compiler_common
3415  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3416  DEFINE_COMPILER;  DEFINE_COMPILER;
3417    
3418  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3419    
3420  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3421  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);
3422  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3423  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);
3424  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3425  if (common->utf8)  #ifdef COMPILE_PCRE8
3426    if (common->utf)
3427    {    {
3428    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  #endif
3429      OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3430    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3431    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);
3432    #ifdef COMPILE_PCRE8
3433    }    }
3434  #endif  #endif
3435  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3436    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3437    
3438  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3439  }  }
# Line 2152  DEFINE_COMPILER; Line 3447  DEFINE_COMPILER;
3447  struct sljit_jump *jump;  struct sljit_jump *jump;
3448  struct sljit_label *label;  struct sljit_label *label;
3449    
3450  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3451  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3452  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);
3453  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);
3454  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
3455  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));
3456    
3457  label = LABEL();  label = LABEL();
3458  OP1(SLJIT_MOVU_UB, CHAR1, 0, SLJIT_MEM1(TMP1), 1);  OP1(MOVU_UCHAR, CHAR1, 0, SLJIT_MEM1(TMP1), IN_UCHARS(1));
3459  OP1(SLJIT_MOVU_UB, CHAR2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOVU_UCHAR, CHAR2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3460  jump = CMP(SLJIT_C_NOT_EQUAL, CHAR1, 0, CHAR2, 0);  jump = CMP(SLJIT_C_NOT_EQUAL, CHAR1, 0, CHAR2, 0);
3461  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));
3462  JUMPTO(SLJIT_C_NOT_ZERO, label);  JUMPTO(SLJIT_C_NOT_ZERO, label);
3463    
3464  JUMPHERE(jump);  JUMPHERE(jump);
3465  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));
3466  OP1(SLJIT_MOV, CHAR1, 0, TMP3, 0);  OP1(SLJIT_MOV, CHAR1, 0, TMP3, 0);
3467  OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3468  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
# Line 2181  DEFINE_COMPILER; Line 3476  DEFINE_COMPILER;
3476  struct sljit_jump *jump;  struct sljit_jump *jump;
3477  struct sljit_label *label;  struct sljit_label *label;
3478    
3479  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3480  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3481    
3482  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);
3483  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR1, 0);
3484  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, CHAR2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, CHAR2, 0);
3485  OP1(SLJIT_MOV, LCC_TABLE, 0, SLJIT_IMM, common->lcc);  OP1(SLJIT_MOV, LCC_TABLE, 0, SLJIT_IMM, common->lcc);
3486  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
3487  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));
3488    
3489  label = LABEL();  label = LABEL();
3490  OP1(SLJIT_MOVU_UB, CHAR1, 0, SLJIT_MEM1(TMP1), 1);  OP1(MOVU_UCHAR, CHAR1, 0, SLJIT_MEM1(TMP1), IN_UCHARS(1));
3491  OP1(SLJIT_MOVU_UB, CHAR2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOVU_UCHAR, CHAR2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3492    #ifndef COMPILE_PCRE8
3493    jump = CMP(SLJIT_C_GREATER, CHAR1, 0, SLJIT_IMM, 255);
3494    #endif
3495  OP1(SLJIT_MOV_UB, CHAR1, 0, SLJIT_MEM2(LCC_TABLE, CHAR1), 0);  OP1(SLJIT_MOV_UB, CHAR1, 0, SLJIT_MEM2(LCC_TABLE, CHAR1), 0);
3496    #ifndef COMPILE_PCRE8
3497    JUMPHERE(jump);
3498    jump = CMP(SLJIT_C_GREATER, CHAR2, 0, SLJIT_IMM, 255);
3499    #endif
3500  OP1(SLJIT_MOV_UB, CHAR2, 0, SLJIT_MEM2(LCC_TABLE, CHAR2), 0);  OP1(SLJIT_MOV_UB, CHAR2, 0, SLJIT_MEM2(LCC_TABLE, CHAR2), 0);
3501    #ifndef COMPILE_PCRE8
3502    JUMPHERE(jump);
3503    #endif
3504  jump = CMP(SLJIT_C_NOT_EQUAL, CHAR1, 0, CHAR2, 0);  jump = CMP(SLJIT_C_NOT_EQUAL, CHAR1, 0, CHAR2, 0);
3505  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));
3506  JUMPTO(SLJIT_C_NOT_ZERO, label);  JUMPTO(SLJIT_C_NOT_ZERO, label);
3507    
3508  JUMPHERE(jump);  JUMPHERE(jump);
3509  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));
3510  OP1(SLJIT_MOV, LCC_TABLE, 0, TMP3, 0);  OP1(SLJIT_MOV, LCC_TABLE, 0, TMP3, 0);
3511  OP1(SLJIT_MOV, CHAR1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  OP1(SLJIT_MOV, CHAR1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3512  OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
# Line 2212  sljit_emit_fast_return(compiler, RETURN_ Line 3517  sljit_emit_fast_return(compiler, RETURN_
3517  #undef CHAR1  #undef CHAR1
3518  #undef CHAR2  #undef CHAR2
3519    
3520  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && defined SUPPORT_UCP
 #ifdef SUPPORT_UCP  
3521    
3522  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)
3523  {  {
3524  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3525  int c1, c2;  pcre_uint32 c1, c2;
3526  uschar *src2 = args->ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3527  uschar *end2 = (uschar*)args->end;  const pcre_uchar *end2 = args->end;
3528    const ucd_record *ur;
3529    const pcre_uint32 *pp;
3530    
3531  while (src1 < end1)  while (src1 < end1)
3532    {    {
3533    if (src2 >= end2)    if (src2 >= end2)
3534      return 0;      return (pcre_uchar*)1;
3535    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3536    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3537    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return 0;    ur = GET_UCD(c2);
3538      if (c1 != c2 && c1 != c2 + ur->other_case)
3539        {
3540        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3541        for (;;)
3542          {
3543          if (c1 < *pp) return NULL;
3544          if (c1 == *pp++) break;
3545          }
3546        }
3547    }    }
3548  return src2;  return src2;
3549  }  }
3550    
3551  #endif  #endif /* SUPPORT_UTF && SUPPORT_UCP */
 #endif  
3552    
3553  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,
3554      compare_context* context, jump_list **fallbacks)      compare_context* context, jump_list **backtracks)
3555  {  {
3556  DEFINE_COMPILER;  DEFINE_COMPILER;
3557  unsigned int othercasebit = 0;  unsigned int othercasebit = 0;
3558  uschar *othercasebyte = NULL;  pcre_uchar *othercasechar = NULL;
3559  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3560  int utf8length;  int utflength;
3561  #endif  #endif
3562    
3563  if (caseless && char_has_othercase(common, cc))  if (caseless && char_has_othercase(common, cc))
# Line 2251  if (caseless && char_has_othercase(commo Line 3565  if (caseless && char_has_othercase(commo
3565    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3566    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3567    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3568    othercasebyte = cc + (othercasebit >> 8);  #if defined COMPILE_PCRE8
3569      othercasechar = cc + (othercasebit >> 8);
3570    othercasebit &= 0xff;    othercasebit &= 0xff;
3571    #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3572      /* Note that this code only handles characters in the BMP. If there
3573      ever are characters outside the BMP whose othercase differs in only one
3574      bit from itself (there currently are none), this code will need to be
3575      revised for COMPILE_PCRE32. */
3576      othercasechar = cc + (othercasebit >> 9);
3577      if ((othercasebit & 0x100) != 0)
3578        othercasebit = (othercasebit & 0xff) << 8;
3579      else
3580        othercasebit &= 0xff;
3581    #endif /* COMPILE_PCRE[8|16|32] */
3582    }    }
3583    
3584  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3585    {    {
3586    #if defined COMPILE_PCRE8
3587  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3588    if (context->length >= 4)    if (context->length >= 4)
3589      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3590    else if (context->length >= 2)    else if (context->length >= 2)
3591      OP1(SLJIT_MOV_SH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3592    else    else
3593  #endif  #endif
3594      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3595    #elif defined COMPILE_PCRE16
3596    #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3597      if (context->length >= 4)
3598        OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3599      else
3600    #endif
3601        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3602    #elif defined COMPILE_PCRE32
3603      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3604    #endif /* COMPILE_PCRE[8|16|32] */
3605    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3606    }    }
3607    
3608  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3609  utf8length = 1;  utflength = 1;
3610  if (common->utf8 && *cc >= 0xc0)  if (common->utf && HAS_EXTRALEN(*cc))
3611    utf8length += _pcre_utf8_table4[*cc & 0x3f];    utflength += GET_EXTRALEN(*cc);
3612    
3613  do  do
3614    {    {
3615  #endif  #endif
3616    
3617    context->length--;    context->length -= IN_UCHARS(1);
3618  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3619    
3620    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3621    if (othercasebit != 0 && othercasebyte == cc)    if (othercasebit != 0 && othercasechar == cc)
3622      {      {
3623      context->c.asbytes[context->byteptr] = *cc | othercasebit;      context->c.asuchars[context->ucharptr] = *cc | othercasebit;
3624      context->oc.asbytes[context->byteptr] = othercasebit;      context->oc.asuchars[context->ucharptr] = othercasebit;
3625      }      }
3626    else    else
3627      {      {
3628      context->c.asbytes[context->byteptr] = *cc;      context->c.asuchars[context->ucharptr] = *cc;
3629      context->oc.asbytes[context->byteptr] = 0;      context->oc.asuchars[context->ucharptr] = 0;
3630      }      }
3631    context->byteptr++;    context->ucharptr++;
3632    
3633    if (context->byteptr >= 4 || context->length == 0 || (context->byteptr == 2 && context->length == 1))  #if defined COMPILE_PCRE8
3634      if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))
3635    #else
3636      if (context->ucharptr >= 2 || context->length == 0)
3637    #endif
3638      {      {
3639      if (context->length >= 4)      if (context->length >= 4)
3640        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);
3641      else if (context->length >= 2)      else if (context->length >= 2)
3642        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);
3643    #if defined COMPILE_PCRE8
3644      else if (context->length >= 1)      else if (context->length >= 1)
3645        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);
3646    #endif /* COMPILE_PCRE8 */
3647      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3648    
3649      switch(context->byteptr)      switch(context->ucharptr)
3650        {        {
3651        case 4:        case 4 / sizeof(pcre_uchar):
3652        if (context->oc.asint != 0)        if (context->oc.asint != 0)
3653          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);
3654        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));
3655        break;        break;
3656    
3657        case 2:        case 2 / sizeof(pcre_uchar):
3658        if (context->oc.asshort != 0)        if (context->oc.asushort != 0)
3659          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);
3660        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));
3661        break;        break;
3662    
3663    #ifdef COMPILE_PCRE8
3664        case 1:        case 1:
3665        if (context->oc.asbyte != 0)        if (context->oc.asbyte != 0)
3666          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);
3667        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));
3668        break;        break;
3669    #endif
3670    
3671        default:        default:
3672        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
3673        break;        break;
3674        }        }
3675      context->byteptr = 0;      context->ucharptr = 0;
3676      }      }
3677    
3678  #else  #else
3679    
3680    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3681    if (context->length > 0)    if (context->length >= 1)
3682      OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3683    
3684    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3685    
3686    if (othercasebit != 0 && othercasebyte == cc)    if (othercasebit != 0 && othercasechar == cc)
3687      {      {
3688      OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, othercasebit);      OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, othercasebit);
3689      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc | othercasebit));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc | othercasebit));
3690      }      }
3691    else    else
3692      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc));
3693    
3694  #endif  #endif
3695    
3696    cc++;    cc++;
3697  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3698    utf8length--;    utflength--;
3699