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

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

Issue 115816: Add immediate operands and arithmetic operations to the x64 assembler. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 6 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/x64/assembler-x64.h ('k') | src/x64/assembler-x64-inl.h » ('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 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 pc_[0] = (adr.buf_[0] & ~0x38) | ((reg.code() && 0x7) << 3); 294 pc_[0] = (adr.buf_[0] & ~0x38) | ((reg.code() && 0x7) << 3);
295 295
296 // Emit the rest of the encoded operand. 296 // Emit the rest of the encoded operand.
297 for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i]; 297 for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i];
298 pc_ += length; 298 pc_ += length;
299 } 299 }
300 300
301 301
302 // Assembler Instruction implementations 302 // Assembler Instruction implementations
303 303
304 void Assembler::add(Register dst, const Operand& src) { 304 void Assembler::arithmetic_op(byte opcode, Register reg, const Operand& op) {
305 EnsureSpace ensure_space(this);
306 last_pc_ = pc_;
307 emit_rex_64(reg, op);
308 EMIT(opcode);
309 emit_operand(reg, op);
310 }
311
312
313 void Assembler::arithmetic_op(byte opcode, Register dst, Register src) {
305 EnsureSpace ensure_space(this); 314 EnsureSpace ensure_space(this);
306 last_pc_ = pc_; 315 last_pc_ = pc_;
307 emit_rex_64(dst, src); 316 emit_rex_64(dst, src);
308 EMIT(0x03); 317 EMIT(opcode);
309 emit_operand(dst, src); 318 EMIT(0xC0 | (dst.code() & 0x7) << 3 | (src.code() & 0x7));
310 } 319 }
311 320
312 321 void Assembler::immediate_arithmetic_op(byte subcode,
313 void Assembler::add(Register dst, Register src) { 322 Register dst,
323 Immediate src) {
314 EnsureSpace ensure_space(this); 324 EnsureSpace ensure_space(this);
315 last_pc_ = pc_; 325 last_pc_ = pc_;
316 emit_rex_64(dst, src); 326 emit_rex_64(rax, dst);
317 EMIT(0x03); 327 if (is_int8(src.value_)) {
318 EMIT(0xC0 | (dst.code() & 0x7) << 3 | (src.code() & 0x7)); 328 EMIT(0x83);
329 EMIT(0xC0 | (subcode << 3) | (dst.code() & 0x7));
330 EMIT(src.value_);
331 } else {
332 EMIT(0x81);
333 EMIT(0xC0 | (subcode << 3) | (dst.code() & 0x7));
334 emitl(src.value_);
335 }
336 }
337
338 void Assembler::immediate_arithmetic_op(byte subcode,
339 const Operand& dst,
340 Immediate src) {
341 EnsureSpace ensure_space(this);
342 last_pc_ = pc_;
343 emit_rex_64(rax, dst);
344 if (is_int8(src.value_)) {
345 EMIT(0x83);
346 emit_operand(Register::toRegister(subcode), dst);
347 EMIT(src.value_);
348 } else {
349 EMIT(0x81);
350 emit_operand(Register::toRegister(subcode), dst);
351 emitl(src.value_);
352 }
319 } 353 }
320 354
321 355
322 void Assembler::call(Label* L) { 356 void Assembler::call(Label* L) {
323 EnsureSpace ensure_space(this); 357 EnsureSpace ensure_space(this);
324 last_pc_ = pc_; 358 last_pc_ = pc_;
325 // 1110 1000 #32-bit disp 359 // 1110 1000 #32-bit disp
326 EMIT(0xE8); 360 EMIT(0xE8);
327 if (L->is_bound()) { 361 if (L->is_bound()) {
328 int offset = L->pos() - pc_offset() - sizeof(int32_t); 362 int offset = L->pos() - pc_offset() - sizeof(int32_t);
329 ASSERT(offset <= 0); 363 ASSERT(offset <= 0);
330 emit(offset); 364 emitl(offset);
331 } else if (L->is_linked()) { 365 } else if (L->is_linked()) {
332 emit(L->pos()); 366 emitl(L->pos());
333 L->link_to(pc_offset() - sizeof(int32_t)); 367 L->link_to(pc_offset() - sizeof(int32_t));
334 } else { 368 } else {
335 ASSERT(L->is_unused()); 369 ASSERT(L->is_unused());
336 int32_t current = pc_offset(); 370 int32_t current = pc_offset();
337 emit(current); 371 emitl(current);
338 L->link_to(current); 372 L->link_to(current);
339 } 373 }
340 } 374 }
341 375
342 376
343 void Assembler::dec(Register dst) { 377 void Assembler::dec(Register dst) {
344 EnsureSpace ensure_space(this); 378 EnsureSpace ensure_space(this);
345 last_pc_ = pc_; 379 last_pc_ = pc_;
346 emit_rex_64(rcx, dst); 380 emit_rex_64(rcx, dst);
347 EMIT(0xFF); 381 EMIT(0xFF);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 int offs = L->pos() - pc_offset(); 434 int offs = L->pos() - pc_offset();
401 ASSERT(offs <= 0); 435 ASSERT(offs <= 0);
402 if (is_int8(offs - short_size)) { 436 if (is_int8(offs - short_size)) {
403 // 0111 tttn #8-bit disp 437 // 0111 tttn #8-bit disp
404 EMIT(0x70 | cc); 438 EMIT(0x70 | cc);
405 EMIT((offs - short_size) & 0xFF); 439 EMIT((offs - short_size) & 0xFF);
406 } else { 440 } else {
407 // 0000 1111 1000 tttn #32-bit disp 441 // 0000 1111 1000 tttn #32-bit disp
408 EMIT(0x0F); 442 EMIT(0x0F);
409 EMIT(0x80 | cc); 443 EMIT(0x80 | cc);
410 emit(offs - long_size); 444 emitl(offs - long_size);
411 } 445 }
412 } else if (L->is_linked()) { 446 } else if (L->is_linked()) {
413 // 0000 1111 1000 tttn #32-bit disp 447 // 0000 1111 1000 tttn #32-bit disp
414 EMIT(0x0F); 448 EMIT(0x0F);
415 EMIT(0x80 | cc); 449 EMIT(0x80 | cc);
416 emit(L->pos()); 450 emitl(L->pos());
417 L->link_to(pc_offset() - sizeof(int32_t)); 451 L->link_to(pc_offset() - sizeof(int32_t));
418 } else { 452 } else {
419 ASSERT(L->is_unused()); 453 ASSERT(L->is_unused());
420 EMIT(0x0F); 454 EMIT(0x0F);
421 EMIT(0x80 | cc); 455 EMIT(0x80 | cc);
422 int32_t current = pc_offset(); 456 int32_t current = pc_offset();
423 emit(current); 457 emitl(current);
424 L->link_to(current); 458 L->link_to(current);
425 } 459 }
426 } 460 }
427 461
428 462
429 void Assembler::jmp(Label* L) { 463 void Assembler::jmp(Label* L) {
430 EnsureSpace ensure_space(this); 464 EnsureSpace ensure_space(this);
431 last_pc_ = pc_; 465 last_pc_ = pc_;
432 if (L->is_bound()) { 466 if (L->is_bound()) {
433 int offs = L->pos() - pc_offset() - 1; 467 int offs = L->pos() - pc_offset() - 1;
434 ASSERT(offs <= 0); 468 ASSERT(offs <= 0);
435 if (is_int8(offs - sizeof(int8_t))) { 469 if (is_int8(offs - sizeof(int8_t))) {
436 // 1110 1011 #8-bit disp 470 // 1110 1011 #8-bit disp
437 EMIT(0xEB); 471 EMIT(0xEB);
438 EMIT((offs - sizeof(int8_t)) & 0xFF); 472 EMIT((offs - sizeof(int8_t)) & 0xFF);
439 } else { 473 } else {
440 // 1110 1001 #32-bit disp 474 // 1110 1001 #32-bit disp
441 EMIT(0xE9); 475 EMIT(0xE9);
442 emit(offs - sizeof(int32_t)); 476 emitl(offs - sizeof(int32_t));
443 } 477 }
444 } else if (L->is_linked()) { 478 } else if (L->is_linked()) {
445 // 1110 1001 #32-bit disp 479 // 1110 1001 #32-bit disp
446 EMIT(0xE9); 480 EMIT(0xE9);
447 emit(L->pos()); 481 emitl(L->pos());
448 L->link_to(pc_offset() - sizeof(int32_t)); 482 L->link_to(pc_offset() - sizeof(int32_t));
449 } else { 483 } else {
450 // 1110 1001 #32-bit disp 484 // 1110 1001 #32-bit disp
451 ASSERT(L->is_unused()); 485 ASSERT(L->is_unused());
452 EMIT(0xE9); 486 EMIT(0xE9);
453 int32_t current = pc_offset(); 487 int32_t current = pc_offset();
454 emit(current); 488 emitl(current);
455 L->link_to(current); 489 L->link_to(current);
456 } 490 }
457 } 491 }
458 492
459 493
460 void Assembler::mov(Register dst, const Operand& src) { 494 void Assembler::movq(Register dst, const Operand& src) {
461 EnsureSpace ensure_space(this); 495 EnsureSpace ensure_space(this);
462 last_pc_ = pc_; 496 last_pc_ = pc_;
463 emit_rex_64(dst, src); 497 emit_rex_64(dst, src);
464 EMIT(0x8B); 498 EMIT(0x8B);
465 emit_operand(dst, src); 499 emit_operand(dst, src);
466 } 500 }
467 501
468 502
469 void Assembler::mov(Register dst, Register src) { 503 void Assembler::movq(Register dst, Register src) {
470 EnsureSpace ensure_space(this); 504 EnsureSpace ensure_space(this);
471 last_pc_ = pc_; 505 last_pc_ = pc_;
472 emit_rex_64(dst, src); 506 emit_rex_64(dst, src);
473 EMIT(0x8B); 507 EMIT(0x8B);
474 EMIT(0xC0 | (dst.code() & 0x7) << 3 | (src.code() & 0x7)); 508 EMIT(0xC0 | (dst.code() & 0x7) << 3 | (src.code() & 0x7));
475 } 509 }
476 510
477 511
512 void Assembler::movq(Register dst, Immediate value) {
513 EnsureSpace ensure_space(this);
514 last_pc_ = pc_;
515 emit_rex_64(rax, dst);
516 EMIT(0xC7);
517 EMIT(0xC0 | (dst.code() & 0x7));
518 emit(value); // Only 32-bit immediates are possible, not 8-bit immediates.
519 }
520
521
522 void Assembler::movq(Register dst, int64_t value, RelocInfo::Mode rmode) {
523 EnsureSpace ensure_space(this);
524 last_pc_ = pc_;
525 emit_rex_64(rax, dst);
526 EMIT(0xB8 | (dst.code() & 0x7));
527 emitq(value, rmode);
528 }
529
530
478 void Assembler::nop() { 531 void Assembler::nop() {
479 EnsureSpace ensure_space(this); 532 EnsureSpace ensure_space(this);
480 last_pc_ = pc_; 533 last_pc_ = pc_;
481 EMIT(0x90); 534 EMIT(0x90);
482 } 535 }
483 536
537
484 void Assembler::pop(Register dst) { 538 void Assembler::pop(Register dst) {
485 EnsureSpace ensure_space(this); 539 EnsureSpace ensure_space(this);
486 last_pc_ = pc_; 540 last_pc_ = pc_;
487 if (dst.code() & 0x8) { 541 if (dst.code() & 0x8) {
488 emit_rex_64(rax, dst); 542 emit_rex_64(rax, dst);
489 } 543 }
490 EMIT(0x58 | (dst.code() & 0x7)); 544 EMIT(0x58 | (dst.code() & 0x7));
491 } 545 }
492 546
493 547
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 UNIMPLEMENTED(); 860 UNIMPLEMENTED();
807 return NULL; 861 return NULL;
808 } 862 }
809 863
810 byte* JavaScriptFrame::GetCallerStackPointer() const { 864 byte* JavaScriptFrame::GetCallerStackPointer() const {
811 UNIMPLEMENTED(); 865 UNIMPLEMENTED();
812 return NULL; 866 return NULL;
813 } 867 }
814 868
815 } } // namespace v8::internal 869 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/x64/assembler-x64.h ('k') | src/x64/assembler-x64-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698