OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_ARM_REGEXP_MACRO_ASSEMBLER_ARM_H_ | 28 #ifndef V8_A64_REGEXP_MACRO_ASSEMBLER_A64_H_ |
29 #define V8_ARM_REGEXP_MACRO_ASSEMBLER_ARM_H_ | 29 #define V8_A64_REGEXP_MACRO_ASSEMBLER_A64_H_ |
30 | 30 |
31 #include "arm/assembler-arm.h" | 31 #include "a64/assembler-a64.h" |
32 #include "arm/assembler-arm-inl.h" | 32 #include "a64/assembler-a64-inl.h" |
33 #include "macro-assembler.h" | 33 #include "macro-assembler.h" |
34 | 34 |
35 namespace v8 { | 35 namespace v8 { |
36 namespace internal { | 36 namespace internal { |
37 | 37 |
38 | 38 |
39 #ifndef V8_INTERPRETED_REGEXP | 39 #ifndef V8_INTERPRETED_REGEXP |
40 class RegExpMacroAssemblerARM: public NativeRegExpMacroAssembler { | 40 class RegExpMacroAssemblerA64: public NativeRegExpMacroAssembler { |
41 public: | 41 public: |
42 RegExpMacroAssemblerARM(Mode mode, int registers_to_save, Zone* zone); | 42 RegExpMacroAssemblerA64(Mode mode, int registers_to_save, Zone* zone); |
43 virtual ~RegExpMacroAssemblerARM(); | 43 virtual ~RegExpMacroAssemblerA64(); |
44 virtual int stack_limit_slack(); | 44 virtual int stack_limit_slack(); |
45 virtual void AdvanceCurrentPosition(int by); | 45 virtual void AdvanceCurrentPosition(int by); |
46 virtual void AdvanceRegister(int reg, int by); | 46 virtual void AdvanceRegister(int reg, int by); |
47 virtual void Backtrack(); | 47 virtual void Backtrack(); |
48 virtual void Bind(Label* label); | 48 virtual void Bind(Label* label); |
49 virtual void CheckAtStart(Label* on_at_start); | 49 virtual void CheckAtStart(Label* on_at_start); |
50 virtual void CheckCharacter(unsigned c, Label* on_equal); | 50 virtual void CheckCharacter(unsigned c, Label* on_equal); |
51 virtual void CheckCharacterAfterAnd(unsigned c, | 51 virtual void CheckCharacterAfterAnd(unsigned c, |
52 unsigned mask, | 52 unsigned mask, |
53 Label* on_equal); | 53 Label* on_equal); |
54 virtual void CheckCharacterGT(uc16 limit, Label* on_greater); | 54 virtual void CheckCharacterGT(uc16 limit, Label* on_greater); |
55 virtual void CheckCharacterLT(uc16 limit, Label* on_less); | 55 virtual void CheckCharacterLT(uc16 limit, Label* on_less); |
| 56 virtual void CheckCharacters(Vector<const uc16> str, |
| 57 int cp_offset, |
| 58 Label* on_failure, |
| 59 bool check_end_of_string); |
56 // A "greedy loop" is a loop that is both greedy and with a simple | 60 // A "greedy loop" is a loop that is both greedy and with a simple |
57 // body. It has a particularly simple implementation. | 61 // body. It has a particularly simple implementation. |
58 virtual void CheckGreedyLoop(Label* on_tos_equals_current_position); | 62 virtual void CheckGreedyLoop(Label* on_tos_equals_current_position); |
59 virtual void CheckNotAtStart(Label* on_not_at_start); | 63 virtual void CheckNotAtStart(Label* on_not_at_start); |
60 virtual void CheckNotBackReference(int start_reg, Label* on_no_match); | 64 virtual void CheckNotBackReference(int start_reg, Label* on_no_match); |
61 virtual void CheckNotBackReferenceIgnoreCase(int start_reg, | 65 virtual void CheckNotBackReferenceIgnoreCase(int start_reg, |
62 Label* on_no_match); | 66 Label* on_no_match); |
63 virtual void CheckNotCharacter(unsigned c, Label* on_not_equal); | 67 virtual void CheckNotCharacter(unsigned c, Label* on_not_equal); |
64 virtual void CheckNotCharacterAfterAnd(unsigned c, | 68 virtual void CheckNotCharacterAfterAnd(unsigned c, |
65 unsigned mask, | 69 unsigned mask, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 virtual void WriteCurrentPositionToRegister(int reg, int cp_offset); | 110 virtual void WriteCurrentPositionToRegister(int reg, int cp_offset); |
107 virtual void ClearRegisters(int reg_from, int reg_to); | 111 virtual void ClearRegisters(int reg_from, int reg_to); |
108 virtual void WriteStackPointerToRegister(int reg); | 112 virtual void WriteStackPointerToRegister(int reg); |
109 virtual bool CanReadUnaligned(); | 113 virtual bool CanReadUnaligned(); |
110 | 114 |
111 // Called from RegExp if the stack-guard is triggered. | 115 // Called from RegExp if the stack-guard is triggered. |
112 // If the code object is relocated, the return address is fixed before | 116 // If the code object is relocated, the return address is fixed before |
113 // returning. | 117 // returning. |
114 static int CheckStackGuardState(Address* return_address, | 118 static int CheckStackGuardState(Address* return_address, |
115 Code* re_code, | 119 Code* re_code, |
116 Address re_frame); | 120 Address re_frame, |
| 121 int start_offset, |
| 122 const byte** input_start, |
| 123 const byte** input_end); |
117 | 124 |
118 private: | 125 private: |
119 // Offsets from frame_pointer() of function parameters and stored registers. | |
120 static const int kFramePointer = 0; | |
121 | |
122 // Above the frame pointer - Stored registers and stack passed parameters. | 126 // Above the frame pointer - Stored registers and stack passed parameters. |
123 // Register 4..11. | 127 // Callee-saved registers x19-x29, where x29 is the old frame pointer. |
124 static const int kStoredRegisters = kFramePointer; | 128 static const int kCalleeSavedRegisters = 0; |
125 // Return address (stored from link register, read into pc on return). | 129 // Return address. |
126 static const int kReturnAddress = kStoredRegisters + 8 * kPointerSize; | 130 // It is placed above the 11 callee-saved registers. |
| 131 static const int kReturnAddress = kCalleeSavedRegisters + 11 * kPointerSize; |
127 static const int kSecondaryReturnAddress = kReturnAddress + kPointerSize; | 132 static const int kSecondaryReturnAddress = kReturnAddress + kPointerSize; |
128 // Stack parameters placed by caller. | 133 // Stack parameter placed by caller. |
129 static const int kRegisterOutput = kSecondaryReturnAddress + kPointerSize; | 134 static const int kIsolate = kSecondaryReturnAddress + kPointerSize; |
130 static const int kNumOutputRegisters = kRegisterOutput + kPointerSize; | |
131 static const int kStackHighEnd = kNumOutputRegisters + kPointerSize; | |
132 static const int kDirectCall = kStackHighEnd + kPointerSize; | |
133 static const int kIsolate = kDirectCall + kPointerSize; | |
134 | 135 |
135 // Below the frame pointer. | 136 // Below the frame pointer. |
136 // Register parameters stored by setup code. | 137 // Register parameters stored by setup code. |
137 static const int kInputEnd = kFramePointer - kPointerSize; | 138 static const int kDirectCall = kCalleeSavedRegisters - kPointerSize; |
138 static const int kInputStart = kInputEnd - kPointerSize; | 139 static const int kStackBase = kDirectCall - kPointerSize; |
139 static const int kStartIndex = kInputStart - kPointerSize; | 140 static const int kOutputSize = kStackBase - kPointerSize; |
140 static const int kInputString = kStartIndex - kPointerSize; | 141 static const int kInput = kOutputSize - kPointerSize; |
141 // When adding local variables remember to push space for them in | 142 // When adding local variables remember to push space for them in |
142 // the frame in GetCode. | 143 // the frame in GetCode. |
143 static const int kSuccessfulCaptures = kInputString - kPointerSize; | 144 static const int kSuccessCounter = kInput - kPointerSize; |
144 static const int kInputStartMinusOne = kSuccessfulCaptures - kPointerSize; | 145 // First position register address on the stack. Following positions are |
145 // First register address. Following registers are below it on the stack. | 146 // below it. A position is a 32 bit value. |
146 static const int kRegisterZero = kInputStartMinusOne - kPointerSize; | 147 static const int kFirstRegisterOnStack = kSuccessCounter - kWRegSizeInBytes; |
| 148 // A capture is a 64 bit value holding two position. |
| 149 static const int kFirstCaptureOnStack = kSuccessCounter - kXRegSizeInBytes; |
147 | 150 |
148 // Initial size of code buffer. | 151 // Initial size of code buffer. |
149 static const size_t kRegExpCodeSize = 1024; | 152 static const size_t kRegExpCodeSize = 1024; |
150 | 153 |
151 static const int kBacktrackConstantPoolSize = 4; | 154 // When initializing registers to a non-position value we can unroll |
| 155 // the loop. Set the limit of registers to unroll. |
| 156 static const int kNumRegistersToUnroll = 16; |
| 157 |
| 158 // We are using x0 to x7 as a register cache. Each hardware register must |
| 159 // contain one capture, that is two 32 bit registers. We can cache at most |
| 160 // 16 registers. |
| 161 static const int kNumCachedRegisters = 16; |
152 | 162 |
153 // Load a number of characters at the given offset from the | 163 // Load a number of characters at the given offset from the |
154 // current position, into the current-character register. | 164 // current position, into the current-character register. |
155 void LoadCurrentCharacterUnchecked(int cp_offset, int character_count); | 165 void LoadCurrentCharacterUnchecked(int cp_offset, int character_count); |
156 | 166 |
157 // Check whether preemption has been requested. | 167 // Check whether preemption has been requested. |
158 void CheckPreemption(); | 168 void CheckPreemption(); |
159 | 169 |
160 // Check whether we are exceeding the stack limit on the backtrack stack. | 170 // Check whether we are exceeding the stack limit on the backtrack stack. |
161 void CheckStackLimit(); | 171 void CheckStackLimit(); |
162 | 172 |
163 | |
164 // Generate a call to CheckStackGuardState. | 173 // Generate a call to CheckStackGuardState. |
165 void CallCheckStackGuardState(Register scratch); | 174 void CallCheckStackGuardState(Register scratch); |
166 | 175 |
167 // The ebp-relative location of a regexp register. | 176 // Location of a 32 bit position register. |
168 MemOperand register_location(int register_index); | 177 MemOperand register_location(int register_index); |
169 | 178 |
| 179 // Location of a 64 bit capture, combining two position registers. |
| 180 MemOperand capture_location(int register_index, Register scratch); |
| 181 |
170 // Register holding the current input position as negative offset from | 182 // Register holding the current input position as negative offset from |
171 // the end of the string. | 183 // the end of the string. |
172 inline Register current_input_offset() { return r6; } | 184 Register current_input_offset() { return w21; } |
173 | 185 |
174 // The register containing the current character after LoadCurrentCharacter. | 186 // The register containing the current character after LoadCurrentCharacter. |
175 inline Register current_character() { return r7; } | 187 Register current_character() { return w22; } |
176 | 188 |
177 // Register holding address of the end of the input string. | 189 // Register holding address of the end of the input string. |
178 inline Register end_of_input_address() { return r10; } | 190 Register input_end() { return x25; } |
| 191 |
| 192 // Register holding address of the start of the input string. |
| 193 Register input_start() { return x26; } |
| 194 |
| 195 // Register holding the offset from the start of the string where we should |
| 196 // start matching. |
| 197 Register start_offset() { return w27; } |
| 198 |
| 199 // Pointer to the output array's first element. |
| 200 Register output_array() { return x28; } |
179 | 201 |
180 // Register holding the frame address. Local variables, parameters and | 202 // Register holding the frame address. Local variables, parameters and |
181 // regexp registers are addressed relative to this. | 203 // regexp registers are addressed relative to this. |
182 inline Register frame_pointer() { return fp; } | 204 Register frame_pointer() { return fp; } |
183 | 205 |
184 // The register containing the backtrack stack top. Provides a meaningful | 206 // The register containing the backtrack stack top. Provides a meaningful |
185 // name to the register. | 207 // name to the register. |
186 inline Register backtrack_stackpointer() { return r8; } | 208 Register backtrack_stackpointer() { return x23; } |
187 | 209 |
188 // Register holding pointer to the current code object. | 210 // Register holding pointer to the current code object. |
189 inline Register code_pointer() { return r5; } | 211 Register code_pointer() { return x20; } |
| 212 |
| 213 // Register holding the value used for clearing capture registers. |
| 214 Register non_position_value() { return w24; } |
| 215 // The top 32 bit of this register is used to store this value |
| 216 // twice. This is used for clearing more than one register at a time. |
| 217 Register twice_non_position_value() { return x24; } |
190 | 218 |
191 // Byte size of chars in the string to match (decided by the Mode argument) | 219 // Byte size of chars in the string to match (decided by the Mode argument) |
192 inline int char_size() { return static_cast<int>(mode_); } | 220 int char_size() { return static_cast<int>(mode_); } |
193 | 221 |
194 // Equivalent to a conditional branch to the label, unless the label | 222 // Equivalent to a conditional branch to the label, unless the label |
195 // is NULL, in which case it is a conditional Backtrack. | 223 // is NULL, in which case it is a conditional Backtrack. |
196 void BranchOrBacktrack(Condition condition, Label* to); | 224 void BranchOrBacktrack(Condition condition, Label* to); |
197 | 225 |
198 // Call and return internally in the generated code in a way that | 226 // Compares reg against immmediate before calling BranchOrBacktrack. |
199 // is GC-safe (i.e., doesn't leave absolute code addresses on the stack) | 227 // It makes use of the Cbz and Cbnz instructions. |
200 inline void SafeCall(Label* to, Condition cond = al); | 228 void CompareAndBranchOrBacktrack(Register reg, |
201 inline void SafeReturn(); | 229 int immediate, |
202 inline void SafeCallTarget(Label* name); | 230 Condition condition, |
| 231 Label* to); |
| 232 |
| 233 inline void CallIf(Label* to, Condition condition); |
| 234 |
| 235 // Save and restore the link register on the stack in a way that |
| 236 // is GC-safe. |
| 237 inline void SaveLinkRegister(); |
| 238 inline void RestoreLinkRegister(); |
203 | 239 |
204 // Pushes the value of a register on the backtrack stack. Decrements the | 240 // Pushes the value of a register on the backtrack stack. Decrements the |
205 // stack pointer by a word size and stores the register's value there. | 241 // stack pointer by a word size and stores the register's value there. |
206 inline void Push(Register source); | 242 inline void Push(Register source); |
207 | 243 |
208 // Pops a value from the backtrack stack. Reads the word at the stack pointer | 244 // Pops a value from the backtrack stack. Reads the word at the stack pointer |
209 // and increments it by a word size. | 245 // and increments it by a word size. |
210 inline void Pop(Register target); | 246 inline void Pop(Register target); |
211 | 247 |
| 248 // This state indicates where the register actually is. |
| 249 enum RegisterState { |
| 250 STACKED, // Resides in memory. |
| 251 CACHED_LSW, // Least Significant Word of a 64 bit hardware register. |
| 252 CACHED_MSW // Most Significant Word of a 64 bit hardware register. |
| 253 }; |
| 254 |
| 255 RegisterState GetRegisterState(int register_index) { |
| 256 ASSERT(register_index >= 0); |
| 257 if (register_index >= kNumCachedRegisters) { |
| 258 return STACKED; |
| 259 } else { |
| 260 if ((register_index % 2) == 0) { |
| 261 return CACHED_LSW; |
| 262 } else { |
| 263 return CACHED_MSW; |
| 264 } |
| 265 } |
| 266 } |
| 267 |
| 268 // Store helper that takes the state of the register into account. |
| 269 inline void StoreRegister(int register_index, Register source); |
| 270 |
| 271 // Returns a hardware W register that holds the value of the capture |
| 272 // register. |
| 273 // |
| 274 // This function will try to use an existing cache register (w0-w7) for the |
| 275 // result. Otherwise, it will load the value into maybe_result. |
| 276 // |
| 277 // If the returned register is anything other than maybe_result, calling code |
| 278 // must not write to it. |
| 279 inline Register GetRegister(int register_index, Register maybe_result); |
| 280 |
| 281 // Returns the harware register (x0-x7) holding the value of the capture |
| 282 // register. |
| 283 // This assumes that the state of the register is not STACKED. |
| 284 inline Register GetCachedRegister(int register_index); |
| 285 |
212 Isolate* isolate() const { return masm_->isolate(); } | 286 Isolate* isolate() const { return masm_->isolate(); } |
213 | 287 |
214 MacroAssembler* masm_; | 288 MacroAssembler* masm_; |
215 | 289 |
216 // Which mode to generate code for (ASCII or UC16). | 290 // Which mode to generate code for (ASCII or UC16). |
217 Mode mode_; | 291 Mode mode_; |
218 | 292 |
219 // One greater than maximal register index actually used. | 293 // One greater than maximal register index actually used. |
220 int num_registers_; | 294 int num_registers_; |
221 | 295 |
222 // Number of registers to output at the end (the saved registers | 296 // Number of registers to output at the end (the saved registers |
223 // are always 0..num_saved_registers_-1) | 297 // are always 0..num_saved_registers_-1) |
224 int num_saved_registers_; | 298 int num_saved_registers_; |
225 | 299 |
226 // Labels used internally. | 300 // Labels used internally. |
227 Label entry_label_; | 301 Label entry_label_; |
228 Label start_label_; | 302 Label start_label_; |
229 Label success_label_; | 303 Label success_label_; |
230 Label backtrack_label_; | 304 Label backtrack_label_; |
231 Label exit_label_; | 305 Label exit_label_; |
232 Label check_preempt_label_; | 306 Label check_preempt_label_; |
233 Label stack_overflow_label_; | 307 Label stack_overflow_label_; |
234 }; | 308 }; |
235 | 309 |
236 #endif // V8_INTERPRETED_REGEXP | 310 #endif // V8_INTERPRETED_REGEXP |
237 | 311 |
238 | 312 |
239 }} // namespace v8::internal | 313 }} // namespace v8::internal |
240 | 314 |
241 #endif // V8_ARM_REGEXP_MACRO_ASSEMBLER_ARM_H_ | 315 #endif // V8_A64_REGEXP_MACRO_ASSEMBLER_A64_H_ |
OLD | NEW |