Mercurial > projects > ldc
annotate gen/complex.cpp @ 607:9526b29ae342
Fixed the optimizer thing, since llvm PR 2800 is already fixed, users need to upgrade LLVM to latest svn.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Thu, 18 Sep 2008 21:07:35 +0200 |
parents | 192b82878b78 |
children | 634fbbdec390 |
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) { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
438
diff
changeset
|
33 if (global.params.cpu == ARCHx86) |
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 { |
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
|
91 Type* t = val->getType()->toBasetype(); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
92 |
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
|
93 if (t->iscomplex()) { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
94 return DtoCastComplex(loc, val, to); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
95 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
96 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
97 const LLType* base = DtoComplexBaseType(to); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
98 |
359 | 99 Type* baserety; |
100 Type* baseimty; | |
101 TY ty = to->ty; | |
102 if (ty == Tcomplex32) { | |
103 baserety = Type::tfloat32; | |
104 baseimty = Type::timaginary32; | |
105 } else if (ty == Tcomplex64) { | |
106 baserety = Type::tfloat64; | |
107 baseimty = Type::timaginary64; | |
108 } 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
|
109 baserety = Type::tfloat80; |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
438
diff
changeset
|
110 baseimty = Type::timaginary80; |
359 | 111 } |
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
|
112 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
|
113 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
|
114 } |
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
|
115 |
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
|
116 const LLType* complexTy = DtoType(to); |
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
|
117 LLValue* res; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
118 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
119 if (t->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
|
120 res = DtoAggrPair(complexTy, 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
|
121 } |
586
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
122 else if (t->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
|
123 res = DtoAggrPair(complexTy, 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
|
124 } |
586
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
125 else if (t->isintegral()) { |
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
126 res = DtoAggrPair(complexTy, DtoCastInt(loc, val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty))); |
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
127 } |
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
|
128 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
|
129 assert(0); |
359 | 130 } |
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
|
131 return new DImValue(to, res); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
132 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
133 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
134 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
135 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
136 void DtoComplexSet(LLValue* c, LLValue* re, LLValue* im) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
137 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
138 DtoStore(re, DtoGEPi(c,0,0,"tmp")); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
139 DtoStore(im, DtoGEPi(c,0,1,"tmp")); |
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 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
142 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
143 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
144 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
|
145 { |
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
|
146 LLValue* v = c->getRVal(); |
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
|
147 Logger::cout() << "extracting real and imaginary parts from: " << *v << '\n'; |
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
|
148 re = 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
|
149 im = gIR->ir->CreateExtractValue(v, 1, ".im_part"); |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
150 } |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
151 |
359 | 152 DValue* resolveLR(DValue* val, bool getlval) |
153 { | |
154 if (DLRValue* lr = val->isLRValue()) { | |
155 if (getlval) | |
156 return lr->lvalue; | |
157 else | |
158 return lr->rvalue; | |
159 } | |
160 return val; | |
161 } | |
162 | |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
163 ////////////////////////////////////////////////////////////////////////////////////////// |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
164 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
165 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
|
166 { |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
167 return |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
168 (t->ty != Timaginary32 && |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
169 t->ty != Timaginary64 && |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
170 t->ty != Timaginary80); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
171 } |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
172 |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
173 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
|
174 { |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
175 return |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
176 (t->ty == Timaginary32 || |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
177 t->ty == Timaginary64 || |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
178 t->ty == Timaginary80 || |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
179 t->ty == Tcomplex32 || |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
180 t->ty == Tcomplex64 || |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
181 t->ty == Tcomplex80); |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
182 } |
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 ////////////////////////////////////////////////////////////////////////////////////////// |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
185 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
186 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
|
187 { |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
188 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
|
189 DValue* crhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
190 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
191 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
|
192 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
193 // lhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
194 DtoGetComplexParts(clhs, lhs_re, lhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
195 // rhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
196 DtoGetComplexParts(crhs, rhs_re, rhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
197 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
198 // add up |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
199 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
|
200 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
|
201 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
208 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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 res_im = rhs_im; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
214 |
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
|
215 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
|
216 return new DImValue(type, res); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
217 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
218 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
219 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
220 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
221 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
|
222 { |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
223 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
|
224 DValue* crhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
225 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
226 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
|
227 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
228 // lhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
229 DtoGetComplexParts(clhs, lhs_re, lhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
230 // rhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
231 DtoGetComplexParts(crhs, rhs_re, rhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
232 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
233 // sub up |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
234 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
|
235 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
|
236 if(hasRe(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
237 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
|
238 else |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
239 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
|
240 |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
241 if(hasIm(rhstype)) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
242 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
|
243 else |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
244 res_im = lhs_im; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
245 |
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
|
246 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
|
247 return new DImValue(type, res); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
248 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
249 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
250 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
251 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
252 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
|
253 { |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
254 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
|
255 DValue* crhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
256 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
257 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
|
258 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
259 // lhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
260 DtoGetComplexParts(clhs, lhs_re, lhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
261 // rhs values |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
262 DtoGetComplexParts(crhs, rhs_re, rhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
263 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
264 // mul up |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 Type* rhstype = rhs->getType(); |
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 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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
281 if(rere && imim) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
282 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
|
283 else if(rere) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
284 res_re = rere; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
285 else if(imim) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
286 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
|
287 else |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
288 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
|
289 |
412
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
290 if(reim && imre) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
291 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
|
292 else if(reim) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
293 res_im = reim; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
294 else if(imre) |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
295 res_im = imre; |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
296 else |
798ee94a0be7
Rework complex addition, substraction and multiplication. Division may need the same.
Christian Kamm <kamm incasoftware de>
parents:
399
diff
changeset
|
297 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
|
298 |
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
|
299 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
|
300 return new DImValue(type, res); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
301 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
302 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
303 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
304 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
305 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
|
306 { |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
307 DValue* clhs = DtoComplex(loc, type, resolveLR(lhs, true)); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
308 DValue* crhs = DtoComplex(loc, type, resolveLR(rhs, false)); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
309 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
310 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
|
311 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
312 // lhs values |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
313 DtoGetComplexParts(clhs, lhs_re, lhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
314 // rhs values |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
315 DtoGetComplexParts(crhs, rhs_re, rhs_im); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
316 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
317 Type* lhstype = lhs->getType(); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
318 Type* rhstype = rhs->getType(); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
319 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
320 // if divisor is only real, division is simple |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
321 if(hasRe(rhstype) && !hasIm(rhstype)) { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
322 if(hasRe(lhstype)) |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
323 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
|
324 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
325 res_re = lhs_re; |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
326 if(hasIm(lhstype)) |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
327 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
|
328 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
329 res_im = lhs_im; |
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 // if divisor is only imaginary, division is simple too |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
332 else if(!hasRe(rhstype) && hasIm(rhstype)) { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
333 if(hasRe(lhstype)) |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
334 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
|
335 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
336 res_im = lhs_re; |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
337 if(hasIm(lhstype)) |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
338 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
|
339 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
340 res_re = lhs_im; |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
341 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
342 // full division |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
343 else { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
344 llvm::Value *tmp1, *tmp2, *denom; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
345 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
346 if(hasRe(lhstype) && hasIm(lhstype)) { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
347 tmp1 = gIR->ir->CreateMul(lhs_re, rhs_re, "rere"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
348 tmp2 = gIR->ir->CreateMul(lhs_im, rhs_im, "imim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
349 res_re = gIR->ir->CreateAdd(tmp1, tmp2, "rere_plus_imim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
350 |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
351 tmp1 = gIR->ir->CreateMul(lhs_re, rhs_im, "reim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
352 tmp2 = gIR->ir->CreateMul(lhs_im, rhs_re, "imre"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
353 res_im = gIR->ir->CreateSub(tmp2, tmp1, "imre_sub_reim"); |
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 else if(hasRe(lhstype)) { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
356 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
|
357 |
438
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
358 res_im = gIR->ir->CreateMul(lhs_re, rhs_im, "reim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
359 res_im = gIR->ir->CreateNeg(res_im); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
360 } |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
361 else if(hasIm(lhstype)) { |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
362 res_re = gIR->ir->CreateMul(lhs_im, rhs_im, "imim"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
363 res_im = gIR->ir->CreateMul(lhs_im, rhs_re, "imre"); |
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 else |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
366 assert(0 && "lhs has neither real nor imaginary part"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
367 |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
368 tmp1 = gIR->ir->CreateMul(rhs_re, rhs_re, "rhs_resq"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
369 tmp2 = gIR->ir->CreateMul(rhs_im, rhs_im, "rhs_imsq"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
370 denom = gIR->ir->CreateAdd(tmp1, tmp2, "denom"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
371 |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
372 res_re = gIR->ir->CreateFDiv(res_re, denom, "res_re"); |
3c133dd1eda3
Rework complex divison.
Christian Kamm <kamm incasoftware de>
parents:
412
diff
changeset
|
373 res_im = gIR->ir->CreateFDiv(res_im, denom, "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 |
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
|
376 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
|
377 return new DImValue(type, res); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
378 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
379 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
380 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
381 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
382 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
|
383 { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
384 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
|
385 |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
386 llvm::Value *a, *b, *re, *im; |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
387 |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
388 // values |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
389 DtoGetComplexParts(val, a, b); |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
390 |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
391 // sub up |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
392 re = gIR->ir->CreateNeg(a, "tmp"); |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
393 im = gIR->ir->CreateNeg(b, "tmp"); |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
394 |
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
|
395 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
|
396 return new DImValue(type, res); |
164
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
397 } |
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 ////////////////////////////////////////////////////////////////////////////////////////// |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
133
diff
changeset
|
400 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
401 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
|
402 { |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
403 Type* type = lhs->getType(); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
404 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
405 lhs = DtoComplex(loc, type, resolveLR(lhs, false)); |
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
406 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
|
407 |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
408 llvm::Value *a, *b, *c, *d; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
409 |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
410 // lhs values |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
411 DtoGetComplexParts(lhs, a, b); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
412 // rhs values |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
413 DtoGetComplexParts(rhs, c, d); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
414 |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
104
diff
changeset
|
415 // select predicate |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
416 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
|
417 if (op == TOKequal) |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
418 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
|
419 else |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
420 cmpop = llvm::FCmpInst::FCMP_UNE; |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
421 |
364
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
422 // (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
|
423 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
|
424 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
|
425 |
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
426 if (op == TOKequal) |
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
427 return gIR->ir->CreateAnd(b1,b2,"tmp"); |
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
428 else |
8014dbd24605
[svn r385] Fix lvalue cast problems with -= and friends.
ChristianK
parents:
359
diff
changeset
|
429 return gIR->ir->CreateOr(b1,b2,"tmp"); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
diff
changeset
|
430 } |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
431 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
432 ////////////////////////////////////////////////////////////////////////////////////////// |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
433 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
434 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
|
435 { |
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
|
436 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
|
437 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
|
438 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
|
439 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
|
440 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
|
441 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
442 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
|
443 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
|
444 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
|
445 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
446 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
|
447 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
|
448 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
|
449 } |
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
|
450 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
|
451 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
|
452 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
|
453 } |
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
|
454 |
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
|
455 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
|
456 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
|
457 |
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
|
458 // 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
|
459 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
|
460 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
|
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 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
463 // 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
|
464 // 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
|
465 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
|
466 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
467 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
|
468 // 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
|
469 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
|
470 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
|
471 DImValue* im = new DImValue(to, impart); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
472 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
|
473 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
474 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
|
475 // 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
|
476 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
|
477 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
|
478 DImValue* re = new DImValue(to, repart); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
364
diff
changeset
|
479 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
|
480 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
481 else |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
482 assert(0); |
303 | 483 } |
484 |