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

Side by Side Diff: src/IceInstX8632.h

Issue 390443005: Lower bitmanip intrinsics, assuming absence of BMI/SSE4.2 for now. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: review Created 6 years, 5 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 | « crosstest/test_bitmanip_main.cpp ('k') | src/IceInstX8632.cpp » ('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.h - Low-level x86 instructions --*- C++ -*-===// 1 //===- subzero/src/IceInstX8632.h - Low-level x86 instructions --*- C++ -*-===//
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 declares the InstX8632 and OperandX8632 classes and 10 // This file declares the InstX8632 and OperandX8632 classes and
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 class InstX8632 : public InstTarget { 132 class InstX8632 : public InstTarget {
133 public: 133 public:
134 enum InstKindX8632 { 134 enum InstKindX8632 {
135 k__Start = Inst::Target, 135 k__Start = Inst::Target,
136 Adc, 136 Adc,
137 Add, 137 Add,
138 Addps, 138 Addps,
139 Addss, 139 Addss,
140 And, 140 And,
141 Br, 141 Br,
142 Bsf,
143 Bsr,
142 Call, 144 Call,
143 Cdq, 145 Cdq,
146 Cmov,
144 Cmpxchg, 147 Cmpxchg,
145 Cmpxchg8b, 148 Cmpxchg8b,
146 Cvt, 149 Cvt,
147 Div, 150 Div,
148 Divps, 151 Divps,
149 Divss, 152 Divss,
150 Fld, 153 Fld,
151 Fstp, 154 Fstp,
152 Icmp, 155 Icmp,
153 Idiv, 156 Idiv,
(...skipping 27 matching lines...) Expand all
181 Sub, 184 Sub,
182 Subps, 185 Subps,
183 Subss, 186 Subss,
184 Test, 187 Test,
185 Ucomiss, 188 Ucomiss,
186 UD2, 189 UD2,
187 Xadd, 190 Xadd,
188 Xchg, 191 Xchg,
189 Xor 192 Xor
190 }; 193 };
194
195 enum BrCond {
196 #define X(tag, dump, emit) tag,
197 ICEINSTX8632BR_TABLE
198 #undef X
199 Br_None
200 };
201
191 static const char *getWidthString(Type Ty); 202 static const char *getWidthString(Type Ty);
192 virtual void emit(const Cfg *Func) const = 0; 203 virtual void emit(const Cfg *Func) const = 0;
193 virtual void dump(const Cfg *Func) const; 204 virtual void dump(const Cfg *Func) const;
194 205
195 protected: 206 protected:
196 InstX8632(Cfg *Func, InstKindX8632 Kind, SizeT Maxsrcs, Variable *Dest) 207 InstX8632(Cfg *Func, InstKindX8632 Kind, SizeT Maxsrcs, Variable *Dest)
197 : InstTarget(Func, static_cast<InstKind>(Kind), Maxsrcs, Dest) {} 208 : InstTarget(Func, static_cast<InstKind>(Kind), Maxsrcs, Dest) {}
198 virtual ~InstX8632() {} 209 virtual ~InstX8632() {}
199 static bool isClassof(const Inst *Inst, InstKindX8632 MyKind) { 210 static bool isClassof(const Inst *Inst, InstKindX8632 MyKind) {
200 return Inst->getKind() == static_cast<InstKind>(MyKind); 211 return Inst->getKind() == static_cast<InstKind>(MyKind);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 InstX8632Label(Cfg *Func, TargetX8632 *Target); 266 InstX8632Label(Cfg *Func, TargetX8632 *Target);
256 InstX8632Label(const InstX8632Label &) LLVM_DELETED_FUNCTION; 267 InstX8632Label(const InstX8632Label &) LLVM_DELETED_FUNCTION;
257 InstX8632Label &operator=(const InstX8632Label &) LLVM_DELETED_FUNCTION; 268 InstX8632Label &operator=(const InstX8632Label &) LLVM_DELETED_FUNCTION;
258 virtual ~InstX8632Label() {} 269 virtual ~InstX8632Label() {}
259 SizeT Number; // used only for unique label string generation 270 SizeT Number; // used only for unique label string generation
260 }; 271 };
261 272
262 // Conditional and unconditional branch instruction. 273 // Conditional and unconditional branch instruction.
263 class InstX8632Br : public InstX8632 { 274 class InstX8632Br : public InstX8632 {
264 public: 275 public:
265 enum BrCond {
266 #define X(tag, dump, emit) tag,
267 ICEINSTX8632BR_TABLE
268 #undef X
269 Br_None
270 };
271
272 // Create a conditional branch to a node. 276 // Create a conditional branch to a node.
273 static InstX8632Br *create(Cfg *Func, CfgNode *TargetTrue, 277 static InstX8632Br *create(Cfg *Func, CfgNode *TargetTrue,
274 CfgNode *TargetFalse, BrCond Condition) { 278 CfgNode *TargetFalse, BrCond Condition) {
275 return new (Func->allocate<InstX8632Br>()) 279 return new (Func->allocate<InstX8632Br>())
276 InstX8632Br(Func, TargetTrue, TargetFalse, NULL, Condition); 280 InstX8632Br(Func, TargetTrue, TargetFalse, NULL, Condition);
277 } 281 }
278 // Create an unconditional branch to a node. 282 // Create an unconditional branch to a node.
279 static InstX8632Br *create(Cfg *Func, CfgNode *Target) { 283 static InstX8632Br *create(Cfg *Func, CfgNode *Target) {
280 return new (Func->allocate<InstX8632Br>()) 284 return new (Func->allocate<InstX8632Br>())
281 InstX8632Br(Func, NULL, Target, NULL, Br_None); 285 InstX8632Br(Func, NULL, Target, NULL, Br_None);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 private: 331 private:
328 InstX8632Call(Cfg *Func, Variable *Dest, Operand *CallTarget); 332 InstX8632Call(Cfg *Func, Variable *Dest, Operand *CallTarget);
329 InstX8632Call(const InstX8632Call &) LLVM_DELETED_FUNCTION; 333 InstX8632Call(const InstX8632Call &) LLVM_DELETED_FUNCTION;
330 InstX8632Call &operator=(const InstX8632Call &) LLVM_DELETED_FUNCTION; 334 InstX8632Call &operator=(const InstX8632Call &) LLVM_DELETED_FUNCTION;
331 virtual ~InstX8632Call() {} 335 virtual ~InstX8632Call() {}
332 }; 336 };
333 337
334 template <InstX8632::InstKindX8632 K> 338 template <InstX8632::InstKindX8632 K>
335 class InstX8632Unaryop : public InstX8632 { 339 class InstX8632Unaryop : public InstX8632 {
336 public: 340 public:
337 // Create an unary-op instruction like neg. 341 static InstX8632Unaryop *create(Cfg *Func, Variable *Dest, Operand *Src) {
338 // The source and dest are the same variable.
339 static InstX8632Unaryop *create(Cfg *Func, Operand *SrcDest) {
340 return new (Func->allocate<InstX8632Unaryop>()) 342 return new (Func->allocate<InstX8632Unaryop>())
341 InstX8632Unaryop(Func, SrcDest); 343 InstX8632Unaryop(Func, Dest, Src);
342 } 344 }
343 virtual void emit(const Cfg *Func) const { 345 virtual void emit(const Cfg *Func) const {
344 Ostream &Str = Func->getContext()->getStrEmit(); 346 Ostream &Str = Func->getContext()->getStrEmit();
345 assert(getSrcSize() == 1); 347 assert(getSrcSize() == 1);
346 Str << "\t" << Opcode << "\t"; 348 Str << "\t" << Opcode << "\t";
349 getDest()->emit(Func);
350 Str << ", ";
347 getSrc(0)->emit(Func); 351 getSrc(0)->emit(Func);
348 Str << "\n"; 352 Str << "\n";
349 } 353 }
350 virtual void dump(const Cfg *Func) const { 354 virtual void dump(const Cfg *Func) const {
351 Ostream &Str = Func->getContext()->getStrDump(); 355 Ostream &Str = Func->getContext()->getStrDump();
352 dumpDest(Func); 356 dumpDest(Func);
353 Str << " = " << Opcode << "." << getDest()->getType() << " "; 357 Str << " = " << Opcode << "." << getDest()->getType() << " ";
354 dumpSources(Func); 358 dumpSources(Func);
355 } 359 }
356 static bool classof(const Inst *Inst) { return isClassof(Inst, K); } 360 static bool classof(const Inst *Inst) { return isClassof(Inst, K); }
357 361
358 private: 362 private:
359 InstX8632Unaryop(Cfg *Func, Operand *SrcDest) 363 InstX8632Unaryop(Cfg *Func, Variable *Dest, Operand *Src)
360 : InstX8632(Func, K, 1, llvm::dyn_cast<Variable>(SrcDest)) { 364 : InstX8632(Func, K, 1, Dest) {
361 addSource(SrcDest); 365 addSource(Src);
362 } 366 }
363 InstX8632Unaryop(const InstX8632Unaryop &) LLVM_DELETED_FUNCTION; 367 InstX8632Unaryop(const InstX8632Unaryop &) LLVM_DELETED_FUNCTION;
364 InstX8632Unaryop &operator=(const InstX8632Unaryop &) LLVM_DELETED_FUNCTION; 368 InstX8632Unaryop &operator=(const InstX8632Unaryop &) LLVM_DELETED_FUNCTION;
365 virtual ~InstX8632Unaryop() {} 369 virtual ~InstX8632Unaryop() {}
366 static const char *Opcode; 370 static const char *Opcode;
367 }; 371 };
368 372
369 // See the definition of emitTwoAddress() for a description of 373 // See the definition of emitTwoAddress() for a description of
370 // ShiftHack. 374 // ShiftHack.
371 void emitTwoAddress(const char *Opcode, const Inst *Inst, const Cfg *Func, 375 void emitTwoAddress(const char *Opcode, const Inst *Inst, const Cfg *Func,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 addSource(Dest); 435 addSource(Dest);
432 addSource(Source1); 436 addSource(Source1);
433 addSource(Source2); 437 addSource(Source2);
434 } 438 }
435 InstX8632Ternop(const InstX8632Ternop &) LLVM_DELETED_FUNCTION; 439 InstX8632Ternop(const InstX8632Ternop &) LLVM_DELETED_FUNCTION;
436 InstX8632Ternop &operator=(const InstX8632Ternop &) LLVM_DELETED_FUNCTION; 440 InstX8632Ternop &operator=(const InstX8632Ternop &) LLVM_DELETED_FUNCTION;
437 virtual ~InstX8632Ternop() {} 441 virtual ~InstX8632Ternop() {}
438 static const char *Opcode; 442 static const char *Opcode;
439 }; 443 };
440 444
441 typedef InstX8632Unaryop<InstX8632::Neg> InstX8632Neg; 445 typedef InstX8632Unaryop<InstX8632::Bsf> InstX8632Bsf;
446 typedef InstX8632Unaryop<InstX8632::Bsr> InstX8632Bsr;
447 typedef InstX8632Unaryop<InstX8632::Sqrtss> InstX8632Sqrtss;
442 typedef InstX8632Binop<InstX8632::Add> InstX8632Add; 448 typedef InstX8632Binop<InstX8632::Add> InstX8632Add;
443 typedef InstX8632Binop<InstX8632::Addps> InstX8632Addps; 449 typedef InstX8632Binop<InstX8632::Addps> InstX8632Addps;
444 typedef InstX8632Binop<InstX8632::Adc> InstX8632Adc; 450 typedef InstX8632Binop<InstX8632::Adc> InstX8632Adc;
445 typedef InstX8632Binop<InstX8632::Addss> InstX8632Addss; 451 typedef InstX8632Binop<InstX8632::Addss> InstX8632Addss;
446 typedef InstX8632Binop<InstX8632::Sub> InstX8632Sub; 452 typedef InstX8632Binop<InstX8632::Sub> InstX8632Sub;
447 typedef InstX8632Binop<InstX8632::Subps> InstX8632Subps; 453 typedef InstX8632Binop<InstX8632::Subps> InstX8632Subps;
448 typedef InstX8632Binop<InstX8632::Subss> InstX8632Subss; 454 typedef InstX8632Binop<InstX8632::Subss> InstX8632Subss;
449 typedef InstX8632Binop<InstX8632::Sbb> InstX8632Sbb; 455 typedef InstX8632Binop<InstX8632::Sbb> InstX8632Sbb;
450 typedef InstX8632Binop<InstX8632::And> InstX8632And; 456 typedef InstX8632Binop<InstX8632::And> InstX8632And;
451 typedef InstX8632Binop<InstX8632::Or> InstX8632Or; 457 typedef InstX8632Binop<InstX8632::Or> InstX8632Or;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 virtual void dump(const Cfg *Func) const; 502 virtual void dump(const Cfg *Func) const;
497 static bool classof(const Inst *Inst) { return isClassof(Inst, Mul); } 503 static bool classof(const Inst *Inst) { return isClassof(Inst, Mul); }
498 504
499 private: 505 private:
500 InstX8632Mul(Cfg *Func, Variable *Dest, Variable *Source1, Operand *Source2); 506 InstX8632Mul(Cfg *Func, Variable *Dest, Variable *Source1, Operand *Source2);
501 InstX8632Mul(const InstX8632Mul &) LLVM_DELETED_FUNCTION; 507 InstX8632Mul(const InstX8632Mul &) LLVM_DELETED_FUNCTION;
502 InstX8632Mul &operator=(const InstX8632Mul &) LLVM_DELETED_FUNCTION; 508 InstX8632Mul &operator=(const InstX8632Mul &) LLVM_DELETED_FUNCTION;
503 virtual ~InstX8632Mul() {} 509 virtual ~InstX8632Mul() {}
504 }; 510 };
505 511
512 // Neg instruction - Two's complement negation.
513 class InstX8632Neg : public InstX8632 {
514 public:
515 static InstX8632Neg *create(Cfg *Func, Operand *SrcDest) {
516 return new (Func->allocate<InstX8632Neg>()) InstX8632Neg(Func, SrcDest);
517 }
518 virtual void emit(const Cfg *Func) const;
519 virtual void dump(const Cfg *Func) const;
520 static bool classof(const Inst *Inst) { return isClassof(Inst, Neg); }
521
522 private:
523 InstX8632Neg(Cfg *Func, Operand *SrcDest);
524 InstX8632Neg(const InstX8632Neg &) LLVM_DELETED_FUNCTION;
525 InstX8632Neg &operator=(const InstX8632Neg &) LLVM_DELETED_FUNCTION;
526 virtual ~InstX8632Neg() {}
527 };
528
506 // Shld instruction - shift across a pair of operands. TODO: Verify 529 // Shld instruction - shift across a pair of operands. TODO: Verify
507 // that the validator accepts the shld instruction. 530 // that the validator accepts the shld instruction.
508 class InstX8632Shld : public InstX8632 { 531 class InstX8632Shld : public InstX8632 {
509 public: 532 public:
510 static InstX8632Shld *create(Cfg *Func, Variable *Dest, Variable *Source1, 533 static InstX8632Shld *create(Cfg *Func, Variable *Dest, Variable *Source1,
511 Variable *Source2) { 534 Variable *Source2) {
512 return new (Func->allocate<InstX8632Shld>()) 535 return new (Func->allocate<InstX8632Shld>())
513 InstX8632Shld(Func, Dest, Source1, Source2); 536 InstX8632Shld(Func, Dest, Source1, Source2);
514 } 537 }
515 virtual void emit(const Cfg *Func) const; 538 virtual void emit(const Cfg *Func) const;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 virtual void dump(const Cfg *Func) const; 579 virtual void dump(const Cfg *Func) const;
557 static bool classof(const Inst *Inst) { return isClassof(Inst, Cdq); } 580 static bool classof(const Inst *Inst) { return isClassof(Inst, Cdq); }
558 581
559 private: 582 private:
560 InstX8632Cdq(Cfg *Func, Variable *Dest, Operand *Source); 583 InstX8632Cdq(Cfg *Func, Variable *Dest, Operand *Source);
561 InstX8632Cdq(const InstX8632Cdq &) LLVM_DELETED_FUNCTION; 584 InstX8632Cdq(const InstX8632Cdq &) LLVM_DELETED_FUNCTION;
562 InstX8632Cdq &operator=(const InstX8632Cdq &) LLVM_DELETED_FUNCTION; 585 InstX8632Cdq &operator=(const InstX8632Cdq &) LLVM_DELETED_FUNCTION;
563 virtual ~InstX8632Cdq() {} 586 virtual ~InstX8632Cdq() {}
564 }; 587 };
565 588
589 // Conditional move instruction.
590 class InstX8632Cmov : public InstX8632 {
591 public:
592 static InstX8632Cmov *create(Cfg *Func, Variable *Dest, Operand *Source,
593 BrCond Cond) {
594 return new (Func->allocate<InstX8632Cmov>())
595 InstX8632Cmov(Func, Dest, Source, Cond);
596 }
597 virtual void emit(const Cfg *Func) const;
598 virtual void dump(const Cfg *Func) const;
599 static bool classof(const Inst *Inst) { return isClassof(Inst, Cmov); }
600
601 private:
602 InstX8632Cmov(Cfg *Func, Variable *Dest, Operand *Source, BrCond Cond);
603 InstX8632Cmov(const InstX8632Cmov &) LLVM_DELETED_FUNCTION;
604 InstX8632Cmov &operator=(const InstX8632Cmov &) LLVM_DELETED_FUNCTION;
605 virtual ~InstX8632Cmov() {}
606
607 BrCond Condition;
608 };
609
566 // Cmpxchg instruction - cmpxchg <dest>, <desired> will compare if <dest> 610 // Cmpxchg instruction - cmpxchg <dest>, <desired> will compare if <dest>
567 // equals eax. If so, the ZF is set and <desired> is stored in <dest>. 611 // equals eax. If so, the ZF is set and <desired> is stored in <dest>.
568 // If not, ZF is cleared and <dest> is copied to eax (or subregister). 612 // If not, ZF is cleared and <dest> is copied to eax (or subregister).
569 // <dest> can be a register or memory, while <desired> must be a register. 613 // <dest> can be a register or memory, while <desired> must be a register.
570 // It is the user's responsiblity to mark eax with a FakeDef. 614 // It is the user's responsiblity to mark eax with a FakeDef.
571 class InstX8632Cmpxchg : public InstX8632Lockable { 615 class InstX8632Cmpxchg : public InstX8632Lockable {
572 public: 616 public:
573 static InstX8632Cmpxchg *create(Cfg *Func, Operand *DestOrAddr, Variable *Eax, 617 static InstX8632Cmpxchg *create(Cfg *Func, Operand *DestOrAddr, Variable *Eax,
574 Variable *Desired, bool Locked) { 618 Variable *Desired, bool Locked) {
575 return new (Func->allocate<InstX8632Cmpxchg>()) 619 return new (Func->allocate<InstX8632Cmpxchg>())
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 virtual void dump(const Cfg *Func) const; 985 virtual void dump(const Cfg *Func) const;
942 static bool classof(const Inst *Inst) { return isClassof(Inst, Ret); } 986 static bool classof(const Inst *Inst) { return isClassof(Inst, Ret); }
943 987
944 private: 988 private:
945 InstX8632Ret(Cfg *Func, Variable *Source); 989 InstX8632Ret(Cfg *Func, Variable *Source);
946 InstX8632Ret(const InstX8632Ret &) LLVM_DELETED_FUNCTION; 990 InstX8632Ret(const InstX8632Ret &) LLVM_DELETED_FUNCTION;
947 InstX8632Ret &operator=(const InstX8632Ret &) LLVM_DELETED_FUNCTION; 991 InstX8632Ret &operator=(const InstX8632Ret &) LLVM_DELETED_FUNCTION;
948 virtual ~InstX8632Ret() {} 992 virtual ~InstX8632Ret() {}
949 }; 993 };
950 994
951 // Sqrtss - Scalar sqrt of a float or double.
952 class InstX8632Sqrtss : public InstX8632 {
953 public:
954 static InstX8632Sqrtss *create(Cfg *Func, Variable *Dest, Operand *Source) {
955 return new (Func->allocate<InstX8632Sqrtss>())
956 InstX8632Sqrtss(Func, Dest, Source);
957 }
958 virtual void emit(const Cfg *Func) const;
959 virtual void dump(const Cfg *Func) const;
960 static bool classof(const Inst *Inst) { return isClassof(Inst, Sqrtss); }
961
962 private:
963 InstX8632Sqrtss(Cfg *Func, Variable *Dest, Operand *Source);
964 InstX8632Sqrtss(const InstX8632Sqrtss &) LLVM_DELETED_FUNCTION;
965 InstX8632Sqrtss &operator=(const InstX8632Sqrtss &) LLVM_DELETED_FUNCTION;
966 virtual ~InstX8632Sqrtss() {}
967 };
968
969 // Exchanging Add instruction. Exchanges the first operand (destination 995 // Exchanging Add instruction. Exchanges the first operand (destination
970 // operand) with the second operand (source operand), then loads the sum 996 // operand) with the second operand (source operand), then loads the sum
971 // of the two values into the destination operand. The destination may be 997 // of the two values into the destination operand. The destination may be
972 // a register or memory, while the source must be a register. 998 // a register or memory, while the source must be a register.
973 // 999 //
974 // Both the dest and source are updated. The caller should then insert a 1000 // Both the dest and source are updated. The caller should then insert a
975 // FakeDef to reflect the second udpate. 1001 // FakeDef to reflect the second udpate.
976 class InstX8632Xadd : public InstX8632Lockable { 1002 class InstX8632Xadd : public InstX8632Lockable {
977 public: 1003 public:
978 static InstX8632Xadd *create(Cfg *Func, Operand *Dest, Variable *Source, 1004 static InstX8632Xadd *create(Cfg *Func, Operand *Dest, Variable *Source,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 private: 1036 private:
1011 InstX8632Xchg(Cfg *Func, Operand *Dest, Variable *Source); 1037 InstX8632Xchg(Cfg *Func, Operand *Dest, Variable *Source);
1012 InstX8632Xchg(const InstX8632Xchg &) LLVM_DELETED_FUNCTION; 1038 InstX8632Xchg(const InstX8632Xchg &) LLVM_DELETED_FUNCTION;
1013 InstX8632Xchg &operator=(const InstX8632Xchg &) LLVM_DELETED_FUNCTION; 1039 InstX8632Xchg &operator=(const InstX8632Xchg &) LLVM_DELETED_FUNCTION;
1014 virtual ~InstX8632Xchg() {} 1040 virtual ~InstX8632Xchg() {}
1015 }; 1041 };
1016 1042
1017 } // end of namespace Ice 1043 } // end of namespace Ice
1018 1044
1019 #endif // SUBZERO_SRC_ICEINSTX8632_H 1045 #endif // SUBZERO_SRC_ICEINSTX8632_H
OLDNEW
« no previous file with comments | « crosstest/test_bitmanip_main.cpp ('k') | src/IceInstX8632.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698