Skip to content

Commit fad4417

Browse files
authored
Implement loading constant into complex (dlang#22532)
* implement complex const loads * implement loading constant into complex
1 parent 0bcf0ac commit fad4417

File tree

4 files changed

+150
-14
lines changed

4 files changed

+150
-14
lines changed

compiler/src/dmd/backend/arm/cod1.d

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2477,7 +2477,25 @@ void loaddata(ref CodeBuilder cdb, elem* e, ref regm_t outretregs)
24772477

24782478
if (tyfloating(tym))
24792479
{
2480-
assert(!tycomplex(tym)); // TODO AArch64
2480+
forregs = outretregs & INSTR.FLOATREGS;
2481+
if (tycomplex(tym))
2482+
{
2483+
const vreg_im = allocreg(cdb, forregs, tym); // allocate floating point register
2484+
const vreg_re = findreg(forregs & INSTR.LSW);
2485+
double value_re = e.Vcfloat.re;
2486+
double value_im = e.Vcfloat.im;
2487+
if (sz == 16)
2488+
{
2489+
value_re = e.Vcdouble.re;
2490+
value_im = e.Vcdouble.im;
2491+
}
2492+
else if (sz == 32)
2493+
assert(0); // TODO AArch64 for Linux
2494+
loadFloatRegConst(cdb,vreg_re,value_re,sz / 2);
2495+
loadFloatRegConst(cdb,vreg_im,value_im,sz / 2);
2496+
fixresult(cdb, e, forregs, outretregs);
2497+
return;
2498+
}
24812499
const vreg = allocreg(cdb, forregs, tym); // allocate floating point register
24822500
double value = e.Vfloat;
24832501
if (sz == 8)

compiler/src/dmd/backend/arm/cod3.d

Lines changed: 121 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,114 @@ void REGSAVE_restore(const ref REGSAVE regsave, ref CodeBuilder cdb, reg_t reg,
128128
cdb.gen(&cs);
129129
}
130130

131+
/*****************************
132+
* Given a type, return a mask of
133+
* registers to hold that type.
134+
* Params:
135+
* tym = type
136+
* tyf = function type
137+
* Returns:
138+
* mask of registers
139+
*/
140+
141+
@trusted
142+
regm_t regmask(tym_t tym, tym_t tyf)
143+
{
144+
assert(cgstate.AArch64);
145+
146+
switch (tybasic(tym))
147+
{
148+
case TYvoid:
149+
case TYnoreturn:
150+
case TYstruct:
151+
case TYarray:
152+
return 0;
153+
154+
case TYbool:
155+
case TYwchar_t:
156+
case TYchar16:
157+
case TYchar:
158+
case TYschar:
159+
case TYuchar:
160+
case TYshort:
161+
case TYushort:
162+
case TYint:
163+
case TYuint:
164+
case TYnullptr:
165+
case TYnptr:
166+
case TYnref:
167+
case TYsptr:
168+
case TYcptr:
169+
case TYimmutPtr:
170+
case TYsharePtr:
171+
case TYrestrictPtr:
172+
case TYfgPtr:
173+
case TYlong:
174+
case TYulong:
175+
case TYdchar:
176+
case TYllong:
177+
case TYullong:
178+
return 1; // r0
179+
180+
case TYfloat:
181+
case TYifloat:
182+
return mask(32); // v0
183+
184+
case TYfptr:
185+
case TYhptr:
186+
case TYvptr:
187+
assert(0);
188+
189+
case TYcent:
190+
case TYucent:
191+
return mask(1) | mask(0); // r1,r0
192+
193+
case TYdouble:
194+
case TYdouble_alias:
195+
case TYidouble:
196+
case TYldouble:
197+
case TYildouble:
198+
return mask(32); // v0
199+
200+
case TYcfloat:
201+
case TYcdouble:
202+
case TYcldouble:
203+
return mask(33) | mask(32); // v33,v32
204+
205+
// SIMD vector types
206+
case TYfloat4:
207+
case TYdouble2:
208+
case TYschar16:
209+
case TYuchar16:
210+
case TYshort8:
211+
case TYushort8:
212+
case TYlong4:
213+
case TYulong4:
214+
case TYllong2:
215+
case TYullong2:
216+
217+
case TYfloat8:
218+
case TYdouble4:
219+
case TYschar32:
220+
case TYuchar32:
221+
case TYshort16:
222+
case TYushort16:
223+
case TYlong8:
224+
case TYulong8:
225+
case TYllong4:
226+
case TYullong4:
227+
if (!config.fpxmmregs)
228+
{ printf("SIMD operations not supported on this platform\n");
229+
exit(1);
230+
}
231+
goto default;
232+
233+
default:
234+
debug printf("%s\n", tym_str(tym));
235+
assert(0);
236+
}
237+
}
238+
131239

132240
// https://www.scs.stanford.edu/~zyedidia/arm64/b_cond.html
133241
// https://www.scs.stanford.edu/~zyedidia/arm64/bc_cond.html
@@ -1293,17 +1401,20 @@ L3:
12931401
@trusted
12941402
void genmovreg(ref CodeBuilder cdb, reg_t to, reg_t from, tym_t ty = TYMAX)
12951403
{
1296-
if (to & INSTR.FLOATREGS)
1297-
{
1298-
// floating point
1299-
uint ftype = INSTR.szToFtype(ty == TYMAX ? 8 : _tysize[ty]);
1300-
cdb.gen1(INSTR.fmov(ftype, from & 31, to & 31));
1301-
}
1302-
else
1404+
if (to != from)
13031405
{
1304-
// integer
1305-
uint sf = ty == TYMAX || _tysize[ty] == 8;
1306-
cdb.gen1(INSTR.mov_register(sf, from, to)); // MOV to,from
1406+
if (mask(to) & INSTR.FLOATREGS)
1407+
{
1408+
// floating point
1409+
uint ftype = INSTR.szToFtype(ty == TYMAX ? 8 : _tysize[ty]);
1410+
cdb.gen1(INSTR.fmov(ftype, from & 31, to & 31));
1411+
}
1412+
else
1413+
{
1414+
// integer
1415+
uint sf = ty == TYMAX || _tysize[ty] == 8;
1416+
cdb.gen1(INSTR.mov_register(sf, from, to)); // MOV to,from
1417+
}
13071418
}
13081419
}
13091420

compiler/src/dmd/backend/codebuilder.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct CodeBuilder
3535
code** pTail;
3636

3737
enum BADINS = 0x1234_5678;
38-
//enum BADINS = 0x00_66_0F_6E;
38+
//enum BADINS = 0xAA_20_03_E0;
3939

4040
nothrow:
4141
public:

compiler/src/dmd/backend/x86/cod3.d

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,13 +680,20 @@ void cod3_buildmodulector(OutBuffer* buf, int codeOffset, int refOffset)
680680
/*****************************
681681
* Given a type, return a mask of
682682
* registers to hold that type.
683-
* Input:
684-
* tyf function type
683+
* Params:
684+
* tym = type
685+
* tyf = function type
686+
* Returns:
687+
* mask of registers
685688
*/
686689

687690
@trusted
688691
regm_t regmask(tym_t tym, tym_t tyf)
689692
{
693+
bool AArch64 = cgstate.AArch64;
694+
if (AArch64)
695+
return dmd.backend.arm.cod3.regmask(tym, tyf);
696+
690697
switch (tybasic(tym))
691698
{
692699
case TYvoid:

0 commit comments

Comments
 (0)