summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/CBackend/Writer.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-12-13 21:52:52 +0000
committerChris Lattner <sabre@nondot.org>2004-12-13 21:52:52 +0000
commitb3b1c279a27515ee05e6209c1e76754756ce98c1 (patch)
tree1c7305c19e0358bc39db491611e647085bbcfc30 /llvm/lib/Target/CBackend/Writer.cpp
parent318a44d8674e590e20a9a6ae12d09291f9c19ef2 (diff)
downloadbcm5719-llvm-b3b1c279a27515ee05e6209c1e76754756ce98c1.tar.gz
bcm5719-llvm-b3b1c279a27515ee05e6209c1e76754756ce98c1.zip
When generating code for X86 targets, make sure the fp control word is set
to 64-bit precision, not 80 bits. llvm-svn: 18915
Diffstat (limited to 'llvm/lib/Target/CBackend/Writer.cpp')
-rw-r--r--llvm/lib/Target/CBackend/Writer.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Target/CBackend/Writer.cpp b/llvm/lib/Target/CBackend/Writer.cpp
index dc8ce2e4742..c922586022b 100644
--- a/llvm/lib/Target/CBackend/Writer.cpp
+++ b/llvm/lib/Target/CBackend/Writer.cpp
@@ -214,6 +214,7 @@ namespace {
unsigned Indent);
void printIndexingExpression(Value *Ptr, gep_type_iterator I,
gep_type_iterator E);
+ void printCodeForMain();
};
}
@@ -1127,6 +1128,9 @@ void CWriter::printFunction(Function &F) {
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 @@ void CWriter::printFunction(Function &F) {
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";
OpenPOWER on IntegriCloud