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

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

Issue 14457: * Removed rep cmpsb everywhere in irregexp-ia32 (Closed)
Patch Set: Changes in back-reference handling Created 12 years 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
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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 int cp_offset, 186 int cp_offset,
187 Label* on_failure, 187 Label* on_failure,
188 bool check_end_of_string) { 188 bool check_end_of_string) {
189 int byte_length = str.length() * char_size(); 189 int byte_length = str.length() * char_size();
190 int byte_offset = cp_offset * char_size(); 190 int byte_offset = cp_offset * char_size();
191 if (check_end_of_string) { 191 if (check_end_of_string) {
192 __ cmp(Operand(edi), Immediate(-(byte_offset + byte_length))); 192 __ cmp(Operand(edi), Immediate(-(byte_offset + byte_length)));
193 BranchOrBacktrack(greater, on_failure); 193 BranchOrBacktrack(greater, on_failure);
194 } 194 }
195 195
196 if (str.length() <= kMaxInlineStringTests) { 196 Label backtrack;
197 for (int i = 0; i < str.length(); i++) { 197 if (on_failure == NULL) {
198 if (mode_ == ASCII) { 198 // Avoid inlining the Backtrack macro for each test.
199 __ cmpb(Operand(esi, edi, times_1, byte_offset + i), 199 Label skip_backtrack;
200 static_cast<int8_t>(str[i])); 200 __ jmp(&skip_backtrack);
201 } else { 201 __ bind(&backtrack);
202 ASSERT(mode_ == UC16); 202 Backtrack();
203 __ cmpw(Operand(esi, edi, times_1, byte_offset + i * sizeof(uc16)), 203 __ bind(&skip_backtrack);
204 Immediate(str[i])); 204 on_failure = &backtrack;
205 }
206 BranchOrBacktrack(not_equal, on_failure);
207 }
208 return;
209 } 205 }
210 206
211 ArraySlice constant_buffer = constants_.GetBuffer(str.length(), char_size()); 207 for (int i = 0; i < str.length(); i++) {
212 if (mode_ == ASCII) { 208 if (mode_ == ASCII) {
213 for (int i = 0; i < str.length(); i++) { 209 __ cmpb(Operand(esi, edi, times_1, byte_offset + i),
214 constant_buffer.at<char>(i) = static_cast<char>(str[i]); 210 static_cast<int8_t>(str[i]));
211 } else {
212 ASSERT(mode_ == UC16);
213 __ cmpw(Operand(esi, edi, times_1, byte_offset + i * sizeof(uc16)),
214 Immediate(str[i]));
215 } 215 }
216 } else { 216 BranchOrBacktrack(not_equal, on_failure);
217 ASSERT(mode_ == UC16);
218 memcpy(constant_buffer.location(),
219 str.start(),
220 str.length() * sizeof(uc16));
221 } 217 }
222
223 __ mov(eax, edi);
224 __ mov(ebx, esi);
225 __ lea(edi, Operand(esi, edi, times_1, byte_offset));
226 LoadConstantBufferAddress(esi, &constant_buffer);
227 __ mov(ecx, str.length());
228 if (char_size() == 1) {
229 __ rep_cmpsb();
230 } else {
231 ASSERT(char_size() == 2);
232 __ rep_cmpsw();
233 }
234 __ mov(esi, ebx);
235 __ mov(edi, eax);
236 BranchOrBacktrack(not_equal, on_failure);
237 } 218 }
238 219
239 220
240 void RegExpMacroAssemblerIA32::CheckGreedyLoop(Label* on_equal) { 221 void RegExpMacroAssemblerIA32::CheckGreedyLoop(Label* on_equal) {
241 Label fallthrough; 222 Label fallthrough;
242 __ cmp(edi, Operand(esp, 0)); 223 __ cmp(edi, Operand(esp, 0));
243 __ j(not_equal, &fallthrough); 224 __ j(not_equal, &fallthrough);
244 __ add(Operand(esp), Immediate(4)); // Pop. 225 __ add(Operand(esp), Immediate(4)); // Pop.
245 BranchOrBacktrack(no_condition, on_equal); 226 BranchOrBacktrack(no_condition, on_equal);
246 __ bind(&fallthrough); 227 __ bind(&fallthrough);
247 } 228 }
248 229
249 230
250 void RegExpMacroAssemblerIA32::CheckNotBackReferenceIgnoreCase( 231 void RegExpMacroAssemblerIA32::CheckNotBackReferenceIgnoreCase(
251 int start_reg, 232 int start_reg,
252 Label* on_no_match) { 233 Label* on_no_match) {
253 Label fallthrough; 234 Label fallthrough;
254 __ mov(eax, register_location(start_reg)); 235 __ mov(edx, register_location(start_reg));
255 __ mov(ecx, register_location(start_reg + 1)); 236 __ mov(ecx, register_location(start_reg + 1));
256 __ sub(ecx, Operand(eax)); // Length to check. 237 __ sub(ecx, Operand(edx)); // Length to check.
257 BranchOrBacktrack(less, on_no_match); 238 BranchOrBacktrack(less, on_no_match);
258 __ j(equal, &fallthrough); 239 __ j(equal, &fallthrough);
259 240
260 if (mode_ == ASCII) { 241 if (mode_ == ASCII) {
261 Label success; 242 Label success;
262 Label fail; 243 Label fail;
263 __ push(esi); 244 Label loop_increment;
264 __ push(edi); 245 __ push(edi);
246 __ add(edx, Operand(esi));
265 __ add(edi, Operand(esi)); 247 __ add(edi, Operand(esi));
266 __ add(esi, Operand(eax)); 248 __ add(ecx, Operand(edi));
249
267 Label loop; 250 Label loop;
268 __ bind(&loop); 251 __ bind(&loop);
269 __ rep_cmpsb(); 252 __ movzx_b(eax, Operand(edi, 0));
270 __ j(equal, &success); 253 __ cmpb_al(Operand(edx, 0));
254 __ j(equal, &loop_increment);
255
271 // Compare lower-case if letters. 256 // Compare lower-case if letters.
272 __ movzx_b(eax, Operand(edi, -1)); 257 __ or_(eax, 0x20); // To lower-case.
273 __ or_(eax, 0x20); // To-lower-case
274 __ lea(ebx, Operand(eax, -'a')); 258 __ lea(ebx, Operand(eax, -'a'));
275 __ cmp(ebx, static_cast<int32_t>('z' - 'a')); 259 __ cmp(ebx, static_cast<int32_t>('z' - 'a'));
276 __ j(above, &fail); 260 __ j(above, &fail);
277 __ movzx_b(ebx, Operand(esi, -1)); 261 __ movzx_b(ebx, Operand(edx, 0));
278 __ or_(ebx, 0x20); // To-lower-case 262 __ or_(ebx, 0x20); // To-lower-case
279 __ cmp(eax, Operand(ebx)); 263 __ cmp(eax, Operand(ebx));
280 __ j(not_equal, &fail); 264 __ j(not_equal, &fail);
281 __ or_(ecx, Operand(ecx)); 265
282 __ j(not_equal, &loop); 266 __ bind(&loop_increment);
267 __ add(Operand(edx), Immediate(1));
268 __ add(Operand(edi), Immediate(1));
269 __ cmp(edi, Operand(ecx));
270 __ j(below, &loop, taken);
283 __ jmp(&success); 271 __ jmp(&success);
284 272
285 __ bind(&fail); 273 __ bind(&fail);
286 __ pop(edi); 274 __ pop(edi);
287 __ pop(esi);
288 BranchOrBacktrack(no_condition, on_no_match); 275 BranchOrBacktrack(no_condition, on_no_match);
289 276
290 __ bind(&success); 277 __ bind(&success);
291 __ pop(eax); // discard original value of edi 278 __ pop(eax); // discard original value of edi
292 __ pop(esi);
293 __ sub(edi, Operand(esi)); 279 __ sub(edi, Operand(esi));
294 } else { 280 } else {
295 ASSERT(mode_ == UC16); 281 ASSERT(mode_ == UC16);
296 __ push(esi); 282 __ push(esi);
297 __ push(edi); 283 __ push(edi);
298 __ push(ecx); 284 __ push(ecx);
299 const int four_arguments = 4; 285 const int four_arguments = 4;
300 FrameAlign(four_arguments); 286 FrameAlign(four_arguments);
301 // Put arguments on stack. 287 // Put arguments on stack.
302 __ mov(Operand(esp, 3 * kPointerSize), ecx); 288 __ mov(Operand(esp, 3 * kPointerSize), ecx);
(...skipping 15 matching lines...) Expand all
318 __ add(edi, Operand(ecx)); 304 __ add(edi, Operand(ecx));
319 } 305 }
320 __ bind(&fallthrough); 306 __ bind(&fallthrough);
321 } 307 }
322 308
323 309
324 void RegExpMacroAssemblerIA32::CheckNotBackReference( 310 void RegExpMacroAssemblerIA32::CheckNotBackReference(
325 int start_reg, 311 int start_reg,
326 Label* on_no_match) { 312 Label* on_no_match) {
327 Label fallthrough; 313 Label fallthrough;
328 __ mov(eax, register_location(start_reg)); 314 Label success;
315 Label fail;
316 __ mov(edx, register_location(start_reg));
329 __ mov(ecx, register_location(start_reg + 1)); 317 __ mov(ecx, register_location(start_reg + 1));
330 __ sub(ecx, Operand(eax)); // Length to check. 318 __ sub(ecx, Operand(edx)); // Length to check.
331 BranchOrBacktrack(less, on_no_match); 319 BranchOrBacktrack(less, on_no_match);
332 __ j(equal, &fallthrough); 320 __ j(equal, &fallthrough);
333 // Check that there are sufficient characters left in the input. 321 // Check that there are sufficient characters left in the input.
322
334 __ mov(ebx, edi); 323 __ mov(ebx, edi);
335 __ add(ebx, Operand(ecx)); 324 __ add(ebx, Operand(ecx));
336 BranchOrBacktrack(greater, on_no_match); 325 BranchOrBacktrack(greater, on_no_match);
337 326
338 __ mov(ebx, edi); 327 __ mov(ebx, edi);
339 __ mov(edx, esi);
340 __ add(edi, Operand(esi)); 328 __ add(edi, Operand(esi));
341 __ add(esi, Operand(eax)); 329 __ add(edx, Operand(esi));
342 __ rep_cmpsb(); 330 __ add(ecx, Operand(edi));
343 __ mov(esi, edx); 331
344 Label success; 332 Label loop;
345 __ j(equal, &success); 333 __ bind(&loop);
334 if (mode_ == ASCII) {
335 __ movzx_b(eax, Operand(edx, 0));
336 __ cmpb_al(Operand(edi, 0));
337 } else {
338 ASSERT(mode_ == UC16);
339 __ movzx_w(eax, Operand(edx, 0));
340 __ cmpw_ax(Operand(edi, 0));
341 }
342 __ j(not_equal, &fail);
343 __ add(Operand(edx), Immediate(char_size()));
344 __ add(Operand(edi), Immediate(char_size()));
345 __ cmp(edi, Operand(ecx));
346 __ j(below, &loop);
347 __ jmp(&success);
348
349 __ bind(&fail);
346 __ mov(edi, ebx); 350 __ mov(edi, ebx);
347 BranchOrBacktrack(no_condition, on_no_match); 351 BranchOrBacktrack(no_condition, on_no_match);
348 352
349 __ bind(&success); 353 __ bind(&success);
350 __ sub(edi, Operand(esi)); 354 __ sub(edi, Operand(esi));
351
352 __ bind(&fallthrough); 355 __ bind(&fallthrough);
353 } 356 }
354 357
355 358
356 void RegExpMacroAssemblerIA32::CheckNotRegistersEqual(int reg1, 359 void RegExpMacroAssemblerIA32::CheckNotRegistersEqual(int reg1,
357 int reg2, 360 int reg2,
358 Label* on_not_equal) { 361 Label* on_not_equal) {
359 __ mov(eax, register_location(reg1)); 362 __ mov(eax, register_location(reg1));
360 __ cmp(eax, register_location(reg2)); 363 __ cmp(eax, register_location(reg2));
361 BranchOrBacktrack(not_equal, on_not_equal); 364 BranchOrBacktrack(not_equal, on_not_equal);
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 883
881 884
882 void RegExpMacroAssemblerIA32::LoadConstantBufferAddress(Register reg, 885 void RegExpMacroAssemblerIA32::LoadConstantBufferAddress(Register reg,
883 ArraySlice* buffer) { 886 ArraySlice* buffer) {
884 __ mov(reg, buffer->array()); 887 __ mov(reg, buffer->array());
885 __ add(Operand(reg), Immediate(buffer->base_offset())); 888 __ add(Operand(reg), Immediate(buffer->base_offset()));
886 } 889 }
887 890
888 #undef __ 891 #undef __
889 }} // namespace v8::internal 892 }} // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698