Use optimized array operators implemented in druntime

This commit is contained in:
Alexey Prokhin 2012-02-11 15:15:28 +04:00
parent e0dc95052b
commit f2ed2e96b0
5 changed files with 31 additions and 13 deletions

View file

@ -32,6 +32,24 @@ extern int binary(const char *p , const char **tab, int high);
*/ */
AA *arrayfuncs; AA *arrayfuncs;
#else
int binary(const char *p , const char **tab, int high)
{
int i = 0, j = high, k, l;
do
{
k = (i + j) / 2;
l = strcmp(p, tab[k]);
if (!l)
return k;
else if (l < 0)
j = k;
else
i = k + 1;
}
while (i != j);
return -1;
}
#endif #endif
/********************************************** /**********************************************
@ -139,7 +157,6 @@ Expression *BinExp::arrayOp(Scope *sc)
FuncDeclaration *fd = (FuncDeclaration *)*pfd; FuncDeclaration *fd = (FuncDeclaration *)*pfd;
if (!fd) if (!fd)
{ {
#if IN_DMD
/* Some of the array op functions are written as library functions, /* Some of the array op functions are written as library functions,
* presumably to optimize them with special CPU vector instructions. * presumably to optimize them with special CPU vector instructions.
* List those library functions here, in alpha order. * List those library functions here, in alpha order.
@ -316,7 +333,6 @@ Expression *BinExp::arrayOp(Scope *sc)
if (strcmp(name, libArrayopFuncs[i]) == 0) if (strcmp(name, libArrayopFuncs[i]) == 0)
assert(0); assert(0);
} }
#endif
#endif #endif
/* Not in library, so generate it. /* Not in library, so generate it.
* Construct the function body: * Construct the function body:
@ -369,8 +385,17 @@ Expression *BinExp::arrayOp(Scope *sc)
fd->semantic2(sc); fd->semantic2(sc);
fd->semantic3(sc); fd->semantic3(sc);
sc->pop(); sc->pop();
#if IN_DMD
} }
#if IN_LLVM
else
{ /* In library, refer to it.
*/
Parameters *fparams = new Parameters();
buildArrayLoop(fparams);
fd = FuncDeclaration::genCfunc(fparams, type, ident);
fd->isArrayOp = 2;
}
#else
else else
{ /* In library, refer to it. { /* In library, refer to it.
*/ */

View file

@ -1562,7 +1562,7 @@ bool mustDefineSymbol(Dsymbol* s)
if (fd->semanticRun < 4) if (fd->semanticRun < 4)
return false; return false;
if (fd->isArrayOp) if (fd->isArrayOp == 1)
return true; return true;
if (global.params.useAvailableExternally && fd->availableExternally) { if (global.params.useAvailableExternally && fd->availableExternally) {

View file

@ -33,7 +33,7 @@ static Module* getDefinedModule(Dsymbol* s)
// array operations as well // array operations as well
else if (FuncDeclaration* fd = s->isFuncDeclaration()) else if (FuncDeclaration* fd = s->isFuncDeclaration())
{ {
if (fd->isArrayOp) if (fd->isArrayOp == 1)
return gIR->dmodule; return gIR->dmodule;
} }
// otherwise use the symbol's module // otherwise use the symbol's module

View file

@ -267,7 +267,7 @@ LLGlobalValue::LinkageTypes DtoLinkage(Dsymbol* sym)
if (fdecl->availableExternally && mustDefineSymbol(sym)) if (fdecl->availableExternally && mustDefineSymbol(sym))
return llvm::GlobalValue::AvailableExternallyLinkage; return llvm::GlobalValue::AvailableExternallyLinkage;
// array operations are always template linkage // array operations are always template linkage
if (fdecl->isArrayOp) if (fdecl->isArrayOp == 1)
return templateLinkage; return templateLinkage;
// template instances should have weak linkage // template instances should have weak linkage
// but only if there's a body, and it's not naked // but only if there's a body, and it's not naked

View file

@ -56,13 +56,6 @@ file(GLOB_RECURSE DCRT_D ${RUNTIME_DC_DIR}/*.d)
file(GLOB_RECURSE LDC_D ${RUNTIME_DIR}/src/ldc/*.d) file(GLOB_RECURSE LDC_D ${RUNTIME_DIR}/src/ldc/*.d)
list(REMOVE_ITEM DCRT_D list(REMOVE_ITEM DCRT_D
${RUNTIME_DC_DIR}/alloca.d ${RUNTIME_DC_DIR}/alloca.d
${RUNTIME_DC_DIR}/arraybyte.d
${RUNTIME_DC_DIR}/arraycast.d
${RUNTIME_DC_DIR}/arraycat.d
${RUNTIME_DC_DIR}/arraydouble.d
${RUNTIME_DC_DIR}/arrayfloat.d
${RUNTIME_DC_DIR}/arrayreal.d
${RUNTIME_DC_DIR}/arrayshort.d
${RUNTIME_DC_DIR}/critical_.d ${RUNTIME_DC_DIR}/critical_.d
${RUNTIME_DC_DIR}/deh.d ${RUNTIME_DC_DIR}/deh.d
${RUNTIME_DC_DIR}/deh2.d ${RUNTIME_DC_DIR}/deh2.d