/[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 736 by zherczeg, Sun Oct 16 15:48:03 2011 UTC revision 1176 by ph10, Sat Oct 27 15:46:35 2012 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    /* Everything else after. */    /* Everything else after. */
161    int offsetcount;    int offsetcount;
162    int calllimit;    int calllimit;
163    uschar notbol;    pcre_uint8 notbol;
164    uschar noteol;    pcre_uint8 noteol;
165    uschar notempty;    pcre_uint8 notempty;
166    uschar notempty_atstart;    pcre_uint8 notempty_atstart;
167  } jit_arguments;  } jit_arguments;
168    
169  typedef struct executable_function {  typedef struct executable_functions {
170    void *executable_func;    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
171    pcre_jit_callback callback;    PUBL(jit_callback) callback;
172    void *userdata;    void *userdata;
173  } executable_function;    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
174    } executable_functions;
175    
176  typedef struct jump_list {  typedef struct jump_list {
177    struct sljit_jump *jump;    struct sljit_jump *jump;
# Line 176  typedef struct stub_list { Line 184  typedef struct stub_list {
184    enum stub_types type;    enum stub_types type;
185    int data;    int data;
186    struct sljit_jump *start;    struct sljit_jump *start;
187    struct sljit_label *leave;    struct sljit_label *quit;
188    struct stub_list *next;    struct stub_list *next;
189  } stub_list;  } stub_list;
190    
191  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
192    
193  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
194  code generator. It is allocated by compile_hotpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
195  the aguments for compile_fallbackpath. Must be the first member  the aguments for compile_backtrackingpath. Must be the first member
196  of its descendants. */  of its descendants. */
197  typedef struct fallback_common {  typedef struct backtrack_common {
198    /* Concatenation stack. */    /* Concatenation stack. */
199    struct fallback_common *prev;    struct backtrack_common *prev;
200    jump_list *nextfallbacks;    jump_list *nextbacktracks;
201    /* Internal stack (for component operators). */    /* Internal stack (for component operators). */
202    struct fallback_common *top;    struct backtrack_common *top;
203    jump_list *topfallbacks;    jump_list *topbacktracks;
204    /* Opcode pointer. */    /* Opcode pointer. */
205    uschar *cc;    pcre_uchar *cc;
206  } fallback_common;  } backtrack_common;
207    
208  typedef struct assert_fallback {  typedef struct assert_backtrack {
209    fallback_common common;    backtrack_common common;
210    jump_list *condfailed;    jump_list *condfailed;
211    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 (-1) if a frame is not needed. */
212    int framesize;    int framesize;
213    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
214    int localptr;    int private_data_ptr;
215    /* For iterators. */    /* For iterators. */
216    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
217  } assert_fallback;  } assert_backtrack;
218    
219  typedef struct bracket_fallback {  typedef struct bracket_backtrack {
220    fallback_common common;    backtrack_common common;
221    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
222    struct sljit_label *althotpath;    struct sljit_label *alternative_matchingpath;
223    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
224    struct sljit_label *recursivehotpath;    struct sljit_label *recursive_matchingpath;
225    /* For greedy ? operator. */    /* For greedy ? operator. */
226    struct sljit_label *zerohotpath;    struct sljit_label *zero_matchingpath;
227    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
228    union {    union {
229      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
230      jump_list *condfailed;      jump_list *condfailed;
231      assert_fallback *assert;      assert_backtrack *assert;
232      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. -1 if not needed. */
233      int framesize;      int framesize;
234    } u;    } u;
235    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
236    int localptr;    int private_data_ptr;
237  } bracket_fallback;  } bracket_backtrack;
238    
239  typedef struct bracketpos_fallback {  typedef struct bracketpos_backtrack {
240    fallback_common common;    backtrack_common common;
241    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
242    int localptr;    int private_data_ptr;
243    /* Reverting stack is needed. */    /* Reverting stack is needed. */
244    int framesize;    int framesize;
245    /* Allocated stack size. */    /* Allocated stack size. */
246    int stacksize;    int stacksize;
247  } bracketpos_fallback;  } bracketpos_backtrack;
248    
249  typedef struct braminzero_fallback {  typedef struct braminzero_backtrack {
250    fallback_common common;    backtrack_common common;
251    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
252  } braminzero_fallback;  } braminzero_backtrack;
253    
254  typedef struct iterator_fallback {  typedef struct iterator_backtrack {
255    fallback_common common;    backtrack_common common;
256    /* Next iteration. */    /* Next iteration. */
257    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
258  } iterator_fallback;  } iterator_backtrack;
259    
260  typedef struct recurse_entry {  typedef struct recurse_entry {
261    struct recurse_entry *next;    struct recurse_entry *next;
# Line 259  typedef struct recurse_entry { Line 267  typedef struct recurse_entry {
267    int start;    int start;
268  } recurse_entry;  } recurse_entry;
269    
270  typedef struct recurse_fallback {  typedef struct recurse_backtrack {
271    fallback_common common;    backtrack_common common;
272  } recurse_fallback;  } recurse_backtrack;
273    
274    #define MAX_RANGE_SIZE 6
275    
276  typedef struct compiler_common {  typedef struct compiler_common {
277    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
278    uschar *start;    pcre_uchar *start;
279    int localsize;  
280    int *localptrs;    /* Maps private data offset to each opcode. */
281    const uschar *fcc;    int *private_data_ptrs;
282    sljit_w lcc;    /* Tells whether the capturing bracket is optimized. */
283      pcre_uint8 *optimized_cbracket;
284      /* Starting offset of private data for capturing brackets. */
285    int cbraptr;    int cbraptr;
286      /* OVector starting point. Must be divisible by 2. */
287      int ovector_start;
288      /* Last known position of the requested byte. */
289      int req_char_ptr;
290      /* Head of the last recursion. */
291      int recursive_head;
292      /* First inspected character for partial matching. */
293      int start_used_ptr;
294      /* Starting pointer for partial soft matches. */
295      int hit_start;
296      /* End pointer of the first line. */
297      int first_line_end;
298      /* Points to the marked string. */
299      int mark_ptr;
300    
301      /* Flipped and lower case tables. */
302      const pcre_uint8 *fcc;
303      sljit_w lcc;
304      /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
305      int mode;
306      /* Newline control. */
307    int nltype;    int nltype;
308    int newline;    int newline;
309    int bsr_nltype;    int bsr_nltype;
310      /* Dollar endonly. */
311    int endonly;    int endonly;
312      BOOL has_set_som;
313      /* Tables. */
314    sljit_w ctypes;    sljit_w ctypes;
315      int digits[2 + MAX_RANGE_SIZE];
316      /* Named capturing brackets. */
317      sljit_uw name_table;
318      sljit_w name_count;
319      sljit_w name_entry_size;
320    
321      /* Labels and jump lists. */
322      struct sljit_label *partialmatchlabel;
323      struct sljit_label *quitlabel;
324    struct sljit_label *acceptlabel;    struct sljit_label *acceptlabel;
325    stub_list *stubs;    stub_list *stubs;
326    recurse_entry *entries;    recurse_entry *entries;
327    recurse_entry *currententry;    recurse_entry *currententry;
328      jump_list *partialmatch;
329      jump_list *quit;
330    jump_list *accept;    jump_list *accept;
331    jump_list *calllimit;    jump_list *calllimit;
332    jump_list *stackalloc;    jump_list *stackalloc;
# Line 291  typedef struct compiler_common { Line 338  typedef struct compiler_common {
338    jump_list *casefulcmp;    jump_list *casefulcmp;
339    jump_list *caselesscmp;    jump_list *caselesscmp;
340    BOOL jscript_compat;    BOOL jscript_compat;
341  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
342    BOOL utf8;    BOOL utf;
343  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
344    BOOL useucp;    BOOL use_ucp;
345    #endif
346    #ifndef COMPILE_PCRE32
347      jump_list *utfreadchar;
348  #endif  #endif
349    jump_list *utf8readchar;  #ifdef COMPILE_PCRE8
350    jump_list *utf8readtype8;    jump_list *utfreadtype8;
351  #endif  #endif
352    #endif /* SUPPORT_UTF */
353  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
354    jump_list *getucd;    jump_list *getucd;
355  #endif  #endif
# Line 310  typedef struct compare_context { Line 361  typedef struct compare_context {
361    int length;    int length;
362    int sourcereg;    int sourcereg;
363  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
364    int byteptr;    int ucharptr;
365    union {    union {
366      int asint;      sljit_i asint;
367      short asshort;      sljit_uh asushort;
368    #if defined COMPILE_PCRE8
369      sljit_ub asbyte;      sljit_ub asbyte;
370      sljit_ub asbytes[4];      sljit_ub asuchars[4];
371    #elif defined COMPILE_PCRE16
372        sljit_uh asuchars[2];
373    #elif defined COMPILE_PCRE32
374        sljit_ui asuchars[1];
375    #endif
376    } c;    } c;
377    union {    union {
378      int asint;      sljit_i asint;
379      short asshort;      sljit_uh asushort;
380    #if defined COMPILE_PCRE8
381      sljit_ub asbyte;      sljit_ub asbyte;
382      sljit_ub asbytes[4];      sljit_ub asuchars[4];
383    #elif defined COMPILE_PCRE16
384        sljit_uh asuchars[2];
385    #elif defined COMPILE_PCRE32
386        sljit_ui asuchars[1];
387    #endif
388    } oc;    } oc;
389  #endif  #endif
390  } compare_context;  } compare_context;
391    
392  enum {  enum {
393    frame_end = 0,    frame_end = 0,
394    frame_setstrbegin = -1    frame_setstrbegin = -1,
395      frame_setmark = -2
396  };  };
397    
398    /* Undefine sljit macros. */
399    #undef CMP
400    
401  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
402  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))
403    
404  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_TEMPORARY_REG1
405  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_TEMPORARY_REG3
406  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
407  #define STR_PTR       SLJIT_GENERAL_REG1  #define STR_PTR       SLJIT_SAVED_REG1
408  #define STR_END       SLJIT_GENERAL_REG2  #define STR_END       SLJIT_SAVED_REG2
409  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_TEMPORARY_REG2
410  #define STACK_LIMIT   SLJIT_GENERAL_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
411  #define ARGUMENTS     SLJIT_GENERAL_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
412  #define CALL_COUNT    SLJIT_GENERAL_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
413  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
414    
415  /* Locals layout. */  /* Local space layout. */
416  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
417  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_w))
418  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_w))
419  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
420  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_w))
421  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_w))
 /* Head of the last recursion. */  
 #define RECURSIVE_HEAD   (4 * sizeof(sljit_w))  
422  /* Max limit of recursions. */  /* Max limit of recursions. */
423  #define CALL_LIMIT       (5 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_w))
 /* Last known position of the requested byte. */  
 #define REQ_BYTE_PTR     (6 * sizeof(sljit_w))  
 /* End pointer of the first line. */  
 #define FIRSTLINE_END    (7 * sizeof(sljit_w))  
424  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
425  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
426  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
427  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
428  #define OVECTOR_START    (8 * sizeof(sljit_w))  #define OVECTOR_START    (common->ovector_start)
429  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))
430  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))
431  #define PRIV(cc)         (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
432    
433    #if defined COMPILE_PCRE8
434    #define MOV_UCHAR  SLJIT_MOV_UB
435    #define MOVU_UCHAR SLJIT_MOVU_UB
436    #elif defined COMPILE_PCRE16
437    #define MOV_UCHAR  SLJIT_MOV_UH
438    #define MOVU_UCHAR SLJIT_MOVU_UH
439    #elif defined COMPILE_PCRE32
440    #define MOV_UCHAR  SLJIT_MOV_UI
441    #define MOVU_UCHAR SLJIT_MOVU_UI
442    #else
443    #error Unsupported compiling mode
444    #endif
445    
446  /* Shortcuts. */  /* Shortcuts. */
447  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 390  the start pointers when the end of the c Line 464  the start pointers when the end of the c
464    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))
465  #define COND_VALUE(op, dst, dstw, type) \  #define COND_VALUE(op, dst, dstw, type) \
466    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))
467    #define GET_LOCAL_BASE(dst, dstw, offset) \
468      sljit_get_local_base(compiler, (dst), (dstw), (offset))
469    
470  static uschar* bracketend(uschar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
471  {  {
472  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));
473  do cc += GET(cc, 1); while (*cc == OP_ALT);  do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 402  return cc; Line 478  return cc;
478    
479  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
480   next_opcode   next_opcode
481   get_localspace   get_private_data_length
482   set_localptrs   set_private_data_ptrs
483   get_framesize   get_framesize
484   init_frame   init_frame
485   get_localsize   get_private_data_length_for_copy
486   copy_locals   copy_private_data
487   compile_hotpath   compile_matchingpath
488   compile_fallbackpath   compile_backtrackingpath
489  */  */
490    
491  static uschar *next_opcode(compiler_common *common, uschar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
492  {  {
493  SLJIT_UNUSED_ARG(common);  SLJIT_UNUSED_ARG(common);
494  switch(*cc)  switch(*cc)
# Line 461  switch(*cc) Line 537  switch(*cc)
537    case OP_BRAZERO:    case OP_BRAZERO:
538    case OP_BRAMINZERO:    case OP_BRAMINZERO:
539    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
540      case OP_COMMIT:
541    case OP_FAIL:    case OP_FAIL:
542    case OP_ACCEPT:    case OP_ACCEPT:
543    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
# Line 468  switch(*cc) Line 545  switch(*cc)
545    return cc + 1;    return cc + 1;
546    
547    case OP_ANYBYTE:    case OP_ANYBYTE:
548  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
549    if (common->utf8) return NULL;    if (common->utf) return NULL;
550  #endif  #endif
551    return cc + 1;    return cc + 1;
552    
# Line 477  switch(*cc) Line 554  switch(*cc)
554    case OP_CHARI:    case OP_CHARI:
555    case OP_NOT:    case OP_NOT:
556    case OP_NOTI:    case OP_NOTI:
   
557    case OP_STAR:    case OP_STAR:
558    case OP_MINSTAR:    case OP_MINSTAR:
559    case OP_PLUS:    case OP_PLUS:
# Line 515  switch(*cc) Line 591  switch(*cc)
591    case OP_NOTPOSPLUSI:    case OP_NOTPOSPLUSI:
592    case OP_NOTPOSQUERYI:    case OP_NOTPOSQUERYI:
593    cc += 2;    cc += 2;
594  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
595    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]);
596  #endif  #endif
597    return cc;    return cc;
598    
# Line 536  switch(*cc) Line 612  switch(*cc)
612    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
613    case OP_NOTEXACTI:    case OP_NOTEXACTI:
614    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
615    cc += 4;    cc += 2 + IMM2_SIZE;
616  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
617    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]);
618  #endif  #endif
619    return cc;    return cc;
620    
621    case OP_NOTPROP:    case OP_NOTPROP:
622    case OP_PROP:    case OP_PROP:
623      return cc + 1 + 2;
624    
625    case OP_TYPEUPTO:    case OP_TYPEUPTO:
626    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
627    case OP_TYPEEXACT:    case OP_TYPEEXACT:
# Line 551  switch(*cc) Line 629  switch(*cc)
629    case OP_REF:    case OP_REF:
630    case OP_REFI:    case OP_REFI:
631    case OP_CREF:    case OP_CREF:
632      case OP_NCREF:
633      case OP_RREF:
634      case OP_NRREF:
635    case OP_CLOSE:    case OP_CLOSE:
636    cc += 3;    cc += 1 + IMM2_SIZE;
637    return cc;    return cc;
638    
639    case OP_CRRANGE:    case OP_CRRANGE:
640    case OP_CRMINRANGE:    case OP_CRMINRANGE:
641    return cc + 5;    return cc + 1 + 2 * IMM2_SIZE;
642    
643    case OP_CLASS:    case OP_CLASS:
644    case OP_NCLASS:    case OP_NCLASS:
645    return cc + 33;    return cc + 1 + 32 / sizeof(pcre_uchar);
646    
647  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
648    case OP_XCLASS:    case OP_XCLASS:
649    return cc + GET(cc, 1);    return cc + GET(cc, 1);
650  #endif  #endif
# Line 593  switch(*cc) Line 674  switch(*cc)
674    case OP_CBRAPOS:    case OP_CBRAPOS:
675    case OP_SCBRA:    case OP_SCBRA:
676    case OP_SCBRAPOS:    case OP_SCBRAPOS:
677    return cc + 1 + LINK_SIZE + 2;    return cc + 1 + LINK_SIZE + IMM2_SIZE;
678    
679      case OP_MARK:
680      return cc + 1 + 2 + cc[1];
681    
682    default:    default:
683    return NULL;    return NULL;
684    }    }
685  }  }
686    
687  static int get_localspace(compiler_common *common, uschar *cc, uschar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
688        case OP_MINSTAR: \
689        case OP_MINPLUS: \
690        case OP_QUERY: \
691        case OP_MINQUERY: \
692        case OP_MINSTARI: \
693        case OP_MINPLUSI: \
694        case OP_QUERYI: \
695        case OP_MINQUERYI: \
696        case OP_NOTMINSTAR: \
697        case OP_NOTMINPLUS: \
698        case OP_NOTQUERY: \
699        case OP_NOTMINQUERY: \
700        case OP_NOTMINSTARI: \
701        case OP_NOTMINPLUSI: \
702        case OP_NOTQUERYI: \
703        case OP_NOTMINQUERYI:
704    
705    #define CASE_ITERATOR_PRIVATE_DATA_2A \
706        case OP_STAR: \
707        case OP_PLUS: \
708        case OP_STARI: \
709        case OP_PLUSI: \
710        case OP_NOTSTAR: \
711        case OP_NOTPLUS: \
712        case OP_NOTSTARI: \
713        case OP_NOTPLUSI:
714    
715    #define CASE_ITERATOR_PRIVATE_DATA_2B \
716        case OP_UPTO: \
717        case OP_MINUPTO: \
718        case OP_UPTOI: \
719        case OP_MINUPTOI: \
720        case OP_NOTUPTO: \
721        case OP_NOTMINUPTO: \
722        case OP_NOTUPTOI: \
723        case OP_NOTMINUPTOI:
724    
725    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
726        case OP_TYPEMINSTAR: \
727        case OP_TYPEMINPLUS: \
728        case OP_TYPEQUERY: \
729        case OP_TYPEMINQUERY:
730    
731    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
732        case OP_TYPESTAR: \
733        case OP_TYPEPLUS:
734    
735    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
736        case OP_TYPEUPTO: \
737        case OP_TYPEMINUPTO:
738    
739    static int get_class_iterator_size(pcre_uchar *cc)
740    {
741    switch(*cc)
742      {
743      case OP_CRSTAR:
744      case OP_CRPLUS:
745      return 2;
746    
747      case OP_CRMINSTAR:
748      case OP_CRMINPLUS:
749      case OP_CRQUERY:
750      case OP_CRMINQUERY:
751      return 1;
752    
753      case OP_CRRANGE:
754      case OP_CRMINRANGE:
755      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
756        return 0;
757      return 2;
758    
759      default:
760      return 0;
761      }
762    }
763    
764    static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
765  {  {
766  int localspace = 0;  int private_data_length = 0;
767  uschar *alternative;  pcre_uchar *alternative;
768    pcre_uchar *name;
769    pcre_uchar *end = NULL;
770    int space, size, i;
771    pcre_uint32 bracketlen;
772    
773  /* 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. */
774  while (cc < ccend)  while (cc < ccend)
775    {    {
776      space = 0;
777      size = 0;
778      bracketlen = 0;
779    switch(*cc)    switch(*cc)
780      {      {
781        case OP_SET_SOM:
782        common->has_set_som = TRUE;
783        cc += 1;
784        break;
785    
786        case OP_REF:
787        case OP_REFI:
788        common->optimized_cbracket[GET2(cc, 1)] = 0;
789        cc += 1 + IMM2_SIZE;
790        break;
791    
792      case OP_ASSERT:      case OP_ASSERT:
793      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
794      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 618  while (cc < ccend) Line 798  while (cc < ccend)
798      case OP_BRAPOS:      case OP_BRAPOS:
799      case OP_SBRA:      case OP_SBRA:
800      case OP_SBRAPOS:      case OP_SBRAPOS:
801      case OP_SCOND:      private_data_length += sizeof(sljit_w);
802      localspace += sizeof(sljit_w);      bracketlen = 1 + LINK_SIZE;
     cc += 1 + LINK_SIZE;  
803      break;      break;
804    
805      case OP_CBRAPOS:      case OP_CBRAPOS:
806      case OP_SCBRAPOS:      case OP_SCBRAPOS:
807      localspace += sizeof(sljit_w);      private_data_length += sizeof(sljit_w);
808      cc += 1 + LINK_SIZE + 2;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
809        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
810      break;      break;
811    
812      case OP_COND:      case OP_COND:
813      /* Might be a hidden SCOND. */      case OP_SCOND:
814      alternative = cc + GET(cc, 1);      bracketlen = cc[1 + LINK_SIZE];
815      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (bracketlen == OP_CREF)
816        localspace += sizeof(sljit_w);        {
817          bracketlen = GET2(cc, 1 + LINK_SIZE + 1);
818          common->optimized_cbracket[bracketlen] = 0;
819          }
820        else if (bracketlen == OP_NCREF)
821          {
822          bracketlen = GET2(cc, 1 + LINK_SIZE + 1);
823          name = (pcre_uchar *)common->name_table;
824          alternative = name;
825          for (i = 0; i < common->name_count; i++)
826            {
827            if (GET2(name, 0) == bracketlen) break;
828            name += common->name_entry_size;
829            }
830          SLJIT_ASSERT(i != common->name_count);
831    
832          for (i = 0; i < common->name_count; i++)
833            {
834            if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
835              common->optimized_cbracket[GET2(alternative, 0)] = 0;
836            alternative += common->name_entry_size;
837            }
838          }
839    
840        if (*cc == OP_COND)
841          {
842          /* Might be a hidden SCOND. */
843          alternative = cc + GET(cc, 1);
844          if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
845            private_data_length += sizeof(sljit_w);
846          }
847        else
848          private_data_length += sizeof(sljit_w);
849        bracketlen = 1 + LINK_SIZE;
850        break;
851    
852        case OP_BRA:
853        bracketlen = 1 + LINK_SIZE;
854        break;
855    
856        case OP_CBRA:
857        case OP_SCBRA:
858        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
859        break;
860    
861        CASE_ITERATOR_PRIVATE_DATA_1
862        space = 1;
863        size = -2;
864        break;
865    
866        CASE_ITERATOR_PRIVATE_DATA_2A
867        space = 2;
868        size = -2;
869        break;
870    
871        CASE_ITERATOR_PRIVATE_DATA_2B
872        space = 2;
873        size = -(2 + IMM2_SIZE);
874        break;
875    
876        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
877        space = 1;
878        size = 1;
879        break;
880    
881        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
882        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
883          space = 2;
884        size = 1;
885        break;
886    
887        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
888        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
889          space = 2;
890        size = 1 + IMM2_SIZE;
891        break;
892    
893        case OP_CLASS:
894        case OP_NCLASS:
895        size += 1 + 32 / sizeof(pcre_uchar);
896        space = get_class_iterator_size(cc + size);
897        break;
898    
899    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
900        case OP_XCLASS:
901        size = GET(cc, 1);
902        space = get_class_iterator_size(cc + size);
903        break;
904    #endif
905    
906        case OP_RECURSE:
907        /* Set its value only once. */
908        if (common->recursive_head == 0)
909          {
910          common->recursive_head = common->ovector_start;
911          common->ovector_start += sizeof(sljit_w);
912          }
913      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
914      break;      break;
915    
916        case OP_MARK:
917        if (common->mark_ptr == 0)
918          {
919          common->mark_ptr = common->ovector_start;
920          common->ovector_start += sizeof(sljit_w);
921          }
922        cc += 1 + 2 + cc[1];
923        break;
924    
925      default:      default:
926      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
927      if (cc == NULL)      if (cc == NULL)
928        return -1;        return -1;
929      break;      break;
930      }      }
931    
932      if (space > 0 && cc >= end)
933        private_data_length += sizeof(sljit_w) * space;
934    
935      if (size != 0)
936        {
937        if (size < 0)
938          {
939          cc += -size;
940    #ifdef SUPPORT_UTF
941          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
942    #endif
943          }
944        else
945          cc += size;
946        }
947    
948      if (bracketlen != 0)
949        {
950        if (cc >= end)
951          {
952          end = bracketend(cc);
953          if (end[-1 - LINK_SIZE] == OP_KET)
954            end = NULL;
955          }
956        cc += bracketlen;
957        }
958    }    }
959  return localspace;  return private_data_length;
960  }  }
961    
962  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)
963  {  {
964  uschar *cc = common->start;  pcre_uchar *cc = common->start;
965  uschar *alternative;  pcre_uchar *alternative;
966    pcre_uchar *end = NULL;
967    int space, size, bracketlen;
968    
969  while (cc < ccend)  while (cc < ccend)
970    {    {
971      space = 0;
972      size = 0;
973      bracketlen = 0;
974    switch(*cc)    switch(*cc)
975      {      {
976      case OP_ASSERT:      case OP_ASSERT:
# Line 665  while (cc < ccend) Line 983  while (cc < ccend)
983      case OP_SBRA:      case OP_SBRA:
984      case OP_SBRAPOS:      case OP_SBRAPOS:
985      case OP_SCOND:      case OP_SCOND:
986      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
987      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_w);
988      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
989      break;      break;
990    
991      case OP_CBRAPOS:      case OP_CBRAPOS:
992      case OP_SCBRAPOS:      case OP_SCBRAPOS:
993      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
994      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_w);
995      cc += 1 + LINK_SIZE + 2;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
996      break;      break;
997    
998      case OP_COND:      case OP_COND:
# Line 682  while (cc < ccend) Line 1000  while (cc < ccend)
1000      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1001      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1002        {        {
1003        common->localptrs[cc - common->start] = localptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1004        localptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_w);
1005        }        }
1006      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1007        break;
1008    
1009        case OP_BRA:
1010        bracketlen = 1 + LINK_SIZE;
1011        break;
1012    
1013        case OP_CBRA:
1014        case OP_SCBRA:
1015        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1016        break;
1017    
1018        CASE_ITERATOR_PRIVATE_DATA_1
1019        space = 1;
1020        size = -2;
1021        break;
1022    
1023        CASE_ITERATOR_PRIVATE_DATA_2A
1024        space = 2;
1025        size = -2;
1026        break;
1027    
1028        CASE_ITERATOR_PRIVATE_DATA_2B
1029        space = 2;
1030        size = -(2 + IMM2_SIZE);
1031      break;      break;
1032    
1033        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1034        space = 1;
1035        size = 1;
1036        break;
1037    
1038        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1039        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1040          space = 2;
1041        size = 1;
1042        break;
1043    
1044        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1045        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1046          space = 2;
1047        size = 1 + IMM2_SIZE;
1048        break;
1049    
1050        case OP_CLASS:
1051        case OP_NCLASS:
1052        size += 1 + 32 / sizeof(pcre_uchar);
1053        space = get_class_iterator_size(cc + size);
1054        break;
1055    
1056    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1057        case OP_XCLASS:
1058        size = GET(cc, 1);
1059        space = get_class_iterator_size(cc + size);
1060        break;
1061    #endif
1062    
1063      default:      default:
1064      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1065      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1066      break;      break;
1067      }      }
1068    
1069      if (space > 0 && cc >= end)
1070        {
1071        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1072        private_data_ptr += sizeof(sljit_w) * space;
1073        }
1074    
1075      if (size != 0)
1076        {
1077        if (size < 0)
1078          {
1079          cc += -size;
1080    #ifdef SUPPORT_UTF
1081          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1082    #endif
1083          }
1084        else
1085          cc += size;
1086        }
1087    
1088      if (bracketlen > 0)
1089        {
1090        if (cc >= end)
1091          {
1092          end = bracketend(cc);
1093          if (end[-1 - LINK_SIZE] == OP_KET)
1094            end = NULL;
1095          }
1096        cc += bracketlen;
1097        }
1098    }    }
1099  }  }
1100    
1101  /* Returns with -1 if no need for frame. */  /* Returns with -1 if no need for frame. */
1102  static int get_framesize(compiler_common *common, uschar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)
1103  {  {
1104  uschar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc);
1105  int length = 0;  int length = 0;
1106  BOOL possessive = FALSE;  BOOL possessive = FALSE;
1107  BOOL setsom_found = FALSE;  BOOL setsom_found = recursive;
1108    BOOL setmark_found = recursive;
1109    
1110  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1111    {    {
# Line 716  while (cc < ccend) Line 1119  while (cc < ccend)
1119    switch(*cc)    switch(*cc)
1120      {      {
1121      case OP_SET_SOM:      case OP_SET_SOM:
1122      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1123      if (!setsom_found)      if (!setsom_found)
1124        {        {
1125        length += 2;        length += 2;
1126        setsom_found = TRUE;        setsom_found = TRUE;
1127        }        }
1128      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      cc += 1;
1129        break;
1130    
1131        case OP_MARK:
1132        SLJIT_ASSERT(common->mark_ptr != 0);
1133        if (!setmark_found)
1134          {
1135          length += 2;
1136          setmark_found = TRUE;
1137          }
1138        cc += 1 + 2 + cc[1];
1139        break;
1140    
1141        case OP_RECURSE:
1142        if (common->has_set_som && !setsom_found)
1143          {
1144          length += 2;
1145          setsom_found = TRUE;
1146          }
1147        if (common->mark_ptr != 0 && !setmark_found)
1148          {
1149          length += 2;
1150          setmark_found = TRUE;
1151          }
1152        cc += 1 + LINK_SIZE;
1153      break;      break;
1154    
1155      case OP_CBRA:      case OP_CBRA:
# Line 730  while (cc < ccend) Line 1157  while (cc < ccend)
1157      case OP_SCBRA:      case OP_SCBRA:
1158      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1159      length += 3;      length += 3;
1160      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1161      break;      break;
1162    
1163      default:      default:
# Line 748  if (length > 0) Line 1175  if (length > 0)
1175  return -1;  return -1;
1176  }  }
1177    
1178  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)
1179  {  {
1180  DEFINE_COMPILER;  DEFINE_COMPILER;
1181  uschar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc);
1182  BOOL setsom_found = FALSE;  BOOL setsom_found = recursive;
1183    BOOL setmark_found = recursive;
1184  int offset;  int offset;
1185    
1186  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
1187    SLJIT_UNUSED_ARG(stacktop);
1188  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1189    
1190  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
# Line 766  while (cc < ccend) Line 1195  while (cc < ccend)
1195    switch(*cc)    switch(*cc)
1196      {      {
1197      case OP_SET_SOM:      case OP_SET_SOM:
1198      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1199      if (!setsom_found)      if (!setsom_found)
1200        {        {
1201        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
# Line 776  while (cc < ccend) Line 1205  while (cc < ccend)
1205        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_w);
1206        setsom_found = TRUE;        setsom_found = TRUE;
1207        }        }
1208      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      cc += 1;
1209        break;
1210    
1211        case OP_MARK:
1212        SLJIT_ASSERT(common->mark_ptr != 0);
1213        if (!setmark_found)
1214          {
1215          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1216          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark);
1217          stackpos += (int)sizeof(sljit_w);
1218          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1219          stackpos += (int)sizeof(sljit_w);
1220          setmark_found = TRUE;
1221          }
1222        cc += 1 + 2 + cc[1];
1223        break;
1224    
1225        case OP_RECURSE:
1226        if (common->has_set_som && !setsom_found)
1227          {
1228          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1229          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);
1230          stackpos += (int)sizeof(sljit_w);
1231          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1232          stackpos += (int)sizeof(sljit_w);
1233          setsom_found = TRUE;
1234          }
1235        if (common->mark_ptr != 0 && !setmark_found)
1236          {
1237          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1238          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark);
1239          stackpos += (int)sizeof(sljit_w);
1240          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1241          stackpos += (int)sizeof(sljit_w);
1242          setmark_found = TRUE;
1243          }
1244        cc += 1 + LINK_SIZE;
1245      break;      break;
1246    
1247      case OP_CBRA:      case OP_CBRA:
# Line 793  while (cc < ccend) Line 1258  while (cc < ccend)
1258      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1259      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_w);
1260    
1261      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1262      break;      break;
1263    
1264      default:      default:
# Line 806  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), st Line 1271  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), st
1271  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1272  }  }
1273    
1274  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)
1275  {  {
1276  int localsize = 2;  int private_data_length = 2;
1277  uschar *alternative;  int size;
1278  /* Calculate the sum of the local variables. */  pcre_uchar *alternative;
1279    /* Calculate the sum of the private machine words. */
1280  while (cc < ccend)  while (cc < ccend)
1281    {    {
1282      size = 0;
1283    switch(*cc)    switch(*cc)
1284      {      {
1285      case OP_ASSERT:      case OP_ASSERT:
# Line 825  while (cc < ccend) Line 1292  while (cc < ccend)
1292      case OP_SBRA:      case OP_SBRA:
1293      case OP_SBRAPOS:      case OP_SBRAPOS:
1294      case OP_SCOND:      case OP_SCOND:
1295      localsize++;      private_data_length++;
1296      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1297      break;      break;
1298    
1299      case OP_CBRA:      case OP_CBRA:
1300      case OP_SCBRA:      case OP_SCBRA:
1301      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1302      cc += 1 + LINK_SIZE + 2;        private_data_length++;
1303        cc += 1 + LINK_SIZE + IMM2_SIZE;
1304      break;      break;
1305    
1306      case OP_CBRAPOS:      case OP_CBRAPOS:
1307      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1308      localsize += 2;      private_data_length += 2;
1309      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1310      break;      break;
1311    
1312      case OP_COND:      case OP_COND:
1313      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1314      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1315      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1316        localsize++;        private_data_length++;
1317      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1318      break;      break;
1319    
1320        CASE_ITERATOR_PRIVATE_DATA_1
1321        if (PRIVATE_DATA(cc))
1322          private_data_length++;
1323        cc += 2;
1324    #ifdef SUPPORT_UTF
1325        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1326    #endif
1327        break;
1328    
1329        CASE_ITERATOR_PRIVATE_DATA_2A
1330        if (PRIVATE_DATA(cc))
1331          private_data_length += 2;
1332        cc += 2;
1333    #ifdef SUPPORT_UTF
1334        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1335    #endif
1336        break;
1337    
1338        CASE_ITERATOR_PRIVATE_DATA_2B
1339        if (PRIVATE_DATA(cc))
1340          private_data_length += 2;
1341        cc += 2 + IMM2_SIZE;
1342    #ifdef SUPPORT_UTF
1343        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1344    #endif
1345        break;
1346    
1347        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1348        if (PRIVATE_DATA(cc))
1349          private_data_length++;
1350        cc += 1;
1351        break;
1352    
1353        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1354        if (PRIVATE_DATA(cc))
1355          private_data_length += 2;
1356        cc += 1;
1357        break;
1358    
1359        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1360        if (PRIVATE_DATA(cc))
1361          private_data_length += 2;
1362        cc += 1 + IMM2_SIZE;
1363        break;
1364    
1365        case OP_CLASS:
1366        case OP_NCLASS:
1367    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1368        case OP_XCLASS:
1369        size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1370    #else
1371        size = 1 + 32 / (int)sizeof(pcre_uchar);
1372    #endif
1373        if (PRIVATE_DATA(cc))
1374          private_data_length += get_class_iterator_size(cc + size);
1375        cc += size;
1376        break;
1377    
1378      default:      default:
1379      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1380      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 856  while (cc < ccend) Line 1382  while (cc < ccend)
1382      }      }
1383    }    }
1384  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1385  return localsize;  return private_data_length;
1386  }  }
1387    
1388  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,
1389    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop)
1390  {  {
1391  DEFINE_COMPILER;  DEFINE_COMPILER;
1392  int srcw[2];  int srcw[2];
1393  int count;  int count, size;
1394  BOOL tmp1next = TRUE;  BOOL tmp1next = TRUE;
1395  BOOL tmp1empty = TRUE;  BOOL tmp1empty = TRUE;
1396  BOOL tmp2empty = TRUE;  BOOL tmp2empty = TRUE;
1397  uschar *alternative;  pcre_uchar *alternative;
1398  enum {  enum {
1399    start,    start,
1400    loop,    loop,
# Line 903  while (status != end) Line 1429  while (status != end)
1429    switch(status)    switch(status)
1430      {      {
1431      case start:      case start:
1432      SLJIT_ASSERT(save);      SLJIT_ASSERT(save && common->recursive_head != 0);
1433      count = 1;      count = 1;
1434      srcw[0] = RECURSIVE_HEAD;      srcw[0] = common->recursive_head;
1435      status = loop;      status = loop;
1436      break;      break;
1437    
# Line 929  while (status != end) Line 1455  while (status != end)
1455        case OP_SBRAPOS:        case OP_SBRAPOS:
1456        case OP_SCOND:        case OP_SCOND:
1457        count = 1;        count = 1;
1458        srcw[0] = PRIV(cc);        srcw[0] = PRIVATE_DATA(cc);
1459        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1460        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1461        break;        break;
1462    
1463        case OP_CBRA:        case OP_CBRA:
1464        case OP_SCBRA:        case OP_SCBRA:
1465        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1466        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1467        cc += 1 + LINK_SIZE + 2;          count = 1;
1468            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1469            }
1470          cc += 1 + LINK_SIZE + IMM2_SIZE;
1471        break;        break;
1472    
1473        case OP_CBRAPOS:        case OP_CBRAPOS:
1474        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1475        count = 2;        count = 2;
1476          srcw[0] = PRIVATE_DATA(cc);
1477        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1478        srcw[0] = PRIV(cc);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
1479        SLJIT_ASSERT(srcw[0] != 0);        cc += 1 + LINK_SIZE + IMM2_SIZE;
       cc += 1 + LINK_SIZE + 2;  
1480        break;        break;
1481    
1482        case OP_COND:        case OP_COND:
# Line 956  while (status != end) Line 1485  while (status != end)
1485        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1486          {          {
1487          count = 1;          count = 1;
1488          srcw[0] = PRIV(cc);          srcw[0] = PRIVATE_DATA(cc);
1489          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1490          }          }
1491        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1492        break;        break;
1493    
1494        default:        CASE_ITERATOR_PRIVATE_DATA_1
1495        cc = next_opcode(common, cc);        if (PRIVATE_DATA(cc))
1496        SLJIT_ASSERT(cc != NULL);          {
1497            count = 1;
1498            srcw[0] = PRIVATE_DATA(cc);
1499            }
1500          cc += 2;
1501    #ifdef SUPPORT_UTF
1502          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1503    #endif
1504        break;        break;
1505        }  
1506          CASE_ITERATOR_PRIVATE_DATA_2A
1507          if (PRIVATE_DATA(cc))
1508            {
1509            count = 2;
1510            srcw[0] = PRIVATE_DATA(cc);
1511            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);
1512            }
1513          cc += 2;
1514    #ifdef SUPPORT_UTF
1515          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1516    #endif
1517          break;
1518    
1519          CASE_ITERATOR_PRIVATE_DATA_2B
1520          if (PRIVATE_DATA(cc))
1521            {
1522            count = 2;
1523            srcw[0] = PRIVATE_DATA(cc);
1524            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);
1525            }
1526          cc += 2 + IMM2_SIZE;
1527    #ifdef SUPPORT_UTF
1528          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1529    #endif
1530          break;
1531    
1532          CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1533          if (PRIVATE_DATA(cc))
1534            {
1535            count = 1;
1536            srcw[0] = PRIVATE_DATA(cc);
1537            }
1538          cc += 1;
1539          break;
1540    
1541          CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1542          if (PRIVATE_DATA(cc))
1543            {
1544            count = 2;
1545            srcw[0] = PRIVATE_DATA(cc);
1546            srcw[1] = srcw[0] + sizeof(sljit_w);
1547            }
1548          cc += 1;
1549          break;
1550    
1551          CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1552          if (PRIVATE_DATA(cc))
1553            {
1554            count = 2;
1555            srcw[0] = PRIVATE_DATA(cc);
1556            srcw[1] = srcw[0] + sizeof(sljit_w);
1557            }
1558          cc += 1 + IMM2_SIZE;
1559          break;
1560    
1561          case OP_CLASS:
1562          case OP_NCLASS:
1563    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1564          case OP_XCLASS:
1565          size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1566    #else
1567          size = 1 + 32 / (int)sizeof(pcre_uchar);
1568    #endif
1569          if (PRIVATE_DATA(cc))
1570            switch(get_class_iterator_size(cc + size))
1571              {
1572              case 1:
1573              count = 1;
1574              srcw[0] = PRIVATE_DATA(cc);
1575              break;
1576    
1577              case 2:
1578              count = 2;
1579              srcw[0] = PRIVATE_DATA(cc);
1580              srcw[1] = srcw[0] + sizeof(sljit_w);
1581              break;
1582    
1583              default:
1584              SLJIT_ASSERT_STOP();
1585              break;
1586              }
1587          cc += size;
1588          break;
1589    
1590          default:
1591          cc = next_opcode(common, cc);
1592          SLJIT_ASSERT(cc != NULL);
1593          break;
1594          }
1595      break;      break;
1596    
1597      case end:      case end:
# Line 1064  if (save) Line 1689  if (save)
1689  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1690  }  }
1691    
1692  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  #undef CASE_ITERATOR_PRIVATE_DATA_1
1693    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1694    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1695    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1696    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1697    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1698    
1699    static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1700  {  {
1701  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1702  }  }
# Line 1074  static SLJIT_INLINE void set_jumps(jump_ Line 1706  static SLJIT_INLINE void set_jumps(jump_
1706  while (list)  while (list)
1707    {    {
1708    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1709    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1710    sljit_set_label(list->jump, label);    sljit_set_label(list->jump, label);
1711    list = list->next;    list = list->next;
1712    }    }
# Line 1101  if (list_item) Line 1733  if (list_item)
1733    list_item->type = type;    list_item->type = type;
1734    list_item->data = data;    list_item->data = data;
1735    list_item->start = start;    list_item->start = start;
1736    list_item->leave = LABEL();    list_item->quit = LABEL();
1737    list_item->next = common->stubs;    list_item->next = common->stubs;
1738    common->stubs = list_item;    common->stubs = list_item;
1739    }    }
# Line 1121  while (list_item) Line 1753  while (list_item)
1753      add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));      add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
1754      break;      break;
1755      }      }
1756    JUMPTO(SLJIT_JUMP, list_item->leave);    JUMPTO(SLJIT_JUMP, list_item->quit);
1757    list_item = list_item->next;    list_item = list_item->next;
1758    }    }
1759  common->stubs = NULL;  common->stubs = NULL;
# Line 1164  struct sljit_label *loop; Line 1796  struct sljit_label *loop;
1796  int i;  int i;
1797  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
1798  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
1799  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_GENERAL_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, 1);  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
1800  if (length < 8)  if (length < 8)
1801    {    {
1802    for (i = 0; i < length; i++)    for (i = 0; i < length; i++)
# Line 1172  if (length < 8) Line 1804  if (length < 8)
1804    }    }
1805  else  else
1806    {    {
1807    OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));
1808    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);
1809    loop = LABEL();    loop = LABEL();
1810    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
# Line 1188  struct sljit_label *loop; Line 1820  struct sljit_label *loop;
1820  struct sljit_jump *earlyexit;  struct sljit_jump *earlyexit;
1821    
1822  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
1823  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));
1824  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);
1825    
1826  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);
1827    if (common->mark_ptr != 0)
1828      OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1829  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));
1830    if (common->mark_ptr != 0)
1831      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_TEMPORARY_REG3, 0);
1832  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
1833  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
1834  OP2(SLJIT_ADD, SLJIT_GENERAL_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
1835  /* Unlikely, but possible */  /* Unlikely, but possible */
1836  earlyexit = CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0);  earlyexit = CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0);
1837  loop = LABEL();  loop = LABEL();
1838  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_TEMPORARY_REG1, 0);
1839  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_w));
1840  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
1841  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_GENERAL_REG2, 0);  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1842    OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
1843    #endif
1844    OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
1845  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);
1846  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
1847  JUMPHERE(earlyexit);  JUMPHERE(earlyexit);
# Line 1210  JUMPHERE(earlyexit); Line 1849  JUMPHERE(earlyexit);
1849  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
1850  if (topbracket > 1)  if (topbracket > 1)
1851    {    {
1852    OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START + topbracket * 2 * sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_w));
1853    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);
1854    
1855    /* OVECTOR(0) is never equal to SLJIT_GENERAL_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
1856    loop = LABEL();    loop = LABEL();
1857    OP1(SLJIT_MOVU, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), -(2 * (sljit_w)sizeof(sljit_w)));    OP1(SLJIT_MOVU, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), -(2 * (sljit_w)sizeof(sljit_w)));
1858    OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);
1859    CMPTO(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG3, 0, SLJIT_GENERAL_REG3, 0, loop);    CMPTO(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG3, 0, loop);
1860    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);
1861    }    }
1862  else  else
1863    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
1864  }  }
1865    
1866  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)
1867    {
1868    DEFINE_COMPILER;
1869    
1870    SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
1871    SLJIT_ASSERT(common->start_used_ptr != 0 && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
1872    
1873    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);
1874    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
1875    OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsetcount));
1876    CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, quit);
1877    
1878    /* Store match begin and end. */
1879    OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, begin));
1880    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
1881    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);
1882    OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);
1883    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1884    OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
1885    #endif
1886    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);
1887    
1888    OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG1, 0);
1889    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1890    OP2(SLJIT_ASHR, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
1891    #endif
1892    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), 0, SLJIT_TEMPORARY_REG3, 0);
1893    
1894    JUMPTO(SLJIT_JUMP, quit);
1895    }
1896    
1897    static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)
1898    {
1899    /* May destroy TMP1. */
1900    DEFINE_COMPILER;
1901    struct sljit_jump *jump;
1902    
1903    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
1904      {
1905      /* The value of -1 must be kept for start_used_ptr! */
1906      OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, 1);
1907      /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting
1908      is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */
1909      jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_PTR, 0);
1910      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
1911      JUMPHERE(jump);
1912      }
1913    else if (common->mode == JIT_PARTIAL_HARD_COMPILE)
1914      {
1915      jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
1916      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
1917      JUMPHERE(jump);
1918      }
1919    }
1920    
1921    static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar* cc)
1922  {  {
1923  /* Detects if the character has an othercase. */  /* Detects if the character has an othercase. */
1924  unsigned int c;  unsigned int c;
1925    
1926  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
1927  if (common->utf8)  if (common->utf)
1928    {    {
1929    GETCHAR(c, cc);    GETCHAR(c, cc);
1930    if (c > 127)    if (c > 127)
# Line 1241  if (common->utf8) Line 1935  if (common->utf8)
1935      return FALSE;      return FALSE;
1936  #endif  #endif
1937      }      }
1938    #ifndef COMPILE_PCRE8
1939      return common->fcc[c] != c;
1940    #endif
1941    }    }
1942  else  else
1943  #endif  #endif
1944    c = *cc;    c = *cc;
1945  return common->fcc[c] != c;  return MAX_255(c) ? common->fcc[c] != c : FALSE;
1946  }  }
1947    
1948  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)
1949  {  {
1950  /* Returns with the othercase. */  /* Returns with the othercase. */
1951  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
1952  if (common->utf8 && c > 127)  if (common->utf && c > 127)
1953    {    {
1954  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
1955    return UCD_OTHERCASE(c);    return UCD_OTHERCASE(c);
# Line 1261  if (common->utf8 && c > 127) Line 1958  if (common->utf8 && c > 127)
1958  #endif  #endif
1959    }    }
1960  #endif  #endif
1961  return common->fcc[c];  return TABLE_GET(c, common->fcc, c);
1962  }  }
1963    
1964  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)
1965  {  {
1966  /* Detects if the character and its othercase has only 1 bit difference. */  /* Detects if the character and its othercase has only 1 bit difference. */
1967  unsigned int c, oc, bit;  unsigned int c, oc, bit;
1968  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
1969  int n;  int n;
1970  #endif  #endif
1971    
1972  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
1973  if (common->utf8)  if (common->utf)
1974    {    {
1975    GETCHAR(c, cc);    GETCHAR(c, cc);
1976    if (c <= 127)    if (c <= 127)
# Line 1290  if (common->utf8) Line 1987  if (common->utf8)
1987  else  else
1988    {    {
1989    c = *cc;    c = *cc;
1990    oc = common->fcc[c];    oc = TABLE_GET(c, common->fcc, c);
1991    }    }
1992  #else  #else
1993  c = *cc;  c = *cc;
1994  oc = common->fcc[c];  oc = TABLE_GET(c, common->fcc, c);
1995  #endif  #endif
1996    
1997  SLJIT_ASSERT(c != oc);  SLJIT_ASSERT(c != oc);
# Line 1305  if (c <= 127 && bit == 0x20) Line 2002  if (c <= 127 && bit == 0x20)
2002    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2003    
2004  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2005  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2006    return 0;    return 0;
2007    
2008  #ifdef SUPPORT_UTF8  #if defined COMPILE_PCRE8
2009  if (common->utf8 && c > 127)  
2010    #ifdef SUPPORT_UTF
2011    if (common->utf && c > 127)
2012    {    {
2013    n = _pcre_utf8_table4[*cc & 0x3f];    n = GET_EXTRALEN(*cc);
2014    while ((bit & 0x3f) == 0)    while ((bit & 0x3f) == 0)
2015      {      {
2016      n--;      n--;
# Line 1319  if (common->utf8 && c > 127) Line 2018  if (common->utf8 && c > 127)
2018      }      }
2019    return (n << 8) | bit;    return (n << 8) | bit;
2020    }    }
2021  #endif  #endif /* SUPPORT_UTF */
2022  return (0 << 8) | bit;  return (0 << 8) | bit;
2023    
2024    #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2025    
2026    #ifdef SUPPORT_UTF
2027    if (common->utf && c > 65535)
2028      {
2029      if (bit >= (1 << 10))
2030        bit >>= 10;
2031      else
2032        return (bit < 256) ? ((2 << 8) | bit) : ((3 << 8) | (bit >> 8));
2033      }
2034    #endif /* SUPPORT_UTF */
2035    return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
2036    
2037    #endif /* COMPILE_PCRE[8|16|32] */
2038    }
2039    
2040    static void check_partial(compiler_common *common, BOOL force)
2041    {
2042    /* Checks whether a partial matching is occured. Does not modify registers. */
2043    DEFINE_COMPILER;
2044    struct sljit_jump *jump = NULL;
2045    
2046    SLJIT_ASSERT(!force || common->mode != JIT_COMPILE);
2047    
2048    if (common->mode == JIT_COMPILE)
2049      return;
2050    
2051    if (!force)
2052      jump = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2053    else if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2054      jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2055    
2056    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2057      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
2058    else
2059      {
2060      if (common->partialmatchlabel != NULL)
2061        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2062      else
2063        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2064      }
2065    
2066    if (jump != NULL)
2067      JUMPHERE(jump);
2068    }
2069    
2070    static struct sljit_jump *check_str_end(compiler_common *common)
2071    {
2072    /* Does not affect registers. Usually used in a tight spot. */
2073    DEFINE_COMPILER;
2074    struct sljit_jump *jump;
2075    struct sljit_jump *nohit;
2076    struct sljit_jump *return_value;
2077    
2078    if (common->mode == JIT_COMPILE)
2079      return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2080    
2081    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2082    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2083      {
2084      nohit = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2085      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
2086      JUMPHERE(nohit);
2087      return_value = JUMP(SLJIT_JUMP);
2088      }
2089    else
2090      {
2091      return_value = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2092      if (common->partialmatchlabel != NULL)
2093        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2094      else
2095        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2096      }
2097    JUMPHERE(jump);
2098    return return_value;
2099  }  }
2100    
2101  static SLJIT_INLINE void check_input_end(compiler_common *common, jump_list **fallbacks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
2102  {  {
2103  DEFINE_COMPILER;  DEFINE_COMPILER;
2104  add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));  struct sljit_jump *jump;
2105    
2106    if (common->mode == JIT_COMPILE)
2107      {
2108      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2109      return;
2110      }
2111    
2112    /* Partial matching mode. */
2113    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2114    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2115    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2116      {
2117      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
2118      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2119      }
2120    else
2121      {
2122      if (common->partialmatchlabel != NULL)
2123        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2124      else
2125        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2126      }
2127    JUMPHERE(jump);
2128  }  }
2129    
2130  static void read_char(compiler_common *common)  static void read_char(compiler_common *common)
# Line 1334  static void read_char(compiler_common *c Line 2132  static void read_char(compiler_common *c
2132  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2133  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2134  DEFINE_COMPILER;  DEFINE_COMPILER;
2135  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2136  struct sljit_jump *jump;  struct sljit_jump *jump;
2137  #endif  #endif
2138    
2139  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2140  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2141  if (common->utf8)  if (common->utf)
2142    {    {
2143    #if defined COMPILE_PCRE8
2144    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2145    add_jump(compiler, &common->utf8readchar, JUMP(SLJIT_FAST_CALL));  #elif defined COMPILE_PCRE16
2146      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2147    #endif /* COMPILE_PCRE[8|16] */
2148      add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2149    JUMPHERE(jump);    JUMPHERE(jump);
2150    }    }
2151  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2152  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));
2153  }  }
2154    
2155  static void peek_char(compiler_common *common)  static void peek_char(compiler_common *common)
# Line 1355  static void peek_char(compiler_common *c Line 2157  static void peek_char(compiler_common *c
2157  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2158  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2159  DEFINE_COMPILER;  DEFINE_COMPILER;
2160  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2161  struct sljit_jump *jump;  struct sljit_jump *jump;
2162  #endif  #endif
2163    
2164  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2165  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2166  if (common->utf8)  if (common->utf)
2167    {    {
2168    #if defined COMPILE_PCRE8
2169    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2170    add_jump(compiler, &common->utf8readchar, JUMP(SLJIT_FAST_CALL));  #elif defined COMPILE_PCRE16
2171      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2172    #endif /* COMPILE_PCRE[8|16] */
2173      add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2174    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2175    JUMPHERE(jump);    JUMPHERE(jump);
2176    }    }
2177  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2178  }  }
2179    
2180  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2181  {  {
2182  /* 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. */
2183  DEFINE_COMPILER;  DEFINE_COMPILER;
2184  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2185  struct sljit_jump *jump;  struct sljit_jump *jump;
2186  #endif  #endif
2187    
2188  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2189  if (common->utf8)  if (common->utf)
2190    {    {
2191    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2192    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));
2193    #if defined COMPILE_PCRE8
2194    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2195    it is a clever early read in most cases. */    it is needed in most cases. */
2196    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2197    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2198    add_jump(compiler, &common->utf8readtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2199    JUMPHERE(jump);    JUMPHERE(jump);
2200    #elif defined COMPILE_PCRE16
2201      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2202      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2203      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2204      JUMPHERE(jump);
2205      /* Skip low surrogate if necessary. */
2206      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2207      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2208      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);
2209      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2210      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2211    #elif defined COMPILE_PCRE32
2212      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2213      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2214      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2215      JUMPHERE(jump);
2216    #endif /* COMPILE_PCRE[8|16|32] */
2217    return;    return;
2218    }    }
2219    #endif /* SUPPORT_UTF */
2220    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2221    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2222    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2223    /* The ctypes array contains only 256 values. */
2224    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2225    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2226    #endif
2227    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2228    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2229    JUMPHERE(jump);
2230  #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);  
2231  }  }
2232    
2233  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
2234  {  {
2235  /* 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. */
2236  DEFINE_COMPILER;  DEFINE_COMPILER;
2237  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2238    #if defined COMPILE_PCRE8
2239  struct sljit_label *label;  struct sljit_label *label;
2240    
2241  if (common->utf8)  if (common->utf)
2242    {    {
2243    label = LABEL();    label = LABEL();
2244    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
2245    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));
2246    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);
2247    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2248    return;    return;
2249    }    }
2250  #endif  #elif defined COMPILE_PCRE16
2251  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  if (common->utf)
2252      {
2253      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
2254      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2255      /* Skip low surrogate if necessary. */
2256      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2257      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);
2258      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);
2259      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2260      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2261      return;
2262      }
2263    #endif /* COMPILE_PCRE[8|16] */
2264    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2265    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2266  }  }
2267    
2268  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)
2269  {  {
2270  /* 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. */
2271  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1426  DEFINE_COMPILER; Line 2273  DEFINE_COMPILER;
2273  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2274    {    {
2275    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2276    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));
2277    }    }
2278  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2279    {    {
# Line 1434  else if (nltype == NLTYPE_ANYCRLF) Line 2281  else if (nltype == NLTYPE_ANYCRLF)
2281    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);
2282    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);
2283    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
2284    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));
2285    }    }
2286  else  else
2287    {    {
2288    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline <= 255);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2289    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));
2290    }    }
2291  }  }
2292    
2293  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2294  static void do_utf8readchar(compiler_common *common)  
2295    #if defined COMPILE_PCRE8
2296    static void do_utfreadchar(compiler_common *common)
2297  {  {
2298  /* Fast decoding an utf8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2299  of the character (>= 0xc0). Return char value in TMP1, length - 1 in TMP2. */  of the character (>= 0xc0). Return char value in TMP1, length - 1 in TMP2. */
2300  DEFINE_COMPILER;  DEFINE_COMPILER;
2301  struct sljit_jump *jump;  struct sljit_jump *jump;
2302    
2303  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2304  /* Searching for the first zero. */  /* Searching for the first zero. */
2305  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);
2306  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2307  /* 2 byte sequence */  /* Two byte sequence. */
2308  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2309  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));
2310  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);
2311  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2312  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2313  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2314  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
2315  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2316  JUMPHERE(jump);  JUMPHERE(jump);
2317    
2318  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);
2319  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2320  /* 3 byte sequence */  /* Three byte sequence. */
2321  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2322  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);
2323  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);
2324  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2325  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2326  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2327  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 2);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2328  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));
2329  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2330  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2331  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 2);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2332  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2333  JUMPHERE(jump);  JUMPHERE(jump);
2334    
2335  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x08);  /* Four byte sequence. */
2336  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);  
2337  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);
2338  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);
2339  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2340  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);
2341  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2342  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 2);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 3);  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 3);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 3);  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 JUMPHERE(jump);  
   
 /* 5 byte sequence */  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x03);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 24);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 18);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 2);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 3);  
2343  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2344  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2345  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2346  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 4);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));
2347  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 4);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2348  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2349  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2350  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 4);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
2351  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2352  }  }
2353    
2354  static void do_utf8readtype8(compiler_common *common)  static void do_utfreadtype8(compiler_common *common)
2355  {  {
2356  /* Fast decoding an utf8 character type. TMP2 contains the first byte  /* Fast decoding a UTF-8 character type. TMP2 contains the first byte
2357  of the character (>= 0xc0) and TMP1 is destroyed. Return value in TMP1. */  of the character (>= 0xc0). Return value in TMP1. */
2358  DEFINE_COMPILER;  DEFINE_COMPILER;
2359  struct sljit_jump *jump;  struct sljit_jump *jump;
2360  struct sljit_jump *compare;  struct sljit_jump *compare;
2361    
2362  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2363    
2364  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);
2365  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2366  /* 2 byte sequence */  /* Two byte sequence. */
2367  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2368  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));
2369  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2370  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2371  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
# Line 1556  sljit_emit_fast_return(compiler, RETURN_ Line 2380  sljit_emit_fast_return(compiler, RETURN_
2380  JUMPHERE(jump);  JUMPHERE(jump);
2381    
2382  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2383  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)_pcre_utf8_char_sizes - 0xc0);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0);
2384  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2385  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2386  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2387  }  }
2388    
2389  #endif  #elif defined COMPILE_PCRE16
2390    
2391    static void do_utfreadchar(compiler_common *common)
2392    {
2393    /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char
2394    of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */
2395    DEFINE_COMPILER;
2396    struct sljit_jump *jump;
2397    
2398    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2399    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);
2400    /* Do nothing, only return. */
2401    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2402    
2403    JUMPHERE(jump);
2404    /* Combine two 16 bit characters. */
2405    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2406    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2407    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2408    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);
2409    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff);
2410    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2411    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
2412    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2413    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2414    }
2415    
2416    #endif /* COMPILE_PCRE[8|16] */
2417    
2418    #endif /* SUPPORT_UTF */
2419    
2420  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2421    
# Line 1578  DEFINE_COMPILER; Line 2431  DEFINE_COMPILER;
2431    
2432  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);
2433    
2434  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2435  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2436  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_w)_pcre_ucd_stage1);  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(ucd_stage1));
2437  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2438  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2439  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2440  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)_pcre_ucd_stage2);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));
2441  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2442  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_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));
2443  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2444  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2445  }  }
# Line 1600  struct sljit_label *newlinelabel = NULL; Line 2453  struct sljit_label *newlinelabel = NULL;
2453  struct sljit_jump *start;  struct sljit_jump *start;
2454  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2455  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2456  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2457  struct sljit_jump *singlebyte;  struct sljit_jump *singlechar;
2458  #endif  #endif
2459  jump_list *newline = NULL;  jump_list *newline = NULL;
2460  BOOL newlinecheck = FALSE;  BOOL newlinecheck = FALSE;
2461  BOOL readbyte = FALSE;  BOOL readuchar = FALSE;
2462    
2463  if (!(hascrorlf || firstline) && (common->nltype == NLTYPE_ANY ||  if (!(hascrorlf || firstline) && (common->nltype == NLTYPE_ANY ||
2464      common->nltype == NLTYPE_ANYCRLF || common->newline > 255))      common->nltype == NLTYPE_ANYCRLF || common->newline > 255))
# Line 1614  if (!(hascrorlf || firstline) && (common Line 2467  if (!(hascrorlf || firstline) && (common
2467  if (firstline)  if (firstline)
2468    {    {
2469    /* Search for the end of the first line. */    /* Search for the end of the first line. */
2470    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2471    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
2472    
2473    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2474      {      {
2475      mainloop = LABEL();      mainloop = LABEL();
2476      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));
2477      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2478      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -1);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
2479      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2480      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);
2481      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);
2482      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0, SLJIT_IMM, 1);      JUMPHERE(end);
2483        OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2484      }      }
2485    else    else
2486      {      {
2487      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2488      mainloop = LABEL();      mainloop = LABEL();
2489      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
2490      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2491      read_char(common);      read_char(common);
2492      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
2493      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2494      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);      JUMPHERE(end);
2495        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2496      set_jumps(newline, LABEL());      set_jumps(newline, LABEL());
2497      }      }
2498    
2499    JUMPHERE(end);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
   OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
2500    }    }
2501    
2502  start = JUMP(SLJIT_JUMP);  start = JUMP(SLJIT_JUMP);
# Line 1650  start = JUMP(SLJIT_JUMP); Line 2504  start = JUMP(SLJIT_JUMP);
2504  if (newlinecheck)  if (newlinecheck)
2505    {    {
2506    newlinelabel = LABEL();    newlinelabel = LABEL();
2507    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));
2508    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2509    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2510    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);
2511    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);
2512    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2513      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2514    #endif
2515    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2516    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
2517    }    }
# Line 1662  if (newlinecheck) Line 2519  if (newlinecheck)
2519  mainloop = LABEL();  mainloop = LABEL();
2520    
2521  /* Increasing the STR_PTR here requires one less jump in the most common case. */  /* Increasing the STR_PTR here requires one less jump in the most common case. */
2522  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2523  if (common->utf8) readbyte = TRUE;  if (common->utf) readuchar = TRUE;
2524  #endif  #endif
2525  if (newlinecheck) readbyte = TRUE;  if (newlinecheck) readuchar = TRUE;
2526    
2527  if (readbyte)  if (readuchar)
2528    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2529    
2530  if (newlinecheck)  if (newlinecheck)
2531    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);
2532    
2533  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));
2534  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2535  if (common->utf8)  #if defined COMPILE_PCRE8
2536    if (common->utf)
2537    {    {
2538    singlebyte = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2539    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)_pcre_utf8_char_sizes - 0xc0);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);
2540    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2541    JUMPHERE(singlebyte);    JUMPHERE(singlechar);
2542    }    }
2543  #endif  #elif defined COMPILE_PCRE16
2544    if (common->utf)
2545      {
2546      singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2547      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2548      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2549      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);
2550      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2551      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2552      JUMPHERE(singlechar);
2553      }
2554    #endif /* COMPILE_PCRE[8|16] */
2555    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2556  JUMPHERE(start);  JUMPHERE(start);
2557    
2558  if (newlinecheck)  if (newlinecheck)
# Line 1694  if (newlinecheck) Line 2564  if (newlinecheck)
2564  return mainloop;  return mainloop;
2565  }  }
2566    
2567  static SLJIT_INLINE void fast_forward_first_byte(compiler_common *common, pcre_uint16 firstbyte, BOOL firstline)  #define MAX_N_CHARS 3
2568    
2569    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2570  {  {
2571  DEFINE_COMPILER;  DEFINE_COMPILER;
2572  struct sljit_label *start;  struct sljit_label *start;
2573  struct sljit_jump *leave;  struct sljit_jump *quit;
2574    pcre_uint32 chars[MAX_N_CHARS * 2];
2575    pcre_uchar *cc = common->start + 1 + IMM2_SIZE;
2576    int location = 0;
2577    pcre_int32 len, c, bit, caseless;
2578    int must_stop;
2579    
2580    /* We do not support alternatives now. */
2581    if (*(common->start + GET(common->start, 1)) == OP_ALT)
2582      return FALSE;
2583    
2584    while (TRUE)
2585      {
2586      caseless = 0;
2587      must_stop = 1;
2588      switch(*cc)
2589        {
2590        case OP_CHAR:
2591        must_stop = 0;
2592        cc++;
2593        break;
2594    
2595        case OP_CHARI:
2596        caseless = 1;
2597        must_stop = 0;
2598        cc++;
2599        break;
2600    
2601        case OP_SOD:
2602        case OP_SOM:
2603        case OP_SET_SOM:
2604        case OP_NOT_WORD_BOUNDARY:
2605        case OP_WORD_BOUNDARY:
2606        case OP_EODN:
2607        case OP_EOD:
2608        case OP_CIRC:
2609        case OP_CIRCM:
2610        case OP_DOLL:
2611        case OP_DOLLM:
2612        /* Zero width assertions. */
2613        cc++;
2614        continue;
2615    
2616        case OP_PLUS:
2617        case OP_MINPLUS:
2618        case OP_POSPLUS:
2619        cc++;
2620        break;
2621    
2622        case OP_EXACT:
2623        cc += 1 + IMM2_SIZE;
2624        break;
2625    
2626        case OP_PLUSI:
2627        case OP_MINPLUSI:
2628        case OP_POSPLUSI:
2629        caseless = 1;
2630        cc++;
2631        break;
2632    
2633        case OP_EXACTI:
2634        caseless = 1;
2635        cc += 1 + IMM2_SIZE;
2636        break;
2637    
2638        default:
2639        must_stop = 2;
2640        break;
2641        }
2642    
2643      if (must_stop == 2)
2644          break;
2645    
2646      len = 1;
2647    #ifdef SUPPORT_UTF
2648      if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
2649    #endif
2650    
2651      if (caseless && char_has_othercase(common, cc))
2652        {
2653        caseless = char_get_othercase_bit(common, cc);
2654        if (caseless == 0)
2655          return FALSE;
2656    #ifdef COMPILE_PCRE8
2657        caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
2658    #else
2659        if ((caseless & 0x100) != 0)
2660          caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
2661        else
2662          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
2663    #endif
2664        }
2665      else
2666        caseless = 0;
2667    
2668      while (len > 0 && location < MAX_N_CHARS * 2)
2669        {
2670        c = *cc;
2671        bit = 0;
2672        if (len == (caseless & 0xff))
2673          {
2674          bit = caseless >> 8;
2675          c |= bit;
2676          }
2677    
2678        chars[location] = c;
2679        chars[location + 1] = bit;
2680    
2681        len--;
2682        location += 2;
2683        cc++;
2684        }
2685    
2686      if (location >= MAX_N_CHARS * 2 || must_stop != 0)
2687        break;
2688      }
2689    
2690    /* At least two characters are required. */
2691    if (location < 2 * 2)
2692        return FALSE;
2693    
2694    if (firstline)
2695      {
2696      SLJIT_ASSERT(common->first_line_end != 0);
2697      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2698      OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, (location >> 1) - 1);
2699      }
2700    else
2701      OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, (location >> 1) - 1);
2702    
2703    start = LABEL();
2704    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2705    
2706    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2707    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2708    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2709    if (chars[1] != 0)
2710      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
2711    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
2712    if (location > 2 * 2)
2713      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2714    if (chars[3] != 0)
2715      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
2716    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
2717    if (location > 2 * 2)
2718      {
2719      if (chars[5] != 0)
2720        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
2721      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);
2722      }
2723    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2724    
2725    JUMPHERE(quit);
2726    
2727    if (firstline)
2728      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2729    else
2730      OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, (location >> 1) - 1);
2731    return TRUE;
2732    }
2733    
2734    #undef MAX_N_CHARS
2735    
2736    static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
2737    {
2738    DEFINE_COMPILER;
2739    struct sljit_label *start;
2740    struct sljit_jump *quit;
2741  struct sljit_jump *found;  struct sljit_jump *found;
2742  pcre_uint16 oc, bit;  pcre_uchar oc, bit;
2743    
2744  if (firstline)  if (firstline)
2745    {    {
2746    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2747    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2748      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
2749    }    }
2750    
2751  start = LABEL();  start = LABEL();
2752  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2753  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2754    
2755  if ((firstbyte & REQ_CASELESS) == 0)  oc = first_char;
2756    found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, firstbyte & 0xff);  if (caseless)
2757      {
2758      oc = TABLE_GET(first_char, common->fcc, first_char);
2759    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
2760      if (first_char > 127 && common->utf)
2761        oc = UCD_OTHERCASE(first_char);
2762    #endif
2763      }
2764    if (first_char == oc)
2765      found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, first_char);
2766  else  else
2767    {    {
2768    firstbyte &= 0xff;    bit = first_char ^ oc;
2769    oc = common->fcc[firstbyte];    if (is_powerof2(bit))
   bit = firstbyte ^ oc;  
   if (ispowerof2(bit))  
2770      {      {
2771      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
2772      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, firstbyte | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
2773      }      }
2774    else    else
2775      {      {
2776      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);
2777      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);
2778      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);
2779      COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);      COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
# Line 1734  else Line 2781  else
2781      }      }
2782    }    }
2783    
2784  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 #ifdef SUPPORT_UTF8  
 if (common->utf8)  
   {  
   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)_pcre_utf8_char_sizes - 0xc0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 #endif  
2785  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
2786  JUMPHERE(found);  JUMPHERE(found);
2787  JUMPHERE(leave);  JUMPHERE(quit);
2788    
2789  if (firstline)  if (firstline)
2790    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2791  }  }
2792    
2793  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 1757  DEFINE_COMPILER; Line 2796  DEFINE_COMPILER;
2796  struct sljit_label *loop;  struct sljit_label *loop;
2797  struct sljit_jump *lastchar;  struct sljit_jump *lastchar;
2798  struct sljit_jump *firstchar;  struct sljit_jump *firstchar;
2799  struct sljit_jump *leave;  struct sljit_jump *quit;
2800  struct sljit_jump *foundcr = NULL;  struct sljit_jump *foundcr = NULL;
2801  struct sljit_jump *notfoundnl;  struct sljit_jump *notfoundnl;
2802  jump_list *newline = NULL;  jump_list *newline = NULL;
2803    
2804  if (firstline)  if (firstline)
2805    {    {
2806    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2807    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2808      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
2809    }    }
2810    
2811  if (common->nltype == NLTYPE_FIXED && common->newline > 255)  if (common->nltype == NLTYPE_FIXED && common->newline > 255)
# Line 1776  if (common->nltype == NLTYPE_FIXED && co Line 2816  if (common->nltype == NLTYPE_FIXED && co
2816    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));
2817    firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);    firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);
2818    
2819    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2);    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
2820    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);
2821    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);
2822    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2823      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
2824    #endif
2825    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2826    
2827    loop = LABEL();    loop = LABEL();
2828    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));
2829    leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2830    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -2);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
2831    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), -1);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
2832    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);
2833    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);
2834    
2835    JUMPHERE(leave);    JUMPHERE(quit);
2836    JUMPHERE(firstchar);    JUMPHERE(firstchar);
2837    JUMPHERE(lastchar);    JUMPHERE(lastchar);
2838    
# Line 1813  set_jumps(newline, loop); Line 2856  set_jumps(newline, loop);
2856    
2857  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
2858    {    {
2859    leave = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
2860    JUMPHERE(foundcr);    JUMPHERE(foundcr);
2861    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2862    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2863    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);
2864    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);
2865    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2866      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2867    #endif
2868    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2869    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
2870    JUMPHERE(leave);    JUMPHERE(quit);
2871    }    }
2872  JUMPHERE(lastchar);  JUMPHERE(lastchar);
2873  JUMPHERE(firstchar);  JUMPHERE(firstchar);
2874    
2875  if (firstline)  if (firstline)
2876    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2877  }  }
2878    
2879  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)
2880  {  {
2881  DEFINE_COMPILER;  DEFINE_COMPILER;
2882  struct sljit_label *start;  struct sljit_label *start;
2883  struct sljit_jump *leave;  struct sljit_jump *quit;
2884  struct sljit_jump *found;  struct sljit_jump *found;
2885    #ifndef COMPILE_PCRE8
2886    struct sljit_jump *jump;
2887    #endif
2888    
2889  if (firstline)  if (firstline)
2890    {    {
2891    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2892    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
2893      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
2894    }    }
2895    
2896  start = LABEL();  start = LABEL();
2897  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2898  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2899  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2900  if (common->utf8)  if (common->utf)
2901    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
2902  #endif  #endif
2903    #ifndef COMPILE_PCRE8
2904    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
2905    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
2906    JUMPHERE(jump);
2907    #endif
2908  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
2909  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
2910  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
# Line 1857  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TM Line 2912  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TM
2912  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
2913  found = JUMP(SLJIT_C_NOT_ZERO);  found = JUMP(SLJIT_C_NOT_ZERO);
2914    
2915  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2916  if (common->utf8)  if (common->utf)
2917    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
2918  #endif  #endif
2919  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));
2920  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2921  if (common->utf8)  #if defined COMPILE_PCRE8
2922    if (common->utf)
2923    {    {
2924    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
2925    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)_pcre_utf8_char_sizes - 0xc0);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);
2926    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2927    }    }
2928  #endif  #elif defined COMPILE_PCRE16
2929    if (common->utf)
2930      {
2931      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
2932      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2933      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2934      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);
2935      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2936      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2937      }
2938    #endif /* COMPILE_PCRE[8|16] */
2939    #endif /* SUPPORT_UTF */
2940  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
2941  JUMPHERE(found);  JUMPHERE(found);
2942  JUMPHERE(leave);  JUMPHERE(quit);
2943    
2944  if (firstline)  if (firstline)
2945    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
2946  }  }
2947    
2948  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)
2949  {  {
2950  DEFINE_COMPILER;  DEFINE_COMPILER;
2951  struct sljit_label *loop;  struct sljit_label *loop;
# Line 1887  struct sljit_jump *alreadyfound; Line 2954  struct sljit_jump *alreadyfound;
2954  struct sljit_jump *found;  struct sljit_jump *found;
2955  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
2956  struct sljit_jump *notfound;  struct sljit_jump *notfound;
2957  pcre_uint16 oc, bit;  pcre_uint32 oc, bit;
2958    
2959  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_BYTE_PTR);  SLJIT_ASSERT(common->req_char_ptr != 0);
2960    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
2961  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);
2962  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);
2963  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);
2964    
2965  if (has_firstbyte)  if (has_firstchar)
2966    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2967  else  else
2968    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);
2969    
2970  loop = LABEL();  loop = LABEL();
2971  notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);  notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);
2972    
2973  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(TMP1), 0);
2974  if ((reqbyte & REQ_CASELESS) == 0)  oc = req_char;
2975    found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte & 0xff);  if (caseless)
2976      {
2977      oc = TABLE_GET(req_char, common->fcc, req_char);
2978    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
2979      if (req_char > 127 && common->utf)
2980        oc = UCD_OTHERCASE(req_char);
2981    #endif
2982      }
2983    if (req_char == oc)
2984      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
2985  else  else
2986    {    {
2987    reqbyte &= 0xff;    bit = req_char ^ oc;
2988    oc = common->fcc[reqbyte];    if (is_powerof2(bit))
   bit = reqbyte ^ oc;  
   if (ispowerof2(bit))  
2989      {      {
2990      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
2991      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
2992      }      }
2993    else    else
2994      {      {
2995      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
2996      foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);      foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);
2997      }      }
2998    }    }
2999  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
3000  JUMPTO(SLJIT_JUMP, loop);  JUMPTO(SLJIT_JUMP, loop);
3001    
3002  JUMPHERE(found);  JUMPHERE(found);
3003  if (foundoc)  if (foundoc)
3004    JUMPHERE(foundoc);    JUMPHERE(foundoc);
3005  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);
3006  JUMPHERE(alreadyfound);  JUMPHERE(alreadyfound);
3007  JUMPHERE(toolong);  JUMPHERE(toolong);
3008  return notfound;  return notfound;
# Line 1939  DEFINE_COMPILER; Line 3014  DEFINE_COMPILER;
3014  struct sljit_jump *jump;  struct sljit_jump *jump;
3015  struct sljit_label *mainloop;  struct sljit_label *mainloop;
3016    
3017  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3018  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);
3019    GET_LOCAL_BASE(TMP3, 0, 0);
3020    
3021  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3022  mainloop = LABEL();  mainloop = LABEL();
3023  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3024  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);
3025  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_LOCALS_REG, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3026  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_w));
3027  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w));
3028  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_w));
# Line 1966  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_R Line 3042  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_R
3042  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3043    
3044  JUMPHERE(jump);  JUMPHERE(jump);
3045    if (common->mark_ptr != 0)
3046      {
3047      jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setmark);
3048      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));
3049      OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));
3050      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);
3051      JUMPTO(SLJIT_JUMP, mainloop);
3052    
3053      JUMPHERE(jump);
3054      }
3055    
3056  /* Unknown command. */  /* Unknown command. */
3057  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_w));
3058  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
# Line 1974  JUMPTO(SLJIT_JUMP, mainloop); Line 3061  JUMPTO(SLJIT_JUMP, mainloop);
3061  static void check_wordboundary(compiler_common *common)  static void check_wordboundary(compiler_common *common)
3062  {  {
3063  DEFINE_COMPILER;  DEFINE_COMPILER;
3064  struct sljit_jump *beginend;  struct sljit_jump *skipread;
3065  #ifdef SUPPORT_UTF8  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3066  struct sljit_jump *jump;  struct sljit_jump *jump;
3067  #endif  #endif
3068    
3069  SLJIT_ASSERT(ctype_word == 0x10);  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
3070    
3071  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);
3072  /* Get type of the previous char, and put it to LOCALS1. */  /* Get type of the previous char, and put it to LOCALS1. */
3073  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
3074  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));
3075  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);
3076  beginend = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);  skipread = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3077  skip_char_back(common);  skip_char_back(common);
3078    check_start_used_ptr(common);
3079  read_char(common);  read_char(common);
3080    
3081  /* Testing char type. */  /* Testing char type. */
3082  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3083  if (common->useucp)  if (common->use_ucp)
3084    {    {
3085    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
3086    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
# Line 2009  if (common->useucp) Line 3097  if (common->useucp)
3097  else  else
3098  #endif  #endif
3099    {    {
3100  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3101      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3102    #elif defined SUPPORT_UTF
3103    /* Here LOCALS1 has already been zeroed. */    /* Here LOCALS1 has already been zeroed. */
3104    jump = NULL;    jump = NULL;
3105    if (common->utf8)    if (common->utf)
3106      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3107  #endif  #endif /* COMPILE_PCRE8 */
3108    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);
3109    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);
3110    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3111    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
3112  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3113      JUMPHERE(jump);
3114    #elif defined SUPPORT_UTF
3115    if (jump != NULL)    if (jump != NULL)
3116      JUMPHERE(jump);      JUMPHERE(jump);
3117  #endif  #endif /* COMPILE_PCRE8 */
3118    }    }
3119  JUMPHERE(beginend);  JUMPHERE(skipread);
3120    
3121  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3122  beginend = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  skipread = check_str_end(common);
3123  peek_char(common);  peek_char(common);
3124    
3125  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
3126  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3127  if (common->useucp)  if (common->use_ucp)
3128      {
3129      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
3130      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
3131      add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3132      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3133      OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
3134      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);
3135      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);
3136      OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
3137      COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);
3138      JUMPHERE(jump);
3139      }
3140    else
3141    #endif
3142      {
3143    #ifndef COMPILE_PCRE8
3144      /* TMP2 may be destroyed by peek_char. */
3145      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3146      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3147    #elif defined SUPPORT_UTF
3148      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3149      jump = NULL;
3150      if (common->utf)
3151        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3152    #endif
3153      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);
3154      OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);
3155      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
3156    #ifndef COMPILE_PCRE8
3157      JUMPHERE(jump);
3158    #elif defined SUPPORT_UTF
3159      if (jump != NULL)
3160        JUMPHERE(jump);
3161    #endif /* COMPILE_PCRE8 */
3162      }
3163    JUMPHERE(skipread);
3164    
3165    OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3166    sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3167    }
3168    
3169    /*
3170      range format:
3171    
3172      ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).
3173      ranges[1] = first bit (0 or 1)
3174      ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)
3175    */
3176    
3177    static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3178    {
3179    DEFINE_COMPILER;
3180    struct sljit_jump *jump;
3181    
3182    if (ranges[0] < 0)
3183      return FALSE;
3184    
3185    switch(ranges[0])
3186      {
3187      case 1:
3188      if (readch)
3189        read_char(common);
3190      add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3191      return TRUE;
3192    
3193      case 2:
3194      if (readch)
3195        read_char(common);
3196      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3197      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3198      return TRUE;
3199    
3200      case 4:
3201      if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])
3202        {
3203        if (readch)
3204          read_char(common);
3205        if (ranges[1] != 0)
3206          {
3207          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3208          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3209          }
3210        else
3211          {
3212          jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);
3213          add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3214          JUMPHERE(jump);
3215          }
3216        return TRUE;
3217        }
3218      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))
3219        {
3220        if (readch)
3221          read_char(common);
3222        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3223        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3224        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3225        return TRUE;
3226        }
3227      return FALSE;
3228    
3229      default:
3230      return FALSE;
3231      }
3232    }
3233    
3234    static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)
3235    {
3236    int i, bit, length;
3237    const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;
3238    
3239    bit = ctypes[0] & flag;
3240    ranges[0] = -1;
3241    ranges[1] = bit != 0 ? 1 : 0;
3242    length = 0;
3243    
3244    for (i = 1; i < 256; i++)
3245      if ((ctypes[i] & flag) != bit)
3246        {
3247        if (length >= MAX_RANGE_SIZE)
3248          return;
3249        ranges[2 + length] = i;
3250        length++;
3251        bit ^= flag;
3252        }
3253    
3254    if (bit != 0)
3255      {
3256      if (length >= MAX_RANGE_SIZE)
3257        return;
3258      ranges[2 + length] = 256;
3259      length++;
3260      }
3261    ranges[0] = length;
3262    }
3263    
3264    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)
3265    {
3266    int ranges[2 + MAX_RANGE_SIZE];
3267    pcre_uint8 bit, cbit, all;
3268    int i, byte, length = 0;
3269    
3270    bit = bits[0] & 0x1;
3271    ranges[1] = bit;
3272    /* Can be 0 or 255. */
3273    all = -bit;
3274    
3275    for (i = 0; i < 256; )
3276    {    {
3277    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);    byte = i >> 3;
3278    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);    if ((i & 0x7) == 0 && bits[byte] == all)
3279    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));      i += 8;
3280    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    else
3281    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);      {
3282    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);      cbit = (bits[byte] >> (i & 0x7)) & 0x1;
3283    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);      if (cbit != bit)
3284    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);        {
3285    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);        if (length >= MAX_RANGE_SIZE)
3286    JUMPHERE(jump);          return FALSE;
3287          ranges[2 + length] = i;
3288          length++;
3289          bit = cbit;
3290          all = -cbit;
3291          }
3292        i++;
3293        }
3294    }    }
3295  else  
3296  #endif  if (((bit == 0) && nclass) || ((bit == 1) && !nclass))
3297    {    {
3298  #ifdef SUPPORT_UTF8    if (length >= MAX_RANGE_SIZE)
3299    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);      return FALSE;
3300    jump = NULL;    ranges[2 + length] = 256;
3301    if (common->utf8)    length++;
     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
 #endif  
   OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);  
   OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);  
   OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);  
 #ifdef SUPPORT_UTF8  
   if (jump != NULL)  
     JUMPHERE(jump);  
 #endif  
3302    }    }
3303  JUMPHERE(beginend);  ranges[0] = length;
3304    
3305  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  return check_ranges(common, ranges, backtracks, FALSE);
 sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
3306  }  }
3307    
3308  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
# Line 2073  static void check_anynewline(compiler_co Line 3310  static void check_anynewline(compiler_co
3310  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3311  DEFINE_COMPILER;  DEFINE_COMPILER;
3312    
3313  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3314    
3315  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3316  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);
3317  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);
3318  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);
3319  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3320  if (common->utf8)  #ifdef COMPILE_PCRE8
3321    if (common->utf)
3322    {    {
3323    #endif
3324    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);
3325    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3326    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);
3327    #ifdef COMPILE_PCRE8
3328    }    }
3329  #endif  #endif
3330    #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3331  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
3332  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3333  }  }
# Line 2096  static void check_hspace(compiler_common Line 3337  static void check_hspace(compiler_common
3337  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3338  DEFINE_COMPILER;  DEFINE_COMPILER;
3339    
3340  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3341    
3342  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);
3343  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);
3344  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);
3345  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);
3346  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);
3347  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3348  if (common->utf8)  #ifdef COMPILE_PCRE8
3349    if (common->utf)
3350    {    {
3351    #endif
3352    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);
3353    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);
3354    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);
# Line 2119  if (common->utf8) Line 3362  if (common->utf8)
3362    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);
3363    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);
3364    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);
3365    #ifdef COMPILE_PCRE8
3366    }    }
3367  #endif  #endif
3368    #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3369  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
3370    
3371  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
# Line 2131  static void check_vspace(compiler_common Line 3376  static void check_vspace(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, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3382  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);
3383  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);
3384  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);
3385  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3386  if (common->utf8)  #ifdef COMPILE_PCRE8
3387    if (common->utf)
3388    {    {
3389    #endif
3390    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
3391    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3392    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);
3393    #ifdef COMPILE_PCRE8
3394    }    }
3395  #endif  #endif
3396    #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3397  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
3398    
3399  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
# Line 2159  DEFINE_COMPILER; Line 3408  DEFINE_COMPILER;
3408  struct sljit_jump *jump;  struct sljit_jump *jump;
3409  struct sljit_label *label;  struct sljit_label *label;
3410    
3411  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3412  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3413  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);
3414  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);
3415  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
3416  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));
3417    
3418  label = LABEL();  label = LABEL();
3419  OP1(SLJIT_MOVU_UB, CHAR1, 0, SLJIT_MEM1(TMP1), 1);  OP1(MOVU_UCHAR, CHAR1, 0, SLJIT_MEM1(TMP1), IN_UCHARS(1));
3420  OP1(SLJIT_MOVU_UB, CHAR2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOVU_UCHAR, CHAR2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3421  jump = CMP(SLJIT_C_NOT_EQUAL, CHAR1, 0, CHAR2, 0);  jump = CMP(SLJIT_C_NOT_EQUAL, CHAR1, 0, CHAR2, 0);
3422  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));
3423  JUMPTO(SLJIT_C_NOT_ZERO, label);  JUMPTO(SLJIT_C_NOT_ZERO, label);
3424    
3425  JUMPHERE(jump);  JUMPHERE(jump);
3426  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));
3427  OP1(SLJIT_MOV, CHAR1, 0, TMP3, 0);  OP1(SLJIT_MOV, CHAR1, 0, TMP3, 0);
3428  OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3429  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
# Line 2188  DEFINE_COMPILER; Line 3437  DEFINE_COMPILER;
3437  struct sljit_jump *jump;  struct sljit_jump *jump;
3438  struct sljit_label *label;  struct sljit_label *label;
3439    
3440  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3441  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3442    
3443  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);
3444  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR1, 0);
3445  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, CHAR2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, CHAR2, 0);
3446  OP1(SLJIT_MOV, LCC_TABLE, 0, SLJIT_IMM, common->lcc);  OP1(SLJIT_MOV, LCC_TABLE, 0, SLJIT_IMM, common->lcc);
3447  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
3448  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));
3449    
3450  label = LABEL();  label = LABEL();
3451  OP1(SLJIT_MOVU_UB, CHAR1, 0, SLJIT_MEM1(TMP1), 1);  OP1(MOVU_UCHAR, CHAR1, 0, SLJIT_MEM1(TMP1), IN_UCHARS(1));
3452  OP1(SLJIT_MOVU_UB, CHAR2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOVU_UCHAR, CHAR2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3453    #ifndef COMPILE_PCRE8
3454    jump = CMP(SLJIT_C_GREATER, CHAR1, 0, SLJIT_IMM, 255);
3455    #endif
3456  OP1(SLJIT_MOV_UB, CHAR1, 0, SLJIT_MEM2(LCC_TABLE, CHAR1), 0);  OP1(SLJIT_MOV_UB, CHAR1, 0, SLJIT_MEM2(LCC_TABLE, CHAR1), 0);
3457    #ifndef COMPILE_PCRE8
3458    JUMPHERE(jump);
3459    jump = CMP(SLJIT_C_GREATER, CHAR2, 0, SLJIT_IMM, 255);
3460    #endif
3461  OP1(SLJIT_MOV_UB, CHAR2, 0, SLJIT_MEM2(LCC_TABLE, CHAR2), 0);  OP1(SLJIT_MOV_UB, CHAR2, 0, SLJIT_MEM2(LCC_TABLE, CHAR2), 0);
3462    #ifndef COMPILE_PCRE8
3463    JUMPHERE(jump);
3464    #endif
3465  jump = CMP(SLJIT_C_NOT_EQUAL, CHAR1, 0, CHAR2, 0);  jump = CMP(SLJIT_C_NOT_EQUAL, CHAR1, 0, CHAR2, 0);
3466  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));
3467  JUMPTO(SLJIT_C_NOT_ZERO, label);  JUMPTO(SLJIT_C_NOT_ZERO, label);
3468    
3469  JUMPHERE(jump);  JUMPHERE(jump);
3470  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));
3471  OP1(SLJIT_MOV, LCC_TABLE, 0, TMP3, 0);  OP1(SLJIT_MOV, LCC_TABLE, 0, TMP3, 0);
3472  OP1(SLJIT_MOV, CHAR1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  OP1(SLJIT_MOV, CHAR1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3473  OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
# Line 2219  sljit_emit_fast_return(compiler, RETURN_ Line 3478  sljit_emit_fast_return(compiler, RETURN_
3478  #undef CHAR1  #undef CHAR1
3479  #undef CHAR2  #undef CHAR2
3480    
3481  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && defined SUPPORT_UCP
 #ifdef SUPPORT_UCP  
3482    
3483  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)
3484  {  {
3485  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3486  int c1, c2;  pcre_uint32 c1, c2;
3487  uschar *src2 = args->ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3488  uschar *end2 = (uschar*)args->end;  const pcre_uchar *end2 = args->end;
3489    const ucd_record *ur;
3490    const pcre_uint32 *pp;
3491    
3492  while (src1 < end1)  while (src1 < end1)
3493    {    {
3494    if (src2 >= end2)    if (src2 >= end2)
3495      return 0;      return (pcre_uchar*)1;
3496    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3497    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3498    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return 0;    ur = GET_UCD(c2);
3499      if (c1 != c2 && c1 != c2 + ur->other_case)
3500        {
3501        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3502        for (;;)
3503          {
3504          if (c1 < *pp) return NULL;
3505          if (c1 == *pp++) break;
3506          }
3507        }
3508    }    }
3509  return src2;  return src2;
3510  }  }
3511    
3512  #endif  #endif /* SUPPORT_UTF && SUPPORT_UCP */
 #endif  
3513    
3514  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,
3515      compare_context* context, jump_list **fallbacks)      compare_context* context, jump_list **backtracks)
3516  {  {
3517  DEFINE_COMPILER;  DEFINE_COMPILER;
3518  unsigned int othercasebit = 0;  unsigned int othercasebit = 0;
3519  uschar *othercasebyte = NULL;  pcre_uchar *othercasechar = NULL;
3520  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3521  int utf8length;  int utflength;
3522  #endif  #endif
3523    
3524  if (caseless && char_has_othercase(common, cc))  if (caseless && char_has_othercase(common, cc))
# Line 2258  if (caseless && char_has_othercase(commo Line 3526  if (caseless && char_has_othercase(commo
3526    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3527    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3528    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3529    othercasebyte = cc + (othercasebit >> 8);  #if defined COMPILE_PCRE8
3530      othercasechar = cc + (othercasebit >> 8);
3531    othercasebit &= 0xff;    othercasebit &= 0xff;
3532    #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3533      /* Note that this code only handles characters in the BMP. If there
3534      ever are characters outside the BMP whose othercase differs in only one
3535      bit from itself (there currently are none), this code will need to be
3536      revised for COMPILE_PCRE32. */
3537      othercasechar = cc + (othercasebit >> 9);
3538      if ((othercasebit & 0x100) != 0)
3539        othercasebit = (othercasebit & 0xff) << 8;
3540      else
3541        othercasebit &= 0xff;
3542    #endif /* COMPILE_PCRE[8|16|32] */
3543    }    }
3544    
3545  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3546    {    {
3547    #if defined COMPILE_PCRE8
3548  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3549    if (context->length >= 4)    if (context->length >= 4)
3550      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3551    else if (context->length >= 2)    else if (context->length >= 2)
3552      OP1(SLJIT_MOV_SH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3553    else    else
3554  #endif  #endif
3555      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3556    #elif defined COMPILE_PCRE16
3557    #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3558      if (context->length >= 4)
3559        OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3560      else
3561    #endif
3562        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3563    #elif defined COMPILE_PCRE32
3564      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3565    #endif /* COMPILE_PCRE[8|16|32] */
3566    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3567    }    }
3568    
3569  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3570  utf8length = 1;  utflength = 1;
3571  if (common->utf8 && *cc >= 0xc0)  if (common->utf && HAS_EXTRALEN(*cc))
3572    utf8length += _pcre_utf8_table4[*cc & 0x3f];    utflength += GET_EXTRALEN(*cc);
3573    
3574  do  do
3575    {    {
3576  #endif  #endif
3577    
3578    context->length--;    context->length -= IN_UCHARS(1);
3579  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3580    
3581    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3582    if (othercasebit != 0 && othercasebyte == cc)    if (othercasebit != 0 && othercasechar == cc)
3583      {      {
3584      context->c.asbytes[context->byteptr] = *cc | othercasebit;      context->c.asuchars[context->ucharptr] = *cc | othercasebit;
3585      context->oc.asbytes[context->byteptr] = othercasebit;      context->oc.asuchars[context->ucharptr] = othercasebit;
3586      }      }
3587    else    else
3588      {      {
3589      context->c.asbytes[context->byteptr] = *cc;      context->c.asuchars[context->ucharptr] = *cc;
3590      context->oc.asbytes[context->byteptr] = 0;      context->oc.asuchars[context->ucharptr] = 0;
3591      }      }
3592    context->byteptr++;    context->ucharptr++;
3593    
3594    if (context->byteptr >= 4 || context->length == 0 || (context->byteptr == 2 && context->length == 1))  #if defined COMPILE_PCRE8
3595      if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))
3596    #elif defined COMPILE_PCRE16
3597      if (context->ucharptr >= 2 || context->length == 0)
3598    #elif defined COMPILE_PCRE32
3599      if (1 /* context->ucharptr >= 1 || context->length == 0 */)
3600    #endif
3601      {      {
3602    #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
3603      if (context->length >= 4)      if (context->length >= 4)
3604        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);
3605    #if defined COMPILE_PCRE8
3606      else if (context->length >= 2)      else if (context->length >= 2)
3607        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);
3608      else if (context->length >= 1)      else if (context->length >= 1)
3609        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);
3610    #elif defined COMPILE_PCRE16
3611        else if (context->length >= 2)
3612          OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3613    #endif /* COMPILE_PCRE[8|16] */
3614    #elif defined COMPILE_PCRE32
3615        OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3616    #endif /* COMPILE_PCRE[8|16|32] */
3617      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3618    
3619      switch(context->byteptr)      switch(context->ucharptr)
3620        {        {
3621        case 4:        case 4 / sizeof(pcre_uchar):
3622        if (context->oc.asint != 0)        if (context->oc.asint != 0)
3623          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);
3624        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));
3625        break;        break;
3626    
3627        case 2:  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
3628        if (context->oc.asshort != 0)        case 2 / sizeof(pcre_uchar):
3629          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asshort);        if (context->oc.asushort != 0)
3630        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asshort | context->oc.asshort));          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);
3631          add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asushort | context->oc.asushort));
3632        break;        break;
3633    
3634    #ifdef COMPILE_PCRE8
3635        case 1:        case 1:
3636        if (context->oc.asbyte != 0)        if (context->oc.asbyte != 0)
3637          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);
3638        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));
3639        break;        break;
3640    #endif
3641    
3642    #endif /* COMPILE_PCRE[8|16] */
3643    
3644        default:        default:
3645        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
3646        break;        break;
3647        }        }
3648      context->byteptr = 0;      context->ucharptr = 0;
3649      }      }
3650    
3651  #else  #else
3652    
3653    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported. */
3654    if (context->length > 0)    if (context->length > 0)
3655      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);
3656    
3657    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3658    
3659    if (othercasebit != 0 && othercasebyte == cc)    if (othercasebit != 0 && othercasechar == cc)
3660      {      {
3661      OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, othercasebit);      OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, othercasebit);
3662      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));
3663      }      }
3664    else    else
3665      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));
3666    
3667  #endif  #endif
3668    
3669    cc++;    cc++;
3670  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3671    utf8length--;    utflength--;
3672    }    }
3673  while (utf8length > 0);  while (utflength > 0);
3674  #endif  #endif
3675    
3676  return cc;  return cc;
3677  }  }
3678    
3679  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3680    
3681  #define SET_TYPE_OFFSET(value) \  #define SET_TYPE_OFFSET(value) \
3682    if ((value) != typeoffset) \    if ((value) != typeoffset) \
# Line 2386  return cc; Line 3698  return cc;
3698      } \      } \
3699    charoffset = (value);    charoffset = (value);
3700    
3701  static void compile_xclass_hotpath(compiler_common *common, uschar *cc, jump_list **fallbacks)  static void compile_xclass_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)
3702  {  {
3703  DEFINE_COMPILER;  DEFINE_COMPILER;
3704  jump_list *found = NULL;  jump_list *found = NULL;
3705  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : fallbacks;  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;
3706  unsigned int c;  pcre_int32 c, charoffset;
3707  int compares;  const pcre_uint32 *other_cases;
3708  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
3709  uschar *ccbegin;  pcre_uchar *ccbegin;
3710    int compares, invertcmp, numberofcmps;
3711  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3712  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
3713  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
3714  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
3715  unsigned int typeoffset;  pcre_int32 typeoffset;
3716  #endif  #endif
 int invertcmp, numberofcmps;  
 unsigned int charoffset;  
3717    
3718  /* Although SUPPORT_UTF8 must be defined, we are not necessary in utf8 mode. */  /* Although SUPPORT_UTF must be defined, we are
3719  check_input_end(common, fallbacks);     not necessary in utf mode even in 8 bit mode. */
3720    detect_partial_match(common, backtracks);
3721  read_char(common);  read_char(common);
3722    
3723  if ((*cc++ & XCL_MAP) != 0)  if ((*cc++ & XCL_MAP) != 0)
3724    {    {
3725    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3726    if (common->utf8)  #ifndef COMPILE_PCRE8
3727      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3728    #elif defined SUPPORT_UTF
3729      if (common->utf)
3730      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3731    #endif
3732    
3733    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, list))
3734    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      {
3735    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3736    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3737    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);
3738    add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3739        OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
3740        add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
3741        }
3742    
3743    if (common->utf8)  #ifndef COMPILE_PCRE8
3744      JUMPHERE(jump);
3745    #elif defined SUPPORT_UTF
3746      if (common->utf)
3747      JUMPHERE(jump);      JUMPHERE(jump);
3748    #endif
3749    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3750  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3751    charsaved = TRUE;    charsaved = TRUE;
3752  #endif  #endif
3753    cc += 32;    cc += 32 / sizeof(pcre_uchar);
3754    }    }
3755    
3756  /* Scanning the necessary info. */  /* Scanning the necessary info. */
# Line 2439  while (*cc != XCL_END) Line 3762  while (*cc != XCL_END)
3762    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
3763      {      {
3764      cc += 2;      cc += 2;
3765  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3766      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]);
3767  #endif  #endif
3768  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3769      needschar = TRUE;      needschar = TRUE;
# Line 2449  while (*cc != XCL_END) Line 3772  while (*cc != XCL_END)
3772    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
3773      {      {
3774      cc += 2;      cc += 2;
3775  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3776      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]);
3777  #endif  #endif
3778      cc++;      cc++;
3779  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3780      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]);
3781  #endif  #endif
3782  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3783      needschar = TRUE;      needschar = TRUE;
# Line 2488  while (*cc != XCL_END) Line 3811  while (*cc != XCL_END)
3811        needschar = TRUE;        needschar = TRUE;
3812        break;        break;
3813    
3814          case PT_CLIST:
3815          needschar = TRUE;
3816          break;
3817    
3818        default:        default:
3819        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
3820        break;        break;
# Line 2524  if (needstype || needsscript) Line 3851  if (needstype || needsscript)
3851      {      {
3852      if (scriptreg == TMP1)      if (scriptreg == TMP1)
3853        {        {
3854        OP1(SLJIT_MOV, scriptreg, 0, SLJIT_IMM, (sljit_w)_pcre_ucd_records + SLJIT_OFFSETOF(ucd_record, script));        OP1(SLJIT_MOV, scriptreg, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));
3855        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
3856        }        }
3857      else      else
3858        {        {
3859        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
3860        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_w)_pcre_ucd_records + SLJIT_OFFSETOF(ucd_record, script));        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));
3861        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
3862        }        }
3863      }      }
# Line 2548  typeoffset = 0; Line 3875  typeoffset = 0;
3875  while (*cc != XCL_END)  while (*cc != XCL_END)
3876    {    {
3877    compares--;    compares--;
3878    invertcmp = (compares == 0 && list != fallbacks);    invertcmp = (compares == 0 && list != backtracks);
3879    jump = NULL;    jump = NULL;
3880    
3881    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
3882      {      {
3883      cc ++;      cc ++;
3884  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3885      if (common->utf8)      if (common->utf)
3886        {        {
3887        GETCHARINC(c, cc);        GETCHARINC(c, cc);
3888        }        }
# Line 2585  while (*cc != XCL_END) Line 3912  while (*cc != XCL_END)
3912    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
3913      {      {
3914      cc ++;      cc ++;
3915  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3916      if (common->utf8)      if (common->utf)
3917        {        {
3918        GETCHARINC(c, cc);        GETCHARINC(c, cc);
3919        }        }
# Line 2594  while (*cc != XCL_END) Line 3921  while (*cc != XCL_END)
3921  #endif  #endif
3922        c = *cc++;        c = *cc++;
3923      SET_CHAR_OFFSET(c);      SET_CHAR_OFFSET(c);
3924  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3925      if (common->utf8)      if (common->utf)
3926        {        {
3927        GETCHARINC(c, cc);        GETCHARINC(c, cc);
3928        }        }
# Line 2630  while (*cc != XCL_END) Line 3957  while (*cc != XCL_END)
3957      switch(*cc)      switch(*cc)
3958        {        {
3959        case PT_ANY:        case PT_ANY:
3960        if (list != fallbacks)        if (list != backtracks)
3961          {          {
3962          if ((cc[-1] == XCL_NOTPROP && compares > 0) || (cc[-1] == XCL_PROP && compares == 0))          if ((cc[-1] == XCL_NOTPROP && compares > 0) || (cc[-1] == XCL_PROP && compares == 0))
3963            continue;            continue;
# Line 2651  while (*cc != XCL_END) Line 3978  while (*cc != XCL_END)
3978        break;        break;
3979    
3980        case PT_GC:        case PT_GC:
3981        c = _pcre_ucp_typerange[(int)cc[1] * 2];        c = PRIV(ucp_typerange)[(int)cc[1] * 2];
3982        SET_TYPE_OFFSET(c);        SET_TYPE_OFFSET(c);
3983        jump = CMP(SLJIT_C_LESS_EQUAL ^ invertcmp, typereg, 0, SLJIT_IMM, _pcre_ucp_typerange[(int)cc[1] * 2 + 1] - c);        jump = CMP(SLJIT_C_LESS_EQUAL ^ invertcmp, typereg, 0, SLJIT_IMM, PRIV(ucp_typerange)[(int)cc[1] * 2 + 1] - c);
3984        break;        break;
3985    
3986        case PT_PC:        case PT_PC:
# Line 2697  while (*cc != XCL_END) Line 4024  while (*cc != XCL_END)
4024        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);
4025        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4026        break;        break;
4027    
4028          case PT_CLIST:
4029          other_cases = PRIV(ucd_caseless_sets) + cc[1];
4030    
4031          /* At least three characters are required.
4032             Otherwise this case would be handled by the normal code path. */
4033          SLJIT_ASSERT(other_cases[0] != NOTACHAR && other_cases[1] != NOTACHAR && other_cases[2] != NOTACHAR);
4034          SLJIT_ASSERT(other_cases[0] < other_cases[1] && other_cases[1] < other_cases[2]);
4035    
4036          /* Optimizing character pairs, if their difference is power of 2. */
4037          if (is_powerof2(other_cases[1] ^ other_cases[0]))