# HG changeset patch # User Frits van Bommel # Date 1244375879 -7200 # Node ID b3ba2c6ff0380a5fd3be1afa342c66cacec9a1f1 # Parent 4f7d50c744ed1ab283baf7d34b28e2e4747e7eca Use `llvm.memset` instead of `_d_array_init_i1` and `_d_array_init_i8`. This exposes what's happening to LLVM, and memset is probably faster than the runtime functions we were using anyway. diff -r 4f7d50c744ed -r b3ba2c6ff038 gen/arrays.cpp --- a/gen/arrays.cpp Sat Jun 06 20:16:13 2009 +0200 +++ b/gen/arrays.cpp Sun Jun 07 13:57:59 2009 +0200 @@ -112,15 +112,16 @@ 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 -r 4f7d50c744ed -r b3ba2c6ff038 gen/tollvm.cpp --- a/gen/tollvm.cpp Sat Jun 06 20:16:13 2009 +0200 +++ b/gen/tollvm.cpp Sun Jun 07 13:57:59 2009 +0200 @@ -411,7 +411,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -void DtoMemSetZero(LLValue* dst, LLValue* nbytes) +void DtoMemSet(LLValue* dst, LLValue* val, LLValue* nbytes) { dst = DtoBitCast(dst,getVoidPtrType()); @@ -419,7 +419,14 @@ 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 -r 4f7d50c744ed -r b3ba2c6ff038 gen/tollvm.h --- a/gen/tollvm.h Sat Jun 06 20:16:13 2009 +0200 +++ b/gen/tollvm.h Sun Jun 07 13:57:59 2009 +0200 @@ -112,6 +112,14 @@ /** * 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. * @param nbytes Number of bytes to overwrite. */ void DtoMemSetZero(LLValue* dst, LLValue* nbytes); diff -r 4f7d50c744ed -r b3ba2c6ff038 runtime/internal/arrayInit.d --- a/runtime/internal/arrayInit.d Sat Jun 06 20:16:13 2009 +0200 +++ b/runtime/internal/arrayInit.d Sun Jun 07 13:57:59 2009 +0200 @@ -12,22 +12,6 @@ // 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;