Skip to content

Commit

Permalink
sync up with D2's backend
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Sep 28, 2015
1 parent ff762d7 commit 69162ce
Show file tree
Hide file tree
Showing 25 changed files with 315 additions and 124 deletions.
1 change: 0 additions & 1 deletion src/backend/cdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ typedef int bool;
#define _far
#define __far
#define __cs
#define __ss
#endif

#if _WINDLL
Expand Down
1 change: 0 additions & 1 deletion src/backend/cdeflnx.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#define __pascal
#define __far
#define _far
#define __ss
#define __cs

#if SCPP
Expand Down
1 change: 1 addition & 0 deletions src/backend/cgcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ STATIC void ecom(elem **pe)
case OPbtc:
case OPbts:
case OPbtr:
case OPcmpxchg:
ecom(&e->E1);
ecom(&e->E2);
touchfunc(0); // indirect assignment
Expand Down
85 changes: 72 additions & 13 deletions src/backend/cgelem.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,10 +784,8 @@ STATIC elem * eladd(elem *e, goal_t goal)
e2 = e->E2;
if (e2->Eoper == OPconst)
{
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
if (e1->Eoper == OPrelconst && e1->EV.sp.Vsym->Sfl == FLgot)
goto ret;
#endif
if (e1->Eoper == OPrelconst /* if (&v) + c */
|| e1->Eoper == OPstring
)
Expand All @@ -800,10 +798,8 @@ STATIC elem * eladd(elem *e, goal_t goal)
}
else if (e1->Eoper == OPconst)
{
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
if (e2->Eoper == OPrelconst && e2->EV.sp.Vsym->Sfl == FLgot)
goto ret;
#endif
if (e2->Eoper == OPrelconst /* if c + (&v) */
|| e2->Eoper == OPstring
)
Expand Down Expand Up @@ -3312,7 +3308,6 @@ STATIC elem * eleq(elem *e, goal_t goal)
unsigned t,w,b;
unsigned sz;
elem *l,*l2,*r,*r2,*e1,*eres;
tym_t tyl;

#if SCPP
goal_t wantres = goal;
Expand Down Expand Up @@ -3341,7 +3336,7 @@ STATIC elem * eleq(elem *e, goal_t goal)
* so that garbage doesn't creep into the extra 2 bytes
* and throw off compares.
*/
tyl = tybasic(e1->Ety);
tym_t tyl = tybasic(e1->Ety);
if (e1->Eoper == OPvar && (tyl == TYldouble || tyl == TYildouble || tyl == TYcldouble))
{
#if 1
Expand Down Expand Up @@ -3525,8 +3520,68 @@ STATIC elem * eleq(elem *e, goal_t goal)
e2->E2 = es;
e2->Eoper = OPxor;
return optelem(e,GOALvalue);

L8: ;
}

// Replace (a=(r1 pair r2)) with (a1=r1), (a2=r2)
if (tysize(e1->Ety) == 2 * REGSIZE &&
e1->Eoper == OPvar &&
(e2->Eoper == OPpair || e2->Eoper == OPrpair) &&
goal == GOALnone
)
{
tym_t ty = (REGSIZE == 8) ? TYllong : TYint;
if (tyfloating(e1->Ety) && REGSIZE >= 4)
ty = (REGSIZE == 8) ? TYdouble : TYfloat;
ty |= e1->Ety & ~mTYbasic;
e2->Ety = ty;
e->Ety = ty;
e1->Ety = ty;
elem *eb = el_copytree(e1);
eb->EV.sp.Voffset += REGSIZE;

if (e2->Eoper == OPpair)
{
e->E2 = e2->E1;
eb = el_bin(OPeq,ty,eb,e2->E2);
e2->E1 = eb;
e2->E2 = e;
}
else
{
e->E2 = e2->E2;
eb = el_bin(OPeq,ty,eb,e2->E1);
e2->E1 = eb;
e2->E2 = e;
}

e2->Eoper = OPcomma;
return optelem(e2,goal);
}

// Replace (a=b) with (a1=b1),(a2=b2)
if (tysize(e1->Ety) == 2 * REGSIZE &&
e1->Eoper == OPvar &&
e2->Eoper == OPvar &&
goal == GOALnone
)
{
tym_t ty = (REGSIZE == 8) ? TYllong : TYint;
if (tyfloating(e1->Ety) && REGSIZE >= 4)
ty = (REGSIZE == 8) ? TYdouble : TYfloat;
ty |= e1->Ety & ~mTYbasic;
e2->Ety = ty;
e->Ety = ty;
e1->Ety = ty;

elem *eb = el_copytree(e);
eb->E1->EV.sp.Voffset += REGSIZE;
eb->E2->EV.sp.Voffset += REGSIZE;

e = el_bin(OPcomma,ty,e,eb);
return optelem(e,goal);
}
L8: ;
}

if (e1->Eoper == OPcomma)
Expand All @@ -3542,7 +3597,7 @@ STATIC elem * eleq(elem *e, goal_t goal)
t = e->Ety;
l = e1->E1; /* lvalue */
r = e->E2;
tyl = l->Ety;
tym_t tyl = l->Ety;
sz = tysize(tyl) * 8;
w = (e1->E2->EV.Vuns >> 8); /* width in bits of field */
m = ((targ_ullong)1 << w) - 1; // mask w bits wide
Expand Down Expand Up @@ -4076,6 +4131,7 @@ STATIC elem * elcmp(elem *e, goal_t goal)

STATIC elem * elbool(elem *e, goal_t goal)
{
//printf("elbool()\n");
if (OTlogical(e->E1->Eoper) ||
// bool bool => bool
(tybasic(e->E1->Ety) == TYbool && tysize(e->Ety) == 1)
Expand Down Expand Up @@ -4245,11 +4301,10 @@ STATIC elem * elvptrfptr(elem *e, goal_t goal)
*/

STATIC elem * ellngsht(elem *e, goal_t goal)
{ elem *e1;
tym_t ty;

ty = e->Ety;
e1 = e->E1;
{
//printf("ellngsht()\n");
tym_t ty = e->Ety;
elem *e1 = e->E1;
switch (e1->Eoper)
{ case OPs16_32:
case OPu16_32:
Expand Down Expand Up @@ -4293,6 +4348,10 @@ STATIC elem * ellngsht(elem *e, goal_t goal)
break;
#endif

case OPbtst:
e = el_selecte1(e);
break;

default: /* operator */
case_default:
/* Attempt to replace (lngsht)(a op b) with */
Expand Down
2 changes: 1 addition & 1 deletion src/backend/cgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ L7B: mov [EDX],ECX
}
}
#else
code * __pascal cat(code *c1,code *c2)
code *cat(code *c1,code *c2)
{ code **pc;

if (!c1)
Expand Down
11 changes: 7 additions & 4 deletions src/backend/cgobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -1130,13 +1130,16 @@ void Obj::dosseg()

STATIC void obj_comment(unsigned char x, const char *string, size_t len)
{
char __ss *library;
char buf[128];

library = (char __ss *) alloca(2 + len);
char *library = (2 + len <= sizeof(buf)) ? buf : (char *) malloc(2 + len);
assert(library);
library[0] = 0;
library[1] = x;
memcpy(library + 2,string,len);
objrecord(COMENT,library,len + 2);
if (library != buf)
free(library);
}

/*******************************
Expand Down Expand Up @@ -1862,7 +1865,7 @@ int Obj::comdatsize(Symbol *s, targ_size_t symsize)
int Obj::comdat(Symbol *s)
{ char lnames[IDMAX+IDOHD+1]; // +1 to allow room for strcpy() terminating 0
char cextdef[2+2];
char __ss *p;
char *p;
size_t lnamesize;
unsigned ti;
int isfunc;
Expand Down Expand Up @@ -2625,7 +2628,7 @@ void Obj::lidata(int seg,targ_size_t offset,targ_size_t count)
unsigned reclen;
static char zero[20];
char data[20];
char __ss *di;
char *di;

//printf("Obj::lidata(seg = %d, offset = x%x, count = %d)\n", seg, offset, count);

Expand Down
46 changes: 21 additions & 25 deletions src/backend/cod2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,27 @@ code *cdnot(elem *e,regm_t *pretregs)
op ^= (OPbool ^ OPnot); // switch operators
goto L2;
}
else if (config.target_cpu >= TARGET_80486 &&
tysize(e->Ety) == 1)
{
int jop = jmpopcode(e->E1);
retregs = mPSW;
c = codelem(e->E1,&retregs,FALSE);
retregs = *pretregs & BYTEREGS;
if (!retregs)
retregs = BYTEREGS;
c1 = allocreg(&retregs,&reg,TYint);

int iop = 0x0F90 | (jop & 0x0F); // SETcc rm8
if (op == OPnot)
iop ^= 1;
c1 = gen2(c1,iop,grex | modregrmx(3,0,reg));
if (reg >= 4)
code_orrex(c1, REX);
if (op == OPbool)
*pretregs &= ~mPSW;
goto L4;
}
else if (sz <= REGSIZE &&
// NEG bytereg is too expensive
(sz != 1 || config.target_cpu < TARGET_PentiumPro))
Expand Down Expand Up @@ -4322,13 +4343,9 @@ code *getoffset(elem *e,unsigned reg)
#endif
case FLdata:
case FLudata:
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
case FLgot:
case FLgotoff:
#endif
#if TARGET_SEGMENTED
case FLcsdata:
#endif
L4:
cs.IEVsym2 = e->EV.sp.Vsym;
cs.IEVoffset2 = e->EV.sp.Voffset;
Expand Down Expand Up @@ -4367,27 +4384,6 @@ code *getoffset(elem *e,unsigned reg)
c = gen(c,&cs);
break;

#if 0 && TARGET_LINUX
case FLgot:
case FLgotoff:
{
gotref = 1;
symbol *s = e->EV.sp.Vsym;
// When using 8B (MOV), indicating that rm is used
// rm operands are always placed in IEV1 not IEV2
cs.IEVsym1 = s;
cs.IEVoffset1 = e->EV.sp.Voffset;
cs.Irm = modregrm(2,reg,BX); // reg,disp32[EBX]
cs.IFL1 = fl;
cs.Iop = (fl == FLgotoff)
? 0x8D // LEA reg, s[EBX]
: 0x8B; // MOV reg, s[EBX]
cs.Iflags = CFoff; // want offset only
c = gen(NULL,&cs);
break;
}
#endif

case FLreg:
/* Allow this since the tree optimizer puts & in front of */
/* register doubles. */
Expand Down
Loading

0 comments on commit 69162ce

Please sign in to comment.