Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: src/regexp-macro-assembler-ia32.h

Issue 18096: Experimental: merge from bleeding_edge. Merge up to and including... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/toiger/
Patch Set: Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/regexp-macro-assembler.cc ('k') | src/regexp-macro-assembler-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 20 matching lines...) Expand all
31 namespace v8 { namespace internal { 31 namespace v8 { namespace internal {
32 32
33 class RegExpMacroAssemblerIA32: public RegExpMacroAssembler { 33 class RegExpMacroAssemblerIA32: public RegExpMacroAssembler {
34 public: 34 public:
35 // Type of input string to generate code for. 35 // Type of input string to generate code for.
36 enum Mode { ASCII = 1, UC16 = 2 }; 36 enum Mode { ASCII = 1, UC16 = 2 };
37 enum Result { EXCEPTION = -1, FAILURE = 0, SUCCESS = 1 }; 37 enum Result { EXCEPTION = -1, FAILURE = 0, SUCCESS = 1 };
38 38
39 RegExpMacroAssemblerIA32(Mode mode, int registers_to_save); 39 RegExpMacroAssemblerIA32(Mode mode, int registers_to_save);
40 virtual ~RegExpMacroAssemblerIA32(); 40 virtual ~RegExpMacroAssemblerIA32();
41 virtual int stack_limit_slack();
41 virtual void AdvanceCurrentPosition(int by); 42 virtual void AdvanceCurrentPosition(int by);
42 virtual void AdvanceRegister(int reg, int by); 43 virtual void AdvanceRegister(int reg, int by);
43 virtual void Backtrack(); 44 virtual void Backtrack();
44 virtual void Bind(Label* label); 45 virtual void Bind(Label* label);
45 virtual void CheckBitmap(uc16 start, Label* bitmap, Label* on_zero); 46 virtual void CheckBitmap(uc16 start, Label* bitmap, Label* on_zero);
46 virtual void CheckCharacter(uint32_t c, Label* on_equal); 47 virtual void CheckCharacter(uint32_t c, Label* on_equal);
47 virtual void CheckCharacterAfterAnd(uint32_t c, 48 virtual void CheckCharacterAfterAnd(uint32_t c,
48 uint32_t mask, 49 uint32_t mask,
49 Label* on_equal); 50 Label* on_equal);
50 virtual void CheckCharacterGT(uc16 limit, Label* on_greater); 51 virtual void CheckCharacterGT(uc16 limit, Label* on_greater);
51 virtual void CheckCharacterLT(uc16 limit, Label* on_less); 52 virtual void CheckCharacterLT(uc16 limit, Label* on_less);
52 virtual void CheckCharacters(Vector<const uc16> str, 53 virtual void CheckCharacters(Vector<const uc16> str,
53 int cp_offset, 54 int cp_offset,
54 Label* on_failure, 55 Label* on_failure,
55 bool check_end_of_string); 56 bool check_end_of_string);
57 // A "greedy loop" is a loop that is both greedy and with a simple
58 // body. It has a particularly simple implementation.
56 virtual void CheckGreedyLoop(Label* on_tos_equals_current_position); 59 virtual void CheckGreedyLoop(Label* on_tos_equals_current_position);
57 virtual void CheckNotAtStart(Label* on_not_at_start); 60 virtual void CheckNotAtStart(Label* on_not_at_start);
58 virtual void CheckNotBackReference(int start_reg, Label* on_no_match); 61 virtual void CheckNotBackReference(int start_reg, Label* on_no_match);
59 virtual void CheckNotBackReferenceIgnoreCase(int start_reg, 62 virtual void CheckNotBackReferenceIgnoreCase(int start_reg,
60 Label* on_no_match); 63 Label* on_no_match);
61 virtual void CheckNotRegistersEqual(int reg1, int reg2, Label* on_not_equal); 64 virtual void CheckNotRegistersEqual(int reg1, int reg2, Label* on_not_equal);
62 virtual void CheckNotCharacter(uint32_t c, Label* on_not_equal); 65 virtual void CheckNotCharacter(uint32_t c, Label* on_not_equal);
63 virtual void CheckNotCharacterAfterAnd(uint32_t c, 66 virtual void CheckNotCharacterAfterAnd(uint32_t c,
64 uint32_t mask, 67 uint32_t mask,
65 Label* on_not_equal); 68 Label* on_not_equal);
(...skipping 13 matching lines...) Expand all
79 const Vector<Label*>& destinations); 82 const Vector<Label*>& destinations);
80 virtual void DispatchHighByteMap(byte start, 83 virtual void DispatchHighByteMap(byte start,
81 Label* byte_map, 84 Label* byte_map,
82 const Vector<Label*>& destinations); 85 const Vector<Label*>& destinations);
83 virtual void EmitOrLink(Label* label); 86 virtual void EmitOrLink(Label* label);
84 virtual void Fail(); 87 virtual void Fail();
85 virtual Handle<Object> GetCode(Handle<String> source); 88 virtual Handle<Object> GetCode(Handle<String> source);
86 virtual void GoTo(Label* label); 89 virtual void GoTo(Label* label);
87 virtual void IfRegisterGE(int reg, int comparand, Label* if_ge); 90 virtual void IfRegisterGE(int reg, int comparand, Label* if_ge);
88 virtual void IfRegisterLT(int reg, int comparand, Label* if_lt); 91 virtual void IfRegisterLT(int reg, int comparand, Label* if_lt);
92 virtual void IfRegisterEqPos(int reg, Label* if_eq);
89 virtual IrregexpImplementation Implementation(); 93 virtual IrregexpImplementation Implementation();
90 virtual void LoadCurrentCharacter(int cp_offset, 94 virtual void LoadCurrentCharacter(int cp_offset,
91 Label* on_end_of_input, 95 Label* on_end_of_input,
92 bool check_bounds = true, 96 bool check_bounds = true,
93 int characters = 1); 97 int characters = 1);
94 virtual void PopCurrentPosition(); 98 virtual void PopCurrentPosition();
95 virtual void PopRegister(int register_index); 99 virtual void PopRegister(int register_index);
96 virtual void PushBacktrack(Label* label); 100 virtual void PushBacktrack(Label* label);
97 virtual void PushCurrentPosition(); 101 virtual void PushCurrentPosition();
98 virtual void PushRegister(int register_index); 102 virtual void PushRegister(int register_index,
103 StackCheckFlag check_stack_limit);
99 virtual void ReadCurrentPositionFromRegister(int reg); 104 virtual void ReadCurrentPositionFromRegister(int reg);
100 virtual void ReadStackPointerFromRegister(int reg); 105 virtual void ReadStackPointerFromRegister(int reg);
101 virtual void SetRegister(int register_index, int to); 106 virtual void SetRegister(int register_index, int to);
102 virtual void Succeed(); 107 virtual void Succeed();
103 virtual void WriteCurrentPositionToRegister(int reg, int cp_offset); 108 virtual void WriteCurrentPositionToRegister(int reg, int cp_offset);
109 virtual void ClearRegister(int reg);
104 virtual void WriteStackPointerToRegister(int reg); 110 virtual void WriteStackPointerToRegister(int reg);
105 111
106 template <typename T> 112 static Result Execute(Code* code,
107 static inline Result Execute(Code* code, 113 Address* input,
108 T** input, 114 int start_offset,
109 int start_offset, 115 int end_offset,
110 int end_offset, 116 int* output,
111 int* output, 117 bool at_start);
112 bool at_start) {
113 typedef int (*matcher)(T**, int, int, int*, int);
114 matcher matcher_func = FUNCTION_CAST<matcher>(code->entry());
115 int at_start_val = at_start ? 1 : 0;
116 int result = matcher_func(input,
117 start_offset,
118 end_offset,
119 output,
120 at_start_val);
121 return (result < 0) ? EXCEPTION : (result ? SUCCESS : FAILURE);
122 }
123 118
124 private: 119 private:
125 // Offsets from ebp of arguments to function. 120 // Offsets from ebp of function parameters and stored registers.
126 static const int kBackup_ebx = sizeof(uint32_t); 121 static const int kFramePointer = 0;
127 static const int kBackup_edi = kBackup_ebx + sizeof(uint32_t); 122 // Above the frame pointer - function parameters and return address.
128 static const int kBackup_esi = kBackup_edi + sizeof(uint32_t); 123 static const int kReturn_eip = kFramePointer + kPointerSize;
129 static const int kReturn_eip = kBackup_esi + sizeof(uint32_t); 124 static const int kInputBuffer = kReturn_eip + kPointerSize;
130 static const int kInputBuffer = kReturn_eip + sizeof(uint32_t); 125 static const int kInputStartOffset = kInputBuffer + kPointerSize;
131 static const int kInputStartOffset = kInputBuffer + sizeof(uint32_t); 126 static const int kInputEndOffset = kInputStartOffset + kPointerSize;
132 static const int kInputEndOffset = kInputStartOffset + sizeof(uint32_t); 127 static const int kRegisterOutput = kInputEndOffset + kPointerSize;
133 static const int kRegisterOutput = kInputEndOffset + sizeof(uint32_t); 128 static const int kAtStart = kRegisterOutput + kPointerSize;
134 static const int kAtStart = kRegisterOutput + sizeof(uint32_t); 129 static const int kStackHighEnd = kAtStart + kPointerSize;
130 // Below the frame pointer - local stack variables.
131 // When adding local variables remember to push space for them in
132 // the frame in GetCode.
133 static const int kBackup_esi = kFramePointer - kPointerSize;
134 static const int kBackup_edi = kBackup_esi - kPointerSize;
135 static const int kBackup_ebx = kBackup_edi - kPointerSize;
136 static const int kInputStartMinusOne = kBackup_ebx - kPointerSize;
137 // First register address. Following registers are below it on the stack.
138 static const int kRegisterZero = kInputStartMinusOne - kPointerSize;
135 139
136 // Initial size of code buffer. 140 // Initial size of code buffer.
137 static const size_t kRegExpCodeSize = 1024; 141 static const size_t kRegExpCodeSize = 1024;
138 // Initial size of constant buffers allocated during compilation. 142 // Initial size of constant buffers allocated during compilation.
139 static const int kRegExpConstantsSize = 256; 143 static const int kRegExpConstantsSize = 256;
140 // Only unroll loops up to this length. TODO(lrn): Actually use this.
141 static const int kMaxInlineStringTests = 32;
142 144
143 // Compares two-byte strings case insensitively. 145 // Compares two-byte strings case insensitively.
146 // Called from generated RegExp code.
144 static int CaseInsensitiveCompareUC16(uc16** buffer, 147 static int CaseInsensitiveCompareUC16(uc16** buffer,
145 int byte_offset1, 148 int byte_offset1,
146 int byte_offset2, 149 int byte_offset2,
147 size_t byte_length); 150 size_t byte_length);
148 151
149 void LoadCurrentCharacterUnchecked(int cp_offset, int characters); 152 // Load a number of characters at the given offset from the
153 // current position, into the current-character register.
154 void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
150 155
151 // Adds code that checks whether preemption has been requested 156 // Check whether preemption has been requested.
152 // (and checks if we have hit the stack limit too). 157 void CheckPreemption();
158
159 // Check whether we are exceeding the stack limit on the backtrack stack.
153 void CheckStackLimit(); 160 void CheckStackLimit();
154 161
155 // Called from RegExp if the stack-guard is triggered. 162 // Called from RegExp if the stack-guard is triggered.
156 // If the code object is relocated, the return address is fixed before 163 // If the code object is relocated, the return address is fixed before
157 // returning. 164 // returning.
158 static int CheckStackGuardState(Address return_address, Code* re_code); 165 static int CheckStackGuardState(Address return_address, Code* re_code);
159 166
167 // Called from RegExp if the backtrack stack limit is hit.
168 // Tries to expand the stack. Returns the new stack-top pointer if
169 // successful, or 0 if unable to grow the stack.
170 // This function must not trigger a garbage collection.
171 static Address GrowStack(Address stack_top);
172
160 // Checks whether the given offset from the current position is before 173 // Checks whether the given offset from the current position is before
161 // the end of the string. 174 // the end of the string.
162 void CheckPosition(int cp_offset, Label* on_outside_input); 175 void CheckPosition(int cp_offset, Label* on_outside_input);
163 176
164 // The ebp-relative location of a regexp register. 177 // The ebp-relative location of a regexp register.
165 Operand register_location(int register_index); 178 Operand register_location(int register_index);
166 179
167 // The register containing the current character after LoadCurrentCharacter. 180 // The register containing the current character after LoadCurrentCharacter.
168 Register current_character(); 181 inline Register current_character() { return edx; }
182
183 // The register containing the backtrack stack top. Provides a meaningful
184 // name to the register.
185 inline Register backtrack_stackpointer() { return ecx; }
169 186
170 // Byte size of chars in the string to match (decided by the Mode argument) 187 // Byte size of chars in the string to match (decided by the Mode argument)
171 size_t char_size(); 188 inline int char_size() { return static_cast<int>(mode_); }
172 189
173 // Equivalent to a conditional branch to the label, unless the label 190 // Equivalent to a conditional branch to the label, unless the label
174 // is NULL, in which case it is a conditional Backtrack. 191 // is NULL, in which case it is a conditional Backtrack.
175 void BranchOrBacktrack(Condition condition, Label* to); 192 void BranchOrBacktrack(Condition condition, Label* to, Hint hint = no_hint);
176 193
177 // Load the address of a "constant buffer" (a slice of a byte array) 194 // Load the address of a "constant buffer" (a slice of a byte array)
178 // into a register. The address is computed from the ByteArray* address 195 // into a register. The address is computed from the ByteArray* address
179 // and an offset. Uses no extra registers. 196 // and an offset. Uses no extra registers.
180 void LoadConstantBufferAddress(Register reg, ArraySlice* buffer); 197 void LoadConstantBufferAddress(Register reg, ArraySlice* buffer);
181 198
182 // Call and return internally in the generated code in a way that 199 // Call and return internally in the generated code in a way that
183 // is GC-safe (i.e., doesn't leave absolute code addresses on the stack) 200 // is GC-safe (i.e., doesn't leave absolute code addresses on the stack)
184 void SafeCall(Label* to); 201 inline void SafeCall(Label* to);
185 void SafeReturn(); 202 inline void SafeReturn();
203
204 // Pushes the value of a register on the backtrack stack. Decrements the
205 // stack pointer (ecx) by a word size and stores the register's value there.
206 inline void Push(Register source);
207
208 // Pushes a value on the backtrack stack. Decrements the stack pointer (ecx)
209 // by a word size and stores the value there.
210 inline void Push(Immediate value);
211
212 // Pops a value from the backtrack stack. Reads the word at the stack pointer
213 // (ecx) and increments it by a word size.
214 inline void Pop(Register target);
186 215
187 // Before calling a C-function from generated code, align arguments on stack. 216 // Before calling a C-function from generated code, align arguments on stack.
188 // After aligning the frame, arguments must be stored in esp[0], esp[4], 217 // After aligning the frame, arguments must be stored in esp[0], esp[4],
189 // etc., not pushed. The argument count assumes all arguments are word sized. 218 // etc., not pushed. The argument count assumes all arguments are word sized.
190 void FrameAlign(int num_arguments); 219 // Some compilers/platforms require the stack to be aligned when calling
220 // C++ code.
221 inline void FrameAlign(int num_arguments);
222
191 // Calls a C function and cleans up the space for arguments allocated 223 // Calls a C function and cleans up the space for arguments allocated
192 // by FrameAlign. The called function is not allowed to trigger a garbage 224 // by FrameAlign. The called function is not allowed to trigger a garbage
193 // collection, since that might move the code and invalidate the return 225 // collection, since that might move the code and invalidate the return
194 // address 226 // address (unless this is somehow accounted for).
195 void CallCFunction(Address function_address, int num_arguments); 227 inline void CallCFunction(Address function_address, int num_arguments);
196 228
197 MacroAssembler* masm_; 229 MacroAssembler* masm_;
230
198 // Constant buffer provider. Allocates external storage for storing 231 // Constant buffer provider. Allocates external storage for storing
199 // constants. 232 // constants.
200 ByteArrayProvider constants_; 233 ByteArrayProvider constants_;
201 // Which mode to generate code for (ASCII or UTF16). 234
235 // Which mode to generate code for (ASCII or UC16).
202 Mode mode_; 236 Mode mode_;
237
203 // One greater than maximal register index actually used. 238 // One greater than maximal register index actually used.
204 int num_registers_; 239 int num_registers_;
240
205 // Number of registers to output at the end (the saved registers 241 // Number of registers to output at the end (the saved registers
206 // are always 0..num_saved_registers_-1) 242 // are always 0..num_saved_registers_-1)
207 int num_saved_registers_; 243 int num_saved_registers_;
244
208 // Labels used internally. 245 // Labels used internally.
209 Label entry_label_; 246 Label entry_label_;
210 Label start_label_; 247 Label start_label_;
211 Label success_label_; 248 Label success_label_;
212 Label backtrack_label_; 249 Label backtrack_label_;
213 Label exit_label_; 250 Label exit_label_;
214 Label check_preempt_label_; 251 Label check_preempt_label_;
252 Label stack_overflow_label_;
253
215 // Handle used to represent the generated code object itself. 254 // Handle used to represent the generated code object itself.
216 Handle<Object> self_; 255 Handle<Object> self_;
217 }; 256 };
218 257
219 }} // namespace v8::internal 258 }} // namespace v8::internal
220 259
221 #endif /* REGEXP_MACRO_ASSEMBLER_IA32_H_ */ 260 #endif /* REGEXP_MACRO_ASSEMBLER_IA32_H_ */
OLDNEW
« no previous file with comments | « src/regexp-macro-assembler.cc ('k') | src/regexp-macro-assembler-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698