diff --git a/gen/arrays.cpp b/gen/arrays.cpp index 6d98462a03..d5e6213c6f 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -112,15 +112,16 @@ void DtoArrayInit(Loc& loc, DValue* array, DValue* value) switch (arrayelemty->ty) { case Tbool: - funcname = "_d_array_init_i1"; - break; + val = gIR->ir->CreateZExt(val, LLType::Int8Ty, ".bool"); + // fall through case Tvoid: case Tchar: case Tint8: case Tuns8: - funcname = "_d_array_init_i8"; - break; + Logger::println("Using memset for array init"); + DtoMemSet(ptr, val, dim); + return; case Twchar: case Tint16: diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 23b04f3d96..2710abbc6a 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -411,7 +411,7 @@ LLConstant* DtoGEPi(LLConstant* ptr, unsigned i0, unsigned i1) ////////////////////////////////////////////////////////////////////////////////////////// -void DtoMemSetZero(LLValue* dst, LLValue* nbytes) +void DtoMemSet(LLValue* dst, LLValue* val, LLValue* nbytes) { dst = DtoBitCast(dst,getVoidPtrType()); @@ -419,7 +419,14 @@ void DtoMemSetZero(LLValue* dst, LLValue* nbytes) llvm::Function* fn = llvm::Intrinsic::getDeclaration(gIR->module, llvm::Intrinsic::memset, &intTy, 1); - gIR->ir->CreateCall4(fn, dst, DtoConstUbyte(0), nbytes, DtoConstUint(0), ""); + gIR->ir->CreateCall4(fn, dst, val, nbytes, DtoConstUint(0), ""); +} + +////////////////////////////////////////////////////////////////////////////////////////// + +void DtoMemSetZero(LLValue* dst, LLValue* nbytes) +{ + DtoMemSet(dst, DtoConstUbyte(0), nbytes); } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/gen/tollvm.h b/gen/tollvm.h index f77889b0e5..97435b610d 100644 --- a/gen/tollvm.h +++ b/gen/tollvm.h @@ -109,6 +109,14 @@ LLValue* DtoAggrPair(LLValue* V1, LLValue* V2, const char* name = 0); LLValue* DtoAggrPaint(LLValue* aggr, const LLType* as); LLValue* DtoAggrPairSwap(LLValue* aggr); +/** + * Generates a call to llvm.memset.i32 (or i64 depending on architecture). + * @param dst Destination memory. + * @param val The value to set. + * @param nbytes Number of bytes to overwrite. + */ +void DtoMemSet(LLValue* dst, LLValue* val, LLValue* nbytes); + /** * Generates a call to llvm.memset.i32 (or i64 depending on architecture). * @param dst Destination memory. diff --git a/runtime/internal/arrayInit.d b/runtime/internal/arrayInit.d index 56e88d877a..f33415c4a5 100644 --- a/runtime/internal/arrayInit.d +++ b/runtime/internal/arrayInit.d @@ -12,22 +12,6 @@ alias llvm_memcpy_i32 llvm_memcpy; // per-element array init routines -void _d_array_init_i1(bool* a, size_t n, bool v) -{ - auto p = a; - auto end = a+n; - while (p !is end) - *p++ = v; -} - -void _d_array_init_i8(ubyte* a, size_t n, ubyte v) -{ - auto p = a; - auto end = a+n; - while (p !is end) - *p++ = v; -} - void _d_array_init_i16(ushort* a, size_t n, ushort v) { auto p = a;