From f2ed2e96b07caf5fbf9a61b07748e1ee385aa10b Mon Sep 17 00:00:00 2001 From: Alexey Prokhin Date: Sat, 11 Feb 2012 15:15:28 +0400 Subject: [PATCH] Use optimized array operators implemented in druntime --- dmd2/arrayop.c | 31 ++++++++++++++++++++++++++++--- gen/llvmhelpers.cpp | 2 +- gen/todebug.cpp | 2 +- gen/tollvm.cpp | 2 +- runtime/CMakeLists.txt | 7 ------- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/dmd2/arrayop.c b/dmd2/arrayop.c index 857c6a8e..0ab8ab68 100644 --- a/dmd2/arrayop.c +++ b/dmd2/arrayop.c @@ -32,6 +32,24 @@ extern int binary(const char *p , const char **tab, int high); */ 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 /********************************************** @@ -139,7 +157,6 @@ Expression *BinExp::arrayOp(Scope *sc) FuncDeclaration *fd = (FuncDeclaration *)*pfd; if (!fd) { -#if IN_DMD /* Some of the array op functions are written as library functions, * presumably to optimize them with special CPU vector instructions. * List those library functions here, in alpha order. @@ -316,7 +333,6 @@ Expression *BinExp::arrayOp(Scope *sc) if (strcmp(name, libArrayopFuncs[i]) == 0) assert(0); } -#endif #endif /* Not in library, so generate it. * Construct the function body: @@ -369,8 +385,17 @@ Expression *BinExp::arrayOp(Scope *sc) fd->semantic2(sc); fd->semantic3(sc); 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 { /* In library, refer to it. */ diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index a1b5d3c3..b17601c4 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -1562,7 +1562,7 @@ bool mustDefineSymbol(Dsymbol* s) if (fd->semanticRun < 4) return false; - if (fd->isArrayOp) + if (fd->isArrayOp == 1) return true; if (global.params.useAvailableExternally && fd->availableExternally) { diff --git a/gen/todebug.cpp b/gen/todebug.cpp index 277d1fc1..efb41155 100644 --- a/gen/todebug.cpp +++ b/gen/todebug.cpp @@ -33,7 +33,7 @@ static Module* getDefinedModule(Dsymbol* s) // array operations as well else if (FuncDeclaration* fd = s->isFuncDeclaration()) { - if (fd->isArrayOp) + if (fd->isArrayOp == 1) return gIR->dmodule; } // otherwise use the symbol's module diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index ed322a8b..f9c4d127 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -267,7 +267,7 @@ LLGlobalValue::LinkageTypes DtoLinkage(Dsymbol* sym) if (fdecl->availableExternally && mustDefineSymbol(sym)) return llvm::GlobalValue::AvailableExternallyLinkage; // array operations are always template linkage - if (fdecl->isArrayOp) + if (fdecl->isArrayOp == 1) return templateLinkage; // template instances should have weak linkage // but only if there's a body, and it's not naked diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 87b6201f..730bca4b 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -56,13 +56,6 @@ file(GLOB_RECURSE DCRT_D ${RUNTIME_DC_DIR}/*.d) file(GLOB_RECURSE LDC_D ${RUNTIME_DIR}/src/ldc/*.d) list(REMOVE_ITEM DCRT_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}/deh.d ${RUNTIME_DC_DIR}/deh2.d