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

Side by Side Diff: src/IceInstX8632.cpp

Issue 427843002: Subzero: Add support for SSE4.1 instructions. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Fix an empty line that was deleted Created 6 years, 4 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
« no previous file with comments | « src/IceInstX8632.h ('k') | src/IceInstX8632.def » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceInstX8632.cpp - X86-32 instruction implementation ---===// 1 //===- subzero/src/IceInstX8632.cpp - X86-32 instruction implementation ---===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This file implements the InstX8632 and OperandX8632 classes, 10 // This file implements the InstX8632 and OperandX8632 classes,
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 template <> const char *InstX8632And::Opcode = "and"; 477 template <> const char *InstX8632And::Opcode = "and";
478 template <> const char *InstX8632Pand::Opcode = "pand"; 478 template <> const char *InstX8632Pand::Opcode = "pand";
479 template <> const char *InstX8632Pandn::Opcode = "pandn"; 479 template <> const char *InstX8632Pandn::Opcode = "pandn";
480 template <> const char *InstX8632Or::Opcode = "or"; 480 template <> const char *InstX8632Or::Opcode = "or";
481 template <> const char *InstX8632Por::Opcode = "por"; 481 template <> const char *InstX8632Por::Opcode = "por";
482 template <> const char *InstX8632Xor::Opcode = "xor"; 482 template <> const char *InstX8632Xor::Opcode = "xor";
483 template <> const char *InstX8632Pxor::Opcode = "pxor"; 483 template <> const char *InstX8632Pxor::Opcode = "pxor";
484 template <> const char *InstX8632Imul::Opcode = "imul"; 484 template <> const char *InstX8632Imul::Opcode = "imul";
485 template <> const char *InstX8632Mulps::Opcode = "mulps"; 485 template <> const char *InstX8632Mulps::Opcode = "mulps";
486 template <> const char *InstX8632Mulss::Opcode = "mulss"; 486 template <> const char *InstX8632Mulss::Opcode = "mulss";
487 template <> const char *InstX8632Pmullw::Opcode = "pmullw"; 487 template <> const char *InstX8632Pmull::Opcode = "pmull";
488 template <> const char *InstX8632Pmuludq::Opcode = "pmuludq"; 488 template <> const char *InstX8632Pmuludq::Opcode = "pmuludq";
489 template <> const char *InstX8632Div::Opcode = "div"; 489 template <> const char *InstX8632Div::Opcode = "div";
490 template <> const char *InstX8632Divps::Opcode = "divps"; 490 template <> const char *InstX8632Divps::Opcode = "divps";
491 template <> const char *InstX8632Idiv::Opcode = "idiv"; 491 template <> const char *InstX8632Idiv::Opcode = "idiv";
492 template <> const char *InstX8632Divss::Opcode = "divss"; 492 template <> const char *InstX8632Divss::Opcode = "divss";
493 template <> const char *InstX8632Rol::Opcode = "rol"; 493 template <> const char *InstX8632Rol::Opcode = "rol";
494 template <> const char *InstX8632Shl::Opcode = "shl"; 494 template <> const char *InstX8632Shl::Opcode = "shl";
495 template <> const char *InstX8632Psll::Opcode = "psll"; 495 template <> const char *InstX8632Psll::Opcode = "psll";
496 template <> const char *InstX8632Shr::Opcode = "shr"; 496 template <> const char *InstX8632Shr::Opcode = "shr";
497 template <> const char *InstX8632Sar::Opcode = "sar"; 497 template <> const char *InstX8632Sar::Opcode = "sar";
498 template <> const char *InstX8632Psra::Opcode = "psra"; 498 template <> const char *InstX8632Psra::Opcode = "psra";
499 template <> const char *InstX8632Pcmpeq::Opcode = "pcmpeq"; 499 template <> const char *InstX8632Pcmpeq::Opcode = "pcmpeq";
500 template <> const char *InstX8632Pcmpgt::Opcode = "pcmpgt"; 500 template <> const char *InstX8632Pcmpgt::Opcode = "pcmpgt";
501 template <> const char *InstX8632Movss::Opcode = "movss"; 501 template <> const char *InstX8632Movss::Opcode = "movss";
502 // Ternary ops 502 // Ternary ops
503 template <> const char *InstX8632Insertps::Opcode = "insertps";
503 template <> const char *InstX8632Shufps::Opcode = "shufps"; 504 template <> const char *InstX8632Shufps::Opcode = "shufps";
504 template <> const char *InstX8632Pinsrw::Opcode = "pinsrw"; 505 template <> const char *InstX8632Pinsr::Opcode = "pinsr";
506 template <> const char *InstX8632Blendvps::Opcode = "blendvps";
507 template <> const char *InstX8632Pblendvb::Opcode = "pblendvb";
505 // Three address ops 508 // Three address ops
506 template <> const char *InstX8632Pextrw::Opcode = "pextrw"; 509 template <> const char *InstX8632Pextr::Opcode = "pextr";
507 template <> const char *InstX8632Pshufd::Opcode = "pshufd"; 510 template <> const char *InstX8632Pshufd::Opcode = "pshufd";
508 511
509 template <> void InstX8632Sqrtss::emit(const Cfg *Func) const { 512 template <> void InstX8632Sqrtss::emit(const Cfg *Func) const {
510 Ostream &Str = Func->getContext()->getStrEmit(); 513 Ostream &Str = Func->getContext()->getStrEmit();
511 assert(getSrcSize() == 1); 514 assert(getSrcSize() == 1);
512 Type Ty = getSrc(0)->getType(); 515 Type Ty = getSrc(0)->getType();
513 assert(Ty == IceType_f32 || Ty == IceType_f64); 516 assert(Ty == IceType_f32 || Ty == IceType_f64);
514 Str << "\tsqrt" << TypeX8632Attributes[Ty].SdSsString << "\t"; 517 Str << "\tsqrt" << TypeX8632Attributes[Ty].SdSsString << "\t";
515 getDest()->emit(Func); 518 getDest()->emit(Func);
516 Str << ", "; 519 Str << ", ";
517 getSrc(0)->emit(Func); 520 getSrc(0)->emit(Func);
518 Str << "\n"; 521 Str << "\n";
519 } 522 }
520 523
521 template <> void InstX8632Addss::emit(const Cfg *Func) const { 524 template <> void InstX8632Addss::emit(const Cfg *Func) const {
522 char buf[30]; 525 char buf[30];
523 snprintf(buf, llvm::array_lengthof(buf), "add%s", 526 snprintf(buf, llvm::array_lengthof(buf), "add%s",
524 TypeX8632Attributes[getDest()->getType()].SdSsString); 527 TypeX8632Attributes[getDest()->getType()].SdSsString);
525 emitTwoAddress(buf, this, Func); 528 emitTwoAddress(buf, this, Func);
526 } 529 }
527 530
528 template <> void InstX8632Padd::emit(const Cfg *Func) const { 531 template <> void InstX8632Padd::emit(const Cfg *Func) const {
529 char buf[30]; 532 char buf[30];
530 snprintf(buf, llvm::array_lengthof(buf), "padd%s", 533 snprintf(buf, llvm::array_lengthof(buf), "padd%s",
531 TypeX8632Attributes[getDest()->getType()].PackString); 534 TypeX8632Attributes[getDest()->getType()].PackString);
532 emitTwoAddress(buf, this, Func); 535 emitTwoAddress(buf, this, Func);
533 } 536 }
534 537
538 template <> void InstX8632Pmull::emit(const Cfg *Func) const {
539 char buf[30];
540 bool TypesAreValid = getDest()->getType() == IceType_v4i32 ||
541 getDest()->getType() == IceType_v8i16;
542 bool InstructionSetIsValid =
543 getDest()->getType() == IceType_v8i16 ||
544 static_cast<TargetX8632 *>(Func->getTarget())->getInstructionSet() >=
545 TargetX8632::SSE4_1;
546 (void)TypesAreValid;
547 (void)InstructionSetIsValid;
548 assert(TypesAreValid);
549 assert(InstructionSetIsValid);
550 snprintf(buf, llvm::array_lengthof(buf), "pmull%s",
551 TypeX8632Attributes[getDest()->getType()].PackString);
552 emitTwoAddress(buf, this, Func);
553 }
554
535 template <> void InstX8632Subss::emit(const Cfg *Func) const { 555 template <> void InstX8632Subss::emit(const Cfg *Func) const {
536 char buf[30]; 556 char buf[30];
537 snprintf(buf, llvm::array_lengthof(buf), "sub%s", 557 snprintf(buf, llvm::array_lengthof(buf), "sub%s",
538 TypeX8632Attributes[getDest()->getType()].SdSsString); 558 TypeX8632Attributes[getDest()->getType()].SdSsString);
539 emitTwoAddress(buf, this, Func); 559 emitTwoAddress(buf, this, Func);
540 } 560 }
541 561
542 template <> void InstX8632Psub::emit(const Cfg *Func) const { 562 template <> void InstX8632Psub::emit(const Cfg *Func) const {
543 char buf[30]; 563 char buf[30];
544 snprintf(buf, llvm::array_lengthof(buf), "psub%s", 564 snprintf(buf, llvm::array_lengthof(buf), "psub%s",
545 TypeX8632Attributes[getDest()->getType()].PackString); 565 TypeX8632Attributes[getDest()->getType()].PackString);
546 emitTwoAddress(buf, this, Func); 566 emitTwoAddress(buf, this, Func);
547 } 567 }
548 568
549 template <> void InstX8632Mulss::emit(const Cfg *Func) const { 569 template <> void InstX8632Mulss::emit(const Cfg *Func) const {
550 char buf[30]; 570 char buf[30];
551 snprintf(buf, llvm::array_lengthof(buf), "mul%s", 571 snprintf(buf, llvm::array_lengthof(buf), "mul%s",
552 TypeX8632Attributes[getDest()->getType()].SdSsString); 572 TypeX8632Attributes[getDest()->getType()].SdSsString);
553 emitTwoAddress(buf, this, Func); 573 emitTwoAddress(buf, this, Func);
554 } 574 }
555 575
556 template <> void InstX8632Pmullw::emit(const Cfg *Func) const {
557 assert(getSrc(0)->getType() == IceType_v8i16 &&
558 getSrc(1)->getType() == IceType_v8i16);
559 emitTwoAddress(Opcode, this, Func);
560 }
561
562 template <> void InstX8632Pmuludq::emit(const Cfg *Func) const { 576 template <> void InstX8632Pmuludq::emit(const Cfg *Func) const {
563 assert(getSrc(0)->getType() == IceType_v4i32 && 577 assert(getSrc(0)->getType() == IceType_v4i32 &&
564 getSrc(1)->getType() == IceType_v4i32); 578 getSrc(1)->getType() == IceType_v4i32);
565 emitTwoAddress(Opcode, this, Func); 579 emitTwoAddress(Opcode, this, Func);
566 } 580 }
567 581
568 template <> void InstX8632Divss::emit(const Cfg *Func) const { 582 template <> void InstX8632Divss::emit(const Cfg *Func) const {
569 char buf[30]; 583 char buf[30];
570 snprintf(buf, llvm::array_lengthof(buf), "div%s", 584 snprintf(buf, llvm::array_lengthof(buf), "div%s",
571 TypeX8632Attributes[getDest()->getType()].SdSsString); 585 TypeX8632Attributes[getDest()->getType()].SdSsString);
572 emitTwoAddress(buf, this, Func); 586 emitTwoAddress(buf, this, Func);
573 } 587 }
574 588
575 template <> void InstX8632Div::emit(const Cfg *Func) const { 589 template <> void InstX8632Div::emit(const Cfg *Func) const {
576 Ostream &Str = Func->getContext()->getStrEmit(); 590 Ostream &Str = Func->getContext()->getStrEmit();
577 assert(getSrcSize() == 3); 591 assert(getSrcSize() == 3);
578 Str << "\t" << Opcode << "\t"; 592 Str << "\t" << Opcode << "\t";
579 getSrc(1)->emit(Func); 593 getSrc(1)->emit(Func);
580 Str << "\n"; 594 Str << "\n";
581 } 595 }
582 596
583 template <> void InstX8632Idiv::emit(const Cfg *Func) const { 597 template <> void InstX8632Idiv::emit(const Cfg *Func) const {
584 Ostream &Str = Func->getContext()->getStrEmit(); 598 Ostream &Str = Func->getContext()->getStrEmit();
585 assert(getSrcSize() == 3); 599 assert(getSrcSize() == 3);
586 Str << "\t" << Opcode << "\t"; 600 Str << "\t" << Opcode << "\t";
587 getSrc(1)->emit(Func); 601 getSrc(1)->emit(Func);
588 Str << "\n"; 602 Str << "\n";
589 } 603 }
590 604
605
606 namespace {
607
608 // pblendvb and blendvps take xmm0 as a final implicit argument.
609 void emitVariableBlendInst(const char *Opcode, const Inst *Inst,
610 const Cfg *Func) {
611 Ostream &Str = Func->getContext()->getStrEmit();
612 assert(Inst->getSrcSize() == 3);
613 assert(llvm::isa<Variable>(Inst->getSrc(2)));
614 assert(llvm::cast<Variable>(Inst->getSrc(2))->getRegNum() ==
615 TargetX8632::Reg_xmm0);
616 Str << "\t" << Opcode << "\t";
617 Inst->getDest()->emit(Func);
618 Str << ", ";
619 Inst->getSrc(1)->emit(Func);
620 Str << "\n";
621 }
622
623 } // end anonymous namespace
624
625 template <> void InstX8632Blendvps::emit(const Cfg *Func) const {
626 assert(static_cast<TargetX8632 *>(Func->getTarget())->getInstructionSet() >=
627 TargetX8632::SSE4_1);
628 emitVariableBlendInst(Opcode, this, Func);
629 }
630
631 template <> void InstX8632Pblendvb::emit(const Cfg *Func) const {
632 assert(static_cast<TargetX8632 *>(Func->getTarget())->getInstructionSet() >=
633 TargetX8632::SSE4_1);
634 emitVariableBlendInst(Opcode, this, Func);
635 }
636
591 template <> void InstX8632Imul::emit(const Cfg *Func) const { 637 template <> void InstX8632Imul::emit(const Cfg *Func) const {
592 Ostream &Str = Func->getContext()->getStrEmit(); 638 Ostream &Str = Func->getContext()->getStrEmit();
593 assert(getSrcSize() == 2); 639 assert(getSrcSize() == 2);
594 if (getDest()->getType() == IceType_i8) { 640 if (getDest()->getType() == IceType_i8) {
595 // The 8-bit version of imul only allows the form "imul r/m8". 641 // The 8-bit version of imul only allows the form "imul r/m8".
596 Variable *Src0 = llvm::dyn_cast<Variable>(getSrc(0)); 642 Variable *Src0 = llvm::dyn_cast<Variable>(getSrc(0));
597 assert(Src0 && Src0->getRegNum() == TargetX8632::Reg_eax); 643 assert(Src0 && Src0->getRegNum() == TargetX8632::Reg_eax);
598 Str << "\timul\t"; 644 Str << "\timul\t";
599 getSrc(1)->emit(Func); 645 getSrc(1)->emit(Func);
600 Str << "\n"; 646 Str << "\n";
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 emitTwoAddress(buf, this, Func); 1166 emitTwoAddress(buf, this, Func);
1121 } 1167 }
1122 1168
1123 template <> void InstX8632Pcmpgt::emit(const Cfg *Func) const { 1169 template <> void InstX8632Pcmpgt::emit(const Cfg *Func) const {
1124 char buf[30]; 1170 char buf[30];
1125 snprintf(buf, llvm::array_lengthof(buf), "pcmpgt%s", 1171 snprintf(buf, llvm::array_lengthof(buf), "pcmpgt%s",
1126 TypeX8632Attributes[getDest()->getType()].PackString); 1172 TypeX8632Attributes[getDest()->getType()].PackString);
1127 emitTwoAddress(buf, this, Func); 1173 emitTwoAddress(buf, this, Func);
1128 } 1174 }
1129 1175
1130 template <> void InstX8632Pextrw::emit(const Cfg *Func) const { 1176 template <> void InstX8632Pextr::emit(const Cfg *Func) const {
1131 Ostream &Str = Func->getContext()->getStrEmit(); 1177 Ostream &Str = Func->getContext()->getStrEmit();
1132 assert(getSrcSize() == 2); 1178 assert(getSrcSize() == 2);
1133 Str << "\t" << Opcode << "\t"; 1179 // pextrb and pextrd are SSE4.1 instructions.
1180 assert(getSrc(0)->getType() == IceType_v8i16 ||
1181 getSrc(0)->getType() == IceType_v8i1 ||
1182 static_cast<TargetX8632 *>(Func->getTarget())->getInstructionSet()
1183 >= TargetX8632::SSE4_1);
1184 Str << "\t" << Opcode
1185 << TypeX8632Attributes[getSrc(0)->getType()].PackString << "\t";
1134 Variable *Dest = getDest(); 1186 Variable *Dest = getDest();
1135 assert(Dest->hasReg() && Dest->getType() == IceType_i16); 1187 // pextrw must take a register dest.
1136 // pextrw takes r32 dest. 1188 assert(Dest->getType() != IceType_i16 || Dest->hasReg());
1137 Dest->asType(IceType_i32).emit(Func); 1189 Dest->asType(IceType_i32).emit(Func);
1138 Str << ", "; 1190 Str << ", ";
1139 getSrc(0)->emit(Func); 1191 getSrc(0)->emit(Func);
1140 Str << ", "; 1192 Str << ", ";
1141 getSrc(1)->emit(Func); 1193 getSrc(1)->emit(Func);
1142 Str << "\n"; 1194 Str << "\n";
1143 } 1195 }
1144 1196
1145 template <> void InstX8632Pinsrw::emit(const Cfg *Func) const { 1197 template <> void InstX8632Pinsr::emit(const Cfg *Func) const {
1146 Ostream &Str = Func->getContext()->getStrEmit(); 1198 Ostream &Str = Func->getContext()->getStrEmit();
1147 assert(getSrcSize() == 3); 1199 assert(getSrcSize() == 3);
1148 Str << "\t" << Opcode << "\t"; 1200 // pinsrb and pinsrd are SSE4.1 instructions.
1201 assert(getDest()->getType() == IceType_v8i16 ||
1202 getDest()->getType() == IceType_v8i1 ||
1203 static_cast<TargetX8632 *>(Func->getTarget())->getInstructionSet()
1204 >= TargetX8632::SSE4_1);
1205 Str << "\t" << Opcode
1206 << TypeX8632Attributes[getDest()->getType()].PackString << "\t";
1149 getDest()->emit(Func); 1207 getDest()->emit(Func);
1150 Str << ", "; 1208 Str << ", ";
1151 Operand *Src1 = getSrc(1); 1209 Operand *Src1 = getSrc(1);
1152 if (Variable *VSrc1 = llvm::dyn_cast<Variable>(Src1)) { 1210 if (Variable *VSrc1 = llvm::dyn_cast<Variable>(Src1)) {
1153 // If src1 is a register, it should be r32. 1211 // If src1 is a register, it should always be r32.
1154 VSrc1->asType(VSrc1->hasReg() ? IceType_i32 : IceType_i16).emit(Func); 1212 if (VSrc1->hasReg()) {
1213 VSrc1->asType(IceType_i32).emit(Func);
1214 } else {
1215 VSrc1->emit(Func);
1216 }
1155 } else { 1217 } else {
1156 Src1->emit(Func); 1218 Src1->emit(Func);
1157 } 1219 }
1158 Str << ", "; 1220 Str << ", ";
1159 getSrc(2)->emit(Func); 1221 getSrc(2)->emit(Func);
1160 Str << "\n"; 1222 Str << "\n";
1161 } 1223 }
1162 1224
1163 void InstX8632Pop::emit(const Cfg *Func) const { 1225 void InstX8632Pop::emit(const Cfg *Func) const {
1164 Ostream &Str = Func->getContext()->getStrEmit(); 1226 Ostream &Str = Func->getContext()->getStrEmit();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 } 1271 }
1210 1272
1211 void InstX8632Push::dump(const Cfg *Func) const { 1273 void InstX8632Push::dump(const Cfg *Func) const {
1212 Ostream &Str = Func->getContext()->getStrDump(); 1274 Ostream &Str = Func->getContext()->getStrDump();
1213 Str << "push." << getSrc(0)->getType() << " "; 1275 Str << "push." << getSrc(0)->getType() << " ";
1214 dumpSources(Func); 1276 dumpSources(Func);
1215 } 1277 }
1216 1278
1217 template <> void InstX8632Psll::emit(const Cfg *Func) const { 1279 template <> void InstX8632Psll::emit(const Cfg *Func) const {
1218 assert(getDest()->getType() == IceType_v8i16 || 1280 assert(getDest()->getType() == IceType_v8i16 ||
1219 getDest()->getType() == IceType_v4i32); 1281 getDest()->getType() == IceType_v8i1 ||
1282 getDest()->getType() == IceType_v4i32 ||
1283 getDest()->getType() == IceType_v4i1);
1220 char buf[30]; 1284 char buf[30];
1221 snprintf(buf, llvm::array_lengthof(buf), "psll%s", 1285 snprintf(buf, llvm::array_lengthof(buf), "psll%s",
1222 TypeX8632Attributes[getDest()->getType()].PackString); 1286 TypeX8632Attributes[getDest()->getType()].PackString);
1223 emitTwoAddress(buf, this, Func); 1287 emitTwoAddress(buf, this, Func);
1224 } 1288 }
1225 1289
1226 template <> void InstX8632Psra::emit(const Cfg *Func) const { 1290 template <> void InstX8632Psra::emit(const Cfg *Func) const {
1227 assert(getDest()->getType() == IceType_v8i16 || 1291 assert(getDest()->getType() == IceType_v8i16 ||
1228 getDest()->getType() == IceType_v4i32); 1292 getDest()->getType() == IceType_v8i1 ||
1293 getDest()->getType() == IceType_v4i32 ||
1294 getDest()->getType() == IceType_v4i1);
1229 char buf[30]; 1295 char buf[30];
1230 snprintf(buf, llvm::array_lengthof(buf), "psra%s", 1296 snprintf(buf, llvm::array_lengthof(buf), "psra%s",
1231 TypeX8632Attributes[getDest()->getType()].PackString); 1297 TypeX8632Attributes[getDest()->getType()].PackString);
1232 emitTwoAddress(buf, this, Func); 1298 emitTwoAddress(buf, this, Func);
1233 } 1299 }
1234 1300
1235 void InstX8632Ret::emit(const Cfg *Func) const { 1301 void InstX8632Ret::emit(const Cfg *Func) const {
1236 Ostream &Str = Func->getContext()->getStrEmit(); 1302 Ostream &Str = Func->getContext()->getStrEmit();
1237 Str << "\tret\n"; 1303 Str << "\tret\n";
1238 } 1304 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 default: 1474 default:
1409 Str << "???"; 1475 Str << "???";
1410 break; 1476 break;
1411 } 1477 }
1412 Str << "("; 1478 Str << "(";
1413 Var->dump(Func); 1479 Var->dump(Func);
1414 Str << ")"; 1480 Str << ")";
1415 } 1481 }
1416 1482
1417 } // end of namespace Ice 1483 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceInstX8632.h ('k') | src/IceInstX8632.def » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698