comparison gen/complex.cpp @ 217:0806379a5eca trunk

[svn r233] Added: -oq command line option for writing fully qualified object names. Added: started support for x86 80bit floating point. Changed: aggregates passed by value now use the llvm 'byval' parameter attribute, also lays ground work for using other attributes. Changed: eliminated a lot more std::vectorS, these showed up pretty much at the top when profiling! Changed: performed other misc. cleanups. Changed: halt expression now call the new llvm trap intrinsic instead of an assert(0). Changed: dstress suite now passes -O0 by default, this only eliminates unreferenced globals, which speeds up linking quite a bit.
author lindquist
date Thu, 05 Jun 2008 06:38:36 +0200
parents 7816aafeea3c
children a95056b3c996
comparison
equal deleted inserted replaced
216:3d022aa016ae 217:0806379a5eca
26 const LLType* DtoComplexBaseType(Type* t) 26 const LLType* DtoComplexBaseType(Type* t)
27 { 27 {
28 TY ty = DtoDType(t)->ty; 28 TY ty = DtoDType(t)->ty;
29 const LLType* base; 29 const LLType* base;
30 if (ty == Tcomplex32) { 30 if (ty == Tcomplex32) {
31 return llvm::Type::FloatTy; 31 return LLType::FloatTy;
32 } 32 }
33 else if (ty == Tcomplex64 || ty == Tcomplex80) { 33 else if (ty == Tcomplex64) {
34 return llvm::Type::DoubleTy; 34 return LLType::DoubleTy;
35 }
36 else if (ty == Tcomplex80) {
37 return (global.params.useFP80) ? LLType::X86_FP80Ty : LLType::DoubleTy;
35 } 38 }
36 else { 39 else {
37 assert(0); 40 assert(0);
38 } 41 }
39 } 42 }
58 TY ty = DtoDType(_ty)->ty; 61 TY ty = DtoDType(_ty)->ty;
59 62
60 llvm::ConstantFP* fre; 63 llvm::ConstantFP* fre;
61 llvm::ConstantFP* fim; 64 llvm::ConstantFP* fim;
62 65
63 const LLType* base; 66 Type* base = 0;
64 67
65 if (ty == Tcomplex32) { 68 if (ty == Tcomplex32) {
66 fre = DtoConstFP(Type::tfloat32, re); 69 base = Type::tfloat32;
67 fim = DtoConstFP(Type::tfloat32, im); 70 }
68 base = llvm::Type::FloatTy; 71 else if (ty == Tcomplex64) {
69 } 72 base = Type::tfloat64;
70 else if (ty == Tcomplex64 || ty == Tcomplex80) { 73 }
71 fre = DtoConstFP(Type::tfloat64, re); 74 else if (ty == Tcomplex80) {
72 fim = DtoConstFP(Type::tfloat64, im); 75 base = (global.params.useFP80) ? Type::tfloat80 : Type::tfloat64;
73 base = llvm::Type::DoubleTy; 76 }
74 }
75 else
76 assert(0);
77 77
78 std::vector<LLConstant*> inits; 78 std::vector<LLConstant*> inits;
79 inits.push_back(fre); 79 inits.push_back(DtoConstFP(base, re));
80 inits.push_back(fim); 80 inits.push_back(DtoConstFP(base, im));
81
81 return llvm::ConstantStruct::get(DtoComplexType(_ty), inits); 82 return llvm::ConstantStruct::get(DtoComplexType(_ty), inits);
82 }
83
84 LLConstant* DtoUndefComplex(Type* _ty)
85 {
86 assert(0);
87 TY ty = DtoDType(_ty)->ty;
88 const LLType* base;
89 if (ty == Tcomplex32) {
90 base = llvm::Type::FloatTy;
91 }
92 else if (ty == Tcomplex64 || ty == Tcomplex80) {
93 base = llvm::Type::DoubleTy;
94 }
95 else
96 assert(0);
97
98 std::vector<LLConstant*> inits;
99 inits.push_back(llvm::UndefValue::get(base));
100 inits.push_back(llvm::UndefValue::get(base));
101
102 const llvm::VectorType* vt = llvm::VectorType::get(base, 2);
103 return llvm::ConstantVector::get(vt, inits);
104 } 83 }
105 84
106 ////////////////////////////////////////////////////////////////////////////////////////// 85 //////////////////////////////////////////////////////////////////////////////////////////
107 86
108 LLValue* DtoRealPart(DValue* val) 87 LLValue* DtoRealPart(DValue* val)
133 const LLType* base = DtoComplexBaseType(to); 112 const LLType* base = DtoComplexBaseType(to);
134 113
135 LLConstant* undef = llvm::UndefValue::get(base); 114 LLConstant* undef = llvm::UndefValue::get(base);
136 LLConstant* zero; 115 LLConstant* zero;
137 if (ty == Tfloat32 || ty == Timaginary32 || ty == Tcomplex32) 116 if (ty == Tfloat32 || ty == Timaginary32 || ty == Tcomplex32)
138 zero = llvm::ConstantFP::get(llvm::APFloat(0.0f)); 117 zero = LLConstant::getNullValue(DtoType(Type::tfloat32)); // llvm::ConstantFP::get(llvm::APFloat(0.0f));
139 else if (ty == Tfloat64 || ty == Timaginary64 || ty == Tcomplex64 || ty == Tfloat80 || ty == Timaginary80 || ty == Tcomplex80) 118 else if (ty == Tfloat64 || ty == Timaginary64 || ty == Tcomplex64)
140 zero = llvm::ConstantFP::get(llvm::APFloat(0.0)); 119 zero = LLConstant::getNullValue(DtoType(Type::tfloat64));
120 else if (ty == Tfloat80 || ty == Timaginary80 || ty == Tcomplex80)
121 zero = LLConstant::getNullValue(DtoType((global.params.useFP80)?Type::tfloat80:Type::tfloat64));
141 122
142 if (t->isimaginary()) { 123 if (t->isimaginary()) {
143 return new DComplexValue(to, zero, val->getRVal()); 124 return new DComplexValue(to, zero, val->getRVal());
144 } 125 }
145 else if (t->isfloating()) { 126 else if (t->isfloating()) {