| OLD | NEW |
| 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 21 matching lines...) Expand all Loading... |
| 32 , | 32 , |
| 33 ICEINSTX8632BR_TABLE | 33 ICEINSTX8632BR_TABLE |
| 34 #undef X | 34 #undef X |
| 35 }; | 35 }; |
| 36 const size_t InstX8632BrAttributesSize = | 36 const size_t InstX8632BrAttributesSize = |
| 37 llvm::array_lengthof(InstX8632BrAttributes); | 37 llvm::array_lengthof(InstX8632BrAttributes); |
| 38 | 38 |
| 39 const struct TypeX8632Attributes_ { | 39 const struct TypeX8632Attributes_ { |
| 40 const char *CvtString; // i (integer), s (single FP), d (double FP) | 40 const char *CvtString; // i (integer), s (single FP), d (double FP) |
| 41 const char *SdSsString; // ss, sd, or <blank> | 41 const char *SdSsString; // ss, sd, or <blank> |
| 42 const char *PackString; // b, w, d, or <blank> |
| 42 const char *WidthString; // {byte,word,dword,qword} ptr | 43 const char *WidthString; // {byte,word,dword,qword} ptr |
| 43 } TypeX8632Attributes[] = { | 44 } TypeX8632Attributes[] = { |
| 44 #define X(tag, cvt, sdss, width) \ | 45 #define X(tag, cvt, sdss, pack, width) \ |
| 45 { cvt, "" sdss, width } \ | 46 { cvt, "" sdss, pack, width } \ |
| 46 , | 47 , |
| 47 ICETYPEX8632_TABLE | 48 ICETYPEX8632_TABLE |
| 48 #undef X | 49 #undef X |
| 49 }; | 50 }; |
| 50 const size_t TypeX8632AttributesSize = | 51 const size_t TypeX8632AttributesSize = |
| 51 llvm::array_lengthof(TypeX8632Attributes); | 52 llvm::array_lengthof(TypeX8632Attributes); |
| 52 | 53 |
| 53 const char *InstX8632SegmentRegNames[] = { | 54 const char *InstX8632SegmentRegNames[] = { |
| 54 #define X(val, name) name, | 55 #define X(val, name) name, |
| 55 SEG_REGX8632_TABLE | 56 SEG_REGX8632_TABLE |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 return false; | 291 return false; |
| 291 if (getDest()->hasReg() && getDest()->getRegNum() == Src->getRegNum()) { | 292 if (getDest()->hasReg() && getDest()->getRegNum() == Src->getRegNum()) { |
| 292 return true; | 293 return true; |
| 293 } | 294 } |
| 294 if (!getDest()->hasReg() && !Src->hasReg() && | 295 if (!getDest()->hasReg() && !Src->hasReg() && |
| 295 Dest->getStackOffset() == Src->getStackOffset()) | 296 Dest->getStackOffset() == Src->getStackOffset()) |
| 296 return true; | 297 return true; |
| 297 return false; | 298 return false; |
| 298 } | 299 } |
| 299 | 300 |
| 300 InstX8632Sqrtss::InstX8632Sqrtss(Cfg *Func, Variable *Dest, Operand *Source) | |
| 301 : InstX8632(Func, InstX8632::Sqrtss, 1, Dest) { | |
| 302 addSource(Source); | |
| 303 } | |
| 304 | |
| 305 InstX8632Ret::InstX8632Ret(Cfg *Func, Variable *Source) | 301 InstX8632Ret::InstX8632Ret(Cfg *Func, Variable *Source) |
| 306 : InstX8632(Func, InstX8632::Ret, Source ? 1 : 0, NULL) { | 302 : InstX8632(Func, InstX8632::Ret, Source ? 1 : 0, NULL) { |
| 307 if (Source) | 303 if (Source) |
| 308 addSource(Source); | 304 addSource(Source); |
| 309 } | 305 } |
| 310 | 306 |
| 307 InstX8632Sqrtss::InstX8632Sqrtss(Cfg *Func, Variable *Dest, Operand *Source) |
| 308 : InstX8632(Func, InstX8632::Sqrtss, 1, Dest) { |
| 309 addSource(Source); |
| 310 } |
| 311 |
| 311 InstX8632Xadd::InstX8632Xadd(Cfg *Func, Operand *Dest, Variable *Source, | 312 InstX8632Xadd::InstX8632Xadd(Cfg *Func, Operand *Dest, Variable *Source, |
| 312 bool Locked) | 313 bool Locked) |
| 313 : InstX8632Lockable(Func, InstX8632::Xadd, 2, | 314 : InstX8632Lockable(Func, InstX8632::Xadd, 2, |
| 314 llvm::dyn_cast<Variable>(Dest), Locked) { | 315 llvm::dyn_cast<Variable>(Dest), Locked) { |
| 315 addSource(Dest); | 316 addSource(Dest); |
| 316 addSource(Source); | 317 addSource(Source); |
| 317 } | 318 } |
| 318 | 319 |
| 319 InstX8632Xchg::InstX8632Xchg(Cfg *Func, Operand *Dest, Variable *Source) | 320 InstX8632Xchg::InstX8632Xchg(Cfg *Func, Operand *Dest, Variable *Source) |
| 320 : InstX8632(Func, InstX8632::Xchg, 2, llvm::dyn_cast<Variable>(Dest)) { | 321 : InstX8632(Func, InstX8632::Xchg, 2, llvm::dyn_cast<Variable>(Dest)) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 } | 431 } |
| 431 | 432 |
| 432 template <> const char *InstX8632Neg::Opcode = "neg"; | 433 template <> const char *InstX8632Neg::Opcode = "neg"; |
| 433 template <> const char *InstX8632Add::Opcode = "add"; | 434 template <> const char *InstX8632Add::Opcode = "add"; |
| 434 template <> const char *InstX8632Addps::Opcode = "addps"; | 435 template <> const char *InstX8632Addps::Opcode = "addps"; |
| 435 template <> const char *InstX8632Adc::Opcode = "adc"; | 436 template <> const char *InstX8632Adc::Opcode = "adc"; |
| 436 template <> const char *InstX8632Addss::Opcode = "addss"; | 437 template <> const char *InstX8632Addss::Opcode = "addss"; |
| 437 template <> const char *InstX8632Sub::Opcode = "sub"; | 438 template <> const char *InstX8632Sub::Opcode = "sub"; |
| 438 template <> const char *InstX8632Subps::Opcode = "subps"; | 439 template <> const char *InstX8632Subps::Opcode = "subps"; |
| 439 template <> const char *InstX8632Subss::Opcode = "subss"; | 440 template <> const char *InstX8632Subss::Opcode = "subss"; |
| 441 template <> const char *InstX8632Psub::Opcode = "psub"; |
| 440 template <> const char *InstX8632Sbb::Opcode = "sbb"; | 442 template <> const char *InstX8632Sbb::Opcode = "sbb"; |
| 441 template <> const char *InstX8632And::Opcode = "and"; | 443 template <> const char *InstX8632And::Opcode = "and"; |
| 444 template <> const char *InstX8632Pand::Opcode = "pand"; |
| 442 template <> const char *InstX8632Or::Opcode = "or"; | 445 template <> const char *InstX8632Or::Opcode = "or"; |
| 443 template <> const char *InstX8632Xor::Opcode = "xor"; | 446 template <> const char *InstX8632Xor::Opcode = "xor"; |
| 444 template <> const char *InstX8632Pxor::Opcode = "pxor"; | 447 template <> const char *InstX8632Pxor::Opcode = "pxor"; |
| 445 template <> const char *InstX8632Imul::Opcode = "imul"; | 448 template <> const char *InstX8632Imul::Opcode = "imul"; |
| 446 template <> const char *InstX8632Mulps::Opcode = "mulps"; | 449 template <> const char *InstX8632Mulps::Opcode = "mulps"; |
| 447 template <> const char *InstX8632Mulss::Opcode = "mulss"; | 450 template <> const char *InstX8632Mulss::Opcode = "mulss"; |
| 448 template <> const char *InstX8632Div::Opcode = "div"; | 451 template <> const char *InstX8632Div::Opcode = "div"; |
| 449 template <> const char *InstX8632Divps::Opcode = "divps"; | 452 template <> const char *InstX8632Divps::Opcode = "divps"; |
| 450 template <> const char *InstX8632Idiv::Opcode = "idiv"; | 453 template <> const char *InstX8632Idiv::Opcode = "idiv"; |
| 451 template <> const char *InstX8632Divss::Opcode = "divss"; | 454 template <> const char *InstX8632Divss::Opcode = "divss"; |
| 452 template <> const char *InstX8632Shl::Opcode = "shl"; | 455 template <> const char *InstX8632Shl::Opcode = "shl"; |
| 456 template <> const char *InstX8632Psll::Opcode = "psll"; |
| 453 template <> const char *InstX8632Shr::Opcode = "shr"; | 457 template <> const char *InstX8632Shr::Opcode = "shr"; |
| 454 template <> const char *InstX8632Sar::Opcode = "sar"; | 458 template <> const char *InstX8632Sar::Opcode = "sar"; |
| 459 template <> const char *InstX8632Psra::Opcode = "psra"; |
| 460 template <> const char *InstX8632Pcmpeq::Opcode = "pcmpeq"; |
| 461 template <> const char *InstX8632Pcmpgt::Opcode = "pcmpgt"; |
| 455 | 462 |
| 456 template <> void InstX8632Addss::emit(const Cfg *Func) const { | 463 template <> void InstX8632Addss::emit(const Cfg *Func) const { |
| 457 char buf[30]; | 464 char buf[30]; |
| 458 snprintf(buf, llvm::array_lengthof(buf), "add%s", | 465 snprintf(buf, llvm::array_lengthof(buf), "add%s", |
| 459 TypeX8632Attributes[getDest()->getType()].SdSsString); | 466 TypeX8632Attributes[getDest()->getType()].SdSsString); |
| 460 emitTwoAddress(buf, this, Func); | 467 emitTwoAddress(buf, this, Func); |
| 461 } | 468 } |
| 462 | 469 |
| 463 template <> void InstX8632Subss::emit(const Cfg *Func) const { | 470 template <> void InstX8632Subss::emit(const Cfg *Func) const { |
| 464 char buf[30]; | 471 char buf[30]; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 if (Locked) { | 631 if (Locked) { |
| 625 Str << "lock "; | 632 Str << "lock "; |
| 626 } | 633 } |
| 627 Str << "cmpxchg8b "; | 634 Str << "cmpxchg8b "; |
| 628 dumpSources(Func); | 635 dumpSources(Func); |
| 629 } | 636 } |
| 630 | 637 |
| 631 void InstX8632Cvt::emit(const Cfg *Func) const { | 638 void InstX8632Cvt::emit(const Cfg *Func) const { |
| 632 Ostream &Str = Func->getContext()->getStrEmit(); | 639 Ostream &Str = Func->getContext()->getStrEmit(); |
| 633 assert(getSrcSize() == 1); | 640 assert(getSrcSize() == 1); |
| 634 Str << "\tcvts" << TypeX8632Attributes[getSrc(0)->getType()].CvtString << "2s" | 641 Str << "\tcvt" << TypeX8632Attributes[getSrc(0)->getType()].CvtString << "2" |
| 635 << TypeX8632Attributes[getDest()->getType()].CvtString << "\t"; | 642 << TypeX8632Attributes[getDest()->getType()].CvtString << "\t"; |
| 636 getDest()->emit(Func); | 643 getDest()->emit(Func); |
| 637 Str << ", "; | 644 Str << ", "; |
| 638 getSrc(0)->emit(Func); | 645 getSrc(0)->emit(Func); |
| 639 Str << "\n"; | 646 Str << "\n"; |
| 640 } | 647 } |
| 641 | 648 |
| 642 void InstX8632Cvt::dump(const Cfg *Func) const { | 649 void InstX8632Cvt::dump(const Cfg *Func) const { |
| 643 Ostream &Str = Func->getContext()->getStrDump(); | 650 Ostream &Str = Func->getContext()->getStrDump(); |
| 644 dumpDest(Func); | 651 dumpDest(Func); |
| 645 Str << " = cvts" << TypeX8632Attributes[getSrc(0)->getType()].CvtString | 652 Str << " = cvt" << TypeX8632Attributes[getSrc(0)->getType()].CvtString |
| 646 << "2s" << TypeX8632Attributes[getDest()->getType()].CvtString << " "; | 653 << "2" << TypeX8632Attributes[getDest()->getType()].CvtString << " "; |
| 647 dumpSources(Func); | 654 dumpSources(Func); |
| 648 } | 655 } |
| 649 | 656 |
| 650 void InstX8632Icmp::emit(const Cfg *Func) const { | 657 void InstX8632Icmp::emit(const Cfg *Func) const { |
| 651 Ostream &Str = Func->getContext()->getStrEmit(); | 658 Ostream &Str = Func->getContext()->getStrEmit(); |
| 652 assert(getSrcSize() == 2); | 659 assert(getSrcSize() == 2); |
| 653 Str << "\tcmp\t"; | 660 Str << "\tcmp\t"; |
| 654 getSrc(0)->emit(Func); | 661 getSrc(0)->emit(Func); |
| 655 Str << ", "; | 662 Str << ", "; |
| 656 getSrc(1)->emit(Func); | 663 getSrc(1)->emit(Func); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 Str << "\tadd\tesp, " << Width << "\n"; | 941 Str << "\tadd\tesp, " << Width << "\n"; |
| 935 } | 942 } |
| 936 | 943 |
| 937 void InstX8632Fstp::dump(const Cfg *Func) const { | 944 void InstX8632Fstp::dump(const Cfg *Func) const { |
| 938 Ostream &Str = Func->getContext()->getStrDump(); | 945 Ostream &Str = Func->getContext()->getStrDump(); |
| 939 dumpDest(Func); | 946 dumpDest(Func); |
| 940 Str << " = fstp." << getDest()->getType() << ", st(0)"; | 947 Str << " = fstp." << getDest()->getType() << ", st(0)"; |
| 941 Str << "\n"; | 948 Str << "\n"; |
| 942 } | 949 } |
| 943 | 950 |
| 951 template <> void InstX8632Pcmpeq::emit(const Cfg *Func) const { |
| 952 char buf[30]; |
| 953 snprintf(buf, llvm::array_lengthof(buf), "pcmpeq%s", |
| 954 TypeX8632Attributes[getDest()->getType()].PackString); |
| 955 emitTwoAddress(buf, this, Func); |
| 956 } |
| 957 |
| 958 template <> void InstX8632Pcmpgt::emit(const Cfg *Func) const { |
| 959 char buf[30]; |
| 960 snprintf(buf, llvm::array_lengthof(buf), "pcmpgt%s", |
| 961 TypeX8632Attributes[getDest()->getType()].PackString); |
| 962 emitTwoAddress(buf, this, Func); |
| 963 } |
| 964 |
| 944 void InstX8632Pop::emit(const Cfg *Func) const { | 965 void InstX8632Pop::emit(const Cfg *Func) const { |
| 945 Ostream &Str = Func->getContext()->getStrEmit(); | 966 Ostream &Str = Func->getContext()->getStrEmit(); |
| 946 assert(getSrcSize() == 0); | 967 assert(getSrcSize() == 0); |
| 947 Str << "\tpop\t"; | 968 Str << "\tpop\t"; |
| 948 getDest()->emit(Func); | 969 getDest()->emit(Func); |
| 949 Str << "\n"; | 970 Str << "\n"; |
| 950 } | 971 } |
| 951 | 972 |
| 952 void InstX8632Pop::dump(const Cfg *Func) const { | 973 void InstX8632Pop::dump(const Cfg *Func) const { |
| 953 Ostream &Str = Func->getContext()->getStrDump(); | 974 Ostream &Str = Func->getContext()->getStrDump(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 Func->getTarget()->updateStackAdjustment(4); | 1009 Func->getTarget()->updateStackAdjustment(4); |
| 989 } | 1010 } |
| 990 } | 1011 } |
| 991 | 1012 |
| 992 void InstX8632Push::dump(const Cfg *Func) const { | 1013 void InstX8632Push::dump(const Cfg *Func) const { |
| 993 Ostream &Str = Func->getContext()->getStrDump(); | 1014 Ostream &Str = Func->getContext()->getStrDump(); |
| 994 Str << "push." << getSrc(0)->getType() << " "; | 1015 Str << "push." << getSrc(0)->getType() << " "; |
| 995 dumpSources(Func); | 1016 dumpSources(Func); |
| 996 } | 1017 } |
| 997 | 1018 |
| 1019 template <> void InstX8632Psll::emit(const Cfg *Func) const { |
| 1020 assert(getDest()->getType() == IceType_v8i16 || |
| 1021 getDest()->getType() == IceType_v4i32); |
| 1022 char buf[30]; |
| 1023 snprintf(buf, llvm::array_lengthof(buf), "psll%s", |
| 1024 TypeX8632Attributes[getDest()->getType()].PackString); |
| 1025 emitTwoAddress(buf, this, Func); |
| 1026 } |
| 1027 |
| 1028 template <> void InstX8632Psra::emit(const Cfg *Func) const { |
| 1029 assert(getDest()->getType() == IceType_v8i16 || |
| 1030 getDest()->getType() == IceType_v4i32); |
| 1031 char buf[30]; |
| 1032 snprintf(buf, llvm::array_lengthof(buf), "psra%s", |
| 1033 TypeX8632Attributes[getDest()->getType()].PackString); |
| 1034 emitTwoAddress(buf, this, Func); |
| 1035 } |
| 1036 |
| 1037 template <> void InstX8632Psub::emit(const Cfg *Func) const { |
| 1038 char buf[30]; |
| 1039 snprintf(buf, llvm::array_lengthof(buf), "psub%s", |
| 1040 TypeX8632Attributes[getDest()->getType()].PackString); |
| 1041 emitTwoAddress(buf, this, Func); |
| 1042 } |
| 1043 |
| 998 void InstX8632Ret::emit(const Cfg *Func) const { | 1044 void InstX8632Ret::emit(const Cfg *Func) const { |
| 999 Ostream &Str = Func->getContext()->getStrEmit(); | 1045 Ostream &Str = Func->getContext()->getStrEmit(); |
| 1000 Str << "\tret\n"; | 1046 Str << "\tret\n"; |
| 1001 } | 1047 } |
| 1002 | 1048 |
| 1003 void InstX8632Ret::dump(const Cfg *Func) const { | 1049 void InstX8632Ret::dump(const Cfg *Func) const { |
| 1004 Ostream &Str = Func->getContext()->getStrDump(); | 1050 Ostream &Str = Func->getContext()->getStrDump(); |
| 1005 Type Ty = (getSrcSize() == 0 ? IceType_void : getSrc(0)->getType()); | 1051 Type Ty = (getSrcSize() == 0 ? IceType_void : getSrc(0)->getType()); |
| 1006 Str << "ret." << Ty << " "; | 1052 Str << "ret." << Ty << " "; |
| 1007 dumpSources(Func); | 1053 dumpSources(Func); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 default: | 1236 default: |
| 1191 Str << "???"; | 1237 Str << "???"; |
| 1192 break; | 1238 break; |
| 1193 } | 1239 } |
| 1194 Str << "("; | 1240 Str << "("; |
| 1195 Var->dump(Func); | 1241 Var->dump(Func); |
| 1196 Str << ")"; | 1242 Str << ")"; |
| 1197 } | 1243 } |
| 1198 | 1244 |
| 1199 } // end of namespace Ice | 1245 } // end of namespace Ice |
| OLD | NEW |