Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add OPnegass code gen #20868

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 83 additions & 39 deletions compiler/src/dmd/backend/arm/cod4.d
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
@trusted
void cdeq(ref CGstate cg, ref CodeBuilder cdb,elem* e,ref regm_t pretregs)
{
//printf("cdeq(e = %p, pretregs = %s)\n",e,regm_str(pretregs));
//elem_print(e);
printf("cdeq(e = %p, pretregs = %s)\n",e,regm_str(pretregs));
elem_print(e);

Check warning on line 59 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L58-L59

Added lines #L58 - L59 were not covered by tests

reg_t reg;
code cs;
Expand Down Expand Up @@ -255,8 +255,8 @@

if (tyfloating(tyml))
{
floatOpAss(cdb,e,pretregs);
return;
floatOpAss(cdb,e,pretregs);
return;

Check warning on line 259 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L258-L259

Added lines #L258 - L259 were not covered by tests
}
regm_t forccs = pretregs & mPSW; // return result in flags
regm_t forregs = pretregs & ~mPSW; // return result in regs
Expand Down Expand Up @@ -430,17 +430,64 @@
}

/********************************
* Generate code for op=
* Generate code for op=, OPnegass
*/
@trusted
void floatOpAss(ref CodeBuilder cdb,elem* e,ref regm_t pretregs)
{
printf("floatOpass(e=%p, pretregs = %s)\n",e,regm_str(pretregs));
elem_print(e);
//printf("floatOpass(e=%p, pretregs = %s)\n",e,regm_str(pretregs));
//elem_print(e);
elem* e1 = e.E1;
elem* e2 = e.E2;
tym_t ty1 = tybasic(e1.Ety);
const sz1 = _tysize[ty1];
code cs;
regm_t retregs;
reg_t reg;

Check warning on line 445 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L443-L445

Added lines #L443 - L445 were not covered by tests

if (e.Eoper == OPnegass)

Check warning on line 447 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L447

Added line #L447 was not covered by tests
{
bool regvar;
getlvalue(cdb,cs,e1,0);
if (cs.reg == NOREG)

Check warning on line 451 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L449-L451

Added lines #L449 - L451 were not covered by tests
{
retregs = INSTR.FLOATREGS;
reg = allocreg(cdb,retregs,ty1);

Check warning on line 454 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L453-L454

Added lines #L453 - L454 were not covered by tests
}
else
{
regvar = true;
retregs = mask(cs.reg);
getregs(cdb,retregs);
reg = cs.reg;

Check warning on line 461 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L458-L461

Added lines #L458 - L461 were not covered by tests
}
uint szw = sz1 == 8 ? 8 : 4;
loadFromEA(cs, reg, szw, sz1);
cdb.gen(&cs);
assert(reg & 32);
uint ftype = sz1 == 2 ? 3 :
sz1 == 4 ? 0 : 1;
cdb.gen1(INSTR.fneg_float(ftype, reg, reg)); // fneg reg,reg
storeToEA(cs, reg, szw);
cdb.gen(&cs);

Check warning on line 471 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L463-L471

Added lines #L463 - L471 were not covered by tests

retregs = mask(reg);
pretregs &= ~mPSW;

Check warning on line 474 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L473-L474

Added lines #L473 - L474 were not covered by tests

if (e1.Ecount || // if lvalue is a CSE or
regvar) // rvalue can't be a CSE

Check warning on line 477 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L476-L477

Added lines #L476 - L477 were not covered by tests
{
getregs_imm(cdb,retregs); // necessary if both lvalue and

Check warning on line 479 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L479

Added line #L479 was not covered by tests
// rvalue are CSEs (since a reg
// can hold only one e at a time)
cssave(e1,retregs,!OTleaf(e1.Eoper)); // if lvalue is a CSE

Check warning on line 482 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L482

Added line #L482 was not covered by tests
}

fixresult(cdb,e,retregs,pretregs);
freenode(e1);
return;

Check warning on line 487 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L485-L487

Added lines #L485 - L487 were not covered by tests
}

elem* e2 = e.E2;

Check warning on line 490 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L490

Added line #L490 was not covered by tests
regm_t rretregs = INSTR.FLOATREGS & ~pretregs;
if (!rretregs)
rretregs = INSTR.FLOATREGS;
Expand All @@ -449,11 +496,8 @@
codelem(cgstate,cdb,e2,rretregs,false); // eval right leaf
reg_t rreg = findreg(rretregs);

code cs;
regm_t retregs;
reg_t reg;
bool regvar = false;
if (config.flags4 & CFG4optimized)
if (0 && config.flags4 & CFG4optimized)

Check warning on line 500 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L500

Added line #L500 was not covered by tests
{
// Be careful of cases like (x = x+x+x). We cannot evaluate in
// x if x is in a register.
Expand All @@ -476,35 +520,35 @@
if (!retregs)
retregs = INSTR.FLOATREGS & ~rretregs;
reg = allocreg(cdb,retregs,ty1);
loadFromEA(cs,reg,sz1,sz1);
cdb.gen(&cs);
loadFromEA(cs,reg,sz1,sz1);
cdb.gen(&cs);

Check warning on line 524 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L523-L524

Added lines #L523 - L524 were not covered by tests
}

reg_t Rd = reg, Rn = rreg, Rm = reg;
uint ftype = sz1 == 2 ? 3 :
sz1 == 4 ? 0 : 1;
sz1 == 4 ? 0 : 1;

Check warning on line 529 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L529

Added line #L529 was not covered by tests
switch (e.Eoper)
{
// FADD/FSUB (extended register)
// http://www.scs.stanford.edu/~zyedidia/arm64/encodingindex.html#addsub_ext
case OPaddass:
cdb.gen1(INSTR.fadd_float(ftype,Rm,Rn,Rd)); // FADD Rd,Rn,Rm
break;

case OPminass:
cdb.gen1(INSTR.fsub_float(ftype,Rm,Rn,Rd)); // FSUB Rd,Rn,Rm
break;

case OPmulass:
cdb.gen1(INSTR.fmul_float(ftype,Rm,Rn,Rd)); // FMUL Rd,Rn,Rm
break;

case OPdivass:
cdb.gen1(INSTR.fdiv_float(ftype,Rm,Rn,Rd)); // FDIV Rd,Rn,Rm
break;

default:
assert(0);
// FADD/FSUB (extended register)
// http://www.scs.stanford.edu/~zyedidia/arm64/encodingindex.html#addsub_ext
case OPaddass:
cdb.gen1(INSTR.fadd_float(ftype,Rm,Rn,Rd)); // FADD Rd,Rn,Rm
break;

Check warning on line 536 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L534-L536

Added lines #L534 - L536 were not covered by tests

case OPminass:
cdb.gen1(INSTR.fsub_float(ftype,Rm,Rn,Rd)); // FSUB Rd,Rn,Rm
break;

Check warning on line 540 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L538-L540

Added lines #L538 - L540 were not covered by tests

case OPmulass:
cdb.gen1(INSTR.fmul_float(ftype,Rm,Rn,Rd)); // FMUL Rd,Rn,Rm
break;

Check warning on line 544 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L542-L544

Added lines #L542 - L544 were not covered by tests

case OPdivass:
cdb.gen1(INSTR.fdiv_float(ftype,Rm,Rn,Rd)); // FDIV Rd,Rn,Rm
break;

Check warning on line 548 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L546-L548

Added lines #L546 - L548 were not covered by tests

default:
assert(0);
}

if (!regvar)
Expand Down Expand Up @@ -551,8 +595,8 @@

if (tyfloating(tyml))
{
floatOpAss(cdb,e,pretregs);
return;
floatOpAss(cdb,e,pretregs);
return;

Check warning on line 599 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L598-L599

Added lines #L598 - L599 were not covered by tests
}

assert(sz <= REGSIZE);
Expand Down Expand Up @@ -618,8 +662,8 @@

if (tyfloating(tyml))
{
floatOpAss(cdb,e,pretregs);
return;
floatOpAss(cdb,e,pretregs);
return;

Check warning on line 666 in compiler/src/dmd/backend/arm/cod4.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod4.d#L665-L666

Added lines #L665 - L666 were not covered by tests
}

code cs;
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dmd/backend/arm/instr.d
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,10 @@
*/
static uint fcvt_float(uint ftype, uint opcode, reg_t Vn, reg_t Vd) { return floatdp1(0,0,ftype,opcode,Vn & 31,Vd & 31); }

/* FNEG fpreg,fpreg https://www.scs.stanford.edu/~zyedidia/arm64/fneg_float.html
*/
static uint fneg_float(uint ftype, reg_t Vn, reg_t Vd) { return floatdp1(0,0,ftype,2,Vn & 31,Vd & 31); }

Check warning on line 739 in compiler/src/dmd/backend/arm/instr.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/instr.d#L739

Added line #L739 was not covered by tests

/* Floating-point compare
*/
/* Floating-point immediate
Expand Down
Loading