Mercurial > projects > ldc
annotate gen/complex.cpp @ 438:3c133dd1eda3
Rework complex divison.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Wed, 30 Jul 2008 16:48:35 +0200 |
parents | 798ee94a0be7 |
children | cc40db549aea |
rev | line source |
---|---|
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
1 #include "gen/llvm.h" |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
2 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
3 #include "mtype.h" |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
4 #include "declaration.h" |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
5 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
6 #include "gen/complex.h" |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
7 #include "gen/tollvm.h" |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
8 #include "gen/llvmhelpers.h" |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
9 #include "gen/irstate.h" |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
10 #include "gen/dvalue.h" |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
11 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
12 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
13 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
14 const llvm::StructType* DtoComplexType(Type* type) |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
15 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
16 Type* t = DtoDType(type); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
17 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
18 const LLType* base = DtoComplexBaseType(t); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
19 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
20 std::vector<const LLType*> types; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
21 types.push_back(base); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
22 types.push_back(base); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
23 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
24 return llvm::StructType::get(types); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
25 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
26 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
27 const LLType* DtoComplexBaseType(Type* t) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
28 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
29 TY ty = DtoDType(t)->ty; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
30 const LLType* base; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
31 if (ty == Tcomplex32) { |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
32 return LLType::FloatTy; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
33 } |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
34 else if (ty == Tcomplex64) { |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
35 return LLType::DoubleTy; |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
36 } |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
37 else if (ty == Tcomplex80) { |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
38 return (global.params.useFP80) ? LLType::X86_FP80Ty : LLType::DoubleTy; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
39 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
40 else { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
41 assert(0); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
42 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
43 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
44 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
45 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
46 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
47 LLConstant* DtoConstComplex(Type* ty, LLConstant* re, LLConstant* im) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
48 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
49 assert(0); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
50 const LLType* base = DtoComplexBaseType(ty); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
51 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
52 std::vector<LLConstant*> inits; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
53 inits.push_back(re); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
54 inits.push_back(im); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
55 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
56 const llvm::VectorType* vt = llvm::VectorType::get(base, 2); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
57 return llvm::ConstantVector::get(vt, inits); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
58 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
59 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
60 LLConstant* DtoConstComplex(Type* _ty, long double re, long double im) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
61 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
62 TY ty = DtoDType(_ty)->ty; |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
63 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
64 llvm::ConstantFP* fre; |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
65 llvm::ConstantFP* fim; |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
66 |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
67 Type* base = 0; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
68 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
69 if (ty == Tcomplex32) { |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
70 base = Type::tfloat32; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
71 } |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
72 else if (ty == Tcomplex64) { |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
73 base = Type::tfloat64; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
74 } |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
75 else if (ty == Tcomplex80) { |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
76 base = (global.params.useFP80) ? Type::tfloat80 : Type::tfloat64; |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
77 } |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
78 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
79 std::vector<LLConstant*> inits; |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
80 inits.push_back(DtoConstFP(base, re)); |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
81 inits.push_back(DtoConstFP(base, im)); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
82 |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
83 return llvm::ConstantStruct::get(DtoComplexType(_ty), inits); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
84 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
85 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
86 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
87 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
88 LLValue* DtoRealPart(DValue* val) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
89 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
90 assert(0); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
91 return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(0), "tmp"); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
92 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
93 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
94 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
95 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
96 LLValue* DtoImagPart(DValue* val) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
97 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
98 assert(0); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
99 return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(1), "tmp"); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
100 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
101 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
102 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
103 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
104 DValue* DtoComplex(Loc& loc, Type* to, DValue* val) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
105 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
106 Type* t = DtoDType(val->getType()); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
107 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
108 if (val->isComplex() || t->iscomplex()) { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
109 return DtoCastComplex(loc, val, to); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
110 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
111 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
112 const LLType* base = DtoComplexBaseType(to); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
113 |
359 | 114 Type* baserety; |
115 Type* baseimty; | |
116 TY ty = to->ty; | |
117 if (ty == Tcomplex32) { | |
118 baserety = Type::tfloat32; | |
119 baseimty = Type::timaginary32; | |
120 } else if (ty == Tcomplex64) { | |
121 baserety = Type::tfloat64; | |
122 baseimty = Type::timaginary64; | |
123 } else if (ty == Tcomplex80) { | |
124 baserety = global.params.useFP80 ? Type::tfloat80 : Type::tfloat64; | |
125 baseimty = global.params.useFP80 ? Type::timaginary80 : Type::timaginary64; | |
126 } | |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
127 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
128 if (t->isimaginary()) { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
129 return new DComplexValue(to, LLConstant::getNullValue(DtoType(baserety)), DtoCastFloat(loc, val, baseimty)->getRVal()); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
130 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
131 else if (t->isfloating()) { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
132 return new DComplexValue(to, DtoCastFloat(loc, val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty))); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
133 } |
359 | 134 else if (t->isintegral()) { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
135 return new DComplexValue(to, DtoCastInt(loc, val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty))); |
359 | 136 } |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
137 assert(0); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
138 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
139 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
140 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
141 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
142 void DtoComplexAssign(LLValue* l, LLValue* r) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
143 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
144 DtoStore(DtoLoad(DtoGEPi(r, 0,0, "tmp")), DtoGEPi(l,0,0,"tmp")); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
145 DtoStore(DtoLoad(DtoGEPi(r, 0,1, "tmp")), DtoGEPi(l,0,1,"tmp")); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
146 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
147 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
148 void DtoComplexSet(LLValue* c, LLValue* re, LLValue* im) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
149 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
150 DtoStore(re, DtoGEPi(c,0,0,"tmp")); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
151 DtoStore(im, DtoGEPi(c,0,1,"tmp")); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
152 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
153 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
154 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
155 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
156 void DtoGetComplexParts(DValue* c, LLValue*& re, LLValue*& im) |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
157 { |
359 | 158 // get LLValues |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
159 if (DComplexValue* cx = c->isComplex()) { |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
160 re = cx->re; |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
161 im = cx->im; |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
162 } |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
163 else { |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
164 re = DtoLoad(DtoGEPi(c->getRVal(),0,0,"tmp")); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
165 im = DtoLoad(DtoGEPi(c->getRVal(),0,1,"tmp")); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
166 } |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
167 } |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
168 |
359 | 169 DValue* resolveLR(DValue* val, bool getlval) |
170 { | |
171 if (DLRValue* lr = val->isLRValue()) { | |
172 if (getlval) | |
173 return lr->lvalue; | |
174 else | |
175 return lr->rvalue; | |
176 } | |
177 return val; | |
178 } | |
179 | |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
180 ////////////////////////////////////////////////////////////////////////////////////////// |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
181 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
182 bool hasRe(Type* t) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
183 { |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
184 return |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
185 (t->ty != Timaginary32 && |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
186 t->ty != Timaginary64 && |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
187 t->ty != Timaginary80); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
188 } |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
189 |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
190 bool hasIm(Type* t) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
191 { |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
192 return |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
193 (t->ty == Timaginary32 || |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
194 t->ty == Timaginary64 || |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
195 t->ty == Timaginary80 || |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
196 t->ty == Tcomplex32 || |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
197 t->ty == Tcomplex64 || |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
198 t->ty == Tcomplex80); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
199 } |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
200 |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
201 ////////////////////////////////////////////////////////////////////////////////////////// |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
202 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
203 DValue* DtoComplexAdd(Loc& loc, Type* type, DValue* lhs, DValue* rhs) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
204 { |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
205 DValue* clhs = DtoComplex(loc, type, resolveLR(lhs, true)); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
206 DValue* crhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
207 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
208 llvm::Value *lhs_re, *lhs_im, *rhs_re, *rhs_im, *res_re, *res_im; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
209 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
210 // lhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
211 DtoGetComplexParts(clhs, lhs_re, lhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
212 // rhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
213 DtoGetComplexParts(crhs, rhs_re, rhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
214 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
215 // add up |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
216 Type* lhstype = lhs->getType(); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
217 Type* rhstype = rhs->getType(); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
218 if(hasRe(lhstype) && hasRe(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
219 res_re = gIR->ir->CreateAdd(lhs_re, rhs_re, "tmp"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
220 else if(hasRe(lhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
221 res_re = lhs_re; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
222 else // either hasRe(rhstype) or no re at all (then use any) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
223 res_re = rhs_re; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
224 |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
225 if(hasIm(lhstype) && hasIm(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
226 res_im = gIR->ir->CreateAdd(lhs_im, rhs_im, "tmp"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
227 else if(hasIm(lhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
228 res_im = lhs_im; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
229 else // either hasIm(rhstype) or no im at all (then use any) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
230 res_im = rhs_im; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
231 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
232 return new DComplexValue(type, res_re, res_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
233 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
234 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
235 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
236 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
237 DValue* DtoComplexSub(Loc& loc, Type* type, DValue* lhs, DValue* rhs) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
238 { |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
239 DValue* clhs = DtoComplex(loc, type, resolveLR(lhs, true)); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
240 DValue* crhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
241 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
242 llvm::Value *lhs_re, *lhs_im, *rhs_re, *rhs_im, *res_re, *res_im; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
243 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
244 // lhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
245 DtoGetComplexParts(clhs, lhs_re, lhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
246 // rhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
247 DtoGetComplexParts(crhs, rhs_re, rhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
248 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
249 // sub up |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
250 Type* lhstype = lhs->getType(); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
251 Type* rhstype = rhs->getType(); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
252 if(hasRe(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
253 res_re = gIR->ir->CreateSub(lhs_re, rhs_re, "tmp"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
254 else |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
255 res_re = lhs_re; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
256 |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
257 if(hasIm(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
258 res_im = gIR->ir->CreateSub(lhs_im, rhs_im, "tmp"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
259 else |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
260 res_im = lhs_im; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
261 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
262 return new DComplexValue(type, res_re, res_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
263 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
264 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
265 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
266 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
267 DValue* DtoComplexMul(Loc& loc, Type* type, DValue* lhs, DValue* rhs) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
268 { |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
269 DValue* clhs = DtoComplex(loc, type, resolveLR(lhs, true)); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
270 DValue* crhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
271 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
272 llvm::Value *lhs_re, *lhs_im, *rhs_re, *rhs_im, *res_re, *res_im; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
273 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
274 // lhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
275 DtoGetComplexParts(clhs, lhs_re, lhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
276 // rhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
277 DtoGetComplexParts(crhs, rhs_re, rhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
278 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
279 // mul up |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
280 llvm::Value *rere = NULL; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
281 llvm::Value *reim = NULL; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
282 llvm::Value *imre = NULL; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
283 llvm::Value *imim = NULL; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
284 Type* lhstype = lhs->getType(); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
285 Type* rhstype = rhs->getType(); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
286 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
287 if(hasRe(lhstype) && hasRe(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
288 rere = gIR->ir->CreateMul(lhs_re, rhs_re, "rere_mul"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
289 if(hasRe(lhstype) && hasIm(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
290 reim = gIR->ir->CreateMul(lhs_re, rhs_im, "reim_mul"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
291 if(hasIm(lhstype) && hasRe(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
292 imre = gIR->ir->CreateMul(lhs_im, rhs_re, "imre_mul"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
293 if(hasIm(lhstype) && hasIm(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
294 imim = gIR->ir->CreateMul(lhs_im, rhs_im, "imim_mul"); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
295 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
296 if(rere && imim) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
297 res_re = gIR->ir->CreateSub(rere, imim, "rere_imim_sub"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
298 else if(rere) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
299 res_re = rere; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
300 else if(imim) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
301 res_re = gIR->ir->CreateNeg(imim, "imim_neg"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
302 else |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
303 res_re = hasRe(lhstype) ? rhs_re : lhs_re; // null! |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
304 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
305 if(reim && imre) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
306 res_im = gIR->ir->CreateAdd(reim, imre, "reim_imre_add"); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
307 else if(reim) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
308 res_im = reim; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
309 else if(imre) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
310 res_im = imre; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
311 else |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
312 res_im = hasRe(lhstype) ? rhs_im : lhs_re; // null! |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
313 |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
314 return new DComplexValue(type, res_re, res_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
315 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
316 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
317 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
318 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
319 DValue* DtoComplexDiv(Loc& loc, Type* type, DValue* lhs, DValue* rhs) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
320 { |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
321 DValue* clhs = DtoComplex(loc, type, resolveLR(lhs, true)); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
322 DValue* crhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
323 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
324 llvm::Value *lhs_re, *lhs_im, *rhs_re, *rhs_im, *res_re, *res_im; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
325 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
326 // lhs values |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
327 DtoGetComplexParts(clhs, lhs_re, lhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
328 // rhs values |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
329 DtoGetComplexParts(crhs, rhs_re, rhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
330 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
331 Type* lhstype = lhs->getType(); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
332 Type* rhstype = rhs->getType(); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
333 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
334 // if divisor is only real, division is simple |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
335 if(hasRe(rhstype) && !hasIm(rhstype)) { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
336 if(hasRe(lhstype)) |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
337 res_re = gIR->ir->CreateFDiv(lhs_re, rhs_re, "re_divby_re"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
338 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
339 res_re = lhs_re; |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
340 if(hasIm(lhstype)) |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
341 res_im = gIR->ir->CreateFDiv(lhs_im, rhs_re, "im_divby_re"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
342 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
343 res_im = lhs_im; |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
344 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
345 // if divisor is only imaginary, division is simple too |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
346 else if(!hasRe(rhstype) && hasIm(rhstype)) { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
347 if(hasRe(lhstype)) |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
348 res_im = gIR->ir->CreateNeg(gIR->ir->CreateFDiv(lhs_re, rhs_im, "re_divby_im"), "neg"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
349 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
350 res_im = lhs_re; |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
351 if(hasIm(lhstype)) |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
352 res_re = gIR->ir->CreateFDiv(lhs_im, rhs_im, "im_divby_im"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
353 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
354 res_re = lhs_im; |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
355 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
356 // full division |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
357 else { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
358 llvm::Value *tmp1, *tmp2, *denom; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
359 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
360 if(hasRe(lhstype) && hasIm(lhstype)) { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
361 tmp1 = gIR->ir->CreateMul(lhs_re, rhs_re, "rere"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
362 tmp2 = gIR->ir->CreateMul(lhs_im, rhs_im, "imim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
363 res_re = gIR->ir->CreateAdd(tmp1, tmp2, "rere_plus_imim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
364 |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
365 tmp1 = gIR->ir->CreateMul(lhs_re, rhs_im, "reim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
366 tmp2 = gIR->ir->CreateMul(lhs_im, rhs_re, "imre"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
367 res_im = gIR->ir->CreateSub(tmp2, tmp1, "imre_sub_reim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
368 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
369 else if(hasRe(lhstype)) { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
370 res_re = gIR->ir->CreateMul(lhs_re, rhs_re, "rere"); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
371 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
372 res_im = gIR->ir->CreateMul(lhs_re, rhs_im, "reim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
373 res_im = gIR->ir->CreateNeg(res_im); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
374 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
375 else if(hasIm(lhstype)) { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
376 res_re = gIR->ir->CreateMul(lhs_im, rhs_im, "imim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
377 res_im = gIR->ir->CreateMul(lhs_im, rhs_re, "imre"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
378 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
379 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
380 assert(0 && "lhs has neither real nor imaginary part"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
381 |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
382 tmp1 = gIR->ir->CreateMul(rhs_re, rhs_re, "rhs_resq"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
383 tmp2 = gIR->ir->CreateMul(rhs_im, rhs_im, "rhs_imsq"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
384 denom = gIR->ir->CreateAdd(tmp1, tmp2, "denom"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
385 |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
386 res_re = gIR->ir->CreateFDiv(res_re, denom, "res_re"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
387 res_im = gIR->ir->CreateFDiv(res_im, denom, "res_im"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
388 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
389 |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
390 return new DComplexValue(type, res_re, res_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
391 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
392 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
393 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
394 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
395 DValue* DtoComplexNeg(Loc& loc, Type* type, DValue* val) |
164
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
396 { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
397 val = DtoComplex(loc, type, resolveLR(val, false)); |
164
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
398 |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
399 llvm::Value *a, *b, *re, *im; |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
400 |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
401 // values |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
402 DtoGetComplexParts(val, a, b); |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
403 |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
404 // sub up |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
405 re = gIR->ir->CreateNeg(a, "tmp"); |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
406 im = gIR->ir->CreateNeg(b, "tmp"); |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
407 |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
408 return new DComplexValue(type, re, im); |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
409 } |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
410 |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
411 ////////////////////////////////////////////////////////////////////////////////////////// |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
412 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
413 LLValue* DtoComplexEquals(Loc& loc, TOK op, DValue* lhs, DValue* rhs) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
414 { |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
415 Type* type = lhs->getType(); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
416 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
417 lhs = DtoComplex(loc, type, resolveLR(lhs, false)); |
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
418 rhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
419 |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
420 llvm::Value *a, *b, *c, *d; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
421 |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
422 // lhs values |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
423 DtoGetComplexParts(lhs, a, b); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
424 // rhs values |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
425 DtoGetComplexParts(rhs, c, d); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
426 |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
427 // select predicate |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
428 llvm::FCmpInst::Predicate cmpop; |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
429 if (op == TOKequal) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
430 cmpop = llvm::FCmpInst::FCMP_OEQ; |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
431 else |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
432 cmpop = llvm::FCmpInst::FCMP_UNE; |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
433 |
364
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
434 // (l.re==r.re && l.im==r.im) or (l.re!=r.re || l.im!=r.im) |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
435 LLValue* b1 = new llvm::FCmpInst(cmpop, a, c, "tmp", gIR->scopebb()); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
436 LLValue* b2 = new llvm::FCmpInst(cmpop, b, d, "tmp", gIR->scopebb()); |
364
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
437 |
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
438 if (op == TOKequal) |
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
439 return gIR->ir->CreateAnd(b1,b2,"tmp"); |
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
440 else |
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
441 return gIR->ir->CreateOr(b1,b2,"tmp"); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
442 } |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
443 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
444 ////////////////////////////////////////////////////////////////////////////////////////// |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
445 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
446 DValue* DtoCastComplex(Loc& loc, DValue* val, Type* _to) |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
447 { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
448 Type* to = DtoDType(_to); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
449 Type* vty = val->getType(); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
450 if (to->iscomplex()) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
451 if (vty->size() == to->size()) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
452 return val; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
453 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
454 llvm::Value *re, *im; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
455 DtoGetComplexParts(val, re, im); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
456 const LLType* toty = DtoComplexBaseType(to); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
457 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
458 if (to->size() < vty->size()) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
459 re = gIR->ir->CreateFPTrunc(re, toty, "tmp"); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
460 im = gIR->ir->CreateFPTrunc(im, toty, "tmp"); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
461 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
462 else if (to->size() > vty->size()) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
463 re = gIR->ir->CreateFPExt(re, toty, "tmp"); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
464 im = gIR->ir->CreateFPExt(im, toty, "tmp"); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
465 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
466 else { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
467 return val; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
468 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
469 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
470 if (val->isComplex()) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
471 return new DComplexValue(_to, re, im); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
472 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
473 // unfortunately at this point, the cast value can show up as the lvalue for += and similar expressions. |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
474 // so we need to give it storage, or fix the system that handles this stuff (DLRValue) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
475 LLValue* mem = new llvm::AllocaInst(DtoType(_to), "castcomplextmp", gIR->topallocapoint()); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
476 DtoComplexSet(mem, re, im); |
359 | 477 return new DLRValue(val, new DImValue(_to, mem)); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
478 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
479 else if (to->isimaginary()) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
480 if (val->isComplex()) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
481 return new DImValue(to, val->isComplex()->im); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
482 LLValue* v = val->getRVal(); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
483 DImValue* im = new DImValue(to, DtoLoad(DtoGEPi(v,0,1,"tmp"))); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
484 return DtoCastFloat(loc, im, to); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
485 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
486 else if (to->isfloating()) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
487 if (val->isComplex()) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
488 return new DImValue(to, val->isComplex()->re); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
489 LLValue* v = val->getRVal(); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
490 DImValue* re = new DImValue(to, DtoLoad(DtoGEPi(v,0,0,"tmp"))); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
491 return DtoCastFloat(loc, re, to); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
492 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
493 else |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
494 assert(0); |
303 | 495 } |
496 |