Mercurial > projects > ldc
annotate gen/complex.cpp @ 905:bd000a7fab18
Applied doob's patch to port GDC's Dyld data segment tracking for Mac.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sat, 24 Jan 2009 00:33:06 +0100 |
parents | 4adf0f742896 |
children | 3cf0066e6faf |
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" |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
11 #include "gen/logger.h" |
104
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 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
15 const llvm::StructType* DtoComplexType(Type* type) |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
16 { |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
479
diff
changeset
|
17 Type* t = type->toBasetype(); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
18 const LLType* base = DtoComplexBaseType(t); |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
19 return llvm::StructType::get(base, base, NULL); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
20 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
21 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
22 const LLType* DtoComplexBaseType(Type* t) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
23 { |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
479
diff
changeset
|
24 TY ty = t->toBasetype()->ty; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
25 const LLType* base; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
26 if (ty == Tcomplex32) { |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
27 return LLType::FloatTy; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
28 } |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
29 else if (ty == Tcomplex64) { |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
30 return LLType::DoubleTy; |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
31 } |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
32 else if (ty == Tcomplex80) { |
741
4ac97ec7c18e
Applied easy part from wilsonk's x86-64 patch in #107
Christian Kamm <kamm incasoftware de>
parents:
625
diff
changeset
|
33 if ((global.params.cpu == ARCHx86) || (global.params.cpu == ARCHx86_64)) |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
438
diff
changeset
|
34 return LLType::X86_FP80Ty; |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
438
diff
changeset
|
35 else |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
438
diff
changeset
|
36 return LLType::DoubleTy; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
37 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
38 else { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
39 assert(0); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
40 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
41 } |
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 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
45 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
|
46 { |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
479
diff
changeset
|
47 TY ty = _ty->toBasetype()->ty; |
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 llvm::ConstantFP* fre; |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
50 llvm::ConstantFP* fim; |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
51 |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
52 Type* base = 0; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
53 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
54 if (ty == Tcomplex32) { |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
55 base = Type::tfloat32; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
56 } |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
57 else if (ty == Tcomplex64) { |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
58 base = Type::tfloat64; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
59 } |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
60 else if (ty == Tcomplex80) { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
438
diff
changeset
|
61 base = Type::tfloat80; |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
62 } |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
63 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
64 std::vector<LLConstant*> inits; |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
65 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
|
66 inits.push_back(DtoConstFP(base, im)); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
67 |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
68 return llvm::ConstantStruct::get(DtoComplexType(_ty), inits); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
69 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
70 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
71 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
72 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
73 LLValue* DtoRealPart(DValue* val) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
74 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
75 assert(0); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
76 return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(0), "tmp"); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
77 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
78 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
79 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
80 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
81 LLValue* DtoImagPart(DValue* val) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
82 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
83 assert(0); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
84 return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(1), "tmp"); |
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 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
88 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
89 DValue* DtoComplex(Loc& loc, Type* to, DValue* val) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
90 { |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
91 const LLType* complexTy = DtoType(to); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
92 |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
93 Type* baserety; |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
94 Type* baseimty; |
625
7e0a766fef47
Make typedef'ed complex types work.
Christian Kamm <kamm incasoftware de>
parents:
617
diff
changeset
|
95 TY ty = to->toBasetype()->ty; |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
96 if (ty == Tcomplex32) { |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
97 baserety = Type::tfloat32; |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
98 baseimty = Type::timaginary32; |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
99 } else if (ty == Tcomplex64) { |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
100 baserety = Type::tfloat64; |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
101 baseimty = Type::timaginary64; |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
102 } else if (ty == Tcomplex80) { |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
103 baserety = Type::tfloat80; |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
104 baseimty = Type::timaginary80; |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
105 } |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
106 else { |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
107 assert(0); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
108 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
109 |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
110 LLValue *re, *im; |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
111 DtoGetComplexParts(loc, to, val, re, im); |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
112 |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
113 if(!re) |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
114 re = LLConstant::getNullValue(DtoType(baserety)); |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
115 if(!im) |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
116 im = LLConstant::getNullValue(DtoType(baseimty)); |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
117 |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
118 LLValue* res = DtoAggrPair(complexTy, re, im); |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
119 |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
120 return new DImValue(to, res); |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
121 } |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
122 |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
123 ////////////////////////////////////////////////////////////////////////////////////////// |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
124 |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
125 void DtoComplexSet(LLValue* c, LLValue* re, LLValue* im) |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
126 { |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
127 DtoStore(re, DtoGEPi(c,0,0,"tmp")); |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
128 DtoStore(im, DtoGEPi(c,0,1,"tmp")); |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
129 } |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
130 |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
131 ////////////////////////////////////////////////////////////////////////////////////////// |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
132 |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
133 void DtoGetComplexParts(Loc& loc, Type* to, DValue* val, LLValue*& re, LLValue*& im) |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
134 { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
135 const LLType* base = DtoComplexBaseType(to); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
136 |
359 | 137 Type* baserety; |
138 Type* baseimty; | |
625
7e0a766fef47
Make typedef'ed complex types work.
Christian Kamm <kamm incasoftware de>
parents:
617
diff
changeset
|
139 TY ty = to->toBasetype()->ty; |
359 | 140 if (ty == Tcomplex32) { |
141 baserety = Type::tfloat32; | |
142 baseimty = Type::timaginary32; | |
143 } else if (ty == Tcomplex64) { | |
144 baserety = Type::tfloat64; | |
145 baseimty = Type::timaginary64; | |
146 } else if (ty == Tcomplex80) { | |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
438
diff
changeset
|
147 baserety = Type::tfloat80; |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
438
diff
changeset
|
148 baseimty = Type::timaginary80; |
359 | 149 } |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
150 else { |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
151 assert(0); |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
152 } |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
153 |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
154 Type* t = val->getType()->toBasetype(); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
155 |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
156 if (t->iscomplex()) { |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
157 DValue* v = DtoCastComplex(loc, val, to); |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
158 if (to->iscomplex()) { |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
159 re = gIR->ir->CreateExtractValue(v->getRVal(), 0, ".re_part"); |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
160 im = gIR->ir->CreateExtractValue(v->getRVal(), 1, ".im_part"); |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
161 } else |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
162 DtoGetComplexParts(loc, to, v, re, im); |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
163 } |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
164 else if (t->isimaginary()) { |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
165 re = NULL; |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
166 im = DtoCastFloat(loc, val, baseimty)->getRVal(); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
167 } |
586
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
168 else if (t->isfloating()) { |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
169 re = DtoCastFloat(loc, val, baserety)->getRVal(); |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
170 im = NULL; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
171 } |
586
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
172 else if (t->isintegral()) { |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
173 re = DtoCastInt(loc, val, baserety)->getRVal(); |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
174 im = NULL; |
586
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
175 } |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
176 else { |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
177 assert(0); |
359 | 178 } |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
179 } |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
180 |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
181 ////////////////////////////////////////////////////////////////////////////////////////// |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
182 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
183 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
|
184 { |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
185 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
|
186 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
187 // lhs values |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
188 DtoGetComplexParts(loc, type, lhs, lhs_re, lhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
189 // rhs values |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
190 DtoGetComplexParts(loc, type, rhs, rhs_re, rhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
191 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
192 // add up |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
193 if(lhs_re && rhs_re) |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
194 res_re = gIR->ir->CreateAdd(lhs_re, rhs_re, "tmp"); |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
195 else if(lhs_re) |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
196 res_re = lhs_re; |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
197 else // either rhs_re or no re at all (then use any) |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
198 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
|
199 |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
200 if(lhs_im && rhs_im) |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
201 res_im = gIR->ir->CreateAdd(lhs_im, rhs_im, "tmp"); |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
202 else if(lhs_im) |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
203 res_im = lhs_im; |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
204 else // either rhs_im or no im at all (then use any) |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
205 res_im = rhs_im; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
206 |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
207 LLValue* res = DtoAggrPair(DtoType(type), res_re, res_im); |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
208 return new DImValue(type, res); |
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 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
211 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
212 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
213 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
|
214 { |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
215 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
|
216 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
217 // lhs values |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
218 DtoGetComplexParts(loc, type, lhs, lhs_re, lhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
219 // rhs values |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
220 DtoGetComplexParts(loc, type, rhs, rhs_re, rhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
221 |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
222 // add up |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
223 if(lhs_re && rhs_re) |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
224 res_re = gIR->ir->CreateSub(lhs_re, rhs_re, "tmp"); |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
225 else if(lhs_re) |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
226 res_re = lhs_re; |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
227 else // either rhs_re or no re at all (then use any) |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
228 res_re = gIR->ir->CreateNeg(rhs_re, "neg"); |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
229 |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
230 if(lhs_im && rhs_im) |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
231 res_im = gIR->ir->CreateSub(lhs_im, rhs_im, "tmp"); |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
232 else if(lhs_im) |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
233 res_im = lhs_im; |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
234 else // either rhs_im or no im at all (then use any) |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
235 res_im = gIR->ir->CreateNeg(rhs_im, "neg"); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
236 |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
237 LLValue* res = DtoAggrPair(DtoType(type), res_re, res_im); |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
238 return new DImValue(type, res); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
239 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
240 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
241 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
242 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
243 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
|
244 { |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
245 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
|
246 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
247 // lhs values |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
248 DtoGetComplexParts(loc, type, lhs, lhs_re, lhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
249 // rhs values |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
250 DtoGetComplexParts(loc, type, rhs, rhs_re, rhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
251 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
252 // mul up |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
253 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
|
254 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
|
255 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
|
256 llvm::Value *imim = NULL; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
257 |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
258 if(lhs_re && rhs_re) |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
259 rere = gIR->ir->CreateMul(lhs_re, rhs_re, "rere_mul"); |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
260 if(lhs_re && rhs_im) |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
261 reim = gIR->ir->CreateMul(lhs_re, rhs_im, "reim_mul"); |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
262 if(lhs_im && rhs_re) |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
263 imre = gIR->ir->CreateMul(lhs_im, rhs_re, "imre_mul"); |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
264 if(lhs_im && rhs_im) |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
265 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
|
266 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
267 if(rere && imim) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
268 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
|
269 else if(rere) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
270 res_re = rere; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
271 else if(imim) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
272 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
|
273 else |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
274 res_re = lhs_re ? rhs_re : lhs_re; // null! |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
275 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
276 if(reim && imre) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
277 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
|
278 else if(reim) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
279 res_im = reim; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
280 else if(imre) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
281 res_im = imre; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
282 else |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
283 res_im = lhs_re ? rhs_im : lhs_re; // null! |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
284 |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
285 LLValue* res = DtoAggrPair(DtoType(type), res_re, res_im); |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
286 return new DImValue(type, res); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
287 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
288 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
289 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
290 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
291 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
|
292 { |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
293 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
|
294 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
295 // lhs values |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
296 DtoGetComplexParts(loc, type, lhs, lhs_re, lhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
297 // rhs values |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
298 DtoGetComplexParts(loc, type, rhs, rhs_re, rhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
299 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
300 // if divisor is only real, division is simple |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
301 if(rhs_re && !rhs_im) { |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
302 if(lhs_re) |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
303 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
|
304 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
305 res_re = lhs_re; |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
306 if(lhs_im) |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
307 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
|
308 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
309 res_im = lhs_im; |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
310 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
311 // if divisor is only imaginary, division is simple too |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
312 else if(!rhs_re && rhs_im) { |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
313 if(lhs_re) |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
314 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
|
315 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
316 res_im = lhs_re; |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
317 if(lhs_im) |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
318 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
|
319 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
320 res_re = lhs_im; |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
321 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
322 // full division |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
323 else { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
324 llvm::Value *tmp1, *tmp2, *denom; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
325 |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
326 if(lhs_re && lhs_im) { |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
327 tmp1 = gIR->ir->CreateMul(lhs_re, rhs_re, "rere"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
328 tmp2 = gIR->ir->CreateMul(lhs_im, rhs_im, "imim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
329 res_re = gIR->ir->CreateAdd(tmp1, tmp2, "rere_plus_imim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
330 |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
331 tmp1 = gIR->ir->CreateMul(lhs_re, rhs_im, "reim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
332 tmp2 = gIR->ir->CreateMul(lhs_im, rhs_re, "imre"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
333 res_im = gIR->ir->CreateSub(tmp2, tmp1, "imre_sub_reim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
334 } |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
335 else if(lhs_re) { |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
336 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
|
337 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
338 res_im = gIR->ir->CreateMul(lhs_re, rhs_im, "reim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
339 res_im = gIR->ir->CreateNeg(res_im); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
340 } |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
341 else if(lhs_im) { |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
342 res_re = gIR->ir->CreateMul(lhs_im, rhs_im, "imim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
343 res_im = gIR->ir->CreateMul(lhs_im, rhs_re, "imre"); |
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 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
346 assert(0 && "lhs has neither real nor imaginary part"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
347 |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
348 tmp1 = gIR->ir->CreateMul(rhs_re, rhs_re, "rhs_resq"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
349 tmp2 = gIR->ir->CreateMul(rhs_im, rhs_im, "rhs_imsq"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
350 denom = gIR->ir->CreateAdd(tmp1, tmp2, "denom"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
351 |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
352 res_re = gIR->ir->CreateFDiv(res_re, denom, "res_re"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
353 res_im = gIR->ir->CreateFDiv(res_im, denom, "res_im"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
354 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
355 |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
356 LLValue* res = DtoAggrPair(DtoType(type), res_re, res_im); |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
357 return new DImValue(type, res); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
358 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
359 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
360 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
361 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
362 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
|
363 { |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
364 llvm::Value *a, *b, *re, *im; |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
365 |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
366 // values |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
367 DtoGetComplexParts(loc, type, val, a, b); |
164
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
368 |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
369 // neg up |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
370 assert(a && b); |
164
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
371 re = gIR->ir->CreateNeg(a, "tmp"); |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
372 im = gIR->ir->CreateNeg(b, "tmp"); |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
373 |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
374 LLValue* res = DtoAggrPair(DtoType(type), re, im); |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
375 return new DImValue(type, res); |
164
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
376 } |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
377 |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
378 ////////////////////////////////////////////////////////////////////////////////////////// |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
379 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
380 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
|
381 { |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
382 Type* type = lhs->getType(); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
383 |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
384 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
|
385 |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
386 // lhs values |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
387 DtoGetComplexParts(loc, type, lhs, lhs_re, lhs_im); |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
388 // rhs values |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
389 DtoGetComplexParts(loc, type, rhs, rhs_re, rhs_im); |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
390 |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
391 // select predicate |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
392 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
|
393 if (op == TOKequal) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
394 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
|
395 else |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
396 cmpop = llvm::FCmpInst::FCMP_UNE; |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
397 |
364
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
398 // (l.re==r.re && l.im==r.im) or (l.re!=r.re || l.im!=r.im) |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
399 LLValue* b1 = new llvm::FCmpInst(cmpop, lhs_re, rhs_re, "tmp", gIR->scopebb()); |
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
400 LLValue* b2 = new llvm::FCmpInst(cmpop, lhs_im, rhs_im, "tmp", gIR->scopebb()); |
364
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
401 |
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
402 if (op == TOKequal) |
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
403 return gIR->ir->CreateAnd(b1,b2,"tmp"); |
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
404 else |
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
405 return gIR->ir->CreateOr(b1,b2,"tmp"); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
406 } |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
407 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
408 ////////////////////////////////////////////////////////////////////////////////////////// |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
409 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
410 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
|
411 { |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
479
diff
changeset
|
412 Type* to = _to->toBasetype(); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
413 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
|
414 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
|
415 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
|
416 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
|
417 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
418 llvm::Value *re, *im; |
617
634fbbdec390
Simplify complex number handling. Fixes bug with complex substraction.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
419 DtoGetComplexParts(loc, val->getType(), val, re, im); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
420 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
|
421 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
422 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
|
423 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
|
424 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
|
425 } |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
426 else { |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
427 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
|
428 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
|
429 } |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
430 |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
431 LLValue* pair = DtoAggrPair(DtoType(_to), re, im); |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
432 DValue* rval = new DImValue(_to, pair); |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
433 |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
434 // if the value we're casting is not a lvalue, the cast value can't be either |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
435 if (!val->isLVal()) { |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
436 return rval; |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
437 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
438 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
439 // unfortunately at this point, the cast value can show up as the lvalue for += and similar expressions. |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
440 // so we need to maintain the storage |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
441 return new DLRValue(val, rval); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
442 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
443 else if (to->isimaginary()) { |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
444 // FIXME: this loads both values, even when we only need one |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
445 LLValue* v = val->getRVal(); |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
446 LLValue* impart = gIR->ir->CreateExtractValue(v, 1, ".im_part"); |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
447 DImValue* im = new DImValue(to, impart); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
448 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
|
449 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
450 else if (to->isfloating()) { |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
451 // FIXME: this loads both values, even when we only need one |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
452 LLValue* v = val->getRVal(); |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
453 LLValue* repart = gIR->ir->CreateExtractValue(v, 0, ".re_part"); |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
454 DImValue* re = new DImValue(to, repart); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
455 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
|
456 } |
778
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
741
diff
changeset
|
457 else if (to->ty == Tbool) { |
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
741
diff
changeset
|
458 return new DImValue(_to, DtoComplexEquals(loc, TOKnotequal, val, DtoNullValue(vty))); |
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
741
diff
changeset
|
459 } |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
460 else |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
461 assert(0); |
303 | 462 } |
463 |