Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Wilson committed Jan 14, 2012
2 parents 9416fdd + ad2a278 commit b69c06a
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 28 deletions.
58 changes: 57 additions & 1 deletion src/backend/el.c
Expand Up @@ -1869,6 +1869,7 @@ elem *el_convfloat(elem *e)
default:
assert(0);
}

#if 0
printf("%gL+%gLi\n", (double)e->EV.Vcldouble.re, (double)e->EV.Vcldouble.im);
printf("el_convfloat() %g %g sz=%d\n", e->EV.Vcdouble.re, e->EV.Vcdouble.im, sz);
Expand All @@ -1877,6 +1878,46 @@ unsigned short *p = (unsigned short *)&e->EV.Vcldouble;
for (int i = 0; i < sz/2; i++) printf("%04x ", p[i]);
printf("\n");
#endif

symbol *s = out_readonly_sym(ty, p, sz);
el_free(e);
e = el_var(s);
e->Ety = ty;
if (e->Eoper == OPvar)
e->Ety |= mTYconst;
//printf("s: %s %d:x%x\n", s->Sident, s->Sseg, s->Soffset);
#endif
return e;
}

/************************************
* Convert vector constant to a read-only symbol.
* Needed iff vector code can't load immediate constants.
*/

elem *el_convxmm(elem *e)
{
unsigned char buffer[16];

#if TX86
// Do not convert if the constants can be loaded with the special XMM instructions
#if 0
if (loadconst(e))
return e;
#endif

changes++;
tym_t ty = e->Ety;
int sz = tysize(ty);
assert(sz <= sizeof(buffer));
void *p = &e->EV.Vcent;

#if 0
printf("el_convxmm(): sz = %d\n", sz);
for (size i = 0; i < sz; i++) printf("%02x ", ((unsigned char *)p)[i]);
printf("\n");
#endif

symbol *s = out_readonly_sym(ty, p, sz);
el_free(e);
e = el_var(s);
Expand Down Expand Up @@ -2027,7 +2068,9 @@ elem *el_convert(elem *e)

case OPconst:
#if TX86
if (tyfloating(e->Ety) && config.inline8087)
if (tyvector(e->Ety))
e = el_convxmm(e);
else if (tyfloating(e->Ety) && config.inline8087)
e = el_convfloat(e);
#endif
break;
Expand Down Expand Up @@ -3125,6 +3168,19 @@ void elem_print(elem *e)
dbg_printf("%gL+%gLi ", (double)e->EV.Vcldouble.re, (double)e->EV.Vcldouble.im);
break;

case TYfloat4:
case TYdouble2:
case TYschar16:
case TYuchar16:
case TYshort8:
case TYushort8:
case TYlong4:
case TYulong4:
case TYllong2:
case TYullong2:
dbg_printf("%llxLL+%llxLL ", e->EV.Vcent.msw, e->EV.Vcent.lsw);
break;

#if !MARS
case TYident:
dbg_printf("'%s' ", e->ET->Tident);
Expand Down
1 change: 1 addition & 0 deletions src/backend/optabgen.c
Expand Up @@ -837,6 +837,7 @@ void dotytab()
#if TX86
static tym_t _xmmreg[] = {
TYfloat,TYdouble,TYifloat,TYidouble,
TYfloat4,TYdouble2,
TYschar16,TYuchar16,TYshort8,TYushort8,
TYlong4,TYulong4,TYllong2,TYullong2,
};
Expand Down
3 changes: 3 additions & 0 deletions src/backend/ty.h
Expand Up @@ -246,6 +246,9 @@ extern unsigned tytab[];
// Can go in XMM floating point register
#define tyxmmreg(ty) (tytab[(ty) & 0xFF] & TYFLxmmreg)

// Is a vector type
#define tyvector(ty) (tybasic(ty) >= TYfloat4 && tybasic(ty) <= TYullong2)

#ifndef tyshort
/* Types that are chars or shorts */
#define tyshort(ty) (tytab[(ty) & 0xFF] & TYFLshort)
Expand Down
12 changes: 12 additions & 0 deletions src/cast.c
Expand Up @@ -209,6 +209,12 @@ MATCH IntegerExp::implicitConvTo(Type *t)
if (m == MATCHnomatch && t->ty == Tenum)
goto Lno;

if (t->ty == Tvector)
{ TypeVector *tv = (TypeVector *)t;
TypeBasic *tb = tv->elementType();
toty = tb->ty;
}

switch (ty)
{
case Tbool:
Expand Down Expand Up @@ -867,6 +873,12 @@ Expression *Expression::castTo(Scope *sc, Type *t)
}
L1: ;
}
else if (tb->ty == Tvector && typeb->ty != Tvector)
{
e = new VectorExp(loc, e, tb);
e = e->semantic(sc);
return e;
}
e = new CastExp(loc, e, tb);
}
}
Expand Down
61 changes: 58 additions & 3 deletions src/e2ir.c
Expand Up @@ -1272,9 +1272,8 @@ elem *ThisExp::toElem(IRState *irs)
*/

elem *IntegerExp::toElem(IRState *irs)
{ elem *e;

e = el_long(type->totym(), value);
{
elem *e = el_long(type->totym(), value);
el_setLoc(e,loc);
return e;
}
Expand Down Expand Up @@ -3692,6 +3691,62 @@ elem *DeleteExp::toElem(IRState *irs)
return e;
}

elem *VectorExp::toElem(IRState *irs)
{
#if 0
printf("VectorExp::toElem()\n");
print();
printf("\tfrom: %s\n", e1->type->toChars());
printf("\tto : %s\n", to->toChars());
#endif

dinteger_t d;
real_t r;
if (e1->type->isfloating())
r = e1->toReal();
else if (e1->type->isintegral())
d = e1->toInteger();
else
assert(0);
elem *e = el_calloc();
e->Eoper = OPconst;
e->Ety = type->totym();
switch (tybasic(e->Ety))
{
case TYfloat4:
for (size_t i = 0; i < 4; i++)
((targ_float *)&e->EV.Vcent)[i] = r;
break;
case TYdouble2:
((targ_double *)&e->EV.Vcent.lsw)[0] = r;
((targ_double *)&e->EV.Vcent.msw)[0] = r;
break;
case TYschar16:
case TYuchar16:
for (size_t i = 0; i < 16; i++)
((targ_uchar *)&e->EV.Vcent)[i] = d;
break;
case TYshort8:
case TYushort8:
for (size_t i = 0; i < 8; i++)
((targ_ushort *)&e->EV.Vcent)[i] = d;
break;
case TYlong4:
case TYulong4:
for (size_t i = 0; i < 4; i++)
((targ_ulong *)&e->EV.Vcent)[i] = d;
break;
case TYllong2:
case TYullong2: e->EV.Vcent.lsw = d;
e->EV.Vcent.msw = d;
break;
default:
assert(0);
}
el_setLoc(e, loc);
return e;
}

elem *CastExp::toElem(IRState *irs)
{
TY fty;
Expand Down

0 comments on commit b69c06a

Please sign in to comment.