Skip to content

Commit

Permalink
vector type start
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jan 8, 2012
1 parent 69d545f commit 304af22
Show file tree
Hide file tree
Showing 19 changed files with 310 additions and 26 deletions.
5 changes: 5 additions & 0 deletions src/argtypes.c
Expand Up @@ -124,6 +124,11 @@ TypeTuple *TypeBasic::toArgTypes()
return t;
}

TypeTuple *TypeVector::toArgTypes()
{
return new TypeTuple(Type::tfloat64);
}

TypeTuple *TypeSArray::toArgTypes()
{
#if DMDV2
Expand Down
14 changes: 10 additions & 4 deletions src/backend/cgxmm.c
Expand Up @@ -57,7 +57,7 @@ code *orthxmm(elem *e, regm_t *pretregs)
elem *e2 = e->E2;
tym_t ty1 = tybasic(e1->Ety);
unsigned sz1 = tysize[ty1];
assert(sz1 == 4 || sz1 == 8); // float or double
assert(sz1 == 4 || sz1 == 8 || sz1 == 16); // float or double
regm_t retregs = *pretregs & XMMREGS;
if (!retregs)
retregs = XMMREGS;
Expand All @@ -71,9 +71,15 @@ code *orthxmm(elem *e, regm_t *pretregs)
switch (e->Eoper)
{
case OPadd:
op = 0xF20F58; // ADDSD
if (sz1 == 4) // float
op = 0xF30F58; // ADDSS
switch (ty1)
{
case TYfloat:
case TYifloat: op = 0xF30F58; break; // ADDSS
case TYdouble:
case TYidouble: op = 0xF20F58; break; // ADDSD
case TYfloat4: op = 0x000F58; break; // ADDPS
default: assert(0);
}
break;

case OPmin:
Expand Down
10 changes: 8 additions & 2 deletions src/backend/cod1.c
Expand Up @@ -3849,8 +3849,14 @@ code *loaddata(elem *e,regm_t *pretregs)
//printf("test2 %s\n", e->EV.sp.Vsym->Sident);
//e->EV.sp.Vsym->Sflags &= ~GTregcand;

assert(sz == 4 || sz == 8); // float or double
unsigned op = (sz == 4) ? 0xF30F10 : 0xF20F10;
switch (tym)
{ case TYfloat:
case TYifloat: op = 0xF30F10; break; // MOVSS
case TYdouble:
case TYidouble: op = 0xF20F10; break; // MOVSD
case TYfloat4: op = 0x0F28; break; // MOVAPS
default: assert(0);
}
if (e->Eoper == OPvar)
{ symbol *s = e->EV.sp.Vsym;
if (s->Sfl == FLreg && !(mask[s->Sreglsw] & XMMREGS))
Expand Down
21 changes: 15 additions & 6 deletions src/backend/cod3.c
Expand Up @@ -436,6 +436,9 @@ regm_t regmask(tym_t tym, tym_t tyf)
case TYcldouble:
return mST01;

case TYfloat4:
return mXMM0;

default:
#if DEBUG
WRTYxx(tym);
Expand Down Expand Up @@ -2826,12 +2829,18 @@ code *prolog()
int op = 0x89; // MOV x[EBP],preg
if (preg >= XMM0 && preg <= XMM15)
{
if (sz == 8)
op = 0xF20F11; // MOVSD x[EBP],preg
else
{
assert(sz == 4);
op = 0xF30F11; // MOVSS x[EBP],preg
switch (sz)
{ case 8:
op = 0xF20F11; // MOVSD x[EBP],preg
break;
case 4:
op = 0xF30F11; // MOVSS x[EBP],preg
break;
case 16:
op = 0x0F29; // MOVAPS x[EBP],preg
break;
default:
assert(0);
}
}
if (hasframe)
Expand Down
3 changes: 3 additions & 0 deletions src/backend/optabgen.c
Expand Up @@ -783,6 +783,7 @@ void dotytab()
static tym_t _ptr_nflat[]= { TYsptr,TYcptr,TYf16ptr,TYfptr,TYhptr,TYvptr };
#endif
static tym_t _real[] = { TYfloat,TYdouble,TYdouble_alias,TYldouble,
TYfloat4,
};
static tym_t _imaginary[] = {
TYifloat,TYidouble,TYildouble,
Expand Down Expand Up @@ -875,6 +876,8 @@ void dotytab()
"complex double", TYcdouble, TYcdouble, TYcdouble, 2*DOUBLESIZE,0x89,0x51,
"complex long double", TYcldouble, TYcldouble, TYcldouble, 2*LNGDBLSIZE,0x89,0x52,

"float[4]", TYfloat4, TYfloat4, TYfloat4, 16, 0, 0,

"__near *", TYjhandle, TYjhandle, TYjhandle, 2, 0x20, 0x100,
"nullptr_t", TYnullptr, TYnullptr, TYptr, 2, 0x20, 0x100,
"*", TYnptr, TYnptr, TYnptr, 2, 0x20, 0x100,
Expand Down
6 changes: 4 additions & 2 deletions src/backend/ty.h
Expand Up @@ -108,13 +108,15 @@ enum TYM
TYvtshape = 0x32, // virtual function table
#endif

TYfloat4 = 0x3E, // float[4]

#if MARS
#define TYaarray TYnptr
#define TYdelegate (I64 ? TYcent : TYllong)
#define TYdarray (I64 ? TYucent : TYullong)
#endif

TYMAX = 0x3E,
TYMAX = 0x3F,
};

#if TX86
Expand Down Expand Up @@ -231,7 +233,7 @@ extern unsigned tytab[];
#define ty64reg(ty) (tytab[(ty) & 0xFF] & (TYFLintegral | TYFLptr) && tysize(ty) <= NPTRSIZE)

// Can go in XMM floating point register
#define tyxmmreg(ty) ((tytab[(ty) & 0xFF] & (TYFLreal | TYFLimaginary)) && tysize(ty) <= 8)
#define tyxmmreg(ty) ((tytab[(ty) & 0xFF] & (TYFLreal | TYFLimaginary)) && tysize(ty) <= 8 || ((ty & 0xFF) == TYfloat4))

#ifndef tyshort
/* Types that are chars or shorts */
Expand Down
5 changes: 4 additions & 1 deletion src/backend/type.c
Expand Up @@ -888,9 +888,12 @@ int type_jparam(type *t)
targ_size_t sz;
type_debug(t);
return tyjparam(t->Tty) ||

((tybasic(t->Tty) == TYstruct || tybasic(t->Tty) == TYarray) &&
(sz = type_size(t)) <= NPTRSIZE &&
(sz == 1 || sz == 2 || sz == 4 || sz == 8));
(sz == 1 || sz == 2 || sz == 4 || sz == 8)) ||

tybasic(t->Tty) == TYfloat4;
}


Expand Down
8 changes: 8 additions & 0 deletions src/cppmangle.c
Expand Up @@ -266,6 +266,14 @@ void TypeBasic::toCppMangle(OutBuffer *buf, CppMangleState *cms)
}


void TypeVector::toCppMangle(OutBuffer *buf, CppMangleState *cms)
{
if (!cms->substitute(buf, this))
{ buf->writestring("U8__vector");
basetype->toCppMangle(buf, cms);
}
}

void TypeSArray::toCppMangle(OutBuffer *buf, CppMangleState *cms)
{
if (!cms->substitute(buf, this))
Expand Down
12 changes: 12 additions & 0 deletions src/declaration.c
Expand Up @@ -2149,6 +2149,18 @@ TypeInfoAssociativeArrayDeclaration::TypeInfoAssociativeArrayDeclaration(Type *t
type = Type::typeinfoassociativearray->type;
}

/***************************** TypeInfoVectorDeclaration ***********************/

TypeInfoVectorDeclaration::TypeInfoVectorDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfoarray)
{
ObjectNotFound(Id::TypeInfo_Vector);
}
type = Type::typeinfovector->type;
}

/***************************** TypeInfoEnumDeclaration ***********************/

TypeInfoEnumDeclaration::TypeInfoEnumDeclaration(Type *tinfo)
Expand Down
7 changes: 7 additions & 0 deletions src/declaration.h
Expand Up @@ -477,6 +477,13 @@ struct TypeInfoWildDeclaration : TypeInfoDeclaration

void toDt(dt_t **pdt);
};

struct TypeInfoVectorDeclaration : TypeInfoDeclaration
{
TypeInfoVectorDeclaration(Type *tinfo);

void toDt(dt_t **pdt);
};
#endif

/**************************************************************/
Expand Down
6 changes: 5 additions & 1 deletion src/glue.c
Expand Up @@ -794,7 +794,7 @@ void FuncDeclaration::toObjFile(int multiobj)
}
if (xmmcnt <= XMM7)
{
if (tyfloating(ty) && tysize(ty) <= 8)
if (tyxmmreg(ty))
{
sp->Sclass = SCfastpar;
sp->Spreg = xmmcnt;
Expand Down Expand Up @@ -1057,6 +1057,10 @@ unsigned Type::totym()
t = TYnptr;
break;

case Tvector:
t = TYfloat4;
break;

default:
#ifdef DEBUG
printf("ty = %d, '%s'\n", ty, toChars());
Expand Down
1 change: 1 addition & 0 deletions src/idgen.c
Expand Up @@ -86,6 +86,7 @@ Msgtable msgtable[] =
{ "TypeInfo_Enum" },
{ "TypeInfo_Typedef" },
{ "TypeInfo_Pointer" },
{ "TypeInfo_Vector" },
{ "TypeInfo_Array" },
{ "TypeInfo_StaticArray" },
{ "TypeInfo_AssociativeArray" },
Expand Down
16 changes: 7 additions & 9 deletions src/lexer.c
Expand Up @@ -3022,6 +3022,7 @@ static Keyword keywords[] =
{ "__thread", TOKtls },
{ "__gshared", TOKgshared },
{ "__traits", TOKtraits },
{ "__vector", TOKvector },
{ "__overloadset", TOKoverloadset },
{ "__FILE__", TOKfile },
{ "__LINE__", TOKline },
Expand All @@ -3041,9 +3042,7 @@ int Token::isKeyword()
}

void Lexer::initKeywords()
{ StringValue *sv;
unsigned u;
enum TOK v;
{
unsigned nkeywords = sizeof(keywords) / sizeof(keywords[0]);

stringtable.init();
Expand All @@ -3053,13 +3052,12 @@ void Lexer::initKeywords()

cmtable_init();

for (u = 0; u < nkeywords; u++)
{ const char *s;

for (unsigned u = 0; u < nkeywords; u++)
{
//printf("keyword[%d] = '%s'\n",u, keywords[u].name);
s = keywords[u].name;
v = keywords[u].value;
sv = stringtable.insert(s, strlen(s));
const char *s = keywords[u].name;
enum TOK v = keywords[u].value;
StringValue *sv = stringtable.insert(s, strlen(s));
sv->ptrvalue = (void *) new Identifier(sv->lstring.string,v);

//printf("tochars[%d] = '%s'\n",v, s);
Expand Down
1 change: 1 addition & 0 deletions src/lexer.h
Expand Up @@ -169,6 +169,7 @@ enum TOK
TOKpow,
TOKpowass,
TOKgoesto,
TOKvector,
#endif

TOKMAX
Expand Down

0 comments on commit 304af22

Please sign in to comment.