[llvm-commits] [llvm-gcc-4.0] r41955 - in /llvm-gcc-4.0/trunk/gcc: llvm-convert.cpp llvm-types.cpp

Dale Johannesen dalej at apple.com
Fri Sep 14 11:51:50 PDT 2007


Author: johannes
Date: Fri Sep 14 13:51:50 2007
New Revision: 41955

URL: http://llvm.org/viewvc/llvm-project?rev=41955&view=rev
Log:
Handle x86 long double in conversions.


Modified:
    llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp
    llvm-gcc-4.0/trunk/gcc/llvm-types.cpp

Modified: llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp?rev=41955&r1=41954&r2=41955&view=diff

==============================================================================
--- llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp Fri Sep 14 13:51:50 2007
@@ -5569,31 +5569,55 @@
     int UArr[2];
     double V;
   };
-  REAL_VALUE_TO_TARGET_DOUBLE(TREE_REAL_CST(exp), RealArr);
-  
-  // Here's how this works:
-  // REAL_VALUE_TO_TARGET_DOUBLE() will generate the floating point number
-  //  as an array of integers in the hosts's representation.  Each integer
-  // in the array will hold 32 bits of the result REGARDLESS OF THE HOST'S
-  //  INTEGER SIZE.
-  //
-  // This, then, makes the conversion pretty simple.  The tricky part is
-  // getting the byte ordering correct and make sure you don't print any
-  // more than 32 bits per integer on platforms with ints > 32 bits.
-  //
-  bool HostBigEndian = false;
+  if (Ty==Type::FloatTy || Ty==Type::DoubleTy) {
+    REAL_VALUE_TO_TARGET_DOUBLE(TREE_REAL_CST(exp), RealArr);
+
+    // Here's how this works:
+    // REAL_VALUE_TO_TARGET_DOUBLE() will generate the floating point number
+    //  as an array of integers in the hosts's representation.  Each integer
+    // in the array will hold 32 bits of the result REGARDLESS OF THE HOST'S
+    //  INTEGER SIZE.
+    //
+    // This, then, makes the conversion pretty simple.  The tricky part is
+    // getting the byte ordering correct and make sure you don't print any
+    // more than 32 bits per integer on platforms with ints > 32 bits.
+    //
+    bool HostBigEndian = false;
 #ifdef HOST_WORDS_BIG_ENDIAN
-  HostBigEndian = true;
+    HostBigEndian = true;
 #endif
-  
-  UArr[0] = RealArr[0];   // Long -> int convert
-  UArr[1] = RealArr[1];
 
-  if (WORDS_BIG_ENDIAN != HostBigEndian)
-    std::swap(UArr[0], UArr[1]);
-  
-  return ConstantFP::get(Ty, Ty==Type::FloatTy ? APFloat((float)V)
-                                               : APFloat(V));
+    UArr[0] = RealArr[0];   // Long -> int convert
+    UArr[1] = RealArr[1];
+
+    if (WORDS_BIG_ENDIAN != HostBigEndian)
+      std::swap(UArr[0], UArr[1]);
+
+    return ConstantFP::get(Ty, Ty==Type::FloatTy ? APFloat((float)V)
+                                                 : APFloat(V));
+  } else if (Ty==Type::X86_FP80Ty) {
+     long RealArr[4];
+     uint64_t UArr[2];
+     REAL_VALUE_TO_TARGET_LONG_DOUBLE(TREE_REAL_CST(exp), RealArr);
+
+    bool HostBigEndian = false;
+#ifdef HOST_WORDS_BIG_ENDIAN
+    HostBigEndian = true;
+#endif
+
+    if (WORDS_BIG_ENDIAN != HostBigEndian) {
+    // FIXME
+    } else {
+      UArr[0] = ((uint64_t)((uint16_t)RealArr[2]) << 48) |
+                ((uint64_t)((uint32_t)RealArr[1]) << 16) |
+                ((uint64_t)((uint16_t)(RealArr[0] >> 16)));
+      UArr[1] = (uint16_t)RealArr[0];
+
+    return ConstantFP::get(Ty, APFloat(APInt(80, 2, UArr)));
+    }
+  }
+  assert(0 && "Floating point type not handled yet");
+  return 0;   // outwit compiler warning
 }
 
 Constant *TreeConstantToLLVM::ConvertVECTOR_CST(tree exp) {

Modified: llvm-gcc-4.0/trunk/gcc/llvm-types.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/llvm-types.cpp?rev=41955&r1=41954&r2=41955&view=diff

==============================================================================
--- llvm-gcc-4.0/trunk/gcc/llvm-types.cpp (original)
+++ llvm-gcc-4.0/trunk/gcc/llvm-types.cpp Fri Sep 14 13:51:50 2007
@@ -698,6 +698,7 @@
       abort();        
     case 32: return SET_TYPE_LLVM(type, Type::FloatTy);
     case 64: return SET_TYPE_LLVM(type, Type::DoubleTy);
+    case 80: return SET_TYPE_LLVM(type, Type::X86_FP80Ty);
     case 128:
       // 128-bit long doubles map onto { double, double }.
       const Type *Ty = Type::DoubleTy;





More information about the llvm-commits mailing list