[llvm-commits] [llvm-gcc-4.2] r41963 - in /llvm-gcc-4.2/trunk/gcc: llvm-convert.cpp llvm-types.cpp

Dale Johannesen dalej at apple.com
Fri Sep 14 14:53:35 PDT 2007


Author: johannes
Date: Fri Sep 14 16:53:34 2007
New Revision: 41963

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


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

Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=41963&r1=41962&r2=41963&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Fri Sep 14 16:53:34 2007
@@ -5164,28 +5164,47 @@
     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 target'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.
-
-  UArr[0] = RealArr[0];   // Long -> int convert
-  UArr[1] = RealArr[1];
-
-  // FIXME: verify on big-endian targets and cross from big- to little- endian
-  // targets
-  if (FLOAT_WORDS_BIG_ENDIAN)
-    std::swap(UArr[0], UArr[1]);
+  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 target'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.
+
+    UArr[0] = RealArr[0];   // Long -> int convert
+    UArr[1] = RealArr[1];
+
+    // FIXME: verify on big-endian targets and cross from big- to little- endian
+    // targets
+    if (FLOAT_WORDS_BIG_ENDIAN)
+      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);
+
+    if (FLOAT_WORDS_BIG_ENDIAN) {
+    // 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, Ty==Type::FloatTy ? APFloat((float)V)
-                                               : APFloat(V));
+    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.2/trunk/gcc/llvm-types.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-types.cpp?rev=41963&r1=41962&r2=41963&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-types.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-types.cpp Fri Sep 14 16:53:34 2007
@@ -730,6 +730,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