Skip to content

Commit 8f60140

Browse files
WalterBrightthewilsonator
authored andcommitted
implement OPnot and OPbook for complex numbers
1 parent 9c699fc commit 8f60140

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,41 @@ void cdnot(ref CGstate cg, ref CodeBuilder cdb,elem* e,ref regm_t pretregs)
439439
OPER op = e.Eoper;
440440
uint sz = tysize(e1.Ety);
441441

442-
if (tyfloating(e1.Ety))
442+
if (tycomplex(e1.Ety))
443+
{
444+
445+
/* Generate:
446+
fcmp d31,#0.0 // https://www.scs.stanford.edu/~zyedidia/arm64/encodingindex.html#floatcmp
447+
movi d31,#0x0 // https://www.scs.stanford.edu/~zyedidia/arm64/encodingindex.html#asimdimm
448+
fccmp d30,d31,#0x0,eq // https://www.scs.stanford.edu/~zyedidia/arm64/encodingindex.html#floatccmp
449+
cset w0,eq // OPnot:eq OPbool:ne // https://www.scs.stanford.edu/~zyedidia/arm64/encodingindex.html#condsel
450+
*/
451+
452+
regm_t retregs1 = INSTR.FLOATREGS;
453+
codelem(cgstate,cdb,e.E1,retregs1,1);
454+
const d0 = findreg(retregs1 & INSTR.LSW);
455+
const d1 = findreg(retregs1 & INSTR.MSW);
456+
const ftype = INSTR.szToFtype(sz / 2);
457+
cdb.gen1(INSTR.fcmp_float(ftype,0,d1)); // FCMP d1,#0.0 https://www.scs.stanford.edu/~zyedidia/arm64/fcmp_float.html
458+
cdb.gen1(INSTR.movi_advsimd(0,1,0xE,0,d1)); // MOVI d1,#0x0 https://www.scs.stanford.edu/~zyedidia/arm64/movi_advsimd.html
459+
const cond = 0; // eq
460+
const nzcv = 0; // #<nzcv>
461+
cdb.gen1(INSTR.fccmp_float(ftype,d1,cond,d0,nzcv)); // FCCMP d0,d1,#0x0,eq https://www.scs.stanford.edu/~zyedidia/arm64/fccmp_float.html
462+
463+
regm_t retregs = pretregs & cgstate.allregs;
464+
if (!retregs)
465+
retregs = cgstate.allregs;
466+
const Rd = allocreg(cdb, retregs, tybasic(e.Ety));
467+
const condx = op == OPnot ? COND.ne : COND.eq;
468+
sz = tysize(e.Ety);
469+
cdb.gen1(INSTR.cset(sz == 8,condx,Rd)); // CSET Rd,eq https://www.scs.stanford.edu/~zyedidia/arm64/cset_csinc.html
470+
//uint N,immr,imms;
471+
//assert(encodeNImmrImms(0xFF,N,immr,imms));
472+
//cdb.gen1(INSTR.log_imm(0,0,0,immr,imms,Rd,Rd)); // AND Rd,Rd,#0xFF
473+
pretregs &= ~mPSW; // flags already set
474+
fixresult(cdb,e,retregs,pretregs);
475+
}
476+
else if (tyfloating(e1.Ety))
443477
{
444478
regm_t retregs1 = INSTR.FLOATREGS;
445479
codelem(cgstate,cdb,e.E1,retregs1,1);

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,12 +2038,16 @@ void disassemble(uint c) @trusted
20382038
uint o2 = field(ins,11,11);
20392039
uint Rd = field(ins,4,0);
20402040

2041-
if (Q == 1 && op == 1 && cmode == 0xE)
2041+
if (op == 1 && cmode == 0xE)
20422042
{
20432043
url2 = "movi_advsimd";
20442044
p1 = "movi"; // https://www.scs.stanford.edu/~zyedidia/arm64/movi_advsimd.html
20452045
// TODO AArch64 implement https://www.scs.stanford.edu/~zyedidia/arm64/shared_pseudocode.html#impl-shared.AdvSIMDExpandImm.3
2046-
uint n = snprintf(buf.ptr, cast(uint)buf.length, "v%d.2d,#0x%x", Rd, abcdefgh);
2046+
uint n;
2047+
if (Q)
2048+
n = snprintf(buf.ptr, cast(uint)buf.length, "v%d.2d,#0x%x", Rd, abcdefgh);
2049+
else
2050+
n = snprintf(buf.ptr, cast(uint)buf.length, "d%d,#0x%x", Rd, abcdefgh);
20472051
p2 = buf[0 .. n];
20482052
}
20492053
}
@@ -2247,7 +2251,7 @@ void disassemble(uint c) @trusted
22472251
url = op ? "fccmpe_float" : "fccmp_float";
22482252
p1 = op ? "fccmpe" : "fccmp";
22492253
p2 = fregString(rbuf[0..4],"sd h"[ftype],Rn);
2250-
p3 = fregString(rbuf[0..4],"sd h"[ftype],Rm);
2254+
p3 = fregString(rbuf[4..8],"sd h"[ftype],Rm);
22512255
uint n = snprintf(buf.ptr, cast(uint)buf.length,"#0x%x", nzcv);
22522256
p4 = buf[0 .. n];
22532257
p5 = condstring[cond];
@@ -3243,8 +3247,9 @@ unittest
32433247
unittest
32443248
{
32453249
int line64 = __LINE__;
3246-
string[98] cases64 = // 64 bit code gen
3250+
string[100] cases64 = // 64 bit code gen
32473251
[
3252+
"1E 61 04 00 fccmp d0,d1,#0x0,eq",
32483253
"1E 65 64 A0 fccmp d5,d5,#0x0,vs",
32493254
"1E 65 64 B0 fccmpe d5,d5,#0x0,vs",
32503255
"79 C0 47 AB ldrsh w11,[x29,#0x22]",
@@ -3260,6 +3265,7 @@ unittest
32603265
"B8 00 93 E0 stur w0,[sp,#9]",
32613266
"F8 00 84 5F str xzr,[x2],#8",
32623267
"6F 00 E4 01 movi v1.2d,#0x0",
3268+
"2F 00 E4 1F movi d31,#0x0",
32633269
"9E AF 00 3E fmov v30.d[1],x1",
32643270
"4E BE 1F C0 mov v0.16b,v30.16b",
32653271
"D4 20 00 20 brk #1",

0 commit comments

Comments
 (0)