[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Dec 13 13:53:06 PST 2004



Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.214 -> 1.215
---
Log message:

When generating code for X86 targets, make sure the fp control word is set
to 64-bit precision, not 80 bits.


---
Diffs of the changes:  (+13 -0)

Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.214 llvm/lib/Target/CBackend/Writer.cpp:1.215
--- llvm/lib/Target/CBackend/Writer.cpp:1.214	Thu Dec  9 23:44:45 2004
+++ llvm/lib/Target/CBackend/Writer.cpp	Mon Dec 13 15:52:52 2004
@@ -214,6 +214,7 @@
                             unsigned Indent);
     void printIndexingExpression(Value *Ptr, gep_type_iterator I,
                                  gep_type_iterator E);
+    void printCodeForMain();
   };
 }
 
@@ -1127,6 +1128,9 @@
 
   Out << "\n";
 
+  if (F.hasExternalLinkage() && F.getName() == "main")
+    printCodeForMain();
+
   // print the basic blocks
   for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
     if (Loop *L = LI->getLoopFor(BB)) {
@@ -1140,6 +1144,15 @@
   Out << "}\n\n";
 }
 
+void CWriter::printCodeForMain() {
+  // On X86, set the FP control word to 64-bits of precision instead of 80 bits.
+  Out << "#if defined(__GNUC__) && !defined(__llvm__)\n"
+      << "#if defined(i386) || defined(__i386__) || defined(__i386)\n"
+      << "{short FPCW;__asm__ (\"fnstcw %0\" : \"=m\" (*&FPCW));\n"
+      << "FPCW=(FPCW&~0x300)|0x200;__asm__(\"fldcw %0\" :: \"m\" (*&FPCW));}\n"
+      << "#endif\n#endif\n";
+}
+
 void CWriter::printLoop(Loop *L) {
   Out << "  do {     /* Syntactic loop '" << L->getHeader()->getName()
       << "' to make GCC happy */\n";






More information about the llvm-commits mailing list