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

Side by Side Diff: src/IceInstX8632.cpp

Issue 613483002: Change some explicit type checks into using helper functions. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: rename Created 6 years, 2 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 | « no previous file | src/IceRegistersX8632.h » ('j') | src/IceTargetLoweringX8632.cpp » ('J')
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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 const Operand *Src, 507 const Operand *Src,
508 const x86::AssemblerX86::GPREmitterRegOp &Emitter) { 508 const x86::AssemblerX86::GPREmitterRegOp &Emitter) {
509 x86::AssemblerX86 *Asm = Func->getAssembler<x86::AssemblerX86>(); 509 x86::AssemblerX86 *Asm = Func->getAssembler<x86::AssemblerX86>();
510 intptr_t StartPosition = Asm->GetPosition(); 510 intptr_t StartPosition = Asm->GetPosition();
511 assert(Var->hasReg()); 511 assert(Var->hasReg());
512 // We cheat a little and use GPRRegister even for byte operations. 512 // We cheat a little and use GPRRegister even for byte operations.
513 RegX8632::GPRRegister VarReg = 513 RegX8632::GPRRegister VarReg =
514 RegX8632::getEncodedByteRegOrGPR(Ty, Var->getRegNum()); 514 RegX8632::getEncodedByteRegOrGPR(Ty, Var->getRegNum());
515 if (const Variable *SrcVar = llvm::dyn_cast<Variable>(Src)) { 515 if (const Variable *SrcVar = llvm::dyn_cast<Variable>(Src)) {
516 if (SrcVar->hasReg()) { 516 if (SrcVar->hasReg()) {
517 RegX8632::GPRRegister SrcReg; 517 RegX8632::GPRRegister SrcReg =
518 if (Ty == IceType_i8 || Ty == IceType_i1) { 518 RegX8632::getEncodedByteRegOrGPR(Ty, SrcVar->getRegNum());
519 SrcReg = static_cast<RegX8632::GPRRegister>(
520 RegX8632::getEncodedByteReg(SrcVar->getRegNum()));
521 } else {
522 SrcReg = RegX8632::getEncodedGPR(SrcVar->getRegNum());
523 }
524 (Asm->*(Emitter.GPRGPR))(Ty, VarReg, SrcReg); 519 (Asm->*(Emitter.GPRGPR))(Ty, VarReg, SrcReg);
525 } else { 520 } else {
526 x86::Address SrcStackAddr = static_cast<TargetX8632 *>(Func->getTarget()) 521 x86::Address SrcStackAddr = static_cast<TargetX8632 *>(Func->getTarget())
527 ->stackVarToAsmOperand(SrcVar); 522 ->stackVarToAsmOperand(SrcVar);
528 (Asm->*(Emitter.GPRAddr))(Ty, VarReg, SrcStackAddr); 523 (Asm->*(Emitter.GPRAddr))(Ty, VarReg, SrcStackAddr);
529 } 524 }
530 } else if (const OperandX8632Mem *Mem = 525 } else if (const OperandX8632Mem *Mem =
531 llvm::dyn_cast<OperandX8632Mem>(Src)) { 526 llvm::dyn_cast<OperandX8632Mem>(Src)) {
532 x86::Address SrcAddr = Mem->toAsmAddress(Asm); 527 x86::Address SrcAddr = Mem->toAsmAddress(Asm);
533 (Asm->*(Emitter.GPRAddr))(Ty, VarReg, SrcAddr); 528 (Asm->*(Emitter.GPRAddr))(Ty, VarReg, SrcAddr);
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 const x86::AssemblerX86::XmmEmitterTwoOps InstX8632Subss::Emitter = { 735 const x86::AssemblerX86::XmmEmitterTwoOps InstX8632Subss::Emitter = {
741 &x86::AssemblerX86::subss, &x86::AssemblerX86::subss, NULL}; 736 &x86::AssemblerX86::subss, &x86::AssemblerX86::subss, NULL};
742 template <> 737 template <>
743 const x86::AssemblerX86::XmmEmitterTwoOps InstX8632Subps::Emitter = { 738 const x86::AssemblerX86::XmmEmitterTwoOps InstX8632Subps::Emitter = {
744 &x86::AssemblerX86::subps, &x86::AssemblerX86::subps, NULL}; 739 &x86::AssemblerX86::subps, &x86::AssemblerX86::subps, NULL};
745 740
746 template <> void InstX8632Sqrtss::emit(const Cfg *Func) const { 741 template <> void InstX8632Sqrtss::emit(const Cfg *Func) const {
747 Ostream &Str = Func->getContext()->getStrEmit(); 742 Ostream &Str = Func->getContext()->getStrEmit();
748 assert(getSrcSize() == 1); 743 assert(getSrcSize() == 1);
749 Type Ty = getSrc(0)->getType(); 744 Type Ty = getSrc(0)->getType();
750 assert(Ty == IceType_f32 || Ty == IceType_f64); 745 assert(isScalarFloatingType(Ty));
751 Str << "\tsqrt" << TypeX8632Attributes[Ty].SdSsString << "\t"; 746 Str << "\tsqrt" << TypeX8632Attributes[Ty].SdSsString << "\t";
752 getDest()->emit(Func); 747 getDest()->emit(Func);
753 Str << ", "; 748 Str << ", ";
754 getSrc(0)->emit(Func); 749 getSrc(0)->emit(Func);
755 Str << "\n"; 750 Str << "\n";
756 } 751 }
757 752
758 template <> void InstX8632Addss::emit(const Cfg *Func) const { 753 template <> void InstX8632Addss::emit(const Cfg *Func) const {
759 char buf[30]; 754 char buf[30];
760 snprintf(buf, llvm::array_lengthof(buf), "add%s", 755 snprintf(buf, llvm::array_lengthof(buf), "add%s",
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 876
882 template <> void InstX8632Pblendvb::emit(const Cfg *Func) const { 877 template <> void InstX8632Pblendvb::emit(const Cfg *Func) const {
883 assert(static_cast<TargetX8632 *>(Func->getTarget())->getInstructionSet() >= 878 assert(static_cast<TargetX8632 *>(Func->getTarget())->getInstructionSet() >=
884 TargetX8632::SSE4_1); 879 TargetX8632::SSE4_1);
885 emitVariableBlendInst(Opcode, this, Func); 880 emitVariableBlendInst(Opcode, this, Func);
886 } 881 }
887 882
888 template <> void InstX8632Imul::emit(const Cfg *Func) const { 883 template <> void InstX8632Imul::emit(const Cfg *Func) const {
889 Ostream &Str = Func->getContext()->getStrEmit(); 884 Ostream &Str = Func->getContext()->getStrEmit();
890 assert(getSrcSize() == 2); 885 assert(getSrcSize() == 2);
891 if (getDest()->getType() == IceType_i8) { 886 if (isByteSizedArithType(getDest()->getType())) {
892 // The 8-bit version of imul only allows the form "imul r/m8". 887 // The 8-bit version of imul only allows the form "imul r/m8".
893 Variable *Src0 = llvm::dyn_cast<Variable>(getSrc(0)); 888 Variable *Src0 = llvm::dyn_cast<Variable>(getSrc(0));
894 (void)Src0; 889 (void)Src0;
895 assert(Src0 && Src0->getRegNum() == RegX8632::Reg_eax); 890 assert(Src0 && Src0->getRegNum() == RegX8632::Reg_eax);
896 Str << "\timul\t"; 891 Str << "\timul\t";
897 getSrc(1)->emit(Func); 892 getSrc(1)->emit(Func);
898 Str << "\n"; 893 Str << "\n";
899 } else if (llvm::isa<Constant>(getSrc(1))) { 894 } else if (llvm::isa<Constant>(getSrc(1))) {
900 Str << "\timul\t"; 895 Str << "\timul\t";
901 getDest()->emit(Func); 896 getDest()->emit(Func);
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after
1736 void InstX8632AdjustStack::dump(const Cfg *Func) const { 1731 void InstX8632AdjustStack::dump(const Cfg *Func) const {
1737 Ostream &Str = Func->getContext()->getStrDump(); 1732 Ostream &Str = Func->getContext()->getStrDump();
1738 Str << "esp = sub.i32 esp, " << Amount; 1733 Str << "esp = sub.i32 esp, " << Amount;
1739 } 1734 }
1740 1735
1741 void InstX8632Push::emit(const Cfg *Func) const { 1736 void InstX8632Push::emit(const Cfg *Func) const {
1742 Ostream &Str = Func->getContext()->getStrEmit(); 1737 Ostream &Str = Func->getContext()->getStrEmit();
1743 assert(getSrcSize() == 1); 1738 assert(getSrcSize() == 1);
1744 Type Ty = getSrc(0)->getType(); 1739 Type Ty = getSrc(0)->getType();
1745 Variable *Var = llvm::dyn_cast<Variable>(getSrc(0)); 1740 Variable *Var = llvm::dyn_cast<Variable>(getSrc(0));
1746 if ((isVectorType(Ty) || Ty == IceType_f32 || Ty == IceType_f64) && Var && 1741 if ((isVectorType(Ty) || isScalarFloatingType(Ty)) && Var && Var->hasReg()) {
1747 Var->hasReg()) {
1748 // The xmm registers can't be directly pushed, so we fake it by 1742 // The xmm registers can't be directly pushed, so we fake it by
1749 // decrementing esp and then storing to [esp]. 1743 // decrementing esp and then storing to [esp].
1750 Str << "\tsub\tesp, " << typeWidthInBytes(Ty) << "\n"; 1744 Str << "\tsub\tesp, " << typeWidthInBytes(Ty) << "\n";
1751 if (!SuppressStackAdjustment) 1745 if (!SuppressStackAdjustment)
1752 Func->getTarget()->updateStackAdjustment(typeWidthInBytes(Ty)); 1746 Func->getTarget()->updateStackAdjustment(typeWidthInBytes(Ty));
1753 if (isVectorType(Ty)) { 1747 if (isVectorType(Ty)) {
1754 Str << "\tmovups\txmmword ptr [esp], "; 1748 Str << "\tmovups\txmmword ptr [esp], ";
1755 } else { 1749 } else {
1756 Str << "\tmov" << TypeX8632Attributes[Ty].SdSsString << "\t" 1750 Str << "\tmov" << TypeX8632Attributes[Ty].SdSsString << "\t"
1757 << TypeX8632Attributes[Ty].WidthString << " [esp], "; 1751 << TypeX8632Attributes[Ty].WidthString << " [esp], ";
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 } 2052 }
2059 Str << "("; 2053 Str << "(";
2060 if (Func) 2054 if (Func)
2061 Var->dump(Func); 2055 Var->dump(Func);
2062 else 2056 else
2063 Var->dump(Str); 2057 Var->dump(Str);
2064 Str << ")"; 2058 Str << ")";
2065 } 2059 }
2066 2060
2067 } // end of namespace Ice 2061 } // end of namespace Ice
OLDNEW
« no previous file with comments | « no previous file | src/IceRegistersX8632.h » ('j') | src/IceTargetLoweringX8632.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698