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

Side by Side Diff: src/IceTargetLoweringX8632.cpp

Issue 291213003: Subzero: Fix x86 floating-point constant emission (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: "Fix" static casting Created 6 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
« no previous file with comments | « src/IceTargetLoweringX8632.h ('k') | src/llvm2ice.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/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// 1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===//
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 TargetLoweringX8632 class, which 10 // This file implements the TargetLoweringX8632 class, which
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 for (SizeT i = 0; i < CalleeSaves.size(); ++i) { 555 for (SizeT i = 0; i < CalleeSaves.size(); ++i) {
556 SizeT j = CalleeSaves.size() - i - 1; 556 SizeT j = CalleeSaves.size() - i - 1;
557 if (j == Reg_ebp && IsEbpBasedFrame) 557 if (j == Reg_ebp && IsEbpBasedFrame)
558 continue; 558 continue;
559 if (CalleeSaves[j] && RegsUsed[j]) { 559 if (CalleeSaves[j] && RegsUsed[j]) {
560 _pop(getPhysicalRegister(j)); 560 _pop(getPhysicalRegister(j));
561 } 561 }
562 } 562 }
563 } 563 }
564 564
565 template <typename T> struct PoolTypeConverter {};
566
567 template <> struct PoolTypeConverter<float> {
568 typedef float PrimitiveFpType;
569 typedef uint32_t PrimitiveIntType;
570 typedef ConstantFloat IceType;
571 static const Type Ty = IceType_f32;
572 static const char *TypeName;
573 static const char *AsmTag;
574 static const char *PrintfString;
575 };
576 const char *PoolTypeConverter<float>::TypeName = "float";
577 const char *PoolTypeConverter<float>::AsmTag = ".long";
578 const char *PoolTypeConverter<float>::PrintfString = "0x%x";
579
580 template <> struct PoolTypeConverter<double> {
581 typedef double PrimitiveFpType;
582 typedef uint64_t PrimitiveIntType;
583 typedef ConstantDouble IceType;
584 static const Type Ty = IceType_f64;
585 static const char *TypeName;
586 static const char *AsmTag;
587 static const char *PrintfString;
588 };
589 const char *PoolTypeConverter<double>::TypeName = "double";
590 const char *PoolTypeConverter<double>::AsmTag = ".quad";
591 const char *PoolTypeConverter<double>::PrintfString = "0x%llx";
592
593 template <typename T> void TargetX8632::emitConstantPool() const {
594 Ostream &Str = Ctx->getStrEmit();
595 Type Ty = T::Ty;
596 SizeT Align = typeAlignInBytes(Ty);
597 ConstantList Pool = Ctx->getConstantPool(Ty);
598
599 Str << "\t.section\t.rodata.cst" << Align << ",\"aM\",@progbits," << Align
600 << "\n";
601 Str << "\t.align\t" << Align << "\n";
602 for (ConstantList::const_iterator I = Pool.begin(), E = Pool.end(); I != E;
603 ++I) {
604 typename T::IceType *Const = llvm::cast<typename T::IceType>(*I);
605 typename T::PrimitiveFpType Value = Const->getValue();
606 // Use memcpy() to copy bits from Value into RawValue in a way
607 // that avoids breaking strict-aliasing rules.
608 typename T::PrimitiveIntType RawValue;
609 memcpy(&RawValue, &Value, sizeof(Value));
610 char buf[30];
611 int CharsPrinted =
612 snprintf(buf, llvm::array_lengthof(buf), T::PrintfString, RawValue);
613 assert(CharsPrinted >= 0 &&
614 (size_t)CharsPrinted < llvm::array_lengthof(buf));
615 (void)CharsPrinted; // avoid warnings if asserts are disabled
616 Str << "L$" << Ty << "$" << Const->getPoolEntryID() << ":\n";
617 Str << "\t" << T::AsmTag << "\t" << buf << "\t# " << T::TypeName << " "
618 << Value << "\n";
619 }
620 }
621
622 void TargetX8632::emitConstants() const {
623 emitConstantPool<PoolTypeConverter<float> >();
624 emitConstantPool<PoolTypeConverter<double> >();
625
626 // No need to emit constants from the int pool since (for x86) they
627 // are embedded as immediates in the instructions.
628 }
629
565 void TargetX8632::split64(Variable *Var) { 630 void TargetX8632::split64(Variable *Var) {
566 switch (Var->getType()) { 631 switch (Var->getType()) {
567 default: 632 default:
568 return; 633 return;
569 case IceType_i64: 634 case IceType_i64:
570 // TODO: Only consider F64 if we need to push each half when 635 // TODO: Only consider F64 if we need to push each half when
571 // passing as an argument to a function call. Note that each half 636 // passing as an argument to a function call. Note that each half
572 // is still typed as I32. 637 // is still typed as I32.
573 case IceType_f64: 638 case IceType_f64:
574 break; 639 break;
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 } 1936 }
1872 assert(AvailableTypedRegisters.any()); 1937 assert(AvailableTypedRegisters.any());
1873 int32_t RegNum = AvailableTypedRegisters.find_first(); 1938 int32_t RegNum = AvailableTypedRegisters.find_first();
1874 Var->setRegNum(RegNum); 1939 Var->setRegNum(RegNum);
1875 AvailableRegisters[RegNum] = false; 1940 AvailableRegisters[RegNum] = false;
1876 } 1941 }
1877 } 1942 }
1878 } 1943 }
1879 } 1944 }
1880 1945
1946 template <> void ConstantFloat::emit(const Cfg *Func) const {
1947 Ostream &Str = Func->getContext()->getStrEmit();
1948 // It would be better to prefix with ".L$" instead of "L$", but
1949 // llvm-mc doesn't parse "dword ptr [.L$foo]".
1950 Str << "dword ptr [L$" << IceType_f32 << "$" << getPoolEntryID() << "]";
1951 }
1952
1953 template <> void ConstantDouble::emit(const Cfg *Func) const {
1954 Ostream &Str = Func->getContext()->getStrEmit();
1955 Str << "qword ptr [L$" << IceType_f64 << "$" << getPoolEntryID() << "]";
1956 }
1957
1881 } // end of namespace Ice 1958 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceTargetLoweringX8632.h ('k') | src/llvm2ice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698