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

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

Issue 8776033: Support multi-byte nop instructions as recommended by (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 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 | Annotate | Revision Log
« no previous file with comments | « src/ia32/assembler-ia32.h ('k') | src/ia32/debug-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 (c) 1994-2006 Sun Microsystems Inc. 1 // Copyright (c) 1994-2006 Sun Microsystems Inc.
2 // All Rights Reserved. 2 // All Rights Reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions 5 // modification, are permitted provided that the following conditions
6 // are met: 6 // are met:
7 // 7 //
8 // - Redistributions of source code must retain the above copyright notice, 8 // - Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer. 9 // this list of conditions and the following disclaimer.
10 // 10 //
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 desc->buffer = buffer_; 381 desc->buffer = buffer_;
382 desc->buffer_size = buffer_size_; 382 desc->buffer_size = buffer_size_;
383 desc->instr_size = pc_offset(); 383 desc->instr_size = pc_offset();
384 desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos(); 384 desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos();
385 desc->origin = this; 385 desc->origin = this;
386 } 386 }
387 387
388 388
389 void Assembler::Align(int m) { 389 void Assembler::Align(int m) {
390 ASSERT(IsPowerOf2(m)); 390 ASSERT(IsPowerOf2(m));
391 while ((pc_offset() & (m - 1)) != 0) { 391 int mask = m - 1;
392 nop(); 392 int addr = pc_offset();
393 Nop((m - (addr & mask)) & mask);
394 }
395
396
397 bool Assembler::IsNop(Address addr) {
398 Address a = addr;
399 while (*a == 0x66) a++;
400 if (*a == 0x90) return true;
401 if (a[0] == 0xf && a[1] == 0x1f) return true;
402 return false;
403 }
404
405
406 void Assembler::Nop(int bytes) {
407 EnsureSpace ensure_space(this);
408
409 if (!CpuFeatures::IsSupported(SSE2)) {
410 // Older CPUs that do not support SSE2 may not support multibyte NOP
411 // instructions.
412 for (; bytes > 0; bytes--) {
413 EMIT(0x90);
414 }
415 return;
416 }
417
418 // Multi byte nops from http://support.amd.com/us/Processor_TechDocs/40546.pdf
419 while (bytes > 0) {
420 switch (bytes) {
421 case 2:
422 EMIT(0x66);
423 case 1:
424 EMIT(0x90);
425 return;
426 case 3:
427 EMIT(0xf);
428 EMIT(0x1f);
429 EMIT(0);
430 return;
431 case 4:
432 EMIT(0xf);
433 EMIT(0x1f);
434 EMIT(0x40);
435 EMIT(0);
436 return;
437 case 6:
438 EMIT(0x66);
439 case 5:
440 EMIT(0xf);
441 EMIT(0x1f);
442 EMIT(0x44);
443 EMIT(0);
444 EMIT(0);
445 return;
446 case 7:
447 EMIT(0xf);
448 EMIT(0x1f);
449 EMIT(0x80);
450 EMIT(0);
451 EMIT(0);
452 EMIT(0);
453 EMIT(0);
454 return;
455 default:
456 case 11:
457 EMIT(0x66);
458 bytes--;
459 case 10:
460 EMIT(0x66);
461 bytes--;
462 case 9:
463 EMIT(0x66);
464 bytes--;
465 case 8:
466 EMIT(0xf);
467 EMIT(0x1f);
468 EMIT(0x84);
469 EMIT(0);
470 EMIT(0);
471 EMIT(0);
472 EMIT(0);
473 EMIT(0);
474 bytes -= 8;
475 }
393 } 476 }
394 } 477 }
395 478
396 479
397 void Assembler::CodeTargetAlign() { 480 void Assembler::CodeTargetAlign() {
398 Align(16); // Preferred alignment of jump targets on ia32. 481 Align(16); // Preferred alignment of jump targets on ia32.
399 } 482 }
400 483
401 484
402 void Assembler::cpuid() { 485 void Assembler::cpuid() {
(...skipping 2090 matching lines...) Expand 10 before | Expand all | Expand 10 after
2493 fprintf(coverage_log, "%s\n", file_line); 2576 fprintf(coverage_log, "%s\n", file_line);
2494 fflush(coverage_log); 2577 fflush(coverage_log);
2495 } 2578 }
2496 } 2579 }
2497 2580
2498 #endif 2581 #endif
2499 2582
2500 } } // namespace v8::internal 2583 } } // namespace v8::internal
2501 2584
2502 #endif // V8_TARGET_ARCH_IA32 2585 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/assembler-ia32.h ('k') | src/ia32/debug-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698