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

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: Address JF comments round 1 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 SizeT Align;
596 Type Ty;
597 ConstantList Pool;
598
599 Ty = T::Ty;
600 Pool = Ctx->getConstantPool(Ty);
601 Align = typeAlignInBytes(Ty);
JF 2014/05/23 16:35:03 Do these in the initialization above.
Jim Stichnoth 2014/05/23 20:37:35 Done.
602 Str << "\t.section\t.rodata.cst" << Align << ",\"aM\",@progbits," << Align
603 << "\n";
604 Str << "\t.align\t" << Align << "\n";
605 for (ConstantList::const_iterator I = Pool.begin(), E = Pool.end(); I != E;
606 ++I) {
607 typename T::IceType *Const = llvm::cast<typename T::IceType>(*I);
608 typename T::PrimitiveFpType Value = Const->getValue();
609 // Use memcpy() to copy bits from Value into RawValue in a way
610 // that avoids breaking strict-aliasing rules.
611 typename T::PrimitiveIntType RawValue;
612 memcpy(&RawValue, &Value, sizeof(Value));
613 char buf[30];
614 snprintf(buf, llvm::array_lengthof(buf), T::PrintfString, RawValue);
JF 2014/05/23 16:35:03 Check that the return is in [0, size-1].
Jim Stichnoth 2014/05/23 20:37:35 Done.
615 Str << "L$" << Ty << "$" << Const->getPoolEntryID() << ":\n";
616 Str << "\t" << T::AsmTag << "\t" << buf << "\t# " << T::TypeName << " "
617 << Value << "\n";
618 }
619 }
620
621 void TargetX8632::emitConstants() const {
622 emitConstantPool<PoolTypeConverter<float> >();
623 emitConstantPool<PoolTypeConverter<double> >();
624
625 // No need to emit constants from the int pool since (for x86) they
626 // are embedded as immediates in the instructions.
627 }
628
565 void TargetX8632::split64(Variable *Var) { 629 void TargetX8632::split64(Variable *Var) {
566 switch (Var->getType()) { 630 switch (Var->getType()) {
567 default: 631 default:
568 return; 632 return;
569 case IceType_i64: 633 case IceType_i64:
570 // TODO: Only consider F64 if we need to push each half when 634 // 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 635 // passing as an argument to a function call. Note that each half
572 // is still typed as I32. 636 // is still typed as I32.
573 case IceType_f64: 637 case IceType_f64:
574 break; 638 break;
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 } 1935 }
1872 assert(AvailableTypedRegisters.any()); 1936 assert(AvailableTypedRegisters.any());
1873 int32_t RegNum = AvailableTypedRegisters.find_first(); 1937 int32_t RegNum = AvailableTypedRegisters.find_first();
1874 Var->setRegNum(RegNum); 1938 Var->setRegNum(RegNum);
1875 AvailableRegisters[RegNum] = false; 1939 AvailableRegisters[RegNum] = false;
1876 } 1940 }
1877 } 1941 }
1878 } 1942 }
1879 } 1943 }
1880 1944
1945 template <> void ConstantFloat::emit(const Cfg *Func) const {
1946 Ostream &Str = Func->getContext()->getStrEmit();
1947 // It would be better to prefix with ".L$" instead of "L$", but
1948 // llvm-mc doesn't parse "dword ptr [.L$foo]".
1949 Str << "dword ptr [L$" << IceType_f32 << "$" << getPoolEntryID() << "]";
1950 }
1951
1952 template <> void ConstantDouble::emit(const Cfg *Func) const {
1953 Ostream &Str = Func->getContext()->getStrEmit();
1954 Str << "qword ptr [L$" << IceType_f64 << "$" << getPoolEntryID() << "]";
1955 }
1956
1881 } // end of namespace Ice 1957 } // 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