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

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

Issue 7060010: Merge bleeding edge into the GC branch up to 7948. The asserts (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 years, 7 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/builtins-x64.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 // Relative address, relative to point after address. 451 // Relative address, relative to point after address.
452 int imm32 = pos - (current + sizeof(int32_t)); 452 int imm32 = pos - (current + sizeof(int32_t));
453 long_at_put(current, imm32); 453 long_at_put(current, imm32);
454 current = next; 454 current = next;
455 next = long_at(next); 455 next = long_at(next);
456 } 456 }
457 // Fix up last fixup on linked list. 457 // Fix up last fixup on linked list.
458 int last_imm32 = pos - (current + sizeof(int32_t)); 458 int last_imm32 = pos - (current + sizeof(int32_t));
459 long_at_put(current, last_imm32); 459 long_at_put(current, last_imm32);
460 } 460 }
461 while (L->is_near_linked()) {
462 int fixup_pos = L->near_link_pos();
463 int offset_to_next =
464 static_cast<int>(*reinterpret_cast<int8_t*>(addr_at(fixup_pos)));
465 ASSERT(offset_to_next <= 0);
466 int disp = pos - (fixup_pos + sizeof(int8_t));
467 ASSERT(is_int8(disp));
468 set_byte_at(fixup_pos, disp);
469 if (offset_to_next < 0) {
470 L->link_to(fixup_pos + offset_to_next, Label::kNear);
471 } else {
472 L->UnuseNear();
473 }
474 }
461 L->bind_to(pos); 475 L->bind_to(pos);
462 } 476 }
463 477
464 478
465 void Assembler::bind(Label* L) { 479 void Assembler::bind(Label* L) {
466 bind_to(L, pc_offset()); 480 bind_to(L, pc_offset());
467 } 481 }
468 482
469 483
470 void Assembler::bind(NearLabel* L) {
471 ASSERT(!L->is_bound());
472 while (L->unresolved_branches_ > 0) {
473 int branch_pos = L->unresolved_positions_[L->unresolved_branches_ - 1];
474 int disp = pc_offset() - branch_pos;
475 ASSERT(is_int8(disp));
476 set_byte_at(branch_pos - sizeof(int8_t), disp);
477 L->unresolved_branches_--;
478 }
479 L->bind_to(pc_offset());
480 }
481
482
483 void Assembler::GrowBuffer() { 484 void Assembler::GrowBuffer() {
484 ASSERT(buffer_overflow()); 485 ASSERT(buffer_overflow());
485 if (!own_buffer_) FATAL("external code buffer is too small"); 486 if (!own_buffer_) FATAL("external code buffer is too small");
486 487
487 // Compute new buffer size. 488 // Compute new buffer size.
488 CodeDesc desc; // the new buffer 489 CodeDesc desc; // the new buffer
489 if (buffer_size_ < 4*KB) { 490 if (buffer_size_ < 4*KB) {
490 desc.buffer_size = 4*KB; 491 desc.buffer_size = 4*KB;
491 } else { 492 } else {
492 desc.buffer_size = 2*buffer_size_; 493 desc.buffer_size = 2*buffer_size_;
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 emit_modrm(0, dst); 1208 emit_modrm(0, dst);
1208 } 1209 }
1209 1210
1210 1211
1211 void Assembler::int3() { 1212 void Assembler::int3() {
1212 EnsureSpace ensure_space(this); 1213 EnsureSpace ensure_space(this);
1213 emit(0xCC); 1214 emit(0xCC);
1214 } 1215 }
1215 1216
1216 1217
1217 void Assembler::j(Condition cc, Label* L) { 1218 void Assembler::j(Condition cc, Label* L, Label::Distance distance) {
1218 if (cc == always) { 1219 if (cc == always) {
1219 jmp(L); 1220 jmp(L);
1220 return; 1221 return;
1221 } else if (cc == never) { 1222 } else if (cc == never) {
1222 return; 1223 return;
1223 } 1224 }
1224 EnsureSpace ensure_space(this); 1225 EnsureSpace ensure_space(this);
1225 ASSERT(is_uint4(cc)); 1226 ASSERT(is_uint4(cc));
1226 if (L->is_bound()) { 1227 if (L->is_bound()) {
1227 const int short_size = 2; 1228 const int short_size = 2;
1228 const int long_size = 6; 1229 const int long_size = 6;
1229 int offs = L->pos() - pc_offset(); 1230 int offs = L->pos() - pc_offset();
1230 ASSERT(offs <= 0); 1231 ASSERT(offs <= 0);
1231 if (is_int8(offs - short_size)) { 1232 if (is_int8(offs - short_size)) {
1232 // 0111 tttn #8-bit disp. 1233 // 0111 tttn #8-bit disp.
1233 emit(0x70 | cc); 1234 emit(0x70 | cc);
1234 emit((offs - short_size) & 0xFF); 1235 emit((offs - short_size) & 0xFF);
1235 } else { 1236 } else {
1236 // 0000 1111 1000 tttn #32-bit disp. 1237 // 0000 1111 1000 tttn #32-bit disp.
1237 emit(0x0F); 1238 emit(0x0F);
1238 emit(0x80 | cc); 1239 emit(0x80 | cc);
1239 emitl(offs - long_size); 1240 emitl(offs - long_size);
1240 } 1241 }
1242 } else if (distance == Label::kNear) {
1243 // 0111 tttn #8-bit disp
1244 emit(0x70 | cc);
1245 byte disp = 0x00;
1246 if (L->is_near_linked()) {
1247 int offset = L->near_link_pos() - pc_offset();
1248 ASSERT(is_int8(offset));
1249 disp = static_cast<byte>(offset & 0xFF);
1250 }
1251 L->link_to(pc_offset(), Label::kNear);
1252 emit(disp);
1241 } else if (L->is_linked()) { 1253 } else if (L->is_linked()) {
1242 // 0000 1111 1000 tttn #32-bit disp. 1254 // 0000 1111 1000 tttn #32-bit disp.
1243 emit(0x0F); 1255 emit(0x0F);
1244 emit(0x80 | cc); 1256 emit(0x80 | cc);
1245 emitl(L->pos()); 1257 emitl(L->pos());
1246 L->link_to(pc_offset() - sizeof(int32_t)); 1258 L->link_to(pc_offset() - sizeof(int32_t));
1247 } else { 1259 } else {
1248 ASSERT(L->is_unused()); 1260 ASSERT(L->is_unused());
1249 emit(0x0F); 1261 emit(0x0F);
1250 emit(0x80 | cc); 1262 emit(0x80 | cc);
1251 int32_t current = pc_offset(); 1263 int32_t current = pc_offset();
1252 emitl(current); 1264 emitl(current);
1253 L->link_to(current); 1265 L->link_to(current);
1254 } 1266 }
1255 } 1267 }
1256 1268
1257 1269
1258 void Assembler::j(Condition cc, 1270 void Assembler::j(Condition cc,
1259 Handle<Code> target, 1271 Handle<Code> target,
1260 RelocInfo::Mode rmode) { 1272 RelocInfo::Mode rmode) {
1261 EnsureSpace ensure_space(this); 1273 EnsureSpace ensure_space(this);
1262 ASSERT(is_uint4(cc)); 1274 ASSERT(is_uint4(cc));
1263 // 0000 1111 1000 tttn #32-bit disp. 1275 // 0000 1111 1000 tttn #32-bit disp.
1264 emit(0x0F); 1276 emit(0x0F);
1265 emit(0x80 | cc); 1277 emit(0x80 | cc);
1266 emit_code_target(target, rmode); 1278 emit_code_target(target, rmode);
1267 } 1279 }
1268 1280
1269 1281
1270 void Assembler::j(Condition cc, NearLabel* L, Hint hint) { 1282 void Assembler::jmp(Label* L, Label::Distance distance) {
1271 EnsureSpace ensure_space(this);
1272 ASSERT(0 <= cc && cc < 16);
1273 if (FLAG_emit_branch_hints && hint != no_hint) emit(hint);
1274 if (L->is_bound()) {
1275 const int short_size = 2;
1276 int offs = L->pos() - pc_offset();
1277 ASSERT(offs <= 0);
1278 ASSERT(is_int8(offs - short_size));
1279 // 0111 tttn #8-bit disp
1280 emit(0x70 | cc);
1281 emit((offs - short_size) & 0xFF);
1282 } else {
1283 emit(0x70 | cc);
1284 emit(0x00); // The displacement will be resolved later.
1285 L->link_to(pc_offset());
1286 }
1287 }
1288
1289
1290 void Assembler::jmp(Label* L) {
1291 EnsureSpace ensure_space(this); 1283 EnsureSpace ensure_space(this);
1292 const int short_size = sizeof(int8_t); 1284 const int short_size = sizeof(int8_t);
1293 const int long_size = sizeof(int32_t); 1285 const int long_size = sizeof(int32_t);
1294 if (L->is_bound()) { 1286 if (L->is_bound()) {
1295 int offs = L->pos() - pc_offset() - 1; 1287 int offs = L->pos() - pc_offset() - 1;
1296 ASSERT(offs <= 0); 1288 ASSERT(offs <= 0);
1297 if (is_int8(offs - short_size)) { 1289 if (is_int8(offs - short_size)) {
1298 // 1110 1011 #8-bit disp. 1290 // 1110 1011 #8-bit disp.
1299 emit(0xEB); 1291 emit(0xEB);
1300 emit((offs - short_size) & 0xFF); 1292 emit((offs - short_size) & 0xFF);
1301 } else { 1293 } else {
1302 // 1110 1001 #32-bit disp. 1294 // 1110 1001 #32-bit disp.
1303 emit(0xE9); 1295 emit(0xE9);
1304 emitl(offs - long_size); 1296 emitl(offs - long_size);
1305 } 1297 }
1306 } else if (L->is_linked()) { 1298 } else if (distance == Label::kNear) {
1299 emit(0xEB);
1300 byte disp = 0x00;
1301 if (L->is_near_linked()) {
1302 int offset = L->near_link_pos() - pc_offset();
1303 ASSERT(is_int8(offset));
1304 disp = static_cast<byte>(offset & 0xFF);
1305 }
1306 L->link_to(pc_offset(), Label::kNear);
1307 emit(disp);
1308 } else if (L->is_linked()) {
1307 // 1110 1001 #32-bit disp. 1309 // 1110 1001 #32-bit disp.
1308 emit(0xE9); 1310 emit(0xE9);
1309 emitl(L->pos()); 1311 emitl(L->pos());
1310 L->link_to(pc_offset() - long_size); 1312 L->link_to(pc_offset() - long_size);
1311 } else { 1313 } else {
1312 // 1110 1001 #32-bit disp. 1314 // 1110 1001 #32-bit disp.
1313 ASSERT(L->is_unused()); 1315 ASSERT(L->is_unused());
1314 emit(0xE9); 1316 emit(0xE9);
1315 int32_t current = pc_offset(); 1317 int32_t current = pc_offset();
1316 emitl(current); 1318 emitl(current);
1317 L->link_to(current); 1319 L->link_to(current);
1318 } 1320 }
1319 } 1321 }
1320 1322
1321 1323
1322 void Assembler::jmp(Handle<Code> target, RelocInfo::Mode rmode) { 1324 void Assembler::jmp(Handle<Code> target, RelocInfo::Mode rmode) {
1323 EnsureSpace ensure_space(this); 1325 EnsureSpace ensure_space(this);
1324 // 1110 1001 #32-bit disp. 1326 // 1110 1001 #32-bit disp.
1325 emit(0xE9); 1327 emit(0xE9);
1326 emit_code_target(target, rmode); 1328 emit_code_target(target, rmode);
1327 } 1329 }
1328 1330
1329 1331
1330 void Assembler::jmp(NearLabel* L) {
1331 EnsureSpace ensure_space(this);
1332 if (L->is_bound()) {
1333 const int short_size = sizeof(int8_t);
1334 int offs = L->pos() - pc_offset();
1335 ASSERT(offs <= 0);
1336 ASSERT(is_int8(offs - short_size));
1337 // 1110 1011 #8-bit disp.
1338 emit(0xEB);
1339 emit((offs - short_size) & 0xFF);
1340 } else {
1341 emit(0xEB);
1342 emit(0x00); // The displacement will be resolved later.
1343 L->link_to(pc_offset());
1344 }
1345 }
1346
1347
1348 void Assembler::jmp(Register target) { 1332 void Assembler::jmp(Register target) {
1349 EnsureSpace ensure_space(this); 1333 EnsureSpace ensure_space(this);
1350 // Opcode FF/4 r64. 1334 // Opcode FF/4 r64.
1351 emit_optional_rex_32(target); 1335 emit_optional_rex_32(target);
1352 emit(0xFF); 1336 emit(0xFF);
1353 emit_modrm(0x4, target); 1337 emit_modrm(0x4, target);
1354 } 1338 }
1355 1339
1356 1340
1357 void Assembler::jmp(const Operand& src) { 1341 void Assembler::jmp(const Operand& src) {
(...skipping 1676 matching lines...) Expand 10 before | Expand all | Expand 10 after
3034 // specially coded on x64 means that it is a relative 32 bit address, as used 3018 // specially coded on x64 means that it is a relative 32 bit address, as used
3035 // by branch instructions. 3019 // by branch instructions.
3036 return (1 << rmode_) & kApplyMask; 3020 return (1 << rmode_) & kApplyMask;
3037 } 3021 }
3038 3022
3039 3023
3040 3024
3041 } } // namespace v8::internal 3025 } } // namespace v8::internal
3042 3026
3043 #endif // V8_TARGET_ARCH_X64 3027 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/x64/assembler-x64.h ('k') | src/x64/builtins-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698